/* ============================================================
   ReLU.chat — Shared Design System v4
   Muted amber + deep neutral palette
   ============================================================ */

/* ----- DESIGN TOKENS ----- */
:root {
  --bg: #050506;
  --bg-elevated: #0b0b0d;
  --bg-surface: rgba(243,239,231,0.02);
  --bg-surface-hover: rgba(243,239,231,0.05);
  --bg-input: rgba(255,255,255,0.025);
  --border: rgba(255,255,255,0.055);
  --border-medium: rgba(255,255,255,0.09);
  --border-strong: rgba(255,255,255,0.14);
  --border-soft: rgba(255,255,255,0.14);
  --border-accent: rgba(201,133,58,0.3);
  --border-accent-strong: rgba(201,133,58,0.5);

  /* Warm text hierarchy */
  --text-main: #f3efe7;
  --text-primary: #f3efe7;
  --text-secondary: rgba(243,239,231,0.72);
  --text-muted: rgba(243,239,231,0.52);
  --text-tertiary: rgba(243,239,231,0.44);

  /* Muted amber accent */
  --accent: #c9853a;
  --accent-hover: #d49346;
  --accent-light: #dfa154;
  --accent-soft: rgba(201,133,58,0.16);
  --accent-glow: rgba(201,133,58,0.18);
  --accent-glow-soft: rgba(201,133,58,0.08);

  /* Muted teal secondary */
  --teal: #417d97;
  --teal-light: #6ba3b8;
  --teal-glow: rgba(65,125,151,0.18);

  /* Status */
  --success: #2d9e5a;
  --success-glow: rgba(45,158,90,0.18);
  --error: #c44130;
  --error-glow: rgba(196,65,48,0.15);

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Spacing (4px base) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  --space-4xl: 64px;

  /* Safe areas */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Easing */
  --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv01", "ss03";
  padding-bottom: var(--safe-bottom);
}

/* ----- TYPOGRAPHY ----- */
h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.18;
  color: var(--text-primary);
}

h1 { font-size: clamp(2rem, 5.5vw, 3.5rem); }
h2 { font-size: clamp(1.25rem, 2vw, 1.75rem); }
h3 { font-size: clamp(1rem, 1.3vw, 1.25rem); }

p { color: var(--text-secondary); line-height: 1.7; }

/* ----- KEYFRAMES ----- */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(228,174,93,0.2); }
  50%      { box-shadow: 0 0 0 5px rgba(228,174,93,0.06); }
}

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

/* ----- GLASS UTILITIES ----- */
.glass {
  background: rgba(20,18,16,0.7);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
}

.glass-elevated {
  background: rgba(20,18,16,0.8);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid var(--border-medium);
}

.glass-surface {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}

