/* CSS Custom Properties */
:root {
  /* Brand */
  --brand: #0891b2;
  --brand-dark: #0e7490;
  --brand-light: #ecfeff;
  --brand-glow: rgba(8, 145, 178, 0.12);

  /* Neutrals — warm stone tones, NOT pure gray */
  --bg: #fafaf9;
  --bg-card: #ffffff;
  --surface: #f5f5f4;
  --border: #e7e5e4;
  --border-light: #f0efed;

  /* Text */
  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-muted: #a8a29e;

  /* Accent colors for topic cards */
  --green: #22c55e;
  --green-bg: #f0fdf4;
  --amber: #f59e0b;
  --violet: #8b5cf6;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 4px 12px rgba(28, 25, 23, 0.06), 0 1px 3px rgba(28, 25, 23, 0.04);
  --shadow-lg: 0 12px 32px rgba(28, 25, 23, 0.08), 0 4px 8px rgba(28, 25, 23, 0.04);
  --shadow-brand: 0 4px 16px rgba(8, 145, 178, 0.2), 0 1px 4px rgba(8, 145, 178, 0.1);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* FAQ panel */
  --panel-width: 380px;
}

/* Global Styles */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Header */
.header {
  background: linear-gradient(135deg, #0e7490 0%, #0891b2 50%, #06b6d4 100%);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  z-index: 20;
}

.header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  opacity: 0.5;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-mark svg {
  width: 20px;
  height: 20px;
  color: white;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: white;
  letter-spacing: -0.01em;
}

.header-right {
  display: flex;
  align-items: center;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  animation: pulse-dot 2s ease infinite;
}

.status-text {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
}

/* Layout Wrapper */
.layout {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* FAQ Overlay */
.faq-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.3);
  backdrop-filter: blur(2px);
  z-index: 5;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.faq-overlay.visible {
  display: block;
  opacity: 1;
}

/* FAQ Panel */
.faq-panel {
  width: var(--panel-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  transform: translateX(calc(-1 * var(--panel-width)));
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}

.faq-panel.open {
  transform: translateX(0);
}

.layout.faq-open .main-content {
  margin-left: var(--panel-width);
}

.faq-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
}

.faq-panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.faq-close-btn {
  width: 32px;
  height: 32px;
  background: var(--surface);
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.faq-close-btn:hover {
  background: var(--border);
}

.faq-close-btn svg {
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
}

.faq-search-wrapper {
  padding: 16px 20px;
}

.faq-search {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a8a29e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 16px 16px;
  transition: all 0.2s;
}

.faq-search:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
  background-color: white;
}

.faq-search::placeholder {
  color: var(--text-muted);
}

.faq-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 20px;
}

.faq-category {
  margin-bottom: 4px;
}

.faq-category-btn {
  width: 100%;
  padding: 12px;
  background: none;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.2s;
  text-align: left;
  font-family: inherit;
}

.faq-category-btn:hover {
  background: var(--surface);
}

.faq-category-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.faq-category-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 8px;
}

.faq-category-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-left: 8px;
}

.faq-category.expanded .faq-category-chevron {
  transform: rotate(90deg);
}

.faq-items {
  display: none;
  padding-left: 12px;
  margin-top: 4px;
}

.faq-category.expanded .faq-items {
  display: block;
}

.faq-item {
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.faq-item:hover {
  background: var(--brand-light);
  color: var(--brand-dark);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 24px 32px;
  transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
}

/* Welcome View */
.welcome-view {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeUp 0.6s ease;
}

.welcome-view.hidden {
  display: none;
}

.welcome {
  text-align: center;
  margin-bottom: 40px;
}

.welcome h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome p {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Topic Cards Grid */
.topics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  max-width: 560px;
  width: 100%;
  margin-bottom: 48px;
}

.topic-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 20px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.topic-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 16px;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.topic-card:hover {
  border-color: transparent;
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
}

.topic-card:hover::before {
  opacity: 1;
}

.topic-card:active {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Build Status Card (Teal) */
.topic-card.build-status .topic-icon {
  background: var(--brand-light);
  color: var(--brand);
}

.topic-card.build-status::before {
  background: linear-gradient(135deg, rgba(8, 145, 178, 0.04) 0%, rgba(8, 145, 178, 0.01) 100%);
}

.topic-card.build-status:hover {
  border-color: var(--brand);
}

/* Edits Card (Violet) */
.topic-card.edits .topic-icon {
  background: #f5f3ff;
  color: var(--violet);
}

.topic-card.edits::before {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.04) 0%, rgba(139, 92, 246, 0.01) 100%);
}

.topic-card.edits:hover {
  border-color: var(--violet);
}

/* Login Card (Amber) */
.topic-card.login .topic-icon {
  background: #fffbeb;
  color: var(--amber);
}

.topic-card.login::before {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.04) 0%, rgba(245, 158, 11, 0.01) 100%);
}

.topic-card.login:hover {
  border-color: var(--amber);
}

/* Other Card (Green) */
.topic-card.other .topic-icon {
  background: var(--green-bg);
  color: var(--green);
}

.topic-card.other::before {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.04) 0%, rgba(34, 197, 94, 0.01) 100%);
}

.topic-card.other:hover {
  border-color: var(--green);
}

.topic-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease;
}

