@import url('https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,300;0,400;0,700;1,300;1,400&family=Source+Sans+3:wght@300;400;600;700&display=swap');

/* ─── TOKENS ─── */
:root {
  --navy: #1a2744; --navy-light: #243456; --cream: #faf8f4; --amber: #d97706;
  --amber-light: #fef3c7; --teal: #0e7490; --teal-dark: #0a5c73; --teal-light: #ecfeff;
  --red: #b91c1c; --red-light: #fef2f2; --green: #15803d; --green-light: #f0fdf4;
  --purple: #6d28d9; --slate: #475569; --border: #e2e8f0;
  --text: #1e293b; --text-secondary: #64748b;
  --serif: 'Merriweather', Georgia, 'Times New Roman', serif;
  --sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ─── RESET ─── */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: var(--serif); font-size: 17px; line-height: 1.75; color: var(--text); background: var(--cream); }
a { color: var(--teal); }
[x-cloak] { display: none !important; }

/* ─── NAVIGATION ─── */
.nav { background: var(--navy); color: white; padding: 0 1.5rem; position: sticky; top: 0; z-index: 100; font-family: var(--sans); }
.nav-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 56px; }
.nav-brand { color: white; text-decoration: none; font-weight: 700; font-size: 1.1rem; font-family: var(--serif); letter-spacing: -0.01em; }
.nav-links { display: flex; gap: 0.25rem; }
.nav-links a { color: rgba(255,255,255,0.7); text-decoration: none; padding: 0.5rem 1rem; border-radius: 6px; font-size: 0.875rem; font-family: var(--sans); font-weight: 600; transition: all 0.15s; }
.nav-links a:hover, .nav-links a.active { color: white; background: rgba(255,255,255,0.1); }

/* ─── MAIN ─── */
.main { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; min-height: calc(100vh - 56px - 80px); }

/* ─── COVER HERO ─── */
.cover { min-height: 100vh; background: linear-gradient(160deg, var(--navy) 0%, var(--teal-dark) 60%, var(--teal) 100%); color: white; display: flex; flex-direction: column; justify-content: center; padding: 80px 24px; position: relative; overflow: hidden; }
.cover::before { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 25% 65%, rgba(217,119,6,0.08) 0%, transparent 55%), radial-gradient(ellipse at 75% 25%, rgba(14,116,144,0.06) 0%, transparent 45%); }
.cover > * { position: relative; z-index: 1; }
.cover-inner { max-width: 720px; margin: 0 auto; }
.cover-label { font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: 2.5px; text-transform: uppercase; color: rgba(255,255,255,0.5); margin-bottom: 24px; }
.cover h1 { font-size: clamp(32px, 5vw, 52px); font-weight: 700; line-height: 1.15; margin-bottom: 24px; letter-spacing: -0.02em; font-family: var(--serif); }
.cover h1 span { color: #fcd34d; }
.cover .subtitle { font-family: var(--serif); font-size: clamp(16px, 2vw, 20px); font-weight: 300; line-height: 1.7; opacity: 0.85; max-width: 580px; margin-bottom: 40px; }
.cover-cta { display: flex; gap: 12px; flex-wrap: wrap; }
.cover-meta { margin-top: 60px; font-family: var(--sans); font-size: 13px; opacity: 0.4; }
.cover-scroll { position: absolute; bottom: 32px; left: 50%; transform: translateX(-50%); font-family: var(--sans); font-size: 12px; letter-spacing: 2px; text-transform: uppercase; opacity: 0.4; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 0.3; } 50% { opacity: 0.7; } }

