/* Bottom Sheet Search Styles */
:root {
  --search-bg: #ffffff;
  --search-bg-secondary: #f8f9fa;
  --search-text: #333333;
  --search-text-secondary: #666666;
  --search-border: #e0e0e0;
  --search-primary: #4a9eff;
  --search-primary-light: rgba(74, 158, 255, 0.1);
  --search-shadow: rgba(0, 0, 0, 0.1);
}

body.dark-mode {
  --search-bg: #1a1a1a;
  --search-bg-secondary: #2a2a2a;
  --search-text: #ffffff;
  --search-text-secondary: #a0a0a0;
  --search-border: #3a3a3a;
  --search-primary: #4a9eff;
  --search-primary-light: rgba(74, 158, 255, 0.15);
  --search-shadow: rgba(0, 0, 0, 0.3);
}

/* Bottom Sheet Container */
.search-bottom-sheet {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  display: none;
  pointer-events: none;
}

.search-bottom-sheet.active {
  display: block;
  pointer-events: auto;
}

/* Overlay */
.search-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.search-bottom-sheet.active .search-overlay {
  opacity: 1;
}

/* Sheet */
.search-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 800px;
  margin: 0 auto;
  background: var(--search-bg);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 40px var(--search-shadow);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.search-bottom-sheet.active .search-sheet {
  transform: translateY(0);
}

/* Handle */
.sheet-handle {
  padding: 12px 0 8px;
  display: flex;
  justify-content: center;
  cursor: grab;
}

.handle-bar {
  width: 40px;
  height: 4px;
  background: var(--search-border);
  border-radius: 2px;
}

/* Header */
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 16px;
  border-bottom: 1px solid var(--search-border);
}

.sheet-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--search-text);
}

.sheet-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--search-text-secondary);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s;
  font-weight: 300;
}

.sheet-close:hover {
  background: var(--search-bg-secondary);
  color: var(--search-text);
  transform: scale(1.05);
}

/* Search Input */
.search-input-container {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--search-border);
}

.search-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

/* Input Container */
.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-input {
  width: 100%;
  padding: 12px 48px 12px 16px;
  border: 2px solid var(--search-border);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--search-bg);
  color: var(--search-text);
  transition: all 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--search-primary);
  box-shadow: 0 0 0 3px var(--search-primary-light);
}

.search-input::placeholder {
  color: var(--search-text-secondary);
}

/* Clear Button - inside input */
.clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  background: var(--search-text-secondary);
  color: var(--search-bg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.2s;
  opacity: 0.6;
  line-height: 1;
  padding: 0;
}

.clear-btn:hover {
  opacity: 1;
  transform: translateY(-50%) scale(1.1);
  background: var(--search-primary);
}

/* Search Button - outside input */
.search-btn {
  padding: 12px;
  background: var(--search-primary);
  color: white;
  border: none;
  border-radius: 12px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.search-btn:hover {
  background: #3a8eef;
  transform: scale(1.05);
}

.search-btn:active {
  transform: scale(0.95);
}

/* Suggestions */
.search-suggestions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.suggestion-chip {
  padding: 8px 16px;
  background: var(--search-bg-secondary);
  border: 1px solid var(--search-border);
  border-radius: 20px;
  font-size: 0.875rem;
  color: var(--search-text);
  cursor: pointer;
  transition: all 0.2s;
}

.suggestion-chip:hover {
  background: var(--search-primary);
  color: white;
  border-color: var(--search-primary);
  transform: translateY(-2px);
}

/* Results Area */
.search-results-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.search-results-area::-webkit-scrollbar {
  width: 8px;
}

.search-results-area::-webkit-scrollbar-track {
  background: var(--search-bg-secondary);
}

.search-results-area::-webkit-scrollbar-thumb {
  background: var(--search-border);
  border-radius: 4px;
}

/* Empty State */
.search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.search-empty svg {
  margin-bottom: 16px;
  stroke: var(--search-text-secondary);
}

.search-empty p {
  color: var(--search-text-secondary);
  line-height: 1.6;
  margin: 0;
}

/* Search Content Container */
.search-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Section Titles */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--search-text);
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--search-border);
  display: flex;
  align-items: center;
}

.section-title svg {
  stroke: var(--search-primary);
  flex-shrink: 0;
}

/* Results Section */
.results-section {
  display: flex;
  flex-direction: column;
}

/* Search Results List */
.search-results-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* AI Chat Section */
.ai-chat-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-result-item {
  padding: 16px;
  background: var(--search-bg-secondary);
  border: 1px solid var(--search-border);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
  display: block;
}

.search-result-item:hover {
  border-color: var(--search-primary);
  box-shadow: 0 4px 12px var(--search-shadow);
  transform: translateY(-2px);
}

.result-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--search-text);
  margin: 0 0 8px;
  line-height: 1.4;
}

.result-excerpt {
  font-size: 0.9rem;
  color: var(--search-text-secondary);
  line-height: 1.6;
  margin: 0 0 8px;
}

.result-meta {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--search-text-secondary);
}

.result-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* AI Section */
.ai-section {
  margin-top: 24px;
}

.ai-divider {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  text-align: center;
}

.ai-divider::before,
.ai-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--search-border);
}

