/* ─── Base ─────────────────────────────────────────────────────────────────── */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ─── Layout ───────────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), var(--chart-4));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-foreground);
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.header-title {
  display: flex;
  flex-direction: column;
}

.header-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--foreground);
  line-height: 1.2;
}

.header-title span {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--chart-2);
  border-color: var(--chart-2);
}

.btn-ghost {
  background: transparent;
  color: var(--foreground);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--secondary);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius);
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ─── Main Content ─────────────────────────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
  overflow: hidden;
}

.chat-container {
  width: 100%;
  max-width: 820px;
  height: 100%;
  max-height: calc(100vh - 180px);
  display: flex;
  flex-direction: column;
}

/* ─── Info Banner ──────────────────────────────────────────────────────────── */

.info-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.8125rem;
  color: var(--accent-foreground);
}

.info-banner svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--primary);
}

/* ─── Custom Chat Widget ───────────────────────────────────────────────────── */

.chat-widget {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 3);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  background: var(--card);
  min-height: 300px;
}

/* ─── Messages Area ────────────────────────────────────────────────────────── */

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar {
  width: 6px;
}

.messages-area::-webkit-scrollbar-track {
  background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ─── Message Bubbles ──────────────────────────────────────────────────────── */

.message {
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
  max-width: 85%;
  animation: msgFadeIn 0.3s ease;
}

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

.message-user {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.message-ai {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.ai-avatar {
  background: linear-gradient(135deg, var(--primary), var(--chart-4));
  color: var(--primary-foreground);
}

.user-avatar {
  background: var(--secondary);
  color: var(--secondary-foreground);
}

.message-bubble {
  padding: 0.625rem 1rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}

.user-bubble {
  background: var(--primary);
  color: var(--primary-foreground);
  border-bottom-right-radius: 4px;
}

.ai-bubble {
  background: var(--secondary);
  color: var(--foreground);
  border-bottom-left-radius: 4px;
}

.ai-bubble strong {
  color: var(--primary);
}

/* ─── Suggested Questions ──────────────────────────────────────────────────── */

.suggested-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.suggestion-btn {
  padding: 0.5rem 0.875rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s ease;
}

.suggestion-btn:hover {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

/* ─── Typing Indicator ─────────────────────────────────────────────────────── */

.typing-indicator {
  padding: 0 1.25rem;
}

.typing-bubble {
  display: inline-flex;
  gap: 4px;
  padding: 0.75rem 1rem;
  background: var(--secondary);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-foreground);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Input Area ───────────────────────────────────────────────────────────── */

.input-area {
  display: flex;
  gap: 0.5rem;
  padding: 0.875rem;
  border-top: 1px solid var(--border);
  background: var(--card);
}

.chat-input {
  flex: 1;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  color: var(--foreground);
  background: var(--background);
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.chat-input::placeholder {
  color: var(--muted-foreground);
}

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-foreground);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.send-btn:hover:not(:disabled) {
  background: var(--chart-2);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

/* ─── Loading Overlay ──────────────────────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--background);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  z-index: 9999;
  transition: opacity 0.4s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--secondary);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.95rem;
  color: var(--muted-foreground);
  text-align: center;
}

.loading-text strong {
  color: var(--foreground);
  display: block;
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

/* ─── Footer ───────────────────────────────────────────────────────────────── */

.footer {
  padding: 0.75rem 2rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  border-top: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}

.footer a {
  color: var(--primary);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .header {
    padding: 0.75rem 1rem;
  }

  .header-title h1 {
    font-size: 1rem;
  }

  .header-title span {
    font-size: 0.7rem;
  }

  .header-logo {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
  }

  .btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  .btn span.btn-label {
    display: none;
  }

  .main {
    padding: 1rem 0.5rem;
  }

  .chat-container {
    max-height: calc(100vh - 140px);
  }

  .footer {
    padding: 0.5rem 1rem;
    font-size: 0.7rem;
  }

  .message {
    max-width: 92%;
  }

  .message-bubble {
    font-size: 0.8125rem;
  }

  .messages-area {
    padding: 0.875rem;
  }

  .input-area {
    padding: 0.625rem;
  }

  .suggestion-btn {
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
  }
}
