/* ============================================================
   BatteryChem-AI V3 — Stanford Academic Design System
   ============================================================ */

:root {
  /* Stanford Official Colors */
  --cardinal-red:       #8C1515;
  --cardinal-red-dark:  #820000;
  --cardinal-red-light: #B83A4B;
  --lagunita-blue:      #007C92;
  --palo-alto-green:    #009B76;
  --poppy-orange:       #E98300;
  --off-white:          #F0F4F5;
  --text-primary:       #2E2D29;
  --text-secondary:     #53565A;
  --text-tertiary:      #7F7776;
  --cool-grey:          #53565A;
  --cool-grey-light:    #EAEAEA;
  --border-light:       rgba(0,0,0,0.07);

  /* AI4S Extended Palette */
  --electrolyte-blue:   #0066CC;
  --ion-orange:         #E67E22;
  --thermal-red:        #D63031;
  --model-purple:       #6C5CE7;
  --stable-green:       #00B894;
  --gold-accent:        #B8860B;
  --teal-accent:        #20B2AA;

  /* Data Quality Colors */
  --quality-high:       #00897B;
  --quality-medium:     #E67E22;
  --quality-low:        #D63031;

  /* Typography */
  --font-heading:   'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-body:      'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-code:      'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  --font-condensed: 'Roboto Condensed', 'Arial Narrow', sans-serif;

  /* Spacing — 8px Grid */
  --s1: 0.25rem; --s2: 0.5rem; --s3: 0.75rem; --s4: 1rem;
  --s5: 1.5rem;  --s6: 2rem;   --s7: 3rem;   --s8: 4rem;
  --s9: 6rem;    --s10: 8rem;

  /* Border Radius */
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px; --r-2xl: 24px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.08);
  --shadow-xl: 0 25px 50px rgba(0,0,0,0.15);
  --shadow-cardinal: 0 4px 20px rgba(140,21,21,0.25);

  /* Transitions */
  --t-fast: 150ms; --t-normal: 250ms; --t-slow: 400ms;
  --ease-default: cubic-bezier(0.4,0,0.2,1);
  --ease-out: cubic-bezier(0,0,0.2,1);
  --ease-bounce: cubic-bezier(0.68,-0.55,0.265,1.55);

  /* Layout */
  --nav-height: 72px;
  --max-width: 1280px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  font-size: 1rem; line-height: 1.6;
  color: var(--text-primary);
  background: var(--off-white);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg { display: block; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ============================================================
   NAVIGATION (shared)
   ============================================================ */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  height: var(--nav-height);
  display: flex; align-items: center;
}
.nav-inner {
  max-width: var(--max-width); width: 100%; margin: 0 auto;
  padding: 0 var(--s5);
  display: flex; align-items: center; gap: var(--s6);
}
.nav-logo {
  display: flex; align-items: center; gap: var(--s3);
  text-decoration: none; flex-shrink: 0;
}
.nav-logo-icon {
  width: 38px; height: 38px;
  background: var(--cardinal-red);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-cardinal);
}
.nav-logo-text {
  font-family: var(--font-heading);
  font-size: 1.15rem; font-weight: 700;
  color: var(--text-primary); letter-spacing: -0.02em;
}
.nav-logo-text span { color: var(--cardinal-red); }
.nav-links { display: flex; align-items: center; gap: 2px; list-style: none; flex: 1; }
.nav-links a {
  font-size: 0.875rem; font-weight: 600; color: var(--text-secondary);
  text-decoration: none; padding: 0.5rem 0.75rem;
  border-radius: var(--r-md); transition: all var(--t-fast);
}
.nav-links a:hover { color: var(--text-primary); background: rgba(0,0,0,0.04); }
.nav-links a.active {
  color: var(--cardinal-red);
  background: rgba(140,21,21,0.06);
}
.nav-right { display: flex; align-items: center; gap: var(--s2); margin-left: auto; }

/* Language Switch */
.lang-switch {
  display: flex; align-items: center; gap: 2px;
  background: var(--off-white); border-radius: var(--r-md);
  padding: 3px; border: 1px solid var(--border-light);
}
.lang-btn {
  padding: 0.35rem 0.6rem; font-size: 0.75rem; font-weight: 700;
  border-radius: 6px; cursor: pointer; border: none; background: none;
  color: var(--text-tertiary); font-family: var(--font-condensed);
  transition: all var(--t-fast); letter-spacing: 0.02em;
}
.lang-btn.active { background: white; color: var(--cardinal-red); box-shadow: var(--shadow-xs); }
.lang-btn:hover:not(.active) { color: var(--text-secondary); }