.ai-divider span {
  padding: 0 16px;
  color: var(--search-text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

/* Ask AI Button */
.ask-ai-btn {
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ask-ai-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.ask-ai-btn:active {
  transform: translateY(0);
}

.ask-ai-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.ask-ai-btn svg {
  animation: float 2s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* AI Question Input - Chat Style */
.ai-question-input {
  margin-top: 16px;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Chat Input Wrapper */
.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 12px 12px 16px;
  background: var(--search-bg-secondary);
  border: 2px solid var(--search-border);
  border-radius: 24px;
  transition: all 0.2s;
}

.chat-input-wrapper:focus-within {
  border-color: var(--search-primary);
  background: var(--search-bg);
}

.chat-input-wrapper textarea {
  flex: 1;
  border: none !important;
  outline: none !important;
  background: transparent !important;
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--search-text);
  max-height: 120px;
  overflow-y: auto;
  padding: 4px 0;
  line-height: 1.5;
  box-shadow: none !important;
}

.chat-input-wrapper textarea:focus {
  outline: none;
}

.chat-input-wrapper textarea::placeholder {
  color: var(--search-text-secondary);
}

/* Send Button */
.send-btn {
  min-width: 32px;
  width: 32px;
  height: 32px;
  background: var(--search-primary);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all 0.2s;
  padding: 0;
}

.send-btn:hover {
  background: #3a8eef;
  transform: scale(1.05);
}

.send-btn:active {
  transform: scale(0.98);
}

.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* Chat Messages Container */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 0;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Chat Messages - Bubble Style */
.chat-message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: messageSlideIn 0.3s ease;
  margin-bottom: 12px;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User Message - Right aligned, blue bubble */
.user-message {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.user-message .message-bubble {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 18px 18px 4px 18px;
  max-width: 70%;
}

/* AI Message - Left aligned, gray bubble */
.ai-message {
  flex-direction: row;
}

.ai-message .message-bubble {
  background: var(--search-bg-secondary);
  border: 1px solid var(--search-border);
  color: var(--search-text);
  border-radius: 18px 18px 18px 4px;
  max-width: 75%;
}

/* Error Message */
.error-message {
  justify-content: center;
}

.error-message .message-bubble {
  background: rgba(255, 0, 0, 0.1);
  border: 1px solid rgba(255, 0, 0, 0.3);
  color: #d32f2f;
  border-radius: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.error-message .message-text {
  margin-bottom: 4px;
}

/* Retry Button */
.retry-btn {
  padding: 8px 16px;
  background: var(--search-primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: center;
}

.retry-btn:hover:not(:disabled) {
  background: #3a8eef;
  transform: scale(1.05);
}

.retry-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.retry-btn:disabled {
  background: var(--search-text-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Countdown text */
.countdown-text {
  font-weight: 600;
  color: var(--search-text);
}

/* Avatar */
.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.user-message .message-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.ai-message .message-avatar {
  background: var(--search-primary-light);
}

/* Message Bubble */
.message-bubble {
  padding: 10px 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-text {
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.95rem;
}

.user-message .message-text {
  color: white;
}

.ai-message .message-text {
  color: var(--search-text);
}

/* Headings in AI messages */
.ai-message .message-text h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--search-text);
  margin: 16px 0 12px 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--search-border);
}

.ai-message .message-text h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--search-text);
  margin: 12px 0 8px 0;
}

/* Code blocks in AI messages */
.ai-message .message-text pre {
  background: #f6f8fa;
  border: 1px solid var(--search-border);
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
  overflow-x: auto;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
}

.ai-message .message-text pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: var(--search-text);
  font-size: inherit;
}

body.dark-mode .ai-message .message-text pre {
  background: #1e1e1e;
  border-color: #3a3a3a;
}

/* Inline code in AI messages */
.ai-message .message-text code {
  background: rgba(0, 0, 0, 0.06);
  color: #e53935;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
  font-weight: 500;
}

body.dark-mode .ai-message .message-text code {
  background: rgba(255, 255, 255, 0.1);
  color: #ff6b6b;
}

/* Lists in AI messages */
.ai-message .message-text ul {
  margin: 8px 0;
  padding-left: 24px;
  list-style-type: disc;
}

.ai-message .message-text ol {
  margin: 8px 0;
  padding-left: 24px;
  list-style-type: decimal;
}

.ai-message .message-text li {
  margin: 4px 0;
  line-height: 1.6;
  color: var(--search-text);
}

.user-message .message-text a {
  color: white;
  text-decoration: underline;
  font-weight: 500;
}

.ai-message .message-text a {
  color: var(--search-primary);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 2px solid var(--search-primary);
  padding-bottom: 1px;
  transition: all 0.2s;
}

.ai-message .message-text a:hover {
  background: var(--search-primary-light);
  border-bottom-width: 3px;
}

.ai-message .message-text strong {
  font-weight: 700;
  color: var(--search-text);
}

/* Loading State - Bouncing Dots */
.ai-loading-dots {
  display: flex;
  gap: 6px;
  padding: 8px 4px;
  align-items: center;
  justify-content: flex-start;
}

.ai-loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--search-text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.ai-loading-dots span:nth-child(1) {
  animation-delay: 0s;
}

.ai-loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Dark mode dots */
body.dark-mode .ai-loading-dots span {
  background: var(--search-text-secondary);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .search-sheet {
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
  }

  .sheet-header,
  .search-input-container,
  .search-results-area {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* Prevent body scroll when bottom sheet is open */
body.search-open {
  overflow: hidden;
}
