/* The status pages' shared look (dashboard/index.html, county_records.html, login.html): colors as tokens for the
   light and dark themes, the top bar, cards, tiles, badges, tables that scroll inside their card, maps with zoom
   controls, the detail panel. Every layout works from a phone (360 px) up; nothing makes the page wider than the
   screen: wide content (tables) scrolls inside its own box. */
:root {
  --bg: #f4f6f9; --panel: #ffffff; --panel-2: #f8fafc; --text: #111827; --muted: #64748b; --faint: #94a3b8;
  --line: #e5e8ee; --line-strong: #d4d9e1; --accent: #2563eb; --accent-soft: #e8efff; --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .14);
  /* listings run statuses */
  --completed: #16a34a; --warning: #d97706; --failed: #dc2626; --running: #2563eb; --queued: #94a3b8;
  --idle: #d6dce5; --unconfigured: #eef1f5;
  /* county records statuses */
  --valid: #16a34a; --expired: #d97706; --never: #b4bfcd; --no_adapter: #e6eaf0;
  --map-line: #ffffff; --map-state-line: #94a3b8;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --panel: #151b23; --panel-2: #1a212b; --text: #e6edf3; --muted: #8b98a8; --faint: #6b7787;
    --line: #262f3a; --line-strong: #344050; --accent: #5b9cff; --accent-soft: #172741; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    --completed: #2fb36a; --warning: #e5a33a; --failed: #ef5b5b; --running: #5b9cff; --queued: #5f6f84;
    --idle: #343e4c; --unconfigured: #1d242e; --valid: #2fb36a; --expired: #e5a33a; --never: #4a5566; --no_adapter: #222a35;
    --map-line: #0d1117; --map-state-line: #5b6879;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --panel: #151b23; --panel-2: #1a212b; --text: #e6edf3; --muted: #8b98a8; --faint: #6b7787;
  --line: #262f3a; --line-strong: #344050; --accent: #5b9cff; --accent-soft: #172741; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  --completed: #2fb36a; --warning: #e5a33a; --failed: #ef5b5b; --running: #5b9cff; --queued: #5f6f84;
  --idle: #343e4c; --unconfigured: #1d242e; --valid: #2fb36a; --expired: #e5a33a; --never: #4a5566; --no_adapter: #222a35;
  --map-line: #0d1117; --map-state-line: #5b6879;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 18px; line-height: 1.3; margin: 0; font-weight: 650; }
h3 { font-size: 12px; margin: 18px 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--panel) 88%, transparent);
          backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1440px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #7c3aed);
               display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 800; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs a { padding: 5px 12px; border-radius: 7px; color: var(--muted); font-weight: 550; font-size: 13px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; min-width: 0; }
.live { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--completed); box-shadow: 0 0 0 3px color-mix(in srgb, var(--completed) 22%, transparent); }
.live .dot.stale { background: var(--failed); box-shadow: 0 0 0 3px color-mix(in srgb, var(--failed) 22%, transparent); }
.account { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }

/* ---------- buttons and inputs ---------- */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--line-strong);
          border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; font-size: 13px; font-weight: 550; cursor: pointer;
          white-space: nowrap; transition: border-color .15s, background .15s, box-shadow .15s; text-decoration: none; }
