/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
  --color-primary: #1a365d;
  --color-primary-light: #2a4a7f;
  --color-primary-dark: #0f2440;
  --color-accent: #3182ce;
  --color-accent-light: #63b3ed;
  --color-accent-hover: #2b6cb0;
  --color-success: #38a169;
  --color-warning: #d69e2e;
  --color-error: #e53e3e;
  --color-bg: #f7fafc;
  --color-surface: #ffffff;
  --color-surface-alt: #edf2f7;
  --color-border: #e2e8f0;
  --color-border-focus: #3182ce;
  --color-text: #1a202c;
  --color-text-secondary: #4a5568;
  --color-text-muted: #718096;
  --color-citation-bg: #ebf8ff;
  --color-citation-border: #90cdf4;
  --color-confidence-high: #38a169;
  --color-confidence-med: #d69e2e;
  --color-confidence-low: #e53e3e;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --line-height: 1.6;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);

  --transition: 200ms ease;
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================
   HEADER
   ============================================ */
.header {
  background: var(--color-primary);
  color: white;
  padding: var(--space-4) var(--space-6);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: white;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--color-accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
}

.logo-text {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-tag {
  font-size: var(--text-xs);
  background: rgba(255,255,255,0.15);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  margin-left: var(--space-2);
  font-weight: 500;
}

.nav-links {
  display: flex;
  gap: var(--space-6);
  list-style: none;
}

.nav-links a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: color var(--transition);
}

.nav-links a:hover { color: white; }

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: var(--text-xl);
  cursor: pointer;
}

/* ============================================
   MAIN LAYOUT
   ============================================ */
.main {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
}

/* ============================================
   HERO
   ============================================ */
.hero {
  text-align: center;
  margin-bottom: var(--space-10);
}

.hero h1 {
  font-size: var(--text-3xl);
  font-weight: 800;
  color: var(--color-primary);
  margin-bottom: var(--space-3);
  letter-spacing: -0.02em;
}

.hero p {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  max-width: 600px;
  margin: 0 auto;
}

/* ============================================
   EXAMPLE PROMPTS
   ============================================ */
.example-prompts {
  margin-bottom: var(--space-8);
}

.example-prompts-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 500;
  margin-bottom: var(--space-3);
}

.prompts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-3);
}

.prompt-chip {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-family: var(--font-sans);
}

.prompt-chip:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-citation-bg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.prompt-chip .chip-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

/* ============================================
   QUESTION INPUT
   ============================================ */
.question-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  border: 2px solid transparent;
  transition: border-color var(--transition);
}

.question-card:focus-within {
  border-color: var(--color-border-focus);
}

.question-textarea {
  width: 100%;
  min-height: 100px;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line-height);
  color: var(--color-text);
  resize: vertical;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--color-bg);
}

.question-textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.15);
  background: white;
}

.question-textarea::placeholder {
  color: var(--color-text-muted);
}

.question-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.jurisdiction-select {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.jurisdiction-select label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
}

.jurisdiction-select select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: white;
  cursor: pointer;
}

.submit-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.submit-btn:hover {
  background: var(--color-accent-hover);
  transform: translateY(-1px);
}

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

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

.submit-btn .icon {
  font-size: var(--text-lg);
}

.kbd-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}

kbd {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* ============================================
   LOADING STATE
   ============================================ */
.loading-state {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  text-align: center;
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-6);
}

.loading-spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: var(--space-4);
}

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

.loading-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.loading-steps {
  display: flex;
  justify-content: center;
  gap: var(--space-6);
  margin-top: var(--space-4);
}

.loading-step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.loading-step.active {
  color: var(--color-accent);
  font-weight: 600;
}

.loading-step.done {
  color: var(--color-success);
}

.loading-step .step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
}

.loading-step.active .step-dot {
  background: var(--color-accent);
  animation: pulse 1s ease infinite;
}

.loading-step.done .step-dot {
  background: var(--color-success);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================
   CONVERSATION
   ============================================ */
.conversation-turn {
  margin-bottom: var(--space-6);
}

.message {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  margin-bottom: var(--space-4);
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 700;
  flex-shrink: 0;
}

.message-user .message-avatar {
  background: var(--color-primary);
  color: white;
}

.message-user .message-bubble {
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  display: inline-block;
  max-width: 85%;
}

/* ============================================
   ANSWER CARD
   ============================================ */
.answer-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-6);
  overflow: hidden;
}

.answer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
}

.answer-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
}

.confidence-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}

.confidence-high {
  background: #f0fff4;
  color: var(--color-confidence-high);
}

.confidence-med {
  background: #fffff0;
  color: var(--color-confidence-med);
}

.confidence-low {
  background: #fff5f5;
  color: var(--color-confidence-low);
}

.answer-body {
  padding: var(--space-6);
}

.answer-text {
  font-size: var(--text-base);
  line-height: 1.75;
  color: var(--color-text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ============================================
   CITATIONS
   ============================================ */
.citations-section {
  margin-top: var(--space-6);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-6);
}

.citations-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.citations-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.citations-count {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
}

.citation-item {
  background: var(--color-citation-bg);
  border: 1px solid var(--color-citation-border);
  border-left: 4px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  transition: box-shadow var(--transition);
}

.citation-item:hover {
  box-shadow: var(--shadow-sm);
}

.citation-item:last-child {
  margin-bottom: 0;
}

.citation-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
  gap: var(--space-2);
}

.citation-id {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-accent);
  font-weight: 600;
  background: rgba(49, 130, 206, 0.1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

.citation-source {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.citation-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.citation-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.relevance-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.relevance-track {
  flex: 1;
  max-width: 80px;
  height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.relevance-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  transition: width 0.5s ease;
}

.relevance-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ============================================
   ERROR STATE
   ============================================ */
.error-card {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.error-icon {
  color: var(--color-error);
  font-size: var(--text-xl);
  flex-shrink: 0;
}

.error-content h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-error);
  margin-bottom: var(--space-1);
}

.error-content p {
  font-size: var(--text-sm);
  color: #9b2c2c;
}

.error-retry {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--color-error);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  font-family: var(--font-sans);
}

.error-retry:hover {
  background: #c53030;
}

/* ============================================
   DISCLAIMER / FOOTER
   ============================================ */
.disclaimer {
  text-align: center;
  padding: var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
  background: var(--color-surface);
}

.disclaimer strong {
  color: var(--color-text-secondary);
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

*:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-accent);
  color: white;
  padding: var(--space-2) var(--space-4);
  z-index: 999;
  transition: top var(--transition);
  text-decoration: none;
}

.skip-link:focus {
  top: 0;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .header-inner {
    flex-wrap: wrap;
  }

  .nav-links {
    display: none;
  }

  .mobile-menu-btn {
    display: block;
  }

  .nav-links.open {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding-top: var(--space-4);
    gap: var(--space-3);
  }

  .hero h1 {
    font-size: var(--text-2xl);
  }

  .hero p {
    font-size: var(--text-base);
  }

  .main {
    padding: var(--space-4) var(--space-4);
  }

  .question-card {
    padding: var(--space-4);
  }

  .question-options {
    flex-direction: column;
    align-items: stretch;
  }

  .submit-btn {
    width: 100%;
    justify-content: center;
  }

  .prompts-grid {
    grid-template-columns: 1fr;
  }

  .loading-steps {
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
  }

  .citation-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .answer-header {
    flex-direction: column;
    gap: var(--space-2);
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: var(--text-xl);
  }

  .question-textarea {
    min-height: 80px;
  }

  .answer-body {
    padding: var(--space-4);
  }
}