/* Mobile hamburger */
.hamburger {
  display: none; width: 40px; height: 40px; border-radius: var(--r-md);
  align-items: center; justify-content: center; cursor: pointer;
  border: none; background: none; color: var(--text-primary);
  flex-shrink: 0;
}
.hamburger svg { width: 22px; height: 22px; }

/* ============================================================
   BUTTON SYSTEM
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 0.625rem 1.25rem; font-family: var(--font-body);
  font-size: 0.875rem; font-weight: 600; line-height: 1;
  border-radius: var(--r-md); border: 2px solid transparent;
  cursor: pointer; transition: all var(--t-fast);
  text-decoration: none; white-space: nowrap; user-select: none;
}
.btn-primary { background: var(--cardinal-red); color: white; border-color: var(--cardinal-red); }
.btn-primary:hover { background: var(--cardinal-red-dark); border-color: var(--cardinal-red-dark); transform: translateY(-1px); box-shadow: var(--shadow-cardinal); }
.btn-primary:active { transform: translateY(0); box-shadow: none; }
.btn-secondary { background: transparent; color: var(--cardinal-red); border-color: var(--cardinal-red); }
.btn-secondary:hover { background: var(--cardinal-red); color: white; }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }
.btn-outline { background: transparent; color: var(--text-secondary); border: 1.5px solid var(--cool-grey-light); }
.btn-outline:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.btn-lg { padding: 0.875rem 2rem; font-size: 1rem; border-radius: var(--r-lg); }
.btn-sm { padding: 0.4rem 0.875rem; font-size: 0.8rem; }
.btn-xl { padding: 1rem 2.5rem; font-size: 1.05rem; border-radius: var(--r-lg); font-weight: 700; }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-secondary); transition: all var(--t-fast);
}
.icon-btn:hover { background: rgba(0,0,0,0.06); color: var(--text-primary); }
.icon-btn-sm { width: 32px; height: 32px; border-radius: var(--r-sm); }

/* ============================================================
   HERO
   ============================================================ */