.topic-card:hover .topic-icon {
  transform: scale(1.08);
}

.topic-icon svg {
  width: 20px;
  height: 20px;
}

.topic-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.topic-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.topic-arrow {
  position: absolute;
  top: 22px;
  right: 18px;
  opacity: 0;
  transform: translateX(-4px);
  transition: all 0.25s ease;
  color: var(--text-muted);
}

.topic-card:hover .topic-arrow {
  opacity: 1;
  transform: translateX(0);
}

.topic-arrow svg {
  width: 16px;
  height: 16px;
}

/* Staggered entrance animations */
.topic-card:nth-child(1) {
  animation: fadeUp 0.6s ease 0.1s backwards;
}

.topic-card:nth-child(2) {
  animation: fadeUp 0.6s ease 0.15s backwards;
}

.topic-card:nth-child(3) {
  animation: fadeUp 0.6s ease 0.2s backwards;
}

.topic-card:nth-child(4) {
  animation: fadeUp 0.6s ease 0.25s backwards;
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 560px;
  margin-bottom: 32px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Chat Input Wrapper */
.chat-input-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow-sm);
  width: 100%;
  max-width: 560px;
}

.chat-input-wrapper:focus-within {
  border-color: var(--brand);
  box-shadow: var(--shadow-md), 0 0 0 3px var(--brand-glow);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  padding: 12px 14px;
  background: transparent;
  color: var(--text-primary);
}

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

.send-button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-button:hover {
  background: var(--brand-dark);
  box-shadow: var(--shadow-brand);
}

.send-button:active {
  transform: scale(0.95);
}

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

/* Chat Hint */
.chat-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.chat-hint svg {
  width: 14px;
  height: 14px;
  color: var(--green);
}

/* Browse Help Articles Button */
.articles-link {
  margin-top: 48px;
  text-align: center;
}

.articles-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: all 0.2s;
}

.articles-link-btn:hover,
.articles-link-btn.active {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-light);
  box-shadow: var(--shadow-sm);
}

.articles-link-btn svg {
  width: 16px;
  height: 16px;
}

/* Chat View */
.chat-view {
  display: none;
  flex-direction: column;
  max-width: 640px;
  width: 100%;
  flex: 1;
}

.chat-view.active {
  display: flex;
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 12px 6px 8px;
  border-radius: 8px;
  border: none;
  background: none;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 8px;
  font-family: inherit;
}

.back-button:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.back-button svg {
  width: 16px;
  height: 16px;
}

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: msgIn 0.35s ease;
}

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

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message.agent .message-avatar {
  background: var(--brand-light);
  color: var(--brand);
  border: 1px solid rgba(8, 145, 178, 0.15);
}

.message.user .message-avatar {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.message-avatar svg {
  width: 18px;
  height: 18px;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.55;
}

.message.agent .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-top-left-radius: 4px;
}

.message.user .message-bubble {
  background: var(--brand);
  color: white;
  border-top-right-radius: 4px;
}

.message-bubble p {
  margin-bottom: 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong {
  font-weight: 600;
}

.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
  font-size: 0.98em;
  font-weight: 600;
  margin: 12px 0 6px;
  line-height: 1.3;
}

.message-bubble h2:first-child,
.message-bubble h3:first-child,
.message-bubble h4:first-child {
  margin-top: 0;
}

.message-bubble blockquote {
  margin: 10px 0;
  padding: 8px 0 8px 12px;
  border-left: 3px solid var(--border);
  color: var(--text-secondary);
}

.message-bubble pre {
  overflow-x: auto;
  margin: 8px 0;
  padding: 10px 12px;
  font-size: 13px;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.message-bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  width: 100%;
}

.message-bubble th,
.message-bubble td {
  border: 1px solid var(--border);
  padding: 6px 8px;
}

.message-bubble a {
  color: var(--brand);
  text-decoration: underline;
}

.message.user .message-bubble a {
  color: rgba(255, 255, 255, 0.9);
}

.message-bubble ol,
.message-bubble ul {
  margin: 8px 0;
  padding-left: 24px;
}

.message-bubble li {
  margin-bottom: 4px;
  line-height: 1.5;
}

.message-bubble ol li {
  list-style-type: decimal;
}

.message-bubble ul li {
  list-style-type: disc;
}

.message-bubble br + br {
  display: block;
  margin-top: 8px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  border-top-left-radius: 4px;
  width: fit-content;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s ease infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

/* Chat View Input */
.chat-view-input {
  padding: 16px 0 0;
  border-top: 1px solid var(--border-light);
  margin-top: auto;
  width: 100%;
}

.chat-view-input .chat-input-wrapper {
  max-width: 100%;
}

/* Footer */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Keyframe Animations */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes pulse-dot {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(74, 222, 128, 0);
  }
}

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

/* Mobile Responsive */
@media (max-width: 768px) {
  .faq-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 30;
    box-shadow: var(--shadow-lg);
    width: min(380px, 85vw);
  }

  .layout.faq-open .main-content {
    margin-left: 0;
  }

  .main-content {
    padding: 32px 16px 24px;
  }

  .welcome h1 {
    font-size: 24px;
  }

  .topics {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .topic-card {
    padding: 18px 16px;
  }

  .topic-arrow {
    opacity: 1;
    transform: none;
  }

  .header {
    padding: 0 16px;
  }
}
