:root {
  /* Purple Atlas — dark mode (default) */
  --bg: #0E0B1A;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #221a3d 0%, #0E0B1A 60%);
  --surface: #16122A;
  --surface-2: #1C1736;
  --surface-3: #241D44;
  --border: #2C2550;
  --border-soft: #221d3f;
  --text: #ECEAF6;
  --text-muted: #9A93B8;
  --text-faint: #6A6390;
  --accent: #A78BFA;       /* violet */
  --accent-2: #6EE7F0;     /* cyan accent (2nd) */
  --logo-bg: #1A1430;

  /* Status palette — On Ballot is the hero, distinct & saturated */
  --st-onballot: #34D399;  /* emerald */
  --st-filed:    #FBBF24;  /* amber */
  --st-early:    #60A5FA;  /* blue */
  --st-review:   #C084FC;  /* violet */
  --st-off:      #6B7280;  /* gray */

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px -12px rgba(0,0,0,.65);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --display: 'Clash Grotesk', 'Satoshi', system-ui, sans-serif;
  --body: 'Satoshi', system-ui, -apple-system, sans-serif;
}

/* v1.6.1: LIGHT MODE — warm off-white, high contrast, still purple-forward */
:root[data-theme="light"] {
  --bg: #F7F5FA;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #EFEAF7 0%, #F7F5FA 60%);
  --surface: #FFFFFF;
  --surface-2: #F4F1FA;
  --surface-3: #EAE4F5;
  --border: #DDD5EB;
  --border-soft: #E8E2F1;
  --text: #201636;
  --text-muted: #605479;
  --text-faint: #948AAB;
  --accent: #6D46D4;          /* deeper purple for contrast on white */
  --accent-2: #0E9CA6;
  --logo-bg: #F2ECFA;

  --st-onballot: #10a468;
  --st-filed:    #B87700;
  --st-early:    #2563EB;
  --st-review:   #7C3AED;
  --st-off:      #6B7280;

  --shadow: 0 18px 40px -14px rgba(60,40,100,.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--body);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: #fff; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

#app { max-width: 1480px; margin: 0 auto; padding: 22px clamp(16px, 3vw, 40px) 60px; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 28px; flex-wrap: wrap; padding-bottom: 20px; border-bottom: 1px solid var(--border-soft); }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { flex: none; filter: drop-shadow(0 0 14px rgba(167,139,250,.25)); }
:root[data-theme="light"] .logo { filter: drop-shadow(0 0 12px rgba(109,70,212,.2)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--display); font-weight: 700; letter-spacing: .14em; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-faint); letter-spacing: .1em; text-transform: uppercase; }
.header-meta { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; flex: 1; justify-content: space-between; }
.title-block { flex: 1; min-width: 260px; }
.title-block h1 { font-family: var(--display); font-size: clamp(20px, 2.4vw, 26px); font-weight: 600; letter-spacing: -.01em; }
.title-block p { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

/* Theme toggle */
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: .02em;
  transition: all .14s;
  white-space: nowrap;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 22px 0; }
.kpi { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 15px 16px; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: .8; }
.kpi.k-onballot::before { background: var(--st-onballot); }
.kpi.k-filed::before { background: var(--st-filed); }
.kpi.k-early::before { background: var(--st-early); }
.kpi .kpi-val { font-family: var(--display); font-size: 28px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi .kpi-label { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; letter-spacing: .03em; text-transform: uppercase; }

/* ---------- Controls ---------- */
.controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.filter-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .1em; width: 68px; flex: none; }
.chip { background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); border-radius: 999px; padding: 7px 14px; font-size: 13px; display: inline-flex; align-items: center; gap: 7px; transition: all .14s; }
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip .cnt { font-family: var(--mono); font-size: 11px; opacity: .7; }
.chip.active { background: var(--surface-3); border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 1px var(--accent) inset; }
.chip.active .cnt { opacity: .9; }

/* Clear filters button */
.filter-actions { padding-top: 4px; }
.clear-filters {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  transition: all .14s;
}
.clear-filters:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.clear-filters:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 1fr 320px; gap: 22px; align-items: start; }
.map-panel { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 20px 22px 18px; }

/* v1.6.1: search bar row above map */
.map-search-row { margin-bottom: 14px; }
.search-wrap { position: relative; display: flex; align-items: center; width: 100%; max-width: 460px; }
.search-wrap svg { position: absolute; left: 14px; color: var(--text-faint); pointer-events: none; z-index: 2; }
#search {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 18px 11px 40px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search::placeholder { color: var(--text-faint); }
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(167,139,250,.16); }
:root[data-theme="light"] #search:focus { box-shadow: 0 0 0 3px rgba(109,70,212,.15); }