.hero {
  position: relative; overflow: hidden; background: white;
  border-bottom: 1px solid var(--border-light);
}
.hero::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 70% 40%, rgba(140,21,21,0.05) 0%, transparent 55%),
    radial-gradient(ellipse at 25% 75%, rgba(0,102,204,0.04) 0%, transparent 50%);
  pointer-events: none;
}
.hero-inner {
  max-width: var(--max-width); margin: 0 auto;
  padding: var(--s10) var(--s5) var(--s8);
  display: grid; grid-template-columns: 1fr 1fr;
  gap: var(--s8); align-items: center; position: relative;
}
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: var(--s2);
  background: rgba(140,21,21,0.07); color: var(--cardinal-red);
  border: 1px solid rgba(140,21,21,0.12);
  padding: 0.3rem 0.875rem; border-radius: 100px;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.03em;
  margin-bottom: var(--s4); width: fit-content;
  font-family: var(--font-condensed); text-transform: uppercase;
}
.hero-eyebrow-dot {
  width: 7px; height: 7px; background: var(--cardinal-red);
  border-radius: 50%; animation: pulse-dot 2.5s ease-in-out infinite;
}
@keyframes pulse-dot { 0%,100% { opacity:1;transform:scale(1); } 50% { opacity:0.4;transform:scale(0.75); } }
.hero h1 {
  font-family: var(--font-heading);
  font-size: clamp(2rem,4vw,3.1rem);
  font-weight: 700; line-height: 1.15; color: var(--text-primary);
  letter-spacing: -0.03em; margin-bottom: var(--s4);
}
.hero h1 em { font-style: normal; color: var(--cardinal-red); }
.hero-sub {
  font-size: 1.05rem; color: var(--text-secondary); line-height: 1.75;
  max-width: 520px; margin-bottom: var(--s6);
}
.hero-actions { display: flex; gap: var(--s3); flex-wrap: wrap; }
.hero-stats {
  display: flex; gap: var(--s5); margin-top: var(--s6);
  padding-top: var(--s5); border-top: 1px solid var(--border-light);
}
.hero-stat-val {
  font-family: var(--font-heading); font-size: 1.6rem;
  font-weight: 700; color: var(--cardinal-red); line-height: 1; letter-spacing: -0.02em;
}
.hero-stat-label { font-size: 0.72rem; color: var(--text-tertiary); margin-top: 0.25rem; font-family: var(--font-condensed); text-transform: uppercase; letter-spacing: 0.06em; }
.hero-visual { position: relative; display: flex; align-items: center; justify-content: center; }
.hero-canvas-wrap { width: 100%; max-width: 500px; position: relative; }
.hero-cardinal-bg {
  width: 100%; aspect-ratio: 1;
  background: linear-gradient(145deg, #f8f9fa 0%, #e9ecef 50%, #dee2e6 100%);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden; position: relative;
}

/* ============================================================
   SECTIONS
   ============================================================ */
.section { padding: var(--s8) 0; }
.section-white { background: white; }
.section-tinted { background: var(--off-white); }
.section-inner { max-width: var(--max-width); margin: 0 auto; padding: 0 var(--s5); }
.section-eyebrow {
  font-family: var(--font-condensed); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase; color: var(--cardinal-red); margin-bottom: var(--s2);
}
.section-title {
  font-family: var(--font-heading); font-size: clamp(1.5rem,3vw,2.1rem);
  font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; line-height: 1.2; margin-bottom: var(--s3);
}
.section-desc { font-size: 0.975rem; color: var(--text-secondary); max-width: 620px; line-height: 1.7; }

/* ============================================================
   TABS
   ============================================================ */
.tab-nav {
  display: flex; gap: 2px; border-bottom: 2px solid var(--cool-grey-light);
  margin-bottom: var(--s6);
}
.tab-btn {
  display: flex; align-items: center; gap: var(--s2); padding: 0.65rem 1.25rem;
  font-family: var(--font-body); font-size: 0.875rem; font-weight: 600;
  color: var(--text-secondary); background: none; border: none; cursor: pointer;
  position: relative; transition: all var(--t-fast); border-radius: var(--r-md) var(--r-md) 0 0;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab-btn:hover { color: var(--text-primary); background: rgba(0,0,0,0.03); }
.tab-btn.active { color: var(--cardinal-red); border-bottom-color: var(--cardinal-red); background: rgba(140,21,21,0.05); }
.tab-btn svg { flex-shrink: 0; transition: stroke var(--t-fast); }
.tab-btn.active svg { stroke: var(--cardinal-red); }
.tab-icon { font-size: 0.9rem; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: white; border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
  overflow: hidden; transition: all var(--t-normal);
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-hdr {
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(105deg, rgba(140,21,21,0.02) 0%, rgba(0,102,204,0.02) 100%);
}
.card-hdr-title { font-family: var(--font-heading); font-size: 0.95rem; font-weight: 700; color: var(--text-primary); display: flex; align-items: center; gap: var(--s2); }
.card-body { padding: var(--s5); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: var(--s4); }
.form-group:last-child { margin-bottom: 0; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: var(--s2); }
.form-select, .form-input {
  width: 100%; padding: 0.6rem 0.875rem; font-family: var(--font-body);
  font-size: 0.875rem; color: var(--text-primary); background: var(--off-white);
  border: 2px solid transparent; border-radius: var(--r-md); transition: all var(--t-fast);
  appearance: none; cursor: pointer; outline: none;
}
.form-select:focus, .form-input:focus {
  border-color: var(--cardinal-red); background: white;
  box-shadow: 0 0 0 3px rgba(140,21,21,0.08);
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2353565A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 17px; padding-right: 40px;
}
.form-input { cursor: text; }

/* Slider */
.slider-wrap { display: flex; align-items: center; gap: var(--s3); }
.slider {
  -webkit-appearance: none; flex: 1; height: 6px; border-radius: 3px;
  background: var(--cool-grey-light);
  outline: none; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: white; border: 3px solid var(--cardinal-red); cursor: pointer;
  box-shadow: 0 2px 8px rgba(140,21,21,0.3); transition: transform var(--t-fast);
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.slider-val {
  font-family: var(--font-code); font-size: 0.8rem; font-weight: 600;
  color: var(--cardinal-red); background: rgba(140,21,21,0.08);
  padding: 0.25rem 0.6rem; border-radius: var(--r-sm); min-width: 52px; text-align: center;
}

/* Radio Group */
.radio-group { display: flex; flex-direction: column; gap: var(--s2); }
.radio-item {
  display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3);
  border-radius: var(--r-md); cursor: pointer; transition: all var(--t-fast);
  border: 2px solid transparent;
}
.radio-item:hover { background: var(--off-white); }
.radio-item.selected { background: rgba(140,21,21,0.04); border-color: rgba(140,21,21,0.18); }
.radio-dot {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--cool-grey-light);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all var(--t-fast);
}
.radio-item.selected .radio-dot { border-color: var(--cardinal-red); background: var(--cardinal-red); }
.radio-dot::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: white; opacity: 0; transition: opacity var(--t-fast); }
.radio-item.selected .radio-dot::after { opacity: 1; }
.radio-lbl { font-size: 0.875rem; font-weight: 500; color: var(--text-primary); }
.radio-sub { font-size: 0.73rem; color: var(--text-tertiary); margin-top: 0.1rem; }

/* Mode Selector */
.mode-selector {
  display: flex; background: var(--off-white); border-radius: var(--r-md);
  padding: 3px; gap: 3px; margin-bottom: var(--s4);
}
.mode-opt {
  flex: 1; padding: 0.5rem; font-size: 0.8rem; font-weight: 600; text-align: center;
  border-radius: 6px; cursor: pointer; transition: all var(--t-fast);
  color: var(--text-secondary); border: none; background: none; font-family: var(--font-body);
}
.mode-opt.active { background: white; color: var(--cardinal-red); box-shadow: var(--shadow-xs); }

/* ============================================================
   DATA QUALITY BADGES
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.73rem; font-weight: 700; padding: 0.28rem 0.6rem; border-radius: 100px;
  font-family: var(--font-condensed); letter-spacing: 0.02em;
}
.badge-a { background: rgba(0,137,123,0.1); color: var(--quality-high); }
.badge-b { background: rgba(230,126,34,0.1); color: var(--quality-medium); }
.badge-c { background: rgba(214,48,49,0.1); color: var(--quality-low); }
.badge-info { background: rgba(0,102,204,0.1); color: var(--electrolyte-blue); }
.badge-purple { background: rgba(108,92,231,0.1); color: var(--model-purple); }

/* Citation Badge (expandable) */
.cite-badge {
  border-radius: var(--r-md); padding: var(--s3); font-size: 0.8rem;
  transition: all var(--t-fast); cursor: pointer; border: 1px solid transparent;
}
.cite-badge:hover { box-shadow: var(--shadow-sm); }
.cite-a { background: rgba(0,137,123,0.07); border-color: rgba(0,137,123,0.2); }
.cite-b { background: rgba(230,126,34,0.07); border-color: rgba(230,126,34,0.2); }
.cite-c { background: rgba(214,48,49,0.05); border-color: rgba(214,48,49,0.15); }
.cite-badge-hdr { display: flex; align-items: center; gap: var(--s2); }
.cite-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cite-a .cite-dot { background: var(--quality-high); }
.cite-b .cite-dot { background: var(--quality-medium); }
.cite-c .cite-dot { background: var(--quality-low); }
.cite-source { font-weight: 700; color: var(--text-primary); flex: 1; }
.cite-ci { font-family: var(--font-code); font-size: 0.73rem; color: var(--text-secondary); background: rgba(0,0,0,0.05); padding: 0.1rem 0.4rem; border-radius: var(--r-sm); }
.cite-detail {
  max-height: 0; overflow: hidden;
  transition: max-height var(--t-normal) ease, padding var(--t-fast);
  padding: 0;
}
.cite-detail.open { max-height: 300px; padding-top: var(--s3); }
.cite-detail-row { display: flex; gap: var(--s3); font-size: 0.75rem; padding: 0.25rem 0; border-bottom: 1px solid rgba(0,0,0,0.05); }
.cite-detail-row span:first-child { color: var(--text-tertiary); min-width: 90px; flex-shrink: 0; }
.cite-detail-row span:last-child { color: var(--text-primary); font-family: var(--font-code); }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: var(--off-white); }
.data-table th {
  padding: 0.7rem 1rem; text-align: left; font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-tertiary);
  border-bottom: 1px solid var(--cool-grey-light); white-space: nowrap; font-family: var(--font-condensed);
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text-primary); }
.data-table td { padding: 0.8rem 1rem; font-size: 0.875rem; border-bottom: 1px solid var(--border-light); color: var(--text-primary); }
.data-table tr:hover td { background: rgba(140,21,21,0.015); }
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: var(--r-sm); font-size: 0.72rem; font-weight: 700;
  background: var(--cardinal-red); color: white;
}
.rank-badge.gold { background: linear-gradient(135deg, #B8860B, #DAA520); }
.rank-badge.silver { background: linear-gradient(135deg, #708090, #A9A9A9); }
.rank-badge.bronze { background: linear-gradient(135deg, #8B4513, #CD7F32); }
.cond-hi { color: var(--stable-green); font-family: var(--font-code); font-weight: 600; }
.cond-md { color: var(--ion-orange); font-family: var(--font-code); font-weight: 600; }
.cond-lo { color: var(--text-secondary); font-family: var(--font-code); }
.conf-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.7rem; font-weight: 700; padding: 0.2rem 0.5rem; border-radius: 100px;
  font-family: var(--font-condensed);
}
.chip-hi { background: rgba(0,137,123,0.1); color: var(--quality-high); }
.chip-md { background: rgba(230,126,34,0.1); color: var(--quality-medium); }
.chip-lo { background: rgba(0,0,0,0.05); color: var(--text-tertiary); }

/* ============================================================
   METRICS GRID
   ============================================================ */
.metrics-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: var(--s4); margin-bottom: var(--s6); }
.metric-card {
  background: white; border-radius: var(--r-lg); padding: var(--s5);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
  border-top: 3px solid var(--cardinal-red); transition: all var(--t-normal);
}
.metric-card:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); }
.metric-card:nth-child(2) { border-top-color: var(--electrolyte-blue); }
.metric-card:nth-child(3) { border-top-color: var(--stable-green); }
.metric-card:nth-child(4) { border-top-color: var(--model-purple); }
.metric-lbl { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: var(--s2); font-family: var(--font-condensed); }
.metric-val { font-family: var(--font-heading); font-size: 2.1rem; font-weight: 700; color: var(--text-primary); line-height: 1; letter-spacing: -0.03em; }
.metric-val span { font-size: 1rem; font-weight: 400; color: var(--text-secondary); }
.metric-sub { font-size: 0.75rem; color: var(--text-tertiary); margin-top: var(--s2); }

/* ============================================================
   CHAT MODULE
   ============================================================ */
.chat-layout { display: grid; grid-template-columns: 1fr 300px; gap: var(--s5); align-items: start; }
.chat-main {
  background: white; border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
  overflow: hidden; display: flex; flex-direction: column; height: 560px;
}
.chat-msgs { flex: 1; overflow-y: auto; padding: var(--s5); display: flex; flex-direction: column; gap: var(--s5); }
.msg { display: flex; gap: var(--s3); max-width: 100%; }
.msg.user { flex-direction: row-reverse; }
.msg-av { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; flex-shrink: 0; }
.msg-av.user-av { background: var(--cardinal-red); color: white; }
.msg-av.ai-av { background: var(--electrolyte-blue); color: white; }
.msg-bubble { max-width: 74%; padding: var(--s4) var(--s5); border-radius: var(--r-lg); font-size: 0.9rem; line-height: 1.65; }
.msg.user .msg-bubble { background: var(--cardinal-red); color: white; border-bottom-right-radius: var(--r-sm); }
.msg.ai .msg-bubble { background: var(--off-white); color: var(--text-primary); border-bottom-left-radius: var(--r-sm); }
.chat-input-area { padding: var(--s4) var(--s5); border-top: 1px solid var(--border-light); display: flex; gap: var(--s3); align-items: flex-end; }
.chat-ta {
  flex: 1; padding: 0.7rem 1rem; font-family: var(--font-body); font-size: 0.9rem;
  border: 2px solid var(--cool-grey-light); border-radius: var(--r-lg);
  resize: none; outline: none; min-height: 48px; max-height: 130px; line-height: 1.5;
  transition: border-color var(--t-fast);
}
.chat-ta:focus { border-color: var(--cardinal-red); }
.chat-ta::placeholder { color: var(--text-tertiary); }

/* Chat Sidebar */
.chat-sidebar { display: flex; flex-direction: column; gap: var(--s4); }
.side-card { background: white; border-radius: var(--r-lg); box-shadow: var(--shadow-sm); border: 1px solid var(--border-light); padding: var(--s4); }
.side-card-title { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: var(--s3); font-family: var(--font-condensed); }
.quick-btn {
  display: block; width: 100%; text-align: left; padding: var(--s3);
  font-size: 0.78rem; color: var(--text-secondary); background: var(--off-white);
  border: 1px solid var(--border-light); border-radius: var(--r-md);
  cursor: pointer; transition: all var(--t-fast); margin-bottom: var(--s2);
  font-family: var(--font-body); line-height: 1.5;
}
.quick-btn:hover { border-color: var(--cardinal-red); color: var(--cardinal-red); background: rgba(140,21,21,0.04); }
.param-row { display: flex; justify-content: space-between; font-size: 0.8rem; padding: 0.3rem 0; }
.param-k { color: var(--text-tertiary); }
.param-v { font-weight: 600; font-family: var(--font-code); font-size: 0.75rem; }

/* API Key Input */
.api-key-section { margin-bottom: var(--s3); }
.api-key-input {
  width: 100%; padding: 0.5rem 0.7rem; font-family: var(--font-code); font-size: 0.7rem;
  border: 1.5px solid var(--cool-grey-light); border-radius: var(--r-md);
  outline: none; background: var(--off-white);
}
.api-key-input:focus { border-color: var(--cardinal-red); }

/* ============================================================
   CHEM INTUITION BOX
   ============================================================ */
.chem-intuition {
  background: linear-gradient(135deg, rgba(0,102,204,0.04) 0%, rgba(0,137,123,0.03) 100%);
  border: 1px solid rgba(0,137,123,0.15); border-radius: var(--r-lg);
  padding: var(--s4) var(--s5); margin-top: var(--s4);
}
.chem-intuition-title {
  font-family: var(--font-heading); font-size: 0.875rem; font-weight: 700;
  color: var(--text-primary); margin-bottom: var(--s2);
  display: flex; align-items: center; gap: var(--s2);
}
.chem-intuition-title::before { content: ''; display: inline-block; width: 4px; height: 1em; background: var(--quality-high); border-radius: 2px; }
.chem-intuition p { font-size: 0.875rem; color: var(--text-secondary); line-height: 1.7; }
.chem-intuition p strong { color: var(--text-primary); }

/* ============================================================
   METHODOLOGY CARDS
   ============================================================ */
.method-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: var(--s5); margin-top: var(--s6); align-items: stretch; }
.method-card {
  background: white; border-radius: var(--r-xl); padding: var(--s6);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
  transition: all var(--t-normal);
}
.method-card:hover { box-shadow: var(--shadow-md); transform: translateY(-4px); }
.method-num { font-family: var(--font-heading); font-size: 2.8rem; font-weight: 700; color: rgba(140,21,21,0.18); line-height: 1; margin-bottom: var(--s3); }
.method-card h3 { font-family: var(--font-heading); font-size: 1.05rem; font-weight: 700; color: var(--text-primary); margin-bottom: var(--s3); line-height: 1.3; }
.method-card p { font-size: 0.875rem; color: var(--text-secondary); line-height: 1.75; }

/* Homepage module cards (with icons + stats) */
.module-card {
  background: white; border-radius: var(--r-xl); padding: var(--s6);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
  transition: all var(--t-normal); text-align: center; display: flex;
  flex-direction: column; align-items: center; gap: var(--s3);
  height: 100%;
}
.module-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-4px); }
.module-icon {
  width: 56px; height: 56px; border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: var(--s2); flex-shrink: 0;
}
.module-card h3 { font-family: var(--font-heading); font-size: 1.05rem; font-weight: 700; color: var(--text-primary); line-height: 1.3; flex-shrink: 0; }
.module-card > p {
  font-size: 0.875rem; color: var(--text-secondary); line-height: 1.65;
  max-width: 280px; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.module-stat { display: flex; align-items: baseline; gap: var(--s2); margin-top: auto; padding-top: var(--s3); border-top: 1px solid var(--border-light); width: 100%; justify-content: center; flex-shrink: 0; }
.module-stat-num { font-family: var(--font-heading); font-size: 1.3rem; font-weight: 700; color: var(--cardinal-red); line-height: 1; }
.module-stat-lbl { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-tertiary); font-family: var(--font-condensed); }

