:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #646a73;
  --line: #e3e3df;
  --accent: #1d5c8f;
  --nodata: #e4e4e0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; }

.panel {
  width: 360px;
  flex: none;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#map { flex: 1; height: 100%; background: #dfe6ea; }

h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
h3 { font-size: 17px; margin: 0 0 2px; }
.sub, .muted { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.sub a { color: inherit; }

.controls { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
select {
  font: inherit; font-size: 14px; color: var(--text); font-weight: 400;
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}

.seg { display: grid; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button {
  font: inherit; font-size: 13px; padding: 7px 0; border: 0; background: #fff; color: var(--text); cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }

.card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.hint { font-size: 13px; color: var(--muted); padding: 2px 2px 0; }
.detail { border-left: 3px solid var(--accent); scroll-margin: 12px; }
.detail.flash { animation: flash 0.9s ease-out; }
@keyframes flash { from { background: #e6f0fa; } to { background: var(--panel); } }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.close {
  flex: none; width: 28px; height: 28px; margin: -4px -6px 0 0;
  border: 0; border-radius: 6px; background: transparent; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.close:hover, .close:focus-visible { background: #efefec; color: var(--text); }
.notice { background: #fff8e6; border: 1px solid #f0dca8; border-radius: 8px; padding: 10px 12px; font-size: 13px; line-height: 1.45; }
.notice code { font-size: 12px; background: #fff; padding: 1px 4px; border-radius: 3px; }

/* "Find your precinct": one line that opens the search form. */
.find { display: flex; flex-direction: column; gap: 6px; }
.find-toggle {
  align-self: flex-start; font: inherit; font-size: 14px; font-weight: 600; color: var(--accent);
  background: none; border: 0; padding: 0; cursor: pointer;
}
.find-toggle::before { content: "🔍 "; }
.find-toggle::after { content: " ▾"; font-size: 11px; }
.find-toggle[aria-expanded="true"]::after { content: " ▴"; }
.find-toggle:hover { text-decoration: underline; }
.find-form { display: flex; flex-direction: column; gap: 4px; }
.find-row { display: flex; gap: 6px; }
.find-row input {
  flex: 1; min-width: 0; font: inherit; font-size: 14px; padding: 7px 8px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text);
}
.find-row button {
  font: inherit; font-size: 14px; padding: 7px 12px; border: 0; border-radius: 6px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.find-row button:disabled { opacity: 0.6; cursor: wait; }
.locate {
  align-self: flex-start; font: inherit; font-size: 13px; color: var(--accent);
  background: none; border: 0; padding: 0; cursor: pointer;
}
.locate::before { content: "📍 "; }
.locate:hover { text-decoration: underline; }
.find-msg { margin: 0; font-size: 12px; color: var(--muted); }
.find-msg:empty { display: none; }
.find-msg.error { color: #a1301f; }
.find-clear {
  font: inherit; font-size: 12px; color: var(--accent); background: none; border: 0; padding: 0;
  margin-left: 6px; cursor: pointer; text-decoration: underline;
}

/* Share and Table, floating in the map's top-right corner. */
.map-actions { display: flex; gap: 6px; }
.map-actions button {
  font: inherit; font-size: 13px; padding: 6px 10px; border: 0; border-radius: 6px; cursor: pointer;
  background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.map-actions button:hover { color: var(--accent); }
.map-actions button.done { color: #14532d; background: #e6f4ea; }

/* Table view: over the map on desktop, full screen on phones. */
.table-view {
  position: fixed; top: 0; right: 0; bottom: 0; left: 360px; z-index: 1000;
  display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line);
}
.table-view[hidden] { display: none; }
.table-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 18px 10px; border-bottom: 1px solid var(--line); }
.table-head h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0; }
.table-head .muted { margin: 2px 0 0; font-size: 12px; }
.table-actions { display: flex; align-items: center; gap: 8px; flex: none; }
#csv { font: inherit; font-size: 13px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); cursor: pointer; }
#csv:hover { border-color: var(--accent); color: var(--accent); }
.table-scroll { flex: 1; overflow: auto; }
#table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
#table th, #table td { padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: right; }
#table th:first-child, #table td:first-child { text-align: left; position: sticky; left: 0; background: var(--panel); }
#table thead th { position: sticky; top: 0; z-index: 1; background: #f3f3f0; font-weight: 600; cursor: pointer; user-select: none; }
#table thead th:first-child { z-index: 2; background: #f3f3f0; }
#table thead th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
#table thead th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
#table tbody tr { cursor: pointer; }
#table tbody tr:hover td { background: #f1f6fb; }
#table tfoot td { font-weight: 600; background: #fafaf8; position: sticky; bottom: 0; }
#table td small { color: var(--muted); margin-left: 4px; }

/* Time of the county's latest count; "new" when it changed while the page was open. */
.updated {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px;
  font-size: 13px; background: #f1f4f7; color: var(--muted);
}
.updated::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #9aa4ae; flex: none; }
.updated.new { background: #e6f4ea; color: #14532d; font-weight: 600; }
.updated.new::before { background: #1f9d55; animation: pulse 1.6s ease-out 4; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(31,157,85,.6); } 100% { box-shadow: 0 0 0 10px rgba(31,157,85,0); } }
#summary.flash { animation: flash 1.2s ease-out; }

.layer-desc { margin: -4px 0 0; font-size: 12px; color: var(--muted); }

/* Ballot progress: counted, received but not yet counted, not returned. */
.progress-text { margin: 0 0 8px; font-size: 14px; line-height: 1.45; }
.progress-text .muted { font-size: 13px; }
.progress { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: #e6e6e1; }
.seg-counted { background: #15508e; }
.seg-received { background: #8fb6dc; }
.seg-rest { background: #e6e6e1; }
.progress-key { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.progress-key i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.chart { position: relative; margin-top: 16px; }
.chart-title { font-size: 13px; font-weight: 600; margin: 0 0 4px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit.on { fill: rgba(29, 92, 143, 0.06); }
.chart-value { font-size: 11px; font-weight: 600; fill: var(--text); font-variant-numeric: tabular-nums; }
.chart-axis { font-size: 10px; fill: var(--muted); }
.chart-dow { font-size: 9px; }
.chart-tip {
  position: absolute; pointer-events: none; white-space: nowrap; padding: 4px 8px; border-radius: 5px;
  font-size: 12px; background: #1f2328; color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.how { margin-top: 18px; }
.how .bars { margin-top: 6px; }
.more { margin-top: 8px; font-size: 13px; }
.more summary { color: var(--accent); cursor: pointer; }
.more .bars { margin-top: 8px; }
.challenged { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.challenged b { color: var(--text); font-weight: 600; }

.bars { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bars li { font-size: 13px; }
.bars .row { display: flex; justify-content: space-between; gap: 8px; }
.bars .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .num { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.bars .track { height: 6px; background: #efefec; border-radius: 3px; margin-top: 3px; overflow: hidden; }
.bars .fill { height: 100%; border-radius: 3px; }
.compare-key { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.compare-key i { display: inline-block; width: 16px; height: 6px; border-radius: 3px; margin-right: 5px; vertical-align: 1px; background: #55595e; }
.compare-key i.k-wide { opacity: 0.4; }
.bars.compare { gap: 10px; }
.pair { display: grid; grid-template-columns: 52px 1fr 46px; align-items: center; gap: 6px; margin-top: 3px; }
.pair .tag { font-size: 11px; color: var(--muted); }
.pair .track { margin-top: 0; }
.pair .num { text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.pair.wide .fill { opacity: 0.4; }
.compare-totals { margin-top: 10px; font-size: 12px; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }

.status { margin-top: auto; font-size: 12px; color: var(--muted); line-height: 1.5; }
.status a { color: var(--accent); }
.about { margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line); }
.badge {
  display: inline-block; vertical-align: 3px; margin-left: 4px; padding: 1px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: #8a5a00; background: #fff4d6; border: 1px solid #f0dca8; border-radius: 4px;
}

.legend { background: #fff; padding: 8px 10px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.2); font-size: 12px; line-height: 1.5; max-width: 220px; }
.legend b { display: block; margin-bottom: 4px; }
.legend i { display: inline-block; width: 14px; height: 10px; margin-right: 6px; vertical-align: -1px; border-radius: 2px; }

/* Stacked layout for phones and portrait tablets: beside a 360px panel, the map
   would be narrow and tall, with the county a thin band in the middle. */
@media (max-width: 900px) {
  body { flex-direction: column-reverse; }
  /* Lewis County is about three times wider than tall, so a tall map on a
     phone is mostly empty space around it. */
  #map { height: clamp(260px, 72vw, 50vh); flex: none; }
  .panel { width: 100%; height: auto; flex: 1; border-right: 0; border-top: 1px solid var(--line); padding: 14px 16px; }
  /* A compact legend strip so it doesn't cover the short map. */
  .legend { max-width: calc(100vw - 24px); padding: 5px 8px; font-size: 11px; line-height: 1.4; }
  .legend b { margin-bottom: 1px; }
  .legend div { display: inline-block; margin-right: 8px; white-space: nowrap; }
  .legend i { width: 10px; height: 8px; margin-right: 4px; }
  .leaflet-control-attribution { font-size: 9px; }
  .table-view { left: 0; border-left: 0; }
}

/* Chrome focuses a precinct path on mousedown and outlines its bounding box,
   leaving a black rectangle behind after a drag. Keep keyboard focus rings. */
.leaflet-container .leaflet-interactive:focus:not(:focus-visible) { outline: none; }