/* ─── COVER STATS ROW ─── */
.cover-stats { display: flex; gap: 32px; flex-wrap: wrap; margin-top: 48px; padding-top: 32px; border-top: 1px solid rgba(255,255,255,0.15); }
.cover-stat-val { font-family: var(--sans); font-size: 28px; font-weight: 700; color: #fcd34d; line-height: 1; }
.cover-stat-label { font-family: var(--sans); font-size: 12px; color: rgba(255,255,255,0.6); text-transform: uppercase; letter-spacing: 1px; margin-top: 4px; }

/* ─── BUTTONS ─── */
.btn { font-family: var(--sans); font-size: 14px; font-weight: 600; padding: 12px 24px; border-radius: 4px; text-decoration: none; transition: all 0.15s; display: inline-flex; align-items: center; gap: 0.5rem; border: none; cursor: pointer; }
.btn-primary { background: var(--teal); color: white; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-primary-cover { background: white; color: var(--navy); }
.btn-primary-cover:hover { background: #fcd34d; }
.btn-secondary { border: 1.5px solid rgba(255,255,255,0.3); color: white; background: transparent; }
.btn-secondary:hover { border-color: rgba(255,255,255,0.6); }
.btn-outline { background: transparent; color: var(--teal); border: 1.5px solid var(--teal); }
.btn-outline:hover { background: var(--teal-light); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #991b1b; }

/* ─── SECTION PATTERN ─── */
.section { max-width: 780px; margin: 0 auto; padding: 72px 24px; }
.section + .section { border-top: 1px solid var(--border); }
.section-num { font-family: var(--sans); font-size: 12px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--teal); margin-bottom: 6px; }
.section h2 { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1.25; margin-bottom: 4px; font-family: var(--serif); }
.section-rule { width: 40px; height: 3px; background: var(--amber); border: none; margin: 12px 0 24px 0; }
.section p { margin-bottom: 18px; }
.section p.lead { font-size: 19px; color: var(--text); font-weight: 400; }

/* ─── DARK SECTION ─── */
.dark { background: var(--navy); color: white; padding: 72px 24px; }
.dark .section { border: none; padding-top: 0; padding-bottom: 0; }
.dark .section-num { color: var(--amber); }
.dark h2 { color: white; }
.dark p { opacity: 0.85; }
.dark a { color: #fcd34d; }

/* ─── CARDS ─── */
.card { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem; }
.card-header { font-family: var(--serif); font-size: 1.1rem; font-weight: 700; color: var(--navy); margin-bottom: 0.75rem; }
.card-subheader { font-family: var(--sans); font-size: 12px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--teal); margin-bottom: 4px; }

/* County card variant */
.county-card { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem; cursor: pointer; transition: border-color 0.15s; }
.county-card:hover { border-color: var(--teal); }
.county-card.selected { border-color: var(--teal); border-width: 2px; }

/* ─── STAT BLOCKS ─── */
.narrative-stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 20px 0 24px; }
.ns { flex: 1; min-width: 120px; border-left: 3px solid var(--teal); padding: 10px 14px; background: var(--teal-light); border-radius: 0 6px 6px 0; }
.ns.warning { border-left-color: var(--amber); background: var(--amber-light); }
.ns.critical { border-left-color: var(--red); background: var(--red-light); }
.ns-val { font-family: var(--sans); font-size: 24px; font-weight: 700; color: var(--navy); line-height: 1.1; }
.ns-label { font-family: var(--sans); font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* Inline stat */
.stat-inline { font-family: var(--sans); font-weight: 700; color: var(--navy); white-space: nowrap; }
.stat-inline.alert { color: var(--red); }
.stat-inline.positive { color: var(--green); }

/* Simple centered stat */
.stat { text-align: center; }
.stat-value { font-family: var(--sans); font-size: 2rem; font-weight: 700; color: var(--navy); line-height: 1.2; }
.stat-label { font-family: var(--sans); font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.25rem; }

/* Context grid (mini stat cells) */
.context-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.ctx-stat { background: white; border-radius: 6px; padding: 10px 12px; text-align: center; }
.ctx-val { font-family: var(--sans); font-size: 20px; font-weight: 700; color: var(--navy); }
.ctx-label { font-family: var(--sans); font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* ─── FILTER PILLS ─── */
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--cream); }
.filter-btn { font-family: var(--sans); font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 100px; border: 1px solid var(--border); background: white; color: var(--text-secondary); cursor: pointer; transition: all 0.12s; }
.filter-btn:hover { border-color: var(--teal); color: var(--teal); }
.filter-btn.active { background: var(--teal); color: white; border-color: var(--teal); }

/* ─── BADGES ─── */
.badge { font-family: var(--sans); display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 0.75rem; font-weight: 700; }
.badge-teal { background: var(--teal-light); color: var(--teal-dark); }
.badge-amber { background: var(--amber-light); color: var(--amber); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-navy { background: var(--navy); color: white; }

/* ─── WIKI TABLE ─── */
.wiki-table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 13px; margin: 24px 0; }
.wiki-table th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: white; background: var(--navy); }
.wiki-table td { padding: 8px 14px; border-bottom: 1px solid var(--border); }
.wiki-table tr:last-child td { border-bottom: none; }
.wiki-table tr:hover td { background: var(--teal-light); }

/* Generic table (less opinionated) */
.table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 0.9rem; }
.table th, .table td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 700; color: white; background: var(--navy); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.table tr:hover td { background: var(--teal-light); }