/* ============================================================
   FOOTER
   ============================================================ */
.footer { background: var(--text-primary); color: rgba(255,255,255,0.65); padding: var(--s7) 0 var(--s5); margin-top: var(--s8); }
.footer-inner { max-width: var(--max-width); margin: 0 auto; padding: 0 var(--s5); text-align: center; }
.footer-logo { font-family: var(--font-heading); font-size: 1.1rem; font-weight: 700; color: white; }
.footer-logo span { color: var(--cardinal-red-light); }
.footer-nav { display: flex; justify-content: center; gap: var(--s5); margin-bottom: var(--s5); flex-wrap: wrap; }
.footer-nav a { color: rgba(255,255,255,0.6); text-decoration: none; font-size: 0.85rem; font-weight: 500; transition: color var(--t-fast); }
.footer-nav a:hover { color: white; }
.footer-bottom { padding-top: var(--s4); border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.78rem; display: flex; justify-content: center; gap: var(--s5); flex-wrap: wrap; }
.footer-bottom span:last-child { color: rgba(255,255,255,0.35); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fade-up { from { opacity:0; transform:translateY(24px); } to { opacity:1; transform:translateY(0); } }
@keyframes fade-in { from { opacity:0; } to { opacity:1; } }
.anim-in { animation: fade-up 0.5s var(--ease-out) forwards; opacity: 0; }
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-4 { animation-delay: 0.4s; }

/* ============================================================
   PLOTLY OVERRIDES
   ============================================================ */
.plot-container { width: 100%; }
.chart-section { margin-top: var(--s5); }
.chart-card {
  background: white; border-radius: var(--r-lg); padding: var(--s4);
  border: 1px solid var(--border-light);
}

/* ============================================================
   FACET FILTER PANEL
   ============================================================ */
.facet-panel {
  background: white; border-radius: var(--r-lg); padding: var(--s4);
  border: 1px solid var(--border-light); margin-bottom: var(--s5);
  display: flex; flex-wrap: wrap; gap: var(--s4);
}
.facet-group { display: flex; flex-direction: column; gap: var(--s2); min-width: 160px; }
.facet-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-tertiary); font-family: var(--font-condensed); }
.facet-select {
  padding: 0.45rem 0.7rem; font-family: var(--font-body); font-size: 0.8rem;
  border: 1.5px solid var(--cool-grey-light); border-radius: var(--r-md);
  background: white; color: var(--text-primary); cursor: pointer; outline: none;
}
.facet-select:focus { border-color: var(--cardinal-red); }

