@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; --white: #ffffff;
  --amber: #d97706; --amber-light: #fef3c7;
  --teal: #0e7490; --teal-dark: #0a5c73; --teal-light: #ecfeff;
  --red: #b91c1c; --red-light: #fef2f2;
  --green: #15803d; --green-light: #f0fdf4;
  --slate: #475569; --border: #e2e8f0;
  --text: #1e293b; --text-muted: #64748b;
  --serif: 'Merriweather', Georgia, serif;
  --sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ─── RESET ─── */
*, *::before, *::after { 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); text-decoration: none; }
a:hover { text-decoration: underline; }
[x-cloak] { display: none !important; }

/* ─── COVER ─── */
.cover { min-height: 100vh; background: linear-gradient(160deg, var(--navy) 0%, var(--teal-dark) 60%, var(--teal) 100%); color: #fff; 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.07) 0%, transparent 55%), radial-gradient(ellipse at 75% 25%, rgba(14,116,144,0.05) 0%, transparent 45%); }
.cover > * { position: relative; z-index: 1; }
.cover-inner { max-width: 680px; margin: 0 auto; }
.cover-label { font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: 2.5px; text-transform: uppercase; color: rgba(255,255,255,0.45); margin-bottom: 20px; }
.cover h1 { font-size: clamp(28px, 4.5vw, 46px); font-weight: 700; line-height: 1.2; margin-bottom: 20px; letter-spacing: -0.01em; }
.cover h1 em { font-style: normal; color: #fcd34d; }
.cover .lead { font-size: clamp(15px, 1.8vw, 18px); font-weight: 300; line-height: 1.7; opacity: 0.8; max-width: 560px; margin-bottom: 36px; }
.cover-cta { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 48px; }
.cover-stats { display: flex; gap: 24px; flex-wrap: wrap; font-family: var(--sans); font-size: 13px; opacity: 0.5; }
.cover-stats span { white-space: nowrap; }

/* ─── NAV ─── */
.nav { background: var(--navy); position: sticky; top: 0; z-index: 100; font-family: var(--sans); }
.nav-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 52px; padding: 0 20px; }
.nav-brand { color: #fff; font-family: var(--serif); font-weight: 700; font-size: 15px; text-decoration: none; }
.nav-links { display: flex; gap: 2px; }
.nav-links a { color: rgba(255,255,255,0.6); font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 4px; text-decoration: none; transition: all 0.12s; }
.nav-links a:hover, .nav-links a.active { color: #fff; background: rgba(255,255,255,0.08); }

/* ─── LAYOUT ─── */
.page { max-width: 1100px; margin: 0 auto; padding: 40px 20px 64px; }

/* ─── SECTION PATTERN ─── */
.overline { font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--teal); margin-bottom: 4px; }
.page h2 { font-size: 26px; font-weight: 700; color: var(--navy); line-height: 1.25; margin-bottom: 4px; }
.rule { width: 40px; height: 3px; background: var(--amber); border: none; margin: 10px 0 24px; }

/* ─── BUTTONS ─── */
.btn { font-family: var(--sans); font-size: 13px; font-weight: 600; padding: 10px 20px; border-radius: 4px; border: none; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; transition: all 0.12s; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); text-decoration: none; }
.btn-cover { background: #fff; color: var(--navy); }
.btn-cover:hover { background: #fcd34d; text-decoration: none; }
.btn-ghost { background: transparent; color: #fff; border: 1.5px solid rgba(255,255,255,0.3); }
.btn-ghost:hover { border-color: rgba(255,255,255,0.6); text-decoration: none; }
.btn-outline { background: transparent; color: var(--teal); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--teal); text-decoration: none; }
.btn-sm { font-size: 12px; padding: 6px 12px; }

/* ─── INPUTS ─── */
.input { font-family: var(--sans); font-size: 14px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 6px; outline: none; background: var(--white); transition: border 0.12s; }
.input:focus { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(14,116,144,0.08); }
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 d='M3 4.5L6 7.5L9 4.5' stroke='%23475569' fill='none' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* ─── CARDS ─── */
.card { background: var(--white); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.card-title { font-family: var(--serif); font-size: 16px; font-weight: 700; color: var(--navy); margin-bottom: 8px; }

/* ─── COUNTY CARD ─── */
.county-card { display: block; text-decoration: none; color: inherit; transition: border-color 0.15s; }
.county-card:hover { border-color: var(--teal); text-decoration: none; }
.county-card .county-name { font-family: var(--serif); font-size: 16px; font-weight: 700; color: var(--navy); margin-bottom: 2px; }
.county-card .county-pop { font-family: var(--sans); font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.county-card .county-stats { display: flex; gap: 16px; }
.county-stat { font-family: var(--sans); text-align: center; flex: 1; }
.county-stat-val { font-size: 18px; font-weight: 700; color: var(--navy); line-height: 1.2; }
.county-stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

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

/* ─── STAT BLOCKS ─── */
.ns { font-family: var(--sans); padding: 10px 14px; border-left: 3px solid var(--teal); background: var(--teal-light); border-radius: 0 6px 6px 0; }
.ns-val { font-size: 22px; font-weight: 700; color: var(--navy); line-height: 1.1; }
.ns-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-top: 2px; }
.ns.warning { border-color: var(--amber); background: var(--amber-light); }
.ns.critical { border-color: var(--red); background: var(--red-light); }

/* ─── BADGES ─── */
.badge { font-family: var(--sans); display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.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: #fff; font-size: 10px; border-radius: 3px; }

/* ─── FILTER PILLS ─── */
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.pill { font-family: var(--sans); font-size: 12px; font-weight: 600; padding: 5px 14px; border-radius: 100px; border: 1px solid var(--border); background: var(--white); color: var(--text-muted); cursor: pointer; transition: all 0.12s; }
.pill:hover { border-color: var(--teal); color: var(--teal); }
.pill.active { background: var(--teal); color: #fff; border-color: var(--teal); }

/* ─── TABLES ─── */
.data-table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 13px; }
.data-table th { background: var(--navy); color: #fff; font-weight: 600; text-align: left; padding: 8px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.data-table th:first-child { border-radius: 6px 0 0 0; }
.data-table th:last-child { border-radius: 0 6px 0 0; }
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: rgba(14,116,144,0.02); }

/* ─── BAR CHART ─── */
.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 150px; font-family: var(--sans); font-size: 12px; text-align: right; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.bar-track { flex: 1; height: 22px; background: #f1f5f9; border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; display: flex; align-items: center; padding-left: 8px; font-family: var(--sans); font-size: 11px; font-weight: 600; color: #fff; min-width: fit-content; }
.bar-fill-teal { background: var(--teal); }
.bar-fill-amber { background: var(--amber); }
.bar-fill-red { background: var(--red); }
.bar-fill-green { background: var(--green); }

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

/* ─── CHAT ─── */
.chat-container { display: flex; flex-direction: column; height: calc(100vh - 200px); max-height: 600px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 0; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; padding: 12px 16px; border-radius: 10px; font-size: 15px; line-height: 1.6; }
.msg-user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 2px; font-family: var(--sans); }
.msg-assistant { align-self: flex-start; background: var(--white); border: 1px solid var(--border); border-bottom-left-radius: 2px; }
.chat-input-row { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.chat-input-row .input { flex: 1; }
.streaming-dot { display: inline-block; width: 6px; height: 6px; background: var(--teal); border-radius: 50%; animation: blink 1s infinite; margin-left: 4px; }
@keyframes blink { 0%,100% { opacity: 0.3; } 50% { opacity: 1; } }

/* ─── STATES ─── */
.loading { display: flex; align-items: center; justify-content: center; padding: 48px; font-family: var(--sans); font-size: 14px; color: var(--text-muted); }
.empty { text-align: center; padding: 48px; font-family: var(--sans); color: var(--text-muted); }
.error-msg { font-family: var(--sans); font-size: 14px; color: var(--red); padding: 12px; background: var(--red-light); border-radius: 6px; margin-bottom: 16px; }

/* ─── FOOTER ─── */
.footer { background: var(--navy); color: rgba(255,255,255,0.5); padding: 24px 20px; text-align: center; font-family: var(--sans); font-size: 12px; }
.footer a { color: rgba(255,255,255,0.7); }
.footer-sub { margin-top: 6px; opacity: 0.5; }

/* ─── ALIASES (bridge between agent-generated HTML and design system) ─── */
.section-num { font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--teal); margin-bottom: 4px; }
.section-rule { width: 40px; height: 3px; background: var(--amber); border: none; margin: 10px 0 24px; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar .input { max-width: 320px; }
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.ns-value { font-size: 22px; font-weight: 700; color: var(--navy); line-height: 1.1; }
.ns-amber { border-color: var(--amber); background: var(--amber-light); }
.card-header { font-family: var(--serif); font-size: 16px; font-weight: 700; color: var(--navy); margin-bottom: 8px; }
.compare-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.compare-controls .input { max-width: 260px; }
.wiki-table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 13px; }
.wiki-table th { background: var(--navy); color: #fff; font-weight: 600; text-align: left; padding: 8px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.wiki-table th:first-child { border-radius: 6px 0 0 0; }
.wiki-table th:last-child { border-radius: 0 6px 0 0; }
.wiki-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.wiki-table tr:hover td { background: rgba(14,116,144,0.02); }
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-btn { font-family: var(--sans); font-size: 12px; font-weight: 600; padding: 5px 14px; border-radius: 100px; border: 1px solid var(--border); background: var(--white); color: var(--text-muted); cursor: pointer; transition: all 0.12s; }
.filter-btn:hover { border-color: var(--teal); color: var(--teal); }
.filter-btn.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn-secondary { background: transparent; color: var(--teal); border: 1px solid var(--border); font-family: var(--sans); font-size: 13px; font-weight: 600; padding: 10px 20px; border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; transition: all 0.12s; }
.btn-secondary:hover { border-color: var(--teal); text-decoration: none; }
.btn-primary-cover { background: #fff; color: var(--navy); font-family: var(--sans); font-size: 13px; font-weight: 600; padding: 10px 20px; border-radius: 4px; border: none; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; transition: all 0.12s; }
.btn-primary-cover:hover { background: #fcd34d; text-decoration: none; }
.subtitle { font-size: clamp(15px, 1.8vw, 18px); font-weight: 300; line-height: 1.7; opacity: 0.8; max-width: 560px; margin-bottom: 36px; }
.cover-stat { text-align: center; }
.cover-stat-value { font-family: var(--sans); font-size: 28px; font-weight: 700; display: block; }
.cover-stat-label { font-family: var(--sans); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.6; }
.link-subtle { font-family: var(--sans); font-size: 13px; color: var(--teal); text-decoration: none; }
.link-subtle:hover { text-decoration: underline; }
.wiki-link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.wiki-link-card { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 6px; color: var(--teal); font-family: var(--sans); font-size: 13px; text-decoration: none; transition: all 0.12s; }
.wiki-link-card:hover { border-color: var(--teal); background: var(--teal-light); text-decoration: none; }
.wiki-link-icon { font-size: 16px; }
.msg-system { padding: 16px; background: var(--teal-light); border: 1px solid var(--border); border-radius: 10px; font-size: 14px; line-height: 1.6; }
.msg-content { white-space: pre-wrap; }
.chat-input { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.chat-input .input { flex: 1; }
.tool-results { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.tool-result-card { background: var(--cream); border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; font-family: var(--sans); font-size: 12px; }
.tool-result-label { font-weight: 600; color: var(--teal); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.tool-result-body { color: var(--text-muted); }

/* ─── RESPONSIVE ─── */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .cover h1 { font-size: 26px; }
  .page h2 { font-size: 22px; }
  .nav-links a { font-size: 11px; padding: 4px 8px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .bar-label { width: 100px; font-size: 11px; }
  .county-card .county-stats { gap: 8px; }
  .cover-stats { flex-direction: column; gap: 8px; }
  .chat-container { height: calc(100vh - 160px); }
}