/* Comparison table helpers */
.yes { color: var(--green); font-weight: 600; }
.no { color: var(--text-secondary); }
.partial { color: var(--amber); font-weight: 500; }
.live { color: var(--green); font-weight: 600; }
.planned { color: var(--text-secondary); }

/* ─── BAR CHARTS ─── */
.bar-chart { display: flex; flex-direction: column; gap: 0.5rem; font-family: var(--sans); }
.bar-row { display: flex; align-items: center; gap: 0.75rem; }
.bar-label { width: 160px; font-size: 0.85rem; text-align: right; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.bar-track { flex: 1; height: 24px; background: #f1f5f9; border-radius: 4px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; display: flex; align-items: center; padding-left: 8px; font-size: 0.75rem; font-weight: 600; color: white; }
.bar-fill-teal { background: var(--teal); }
.bar-fill-amber { background: var(--amber); }
.bar-fill-red { background: var(--red); }
.bar-fill-green { background: var(--green); }

/* ─── INPUTS ─── */
.input { font-family: var(--sans); width: 100%; padding: 0.6rem 1rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.95rem; outline: none; transition: border 0.15s; background: white; color: var(--text); }
.input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,116,144,0.1); }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2rem; cursor: pointer; }

/* ─── NARRATIVE EXCERPT ─── */
.narrative-excerpt { background: white; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 32px 0; }
.narrative-header { background: var(--navy); color: white; padding: 20px 28px; }
.narrative-header .label { font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--amber); margin-bottom: 4px; }
.narrative-header h3 { font-size: 22px; font-weight: 700; font-family: var(--serif); }
.narrative-header .location { font-family: var(--sans); font-size: 13px; opacity: 0.6; margin-top: 4px; }
.narrative-body { padding: 28px; }
.narrative-body p { font-size: 16px; line-height: 1.8; }
.narrative-source { font-family: var(--sans); font-size: 12px; color: var(--text-secondary); padding: 12px 28px; border-top: 1px solid var(--border); background: var(--cream); }