/* ============================================================
   TOOLBAR
   ============================================================ */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4); padding: var(--s4) 0; flex-wrap: wrap;
}
.toolbar-search {
  display: flex; align-items: center; gap: var(--s2);
  background: white; border: 1.5px solid var(--cool-grey-light);
  border-radius: var(--r-md); padding: 0.5rem 0.875rem; flex: 1; max-width: 320px;
}
.toolbar-search input {
  border: none; background: none; font-family: var(--font-body);
  font-size: 0.875rem; color: var(--text-primary); outline: none; width: 100%;
}
.toolbar-search input::placeholder { color: var(--text-tertiary); }
.toolbar-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: var(--s4) 0; font-size: 0.8rem; color: var(--text-tertiary); }
.pag-btns { display: flex; gap: 3px; }
.page-btn {
  min-width: 32px; height: 32px; border-radius: var(--r-md);
  border: 1px solid var(--cool-grey-light); background: white;
  cursor: pointer; font-size: 0.8rem; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--t-fast); padding: 0 0.4rem;
}
.page-btn:hover, .page-btn.active { border-color: var(--cardinal-red); color: var(--cardinal-red); background: rgba(140,21,21,0.04); }
.page-btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

/* ============================================================
   DESIGNER LAYOUT
   ============================================================ */
