:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --border: #e2e0d8;
  --text: #1c2228;
  --muted: #69707a;
  --accent: #0f6e6a;
  --accent-soft: #e2f0ee;
  --open: #1d7a4a;      --open-bg: #e4f3ea;
  --closed: #a1382e;    --closed-bg: #f8e7e4;
  --waitlist: #9a6400;  --waitlist-bg: #fbf0d9;
  --seeking: #2d5c9c;   --seeking-bg: #e5edf8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 28, .05), 0 2px 8px rgba(20, 24, 28, .04);
  --font: 'General Sans', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #121417;
  --surface: #1a1d21;
  --surface-2: #22262b;
  --border: #2e3339;
  --text: #e6e8ea;
  --muted: #9aa1a9;
  --accent: #2aa39c;
  --accent-soft: #173331;
  --open: #5ccb8e;      --open-bg: #16301f;
  --closed: #f0877b;    --closed-bg: #3a1d1a;
  --waitlist: #f0bf5f;  --waitlist-bg: #3a2c10;
  --seeking: #82aef0;   --seeking-bg: #1b2a40;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 600; font-size: 16px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.live { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--open); box-shadow: 0 0 0 0 color-mix(in srgb, var(--open) 60%, transparent); animation: pulse 2s infinite; }
.live.is-error .live-dot { background: var(--closed); animation: none; }
.live.is-busy .live-dot { background: var(--seeking); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--open) 55%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.btn {
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; font-weight: 500; font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-icon { width: 34px; padding: 0; justify-content: center; }
.btn-ghost { background: transparent; }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.wrap { max-width: 1320px; margin: 0 auto; padding: 20px 24px 40px; }

[hidden] { display: none !important; }

/* Summary */
.summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px; min-height: 76px; text-align: left; cursor: pointer;
  transition: border-color .15s;
}
.stat:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.stat.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.stat b { display: block; font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums lining-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.s-open b { color: var(--open); }
.stat.s-closed b { color: var(--closed); }
.stat.s-needs b { color: var(--waitlist); }
.stat.s-needs.is-zero b { color: var(--muted); }

/* Site cards */
.sites { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.site-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px 12px; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 6px; transition: border-color .15s; min-width: 0;
}
.site-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.site-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.site-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.site-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-total { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.site-counts { display: flex; gap: 10px; font-size: 12px; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.site-counts b { font-weight: 600; }
.c-open { color: var(--open); } .c-closed { color: var(--closed); } .c-waitlist { color: var(--waitlist); } .c-seeking { color: var(--seeking); }
.site-meta { display: flex; justify-content: space-between; gap: 6px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.site-meta a { color: var(--accent); }
.site-error { font-size: 11.5px; color: var(--closed); line-height: 1.35; }
.bar { display: flex; height: 5px; border-radius: 3px; overflow: hidden; background: var(--surface-2); }
.bar i { display: block; height: 100%; }
.bar .b-open { background: var(--open); }
.bar .b-waitlist { background: var(--waitlist); opacity: .85; }
.bar .b-seeking { background: var(--seeking); opacity: .8; }
.bar .b-closed { background: var(--closed); opacity: .8; }
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--border); }
.tab {
  border: 0; background: none; padding: 8px 14px; font-weight: 600; font-size: 13px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* Filters */
.filters {
  display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)) minmax(200px, 1.7fr) minmax(130px, 1fr); gap: 12px; align-items: end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.field-actions { min-width: 0; grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
.field-actions > span { display: none; }
.actions { display: flex; gap: 6px; }
select, input[type="search"] {
  height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); min-width: 0; width: 100%;
}
select { padding-right: 28px; }

/* Panels */
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 10px; }
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.legend { display: flex; gap: 6px; }
aside.panel { position: sticky; top: 76px; }

/* Table */
.table-wrap { max-height: calc(100dvh - 330px); min-height: 320px; overflow: auto; overscroll-behavior: contain; }
table.funds { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.funds th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap;
}
.funds th:hover { color: var(--text); }
.funds th.sorted::after { content: ' ↑'; }
.funds th.sorted.desc::after { content: ' ↓'; }
.funds td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.funds tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.funds td.name a { color: var(--text); font-weight: 500; }
.funds td.name a:hover { color: var(--accent); }
.sub { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px !important; }
tr.flash td { animation: flash 2.4s ease-out; }
@keyframes flash { 0%, 30% { background: color-mix(in srgb, var(--accent) 22%, transparent); } 100% { background: transparent; } }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-open { color: var(--open); background: var(--open-bg); }
.pill-closed { color: var(--closed); background: var(--closed-bg); }
.pill-waitlist { color: var(--waitlist); background: var(--waitlist-bg); }
.pill-seeking { color: var(--seeking); background: var(--seeking-bg); }
.pill-unknown { color: var(--muted); background: var(--surface-2); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 12px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.tag-medicare { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.site { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* Changes feed */
.changes { list-style: none; margin: 0; padding: 6px 0; max-height: calc(100dvh - 330px); overflow: auto; }
.changes li { padding: 9px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.changes li:last-child { border-bottom: 0; }
.changes .c-name { font-weight: 500; }
.changes .c-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--muted); align-items: center; }
.changes .arrow { color: var(--muted); margin: 0 3px; }
.note { margin: 0; padding: 10px 16px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: 360px;
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

@media (max-width: 1080px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .field-disease { grid-column: span 2; }
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sites { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: 1fr; }
  aside.panel { position: static; }
  .table-wrap, .changes { max-height: none; }
}
@media (max-width: 760px) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sites { grid-template-columns: 1fr; }
  .actions { flex-wrap: wrap; }
  .topbar { padding: 10px 14px; }
  .brand-sub, .btn span { display: none; }
  .wrap { padding: 14px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .field-disease, .field-grow, .field-actions { grid-column: 1 / -1; }
  .actions .btn { flex: 1; justify-content: center; }
  .actions .btn span { display: inline; }
  .hide-sm, .legend { display: none; }
  .live #live-text { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar-right { width: 100%; flex-wrap: wrap; gap: 8px; }
  .live { order: 5; width: 100%; }
  .topbar-right .btn { flex: 1 1 auto; justify-content: center; }
  .topbar-right .btn-icon { flex: 0 0 auto; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.funds td.since { white-space: nowrap; }

/* Comparison + My status */
.cmp { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.cmp-match { color: var(--muted); background: var(--surface-2); }
.cmp-set_active { color: var(--open); border-color: var(--open); background: var(--open-bg); }
.cmp-set_inactive { color: var(--closed); border-color: var(--closed); background: var(--closed-bg); }
.cmp-unset { color: var(--muted); border: 1px dashed var(--border); }
.cmp-na { color: var(--muted); background: transparent; font-weight: 500; }
.my-select { height: 30px; padding: 0 24px 0 8px; font-size: 13px; width: auto; min-width: 96px; }
.my-select.v-Active { color: var(--open); font-weight: 600; }
.my-select.v-Inactive { color: var(--closed); font-weight: 600; }
.my-select.v-NA { color: var(--muted); }
.my-text { font-size: 13px; font-weight: 600; }
.my-text.v-Active { color: var(--open); } .my-text.v-Inactive { color: var(--closed); } .my-text.v-NA, .my-text.v-none { color: var(--muted); font-weight: 500; }
tr.row-needs td:first-child { box-shadow: inset 3px 0 0 var(--waitlist); }
.col-hist { width: 36px; }
.hist-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.hist-btn:hover { color: var(--accent); background: var(--surface-2); }
.small { font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn.is-unlocked { color: var(--open); border-color: color-mix(in srgb, var(--open) 50%, var(--border)); }
.bell { font-size: 11px; color: var(--muted); }

/* History view */
.history { display: grid; grid-template-columns: 1fr; gap: 16px; }
.tl { padding: 14px 16px; overflow-x: auto; }
.tl svg { display: block; }
.tl .empty { padding: 30px 0 !important; text-align: center; color: var(--muted); }
.tl-row-label { font-size: 12px; fill: var(--text); }
.tl-row-sub { font-size: 11px; fill: var(--muted); }
.tl-axis { font-size: 11px; fill: var(--muted); }
.tl-grid { stroke: var(--border); }
.seg-open { fill: var(--open); } .seg-closed { fill: var(--closed); opacity: .85; }
.seg-waitlist { fill: var(--waitlist); opacity: .9; } .seg-seeking { fill: var(--seeking); opacity: .85; }
.tl-changes { padding: 0 16px 14px; font-size: 13px; }
.tl-changes h4 { margin: 4px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tl-changes ul { margin: 0; padding: 0; list-style: none; }
.tl-changes li { padding: 6px 0; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chart-box { position: relative; height: 320px; padding: 12px 16px 16px; }

/* Modal */
.modal { border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(380px, 92vw); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(10, 14, 18, .45); }
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal p { margin: 0 0 12px; font-size: 13px; }
.modal input[type="password"] { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.form-error { color: var(--closed); margin-top: 8px !important; }

/* Manual upload */
.site-upload {
  align-self: flex-start; margin-top: 2px; font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; cursor: pointer;
}
.site-upload:hover { border-color: var(--accent); }
.site-manual { font-size: 11.5px; color: var(--muted); }
.modal-wide { width: min(520px, 94vw); }
.steps { margin: 0 0 12px; padding-left: 20px; font-size: 13px; line-height: 1.55; }
.steps li { margin-bottom: 4px; }
.steps a { color: var(--accent); }
.modal input[type="file"] { width: 100%; font-size: 13px; padding: 8px; border: 1px dashed var(--border); border-radius: 8px; background: var(--surface-2); }