.button:hover:not(:disabled) { border-color: var(--accent); text-decoration: none; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover:not(:disabled) { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.button.ghost { border-color: transparent; background: transparent; }
.button.icon { width: 34px; padding: 0; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input { height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); color: var(--text);
         font: inherit; font-size: 13px; min-width: 0; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.search { position: relative; flex: 1 1 220px; max-width: 320px; }
.search .input { width: 100%; padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }

/* ---------- page ---------- */
.page { max-width: 1440px; margin: 0 auto; padding: 22px 20px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 14px 16px 0; }
.card-head h2 { font-size: 15px; }
.card-body { padding: 14px 16px 16px; }

/* ---------- tiles (also filters) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 12px 16px;
        box-shadow: var(--shadow); text-align: left; font: inherit; color: inherit; cursor: pointer; overflow: hidden; min-width: 0;
        transition: border-color .15s, transform .15s, box-shadow .15s; }
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tile-color, var(--line-strong)); }
.tile:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.tile.active { border-color: var(--tile-color, var(--accent)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tile-color, var(--accent)) 18%, transparent); }
.tile .n { font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; line-height: 1.3; overflow: hidden; display: -webkit-box;
           -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile.static { cursor: default; }
.tile.static:hover { transform: none; border-color: var(--line); }

/* ---------- map + detail layout ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.split .side { position: sticky; top: 74px; max-height: calc(100vh - 92px); overflow: auto; }
.map-card { position: relative; padding: 12px; }
.map { position: relative; width: 100%; aspect-ratio: 975 / 610; border-radius: 10px; overflow: hidden; background: var(--panel-2); touch-action: none; }
.map svg { width: 100%; height: 100%; display: block; cursor: grab; }
.map svg:active { cursor: grabbing; }
.map path { vector-effect: non-scaling-stroke; }
.map path.area { stroke: var(--map-line); stroke-width: 1; cursor: pointer; transition: opacity .2s, filter .15s; }
.map path.area:hover { filter: brightness(.92); }
.map path.area.dim { opacity: .28; }
.map path.area.selected { stroke: var(--text); stroke-width: 2.4; }
.map path.area.inert { cursor: default; }
.map path.borders { fill: none; stroke: var(--map-state-line); stroke-width: .8; pointer-events: none; }
.map text { fill: #fff; pointer-events: none; text-anchor: middle; font-weight: 650; paint-order: stroke; stroke: rgba(0, 0, 0, .25); stroke-width: 2px; }
.map-tools { position: absolute; right: 22px; top: 22px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.map-tools .button { width: 32px; height: 32px; padding: 0; box-shadow: var(--shadow); font-size: 16px; }
.map-hint { position: absolute; left: 22px; top: 20px; z-index: 2; font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--panel) 85%, transparent);
            padding: 3px 8px; border-radius: 6px; pointer-events: none; }
/* only the state (or county) running now pulses; the waiting ones keep their color */
@keyframes pulse { 50% { opacity: .5; } }
.map path.area.running { animation: pulse 1.4s ease-in-out infinite; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 12.5px; padding: 10px 4px 2px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg); padding: 7px 10px; border-radius: 8px; font-size: 12.5px;
       line-height: 1.4; max-width: 260px; opacity: 0; transition: opacity .1s; box-shadow: var(--shadow-lg); }

/* ---------- detail panel ---------- */
.detail { padding: 18px; }
.detail .empty { color: var(--muted); text-align: center; padding: 40px 10px; }
.detail .empty svg { color: var(--faint); margin-bottom: 8px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.detail .sub { color: var(--muted); font-size: 12.5px; margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.progress { height: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; margin: 14px 0 6px; }
.progress > div { height: 100%; border-radius: 99px; transition: width .4s; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 7px 16px; margin: 14px 0 4px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 12px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.stat .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box { border-radius: 10px; padding: 10px 12px; font-size: 12.5px; margin: 12px 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.box.err { background: color-mix(in srgb, var(--failed) 10%, transparent); border: 1px solid color-mix(in srgb, var(--failed) 35%, transparent); }
.box.warn { background: color-mix(in srgb, var(--warning) 10%, transparent); border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent); }
.strip { display: flex; flex-wrap: wrap; gap: 4px; }
.strip button { width: 16px; height: 16px; border-radius: 4px; border: 0; padding: 0; cursor: pointer; }
.strip button.current { outline: 2px solid var(--text); outline-offset: 1px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; align-items: center; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600;
         white-space: nowrap; color: var(--badge-color); background: color-mix(in srgb, var(--badge-color) 13%, transparent);
         border: 1px solid color-mix(in srgb, var(--badge-color) 28%, transparent); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--badge-color); }
.badge.dim { --badge-color: var(--muted); }

/* ---------- tables (scroll inside their card) ---------- */
.table-card { margin-top: 18px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar .count { color: var(--muted); font-size: 12.5px; margin-left: auto; white-space: nowrap; }
/* the table scrolls inside its card, about a screen tall, so its header stays in view while the rows scroll */
.table-wrap { overflow: auto; max-height: calc(100vh - 150px); max-height: calc(100dvh - 150px); overscroll-behavior: contain; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
     padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.group { text-align: center; }
thead tr:first-child th { height: 37px; }
thead tr + tr th { top: 37px; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
th[data-sort]::after { content: "↕"; opacity: .3; margin-left: 4px; font-size: 11px; }
th.sorted-asc::after { content: "↑"; opacity: 1; color: var(--accent); }
th.sorted-desc::after { content: "↓"; opacity: 1; color: var(--accent); }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
td.wrap { white-space: normal; min-width: 220px; max-width: 420px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 5%, var(--panel)); }
tbody tr.selected td { background: color-mix(in srgb, var(--accent) 11%, var(--panel)); }
tbody tr:last-child td { border-bottom: 0; }
/* the first column stays in view while the table scrolls sideways */
.pin-first th:first-child, .pin-first td:first-child { position: sticky; left: 0; z-index: 1; background: var(--panel); }
.pin-first th:first-child { z-index: 3; background: var(--panel-2); }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; cursor: default; }
.mini-table { width: 100%; margin-top: 4px; }
.mini-table th { position: static; background: none; padding: 6px 6px; }
.mini-table td { padding: 6px 6px; }
.mini-table th:first-child, .mini-table td:first-child { padding-left: 0; }
.mini-table tbody tr { cursor: default; }
.mini-table tbody tr:hover td { background: none; }
.scroll-x { overflow-x: auto; }

/* ---------- popover (run calendar) ---------- */
.picker { position: relative; }
.popover { position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; width: 340px; max-width: calc(100vw - 24px); background: var(--panel);
           border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow-lg); color: var(--text); }
.popover[hidden] { display: none; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 650; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
.cal-grid .dow { color: var(--muted); font-size: 11px; padding: 2px 0; }
.cal-day { border-radius: 8px; padding: 5px 0 4px; min-height: 40px; font-size: 12.5px; border: 1px solid transparent; }
.cal-day.runs { cursor: pointer; background: var(--panel-2); }
.cal-day.runs:hover { border-color: var(--line-strong); }
.cal-day.chosen { border-color: var(--accent); }
.cal-day.today .n { font-weight: 800; color: var(--accent); }
.cal-day .dots { display: flex; justify-content: center; flex-wrap: wrap; gap: 2px; margin-top: 3px; padding: 0 3px; }
.cal-day .dots i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.run-list { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; max-height: 260px; overflow-y: auto; }
.run-item { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center; padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 12.5px; }
.run-item:hover { background: var(--panel-2); }
.run-item.current { background: var(--accent-soft); }
.run-item .when { font-weight: 650; font-variant-numeric: tabular-nums; }
.run-item .sub { grid-column: 2 / 4; color: var(--muted); font-size: 11.5px; }
.link-button { margin-top: 8px; font: inherit; font-size: 12.5px; background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px;
         border-radius: 10px; font-size: 13px; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--failed); color: #fff; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px;
              background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 30px 26px; }
.login-card .brand { margin-bottom: 20px; }
.login-card label { display: block; font-size: 13px; margin: 14px 0 6px; color: var(--muted); font-weight: 550; }
.login-card .input { width: 100%; height: 40px; }
.login-card .button { width: 100%; height: 40px; margin-top: 22px; }
.login-card .error { color: var(--failed); font-size: 13px; margin-top: 12px; }
.login-card .error:empty { display: none; }

/* ---------- smaller screens ---------- */
@media (max-width: 1100px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .split .side { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .topbar-inner { padding: 8px 12px; gap: 8px 10px; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .account { max-width: 140px; }
  .live #updated { display: none; }
  .page { padding: 16px 12px 40px; }
  h1 { font-size: 19px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile .n { font-size: 22px; }
  .map-card { padding: 8px; }
  .map-tools { right: 14px; top: 14px; }
  .map-hint { display: none; }
  .detail { padding: 14px; }
  .search { max-width: none; flex-basis: 100%; }
  .toolbar .count { margin-left: 0; }
  .table-wrap { max-height: calc(100dvh - 120px); }
}