.designer-grid { display: grid; grid-template-columns: 360px 1fr; gap: var(--s5); align-items: start; }
.designer-grid.with-sidebar { grid-template-columns: 360px 1fr 300px; }
.designer-panel { background: white; border-radius: var(--r-xl); box-shadow: var(--shadow-sm); border: 1px solid var(--border-light); overflow: hidden; }

/* Compact chart heights for one-screen view */
.chart-compact { height: 250px; }
.chart-mini { height: 200px; }
.designer-panel { background: white; border-radius: var(--r-xl); box-shadow: var(--shadow-sm); border: 1px solid var(--border-light); overflow: hidden; }
.panel-hdr {
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-hdr-title { font-family: var(--font-heading); font-size: 0.95rem; font-weight: 700; color: var(--text-primary); display: flex; align-items: center; gap: var(--s2); }
.panel-section { padding: var(--s5); border-bottom: 1px solid var(--border-light); }
.panel-section:last-child { border-bottom: none; }
.panel-section-title {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-tertiary); margin-bottom: var(--s4);
  display: flex; align-items: center; gap: var(--s2); font-family: var(--font-condensed);
}
.panel-action { padding: var(--s4) var(--s5); border-top: 1px solid var(--border-light); }

/* Offline Banner */
.offline-banner {
  display: none; align-items: center; gap: var(--s2);
  background: rgba(230,126,34,0.1); border: 1px solid rgba(230,126,34,0.25);
  border-radius: var(--r-md); padding: var(--s2) var(--s3);
  font-size: 0.78rem; color: #E67E22; font-weight: 600; margin-bottom: var(--s3);
}
.offline-banner.show { display: flex; }