/* ─── EVIDENCE CARD EXPLORER ─── */
.explorer { background: white; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 32px 0; }
.explorer-header { background: var(--navy); color: white; padding: 16px 24px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.explorer-header h3 { font-family: var(--sans); font-size: 14px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
.explorer-header .count { font-family: var(--sans); font-size: 13px; opacity: 0.6; }
.card-list { max-height: 360px; overflow-y: auto; }
.card-item { display: flex; gap: 14px; padding: 14px 24px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.card-item:hover { background: var(--teal-light); }
.card-item.selected { background: #dbeafe; border-left: 3px solid var(--teal); }
.card-badge { flex-shrink: 0; font-family: var(--sans); font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 3px; background: var(--navy); color: white; margin-top: 2px; white-space: nowrap; }
.card-info { flex: 1; }
.card-info h4 { font-family: var(--sans); font-size: 14px; font-weight: 600; color: var(--navy); margin-bottom: 3px; }
.card-info p { font-family: var(--sans); font-size: 13px; color: var(--text-secondary); line-height: 1.4; margin: 0; }
.quality-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.quality-dot.strong { background: var(--green); }
.quality-dot.moderate { background: var(--amber); }
.card-detail { padding: 24px; border-top: 2px solid var(--teal); background: var(--teal-light); }
.card-detail h4 { font-family: var(--sans); font-size: 16px; font-weight: 700; color: var(--navy); margin-bottom: 12px; }
.card-detail .finding { font-size: 15px; line-height: 1.7; margin-bottom: 16px; }

/* ─── METHODOLOGY TABS ─── */
.method-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 0; background: var(--navy); border-radius: 10px 10px 0 0; padding: 12px 16px 0; }
.method-tab { font-family: var(--sans); font-size: 12px; font-weight: 600; padding: 8px 16px; border: none; border-radius: 6px 6px 0 0; cursor: pointer; transition: all 0.12s; background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.6); }
.method-tab:hover { background: rgba(255,255,255,0.15); color: white; }
.method-tab.active { background: var(--cream); color: var(--navy); }
.method-panel { background: white; border: 1px solid var(--border); border-top: none; border-radius: 0 0 10px 10px; padding: 28px; }
.method-panel h4 { font-family: var(--sans); font-size: 18px; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.method-panel .cite { font-family: var(--sans); font-size: 12px; color: var(--teal); font-weight: 600; margin-bottom: 16px; }
.method-panel p { font-size: 15px; margin-bottom: 14px; }
.method-example { background: var(--cream); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin: 20px 0; }
.method-example .ex-label { font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 8px; }

/* ─── CHAT ─── */
.chat-container { display: flex; flex-direction: column; height: calc(100vh - 56px - 4rem); background: white; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.chat-input { display: flex; gap: 0.75rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--cream); align-items: flex-end; }
.chat-input textarea { font-family: var(--serif); flex: 1; padding: 0.6rem 1rem; border: 1px solid var(--border); border-radius: 6px; font-size: 15px; line-height: 1.5; resize: none; min-height: 44px; max-height: 140px; outline: none; transition: border 0.15s; background: white; color: var(--text); }
.chat-input textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,116,144,0.1); }
.msg-user { align-self: flex-end; max-width: 80%; background: var(--navy); color: white; padding: 12px 16px; border-radius: 10px 10px 2px 10px; font-size: 15px; line-height: 1.6; font-family: var(--serif); }
.msg-assistant { align-self: flex-start; max-width: 85%; background: white; border: 1px solid var(--border); padding: 12px 16px; border-radius: 10px 10px 10px 2px; font-size: 15px; line-height: 1.7; font-family: var(--serif); }
.msg-assistant.streaming::after { content: '▍'; animation: blink 0.8s steps(1) infinite; color: var(--teal); margin-left: 2px; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
.msg-label { font-family: var(--sans); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-secondary); margin-bottom: 4px; }

/* ─── GRIDS ─── */
.grid-3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* ─── LOADING / EMPTY ─── */
.loading { font-family: var(--sans); display: flex; align-items: center; justify-content: center; padding: 3rem; color: var(--text-secondary); gap: 0.5rem; }
.loading::before { content: ''; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--teal); border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { font-family: var(--sans); text-align: center; padding: 3rem; color: var(--text-secondary); }
.empty-icon { font-size: 2rem; margin-bottom: 0.5rem; opacity: 0.5; }

/* ─── WIKI LINKS ─── */
.wiki-links { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--border); }
.wiki-links-label { font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 10px; }
.wiki-links-list { display: flex; flex-wrap: wrap; gap: 6px; }
.wiki-links-list a { font-family: var(--sans); font-size: 13px; color: var(--teal); text-decoration: none; padding: 3px 10px; border: 1px solid var(--teal-light); border-radius: 4px; background: var(--teal-light); transition: all 0.12s; }
.wiki-links-list a:hover { background: var(--teal); color: white; border-color: var(--teal); }

/* ─── FOOTER ─── */
.footer { background: var(--navy); color: rgba(255,255,255,0.7); padding: 2rem 1.5rem; text-align: center; font-family: var(--sans); font-size: 0.85rem; }
.footer a { color: rgba(255,255,255,0.9); }
.footer-sub { font-size: 0.75rem; margin-top: 0.5rem; opacity: 0.6; }

/* ─── RESPONSIVE ─── */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .cover h1 { font-size: 28px; }
  .section h2 { font-size: 22px; }
  .narrative-stats { flex-direction: column; }
  .context-grid { grid-template-columns: 1fr 1fr; }
  .cover-stats { gap: 20px; }
  .nav-links a { padding: 0.5rem 0.6rem; font-size: 0.8rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .bar-label { width: 100px; }
  .main { padding: 1rem; }
  .chat-container { height: calc(100vh - 56px - 2rem); }
  .method-tabs { gap: 2px; }
  .method-tab { font-size: 11px; padding: 6px 10px; }
}