/* ----- NAVIGATION ----- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  background: rgba(5,5,6,0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.nav-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  min-height: 56px;
  gap: 1.25rem;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.9375rem;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

.nav-logo img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 1.5rem;
  align-items: center;
}

.nav-links a, .nav-link {
  text-decoration: none;
  color: rgba(243,239,231,0.68);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: color 0.2s var(--ease-out);
}

.nav-links a:hover, .nav-link:hover {
  color: var(--text-main);
}

/* ----- BUTTONS ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 46px;
  padding: 0 24px;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
  color: #fff7ed;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 12px 34px rgba(0,0,0,0.32), 0 0 0 1px rgba(255,255,255,0.05) inset;
}

.btn-primary:hover {
  background: linear-gradient(180deg, #dfa154, var(--accent));
  border-color: rgba(255,255,255,0.2);
  box-shadow: 0 14px 40px rgba(0,0,0,0.38), 0 0 0 1px rgba(255,255,255,0.08) inset;
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255,255,255,0.055);
  color: rgba(243,239,231,0.86);
  border: 1px solid var(--border-soft);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.09);
  color: var(--text-main);
  transform: translateY(-1px);
}

.btn-ghost {
  background: rgba(255,255,255,0.055);
  color: rgba(243,239,231,0.86);
  border: 1px solid var(--border-soft);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.09);
  color: var(--text-main);
  transform: translateY(-1px);
}

.btn-sm {
  min-height: 36px;
  padding: 0 14px;
  height: 36px;
  font-size: 0.75rem;
  border-radius: 8px;
}

/* ----- BADGES / CHIPS ----- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-full);
  background: rgba(243,239,231,0.04);
  border: 1px solid rgba(243,239,231,0.1);
  color: rgba(243,239,231,0.5);
  font-size: 0.84rem;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color 0.2s var(--ease-out), color 0.2s var(--ease-out);
}

.badge:hover {
  border-color: rgba(243,239,231,0.18);
  color: rgba(243,239,231,0.7);
}

.badge svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  flex-shrink: 0;
}

/* Chip variants */
.chip {
  font-size: 0.625rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(255,248,235,0.02);
  color: var(--text-tertiary);
  border: 1px solid var(--border);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.chip.intent {
  background: rgba(228,174,93,0.12);
  border-color: rgba(228,174,93,0.3);
  color: var(--accent-light);
  font-weight: 600;
}

.chip.score {
  background: rgba(228,174,93,0.08);
  border-color: rgba(228,174,93,0.2);
  color: var(--accent-light);
}

.chip.warn {
  background: rgba(196,65,48,0.08);
  border-color: rgba(196,65,48,0.2);
  color: #e87a6a;
}

/* ----- SECTION LAYOUT ----- */
.section-wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 3vw, 2rem);
}

.section-header {
  margin-bottom: 2.5rem;
  text-align: center;
}

.section-label {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
}

/* ----- REVEAL ANIMATION ----- */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ----- REDUCED MOTION ----- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1; transform: none; }
}

/* ----- SCROLLBAR ----- */
.custom-scrollbar::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: var(--border-medium);
}

/* ----- CODE / PRE ----- */
code {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.85em;
  background: rgba(228,174,93,0.08);
  color: var(--accent-light);
  padding: 0.125em 0.375em;
  border-radius: 3px;
  border: 1px solid rgba(228,174,93,0.12);
}

pre {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.6;
}

pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-secondary);
}

/* ----- KATEX ----- */
.katex { font-size: 1.02em; }
.katex-display { margin: 0.5em 0 !important; overflow-x: auto; overflow-y: hidden; }

/* ============================================================
   CHAT-SPECIFIC STYLES (shared across all 3 chat pages)
   ============================================================ */

/* Chat layout */
.chat-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Mobile header (shown on small screens) */
.chat-header-mobile {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(12,11,9,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.back-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.2s var(--ease-out), border-color 0.2s var(--ease-out), color 0.2s var(--ease-out);
  flex-shrink: 0;
}

.back-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-accent);
  color: var(--accent-light);
}

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

.chat-title-mobile {
  display: flex;
  flex-direction: column;
}

.chat-title-mobile span {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.chat-title-mobile small {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-weight: 500;
  margin-top: 1px;
}

/* Messages area */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar {
  width: 4px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

#messages::-webkit-scrollbar-thumb:hover {
  background: var(--border-accent);
}

/* Message bubbles */
.msg {
  max-width: 85%;
  margin: 0 0 1rem;
  animation: fadeUp 0.35s var(--ease-out) both;
}

.msg-content {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.msg-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  border: 1px solid rgba(228,174,93,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 18px var(--accent-glow);
}

.msg-icon svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
}

.msg-body {
  flex: 1;
  min-width: 0;
}

.msg.bot .msg-body {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  position: relative;
  overflow: visible;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.015);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.msg.bot .msg-body p {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--text-primary);
}

.msg.bot .msg-body strong {
  color: var(--accent-light);
  font-weight: 600;
}

.msg.bot .msg-body a {
  color: var(--accent-light);
  text-decoration: none;
  border-bottom: 1px solid rgba(228,174,93,0.2);
  transition: border-color 0.2s var(--ease-out);
}