/* Search dropdown */
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 20;
  max-height: 340px;
  overflow-y: auto;
}
.sd-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  color: var(--text);
  font-size: 13px;
  transition: background .1s;
}
.sd-item:last-child { border-bottom: none; }
.sd-item:hover { background: var(--surface-2); }
.sd-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sd-name { font-weight: 500; }
.sd-meta { font-size: 11.5px; color: var(--text-faint); font-family: var(--mono); }
.sd-empty { padding: 14px; color: var(--text-faint); font-size: 12.5px; text-align: center; }

.map-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.map-head h2 { font-family: var(--display); font-size: 16px; font-weight: 600; }
.map-hint { font-size: 12px; color: var(--text-faint); }
.map-scroll { overflow-x: auto; padding-bottom: 4px; }

/* Tile map */
.tile-map { display: grid; grid-template-columns: repeat(13, minmax(46px, 1fr)); grid-auto-rows: 1fr; gap: 6px; min-width: 660px; }
.tile-map::before { content: ''; grid-column: 1 / 2; grid-row: 1 / 2; }
.tile { aspect-ratio: 1 / 1; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; transition: transform .12s, box-shadow .12s, border-color .12s; padding: 2px; }
.tile:hover { transform: translateY(-2px); border-color: var(--text); box-shadow: 0 8px 20px -6px rgba(0,0,0,.35); z-index: 2; }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile.empty { background: transparent; border: none; pointer-events: none; }
.tile .ab { font-family: var(--display); font-weight: 600; font-size: 13px; color: var(--text); }
.tile .ct { font-family: var(--mono); font-size: 10px; color: var(--text); opacity: .82; line-height: 1; }
.tile .bar { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 3px; border-radius: 2px; }
.tile.dim { opacity: .28; filter: saturate(.4); }
.tile.no-cand .ab { color: var(--text-faint); }

/* Territories */
.territories { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.terr-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .1em; }
.terr-list { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.terr-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 13px; display: flex; align-items: center; gap: 10px; transition: all .14s; }
.terr-card:hover { border-color: var(--text); transform: translateY(-1px); }
.terr-card .tname { font-size: 13px; font-weight: 500; color: var(--text); }
.terr-card .tdot { width: 9px; height: 9px; border-radius: 50%; }
.terr-card .tcnt { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.terr-card.dim { opacity: .3; }

/* Legend */
.legend { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.legend-title { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .1em; }
.legend-items { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-muted); }
.legend-item .swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.legend-item.hero { color: var(--text); font-weight: 500; }
.legend-item.hero .swatch { box-shadow: 0 0 0 2px rgba(52,211,153,.3); }
.legend-note { font-size: 11.5px; color: var(--text-faint); margin-top: 12px; line-height: 1.5; }

/* Methodology */
.method-panel { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 20px; position: sticky; top: 18px; }
.method-panel h3 { font-family: var(--display); font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text); }
.method-panel p { font-size: 12.5px; color: var(--text-muted); margin-bottom: 12px; line-height: 1.6; }
.method-panel strong { color: var(--text); font-weight: 600; }
.method-panel em { color: var(--accent); font-style: normal; }
.method-panel .honesty { background: var(--surface-2); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 0 8px 8px 0; }
.method-panel .honesty-cta { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; border-radius: 3px; }
.method-panel .honesty-cta:hover { text-decoration-thickness: 2px; }
.method-panel .honesty-cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.method-panel .honesty-copied { display: inline-block; margin-left: 8px; font-size: 12px; color: var(--text-faint); font-style: italic; }
.method-panel .gen { font-size: 11px; color: var(--text-faint); border-top: 1px solid var(--border-soft); padding-top: 12px; margin-bottom: 0; }

