:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --meta: #2a78d6;      /* categorical slot 1 */
  --google: #008300;    /* categorical slot 2 */
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --meta: #3987e5;
    --google: #008300;
    --good-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --meta: #3987e5;
  --good-text: #0ca30c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
.wrap { max-width: 1240px; margin: 0 auto; padding: 20px 16px 60px; }

header.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
}
header.top h1 { font-size: 22px; margin: 0; letter-spacing: .5px; }
header.top .sub { color: var(--text-secondary); font-size: 13px; }
.controls { display: flex; gap: 8px; align-items: center; }
select, input, button {
  font: inherit; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px;
}
button.primary { background: var(--meta); color: #fff; border-color: transparent; cursor: pointer; }
button { cursor: pointer; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 24px; }
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.card .label { color: var(--text-secondary); font-size: 12px; margin-bottom: 4px; }
.card .value { font-size: 24px; font-weight: 650; }
.card .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card .value .unit { font-size: 14px; color: var(--text-secondary); font-weight: 400; }
.delta-good { color: var(--good-text); }
.delta-bad { color: var(--critical); }

section { margin-bottom: 32px; }
section h2 {
  font-size: 16px; margin: 0 0 10px;
  display: flex; align-items: center; gap: 8px;
}
section h2 .tag { font-size: 11px; font-weight: 400; color: var(--muted); }

.tableWrap {
  overflow-x: auto; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 12px;
}
table { border-collapse: collapse; width: 100%; min-width: 900px; }
th, td {
  padding: 8px 10px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
th { color: var(--text-secondary); font-weight: 500; font-size: 12px; background: transparent; }
tbody tr:hover { background: color-mix(in oklab, var(--text-primary) 4%, transparent); }
tr.subtotal td { font-weight: 600; background: color-mix(in oklab, var(--text-primary) 3%, transparent); }
tr.total td { font-weight: 700; border-top: 2px solid var(--baseline); }
td.campaign { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
}
.chip::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--muted)); }
.chip.meta { --c: var(--meta); }
.chip.google { --c: var(--google); }

.bar {
  position: relative; height: 8px; width: 110px; border-radius: 4px;
  background: color-mix(in oklab, var(--text-primary) 8%, transparent);
  display: inline-block; vertical-align: middle; margin-inline-start: 8px;
}
.bar i {
  position: absolute; inset-inline-start: 0; top: 0; bottom: 0;
  border-radius: 4px; background: var(--c, var(--meta));
}
.bar i.over { background: var(--critical); }

.status { font-size: 12px; font-weight: 600; }
.status.ok::before { content: "✓ "; }
.status.warn::before { content: "◐ "; }
.status.bad::before { content: "✕ "; }
.status.ok { color: var(--good-text); }
.status.warn { color: var(--serious); }
.status.bad { color: var(--critical); }

.note {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; color: var(--text-secondary); font-size: 13px;
}
.error { border-color: var(--critical); color: var(--critical); }

footer { margin-top: 40px; color: var(--muted); font-size: 12px; text-align: center; }

/* view gate */
#gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--page);
  display: flex; align-items: center; justify-content: center;
}
.gateBox {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; max-width: 360px; width: calc(100% - 32px);
  text-align: center;
}
.gateBox h1 { font-size: 18px; margin: 0 0 8px; }
.gateBox p { color: var(--text-secondary); font-size: 13px; margin: 0 0 16px; }
.gateBox form { display: flex; gap: 8px; }
.gateBox input { flex: 1; }
.gateError { color: var(--critical); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* admin */
.formGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.field input { width: 100%; }
.drop {
  border: 2px dashed var(--baseline); border-radius: 12px;
  padding: 32px; text-align: center; color: var(--text-secondary);
  background: var(--surface-1); cursor: pointer;
}
.drop.active { border-color: var(--meta); color: var(--meta); }
#toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--text-primary); color: var(--page);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; display: none;
}