/* Composition Bar */
.comp-bar-section { margin-top: var(--s4); }
.comp-bar-label { font-size: 0.68rem; font-weight: 700; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: var(--s2); font-family: var(--font-condensed); }
.comp-bar { display: flex; height: 28px; border-radius: var(--r-md); overflow: hidden; background: var(--off-white); }
.comp-seg { display: flex; align-items: center; justify-content: center; font-size: 0.68rem; font-weight: 700; color: white; min-width: 0; overflow: hidden; white-space: nowrap; }
.seg-ec { background: var(--stable-green); }
.seg-dmc { background: var(--electrolyte-blue); }
.seg-emc { background: var(--teal-accent); }
.seg-salt { background: var(--ion-orange); }
.seg-add { background: var(--cardinal-red); }

/* Confidence Gauge */
.conf-section { margin-top: var(--s4); }
.conf-label { display: flex; justify-content: space-between; font-size: 0.73rem; color: var(--text-tertiary); margin-bottom: var(--s2); font-family: var(--font-condensed); text-transform: uppercase; letter-spacing: 0.06em; }
.conf-gauge { position: relative; height: 8px; background: var(--off-white); border-radius: 100px; overflow: visible; }
.conf-fill { height: 100%; background: linear-gradient(90deg, var(--thermal-red) 0%, var(--ion-orange) 35%, var(--stable-green) 70%); border-radius: 100px; width: 0%; transition: width 1.8s var(--ease-out); }
.conf-marker { position: absolute; top: -5px; left: 0; width: 18px; height: 18px; background: white; border: 3px solid var(--model-purple); border-radius: 50%; transform: translateX(-50%); box-shadow: var(--shadow-md); transition: left 1.8s var(--ease-out); }

