:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series: #2a78d6;
  --series-out: #c3c2b7;
  --accent: #2a78d6;
  --danger: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series: #3987e5;
    --series-out: #4a4a46;
    --accent: #3987e5;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 24px clamp(16px, 4vw, 40px) 48px;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
  max-width: 1200px;
  margin-inline: auto;
}

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); margin: 2px 0 0; }

.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.sync { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.downloads { display: flex; gap: 14px; flex-wrap: wrap; }
@media (max-width: 720px) { .actions { align-items: flex-start; } }

input, select, button {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}
input[type='number'] { width: 64px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.6; cursor: progress; }
#sync-button { background: var(--accent); border-color: var(--accent); color: #fff; }

.filters { display: grid; gap: 12px; margin-bottom: 16px; }
fieldset { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 10px 14px 12px; margin: 0; }
legend { color: var(--ink-2); font-weight: 600; padding: 0 4px; }
.row { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
label { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.presets { display: inline-flex; gap: 4px; }
.types { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; }
.types:empty::before { content: 'No call types yet - sync first'; color: var(--muted); }

.error { color: var(--danger); background: var(--surface); border: 1px solid var(--danger); border-radius: 8px; padding: 8px 12px; }

.hero { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 12px; margin-bottom: 8px; }
@media (max-width: 720px) { .hero { grid-template-columns: 1fr; } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hero-tile .value { font-size: 48px; line-height: 1.1; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.funnel { margin: 0 0 16px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 16px; position: relative; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.legend { color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }
.key-in { background: var(--series); }
.key-out { background: var(--series-out); }
.link { color: var(--accent); }

.chart { width: 100%; min-height: 240px; }
.chart svg { display: block; width: 100%; height: 260px; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .cap { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; pointer-events: none; }
.chart .in { fill: var(--series); pointer-events: none; }
.chart .out { fill: var(--series-out); pointer-events: none; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit.active { fill: var(--grid); opacity: 0.5; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); }
th { color: var(--ink-2); font-weight: 600; }
td:not(:first-child), th:not(:first-child) { text-align: right; }

.auth-gate { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 10vh; }
.account { display: flex; align-items: center; gap: 12px; }

/* Searchable filter, after Connect's FilterSelect. */
.fs { position: relative; display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font-size: 12.5px; }
.fs.fs-active { border-color: color-mix(in srgb, var(--accent) 50%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 15%, transparent); }
.fs-trigger { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 6px 8px 6px 12px; font: inherit; color: var(--ink); cursor: pointer; border-radius: 6px; }
.fs.fs-active .fs-trigger { padding-right: 6px; }
.fs-trigger:focus-visible, .fs-clear:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); outline-offset: 0; }
.fs-label { color: var(--muted); }
.fs-summary { max-width: 220px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); }
.fs.fs-active .fs-summary { color: var(--ink); font-weight: 500; }
.fs-chevrons { width: 14px; height: 14px; flex-shrink: 0; color: var(--muted); }
.fs-clear { display: grid; place-items: center; width: 20px; height: 20px; margin-right: 4px; padding: 0; border: 0; border-radius: 4px; background: none; color: var(--muted); cursor: pointer; }
.fs-clear:hover { background: var(--grid); color: var(--ink); }
.fs-x { width: 14px; height: 14px; }
.fs-panel { position: absolute; top: calc(100% + 4px); left: -1px; z-index: 20; width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14); overflow: hidden; }
.fs-search { width: 100%; height: 36px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 0 12px; font: inherit; font-size: 13px; background: transparent; outline: none; }
.fs-list { list-style: none; margin: 0; padding: 4px; max-height: 300px; overflow-y: auto; }
.fs-option { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; cursor: pointer; color: var(--ink); }
.fs-option-active { background: var(--grid); }
.fs-option[aria-selected='true'] .fs-name { font-weight: 500; }
.fs-check { width: 16px; height: 16px; flex-shrink: 0; }
.fs-hidden { opacity: 0; }
.fs-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fs-hint { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fs-empty { padding: 20px 8px; text-align: center; color: var(--muted); }
@media (max-width: 720px) { .fs-panel { width: min(280px, calc(100vw - 48px)); } }

/* Expandable weeks */
.row-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; font: inherit; color: var(--ink); cursor: pointer; }
.row-toggle:hover { color: var(--accent); }
.row-toggle:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); outline-offset: 2px; border-radius: 3px; }
.row-caret { display: inline-block; width: 10px; color: var(--muted); transition: transform 0.15s; }
.row-caret-open { transform: rotate(90deg); }
.day-row td { background: color-mix(in srgb, var(--grid) 35%, transparent); color: var(--ink-2); }
.day-row .day-label { padding-left: 32px; }