/* ---------- Drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8,6,18,.6); backdrop-filter: blur(2px); z-index: 40; animation: fade .2s ease; }
:root[data-theme="light"] .overlay { background: rgba(60,40,100,.28); }
@keyframes fade { from { opacity: 0; } }
.drawer[hidden], .overlay[hidden] { display: none; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(480px, 94vw); background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow); z-index: 50; display: flex; flex-direction: column; animation: slide .26s cubic-bezier(.22,1,.36,1); }
@keyframes slide { from { transform: translateX(100%); } }
.drawer-head { padding: 22px 22px 16px; border-bottom: 1px solid var(--border-soft); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer-eyebrow { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .12em; }
.drawer-head h2 { font-family: var(--display); font-size: 22px; font-weight: 600; margin-top: 4px; color: var(--text); }
.drawer-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.drawer-stats .ds { font-size: 11px; font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--border); padding: 4px 9px; border-radius: 6px; color: var(--text-muted); }
.close-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); border-radius: 8px; width: 36px; height: 36px; display: grid; place-items: center; flex: none; transition: all .14s; }
.close-btn:hover { color: var(--text); border-color: var(--text); }
.drawer-body { overflow-y: auto; padding: 16px 22px 40px; flex: 1; display: flex; flex-direction: column; gap: 14px; }

/* Candidate card */
.card { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 16px; border-left: 3px solid var(--st-off); }
.card-top { display: flex; gap: 13px; align-items: flex-start; }
.avatar { width: 52px; height: 52px; border-radius: 11px; flex: none; object-fit: cover; background: var(--surface-3); display: grid; place-items: center; font-family: var(--display); font-weight: 600; font-size: 17px; color: var(--accent); border: 1px solid var(--border); }
.card-id { flex: 1; min-width: 0; }
.card-name { font-family: var(--display); font-size: 16px; font-weight: 600; line-height: 1.2; color: var(--text); }
.card-office { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.card-office .party { color: var(--text-faint); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 999px; white-space: nowrap; margin-top: 8px; letter-spacing: .01em; }
.badge .bdot { width: 7px; height: 7px; border-radius: 50%; }

/* v1.6.1: endorsements — clearer, proper spacing so they aren't covered */
.endorsements { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.endorsement-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, #F0C24B 16%, transparent);
  color: #C08A00;
  letter-spacing: .01em;
  white-space: nowrap;
  border: 1px solid color-mix(in srgb, #F0C24B 25%, transparent);
}
:root:not([data-theme="light"]) .endorsement-badge { color: #E8B93B; }

.ballot-label { font-size: 12px; margin-top: 11px; color: var(--text-muted); }
.ballot-label .bl-val { color: var(--text); font-weight: 500; }
.card-bio { font-size: 12.5px; color: var(--text-muted); margin-top: 11px; line-height: 1.55; }
.card-bio.fallback { color: var(--text-faint); font-style: italic; }
.card-notes { font-size: 11.5px; color: var(--text-faint); margin-top: 11px; line-height: 1.5; border-top: 1px dashed var(--border); padding-top: 10px; }
.card-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.card-link { font-size: 11.5px; display: inline-flex; align-items: center; gap: 5px; background: var(--surface-3); border: 1px solid var(--border); padding: 5px 10px; border-radius: 7px; color: var(--text); transition: all .14s; }
.card-link:hover { border-color: var(--accent); text-decoration: none; color: var(--accent); }
.card-link.muted { color: var(--text-faint); cursor: default; pointer-events: none; }
.empty-state { text-align: center; color: var(--text-faint); padding: 40px 20px; font-size: 13px; }

/* Responsive */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .method-panel { position: static; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .header-meta { justify-content: flex-start; }
  .search-wrap { max-width: 100%; }
  .filter-label { width: 100%; }
  .filter-actions { width: 100%; }
}

/* v1.7: Beta chip — subtle, next to Purple Atlas brand mark */
.beta-chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: .12em;
  padding: 2px 6px;
  margin-left: 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  vertical-align: 2px;
  line-height: 1;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
}

/* v1.8: Attribution footer — Purple Atlas is the canonical host, Independent Voice is the partner */
.pa-attribution {
  margin-top: 30px;
  padding: 18px 0 6px;
  border-top: 1px solid var(--border-soft);
}
.pa-attr-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
  text-align: center;
}
.pa-attr-host strong { color: var(--text); font-weight: 600; letter-spacing: .01em; }
.pa-attr-sep { color: var(--text-faint); user-select: none; }
.pa-attr-partner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.pa-iv-link {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border-radius: 4px;
  transition: opacity .15s ease;
}
.pa-iv-link:hover,
.pa-iv-link:focus-visible { opacity: .7; }
.pa-iv-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.pa-iv-logo {
  height: 36px;
  width: auto;
  display: block;
}
/* Logo is solid black; on dark theme invert to keep visible while preserving alpha */
:root[data-theme="dark"] .pa-iv-logo { filter: invert(1); }
@media (max-width: 640px) {
  .pa-attr-inner { gap: 4px 10px; font-size: 12px; }
  .pa-attr-sep { display: none; }
  .pa-iv-logo { height: 32px; }
}

/* Embed mode — chrome-free for iframe use */
html.embed-mode .topbar { display: none; }
html.embed-mode #app { padding-top: 0; }
html.embed-mode body { background: transparent; }
html.embed-mode .pa-attribution { display: none; }