.msg.bot .msg-body a:hover {
  border-color: var(--accent-light);
}

.msg.user {
  display: flex;
  justify-content: flex-end;
}

.msg.user .msg-content {
  flex-direction: row-reverse;
}

.msg.user .msg-icon { display: none; }

.msg.user .msg-body {
  background: var(--accent);
  border: 1px solid rgba(228,174,93,0.35);
  color: #fff;
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 12px var(--accent-glow);
  position: relative;
  overflow: hidden;
  padding: 0.75rem 1.125rem;
}

.msg.user .msg-body p {
  color: #fff;
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.6;
}

/* Meta / chips */
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}

/* Typing indicator */
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-light);
  animation: typing 1.2s infinite;
}

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

/* Suggestions */
.suggestions {
  display: flex;
  gap: 8px;
  padding: 0 1.25rem 1rem;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch;
}

.suggestions::-webkit-scrollbar {
  height: 3px;
}

.suggestions::-webkit-scrollbar-track {
  background: transparent;
}

.suggestions::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.suggestion {
  font-size: 0.8125rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.2s var(--ease-out), color 0.2s var(--ease-out), background 0.2s var(--ease-out), transform 0.15s var(--ease-out);
  font-weight: 500;
  user-select: none;
  font-family: var(--font);
  letter-spacing: -0.01em;
}

.suggestion:hover {
  border-color: var(--border-accent);
  color: var(--text-primary);
  background: rgba(228,174,93,0.06);
  transform: translateY(-1px);
}

.suggestion:active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(0);
}

.suggestion.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Input form */
#form {
  flex-shrink: 0;
  padding: 0.875rem 1.25rem calc(0.875rem + var(--safe-bottom));
  background: rgba(12,11,9,0.75);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid rgba(255,255,255,0.05);
}

.input-container {
  display: flex;
  gap: 8px;
  max-width: 100%;
}

#input {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 0.875rem 1.25rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  outline: none;
  font-family: var(--font);
  transition: border-color 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out), background 0.25s var(--ease-out);
  min-height: 48px;
  resize: none;
}

#input::placeholder {
  color: var(--text-tertiary);
}

#input:focus {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 3px var(--accent-glow-soft);
  background: var(--bg-elevated);
  outline: none;
}

#send {
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out), transform 0.15s var(--ease-out);
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(228,174,93,0.1), 0 1px 2px rgba(0,0,0,0.25);
}

#send:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 0 1px rgba(228,174,93,0.18), 0 0 20px var(--accent-glow);
  transform: translateY(-1px);
}

#send:active:not(:disabled) {
  transform: scale(0.95);
}

#send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

#send svg {
  width: 18px;
  height: 18px;
}

/* Progress bar */
.progress {
  height: 2px;
  background: rgba(255,255,255,0.02);
  overflow: hidden;
  flex-shrink: 0;
}

.progress > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  transition: width 0.3s var(--ease-out);
}

/* Status indicator */
.nav-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
  background: var(--bg-surface);
  padding: 3px 10px 3px 5px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  letter-spacing: -0.01em;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: background 0.3s;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.06);
}
.status-dot.ready { background: var(--success); box-shadow: 0 0 8px var(--success-glow); }

/* Desktop refinements */
@media (min-width: 720px) {
  body {
    box-shadow: 0 0 60px rgba(0,0,0,0.4);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .nav-container { padding: 0.75rem 2rem; }
  #messages { padding: 2rem; }
  .msg { max-width: 72%; }
  .suggestions { padding: 0 2rem 1.25rem; }
  #form { padding: 0.875rem 2rem calc(0.875rem + var(--safe-bottom)); }
}

/* Mobile */
@media (max-width: 719px) {
  .chat-header-mobile { display: flex; }
  .nav-status { display: none; }
  .nav-logo span { display: none; }
}

/* Notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .site-nav { padding-top: var(--safe-top); }
  #form { padding-bottom: calc(12px + var(--safe-bottom)); }
}