/* Prediction Card */
.pred-card {
  background: linear-gradient(135deg, rgba(108,92,231,0.06) 0%, rgba(0,102,204,0.03) 100%);
  border: 1px solid rgba(108,92,231,0.12); border-radius: var(--r-lg);
  padding: var(--s4); margin-bottom: var(--s4); border-left: 4px solid var(--model-purple);
}
.pred-big-num { font-family: var(--font-heading); font-size: 2.6rem; font-weight: 700; color: var(--text-primary); line-height: 1; letter-spacing: -0.04em; }
.pred-big-unit { font-size: 1rem; color: var(--text-secondary); margin-left: 0.2rem; font-weight: 400; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .designer-grid, .designer-grid.with-sidebar { grid-template-columns: 1fr; }
  .charts-row { grid-template-columns: 1fr !important; }
  .hero-inner { grid-template-columns: 1fr; }
  .hero-visual { display: none; }
  .metrics-grid { grid-template-columns: repeat(2,1fr); }
  .method-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-sidebar { display: none; }
}
@media (max-width: 768px) {
  .nav-links { display: none; }
  .nav-links.open {
    display: flex; flex-direction: column; position: absolute;
    top: var(--nav-height); left: 0; right: 0;
    background: white; border-bottom: 1px solid var(--border-light);
    padding: var(--s4); box-shadow: var(--shadow-lg); gap: 0;
  }
  .hamburger { display: flex; }
  .hero-stats { flex-wrap: wrap; }
  .hero-actions { flex-direction: column; }
  .btn-xl { width: 100%; justify-content: center; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .facet-panel { flex-direction: column; }
  .toolbar { flex-wrap: wrap; }
  .toolbar-search { max-width: 100%; }
}
@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.6rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--cool-grey-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--cool-grey); }

/* Utility */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.text-center { text-align: center; }
.mt-4 { margin-top: var(--s4); }
.mt-5 { margin-top: var(--s5); }
.mt-6 { margin-top: var(--s6); }
.mb-4 { margin-bottom: var(--s4); }
.mb-5 { margin-bottom: var(--s5); }
