/* ---- Design tokens (light default, dark via OS or data-theme) ---- */
:root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --hairline:       #e1e0d9;
  --border:         rgba(11, 11, 11, 0.10);
  --accent:         #2a78d6;   /* series blue */
  --accent-soft:    #86b6ef;   /* sequential step 250 — sparkline de-emphasis */
  --delta-good:     #006300;
  --delta-bad:      #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --hairline:       #2c2c2a;
    --border:         rgba(255, 255, 255, 0.10);
    --accent:         #3987e5;
    --accent-soft:    #1c5cab;
    --delta-good:     #0ca30c;
    --delta-bad:      #d03b3b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface-1:      #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --hairline:       #2c2c2a;
  --border:         rgba(255, 255, 255, 0.10);
  --accent:         #3987e5;
  --accent-soft:    #1c5cab;
  --delta-good:     #0ca30c;
  --delta-bad:      #d03b3b;
}

/* ---- Base ---- */
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.wrap { max-width: 1160px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---- Header ---- */
header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-bottom: 16px; margin-bottom: 20px;
  border-bottom: 1px solid var(--hairline);
}
header h1 { font-size: 20px; font-weight: 650; margin: 0; }
header .sub { color: var(--text-muted); font-size: 13px; }
.spacer { flex: 1; }

select#range {
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font: inherit; font-size: 14px;
}
button.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 16px; font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }
button.ghost {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.status { color: var(--text-muted); font-size: 13px; }
button.icon-only, a.ghost.icon-only {
  padding: 7px 10px; line-height: 1;
  display: inline-flex; align-items: center; text-decoration: none;
}
button.ghost.active {
  background: var(--accent); border-color: var(--accent);
}
button.ghost.active .fa-solid { color: #fff; }

/* Demo mode: a quiet, always-visible reminder that data is fake. */
body.demo-mode header h1::after {
  content: "demo data";
  margin-left: 10px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 600; vertical-align: middle;
}

/* ---- Login ---- */
body.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-box {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { font-size: 30px; color: var(--accent); }
.login-brand .fa-solid { color: var(--accent); }
.login-box h1 { margin: 0; font-size: 20px; font-weight: 650; }
.login-box .sub { margin: -10px 0 6px; color: var(--text-muted); font-size: 13px; }
.login-box label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-secondary); }
.login-box input {
  background: var(--page); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font: inherit; font-size: 15px;
}
.login-box input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-box button { margin-top: 6px; }

/* ---- Messages ---- */
.notice {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; margin: 16px 0;
  color: var(--text-secondary); max-width: 640px;
}
.notice code {
  background: var(--page); border: 1px solid var(--hairline);
  border-radius: 4px; padding: 1px 5px; font-size: 13px;
}
.error-banner {
  border-left: 3px solid var(--delta-bad);
  background: var(--surface-1); border-radius: 8px;
  padding: 12px 16px; margin: 12px 0; color: var(--text-secondary); font-size: 14px;
}
.warn-banner {
  border-left: 3px solid #fab219;
  background: var(--surface-1); border-radius: 8px;
  padding: 12px 16px; margin: 12px 0; color: var(--text-secondary); font-size: 14px;
}
.hidden { display: none !important; }

/* ---- Summary panel ---- */
.summary {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px 22px; margin-bottom: 24px;
}
.summary-head {
  display: flex; align-items: flex-start; gap: 32px; flex-wrap: wrap;
  padding-bottom: 18px; border-bottom: 1px solid var(--hairline);
}
/* Fixed width so the KPI grid never moves as the day's numbers change size. */
.hero { flex: 0 0 250px; }
.hero .label { color: var(--text-secondary); font-size: 14px; }
.hero .value { font-size: 54px; font-weight: 650; line-height: 1.05; }
#hero-delta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 2px; }
.delta { font-size: 13px; color: var(--text-muted); }

.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 22px; flex: 1; min-width: 260px; padding-top: 4px;
}
.kpi .label { color: var(--text-muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 650; line-height: 1.2; }
.kpi .sub, .kpi .delta { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.delta.up   { color: var(--delta-good); }
.delta.down { color: var(--delta-bad); }

/* ---- Day walker ---- */
.day-nav {
  display: flex; align-items: center; gap: 8px;
  padding-bottom: 14px;
}
.day-nav .day-label {
  font-size: 15px; font-weight: 650; margin-left: 4px;
  font-variant-numeric: tabular-nums;
}
.day-nav button.ghost:disabled {
  opacity: 0.35; cursor: default;
}
#day-today { margin-left: auto; }
.invisible { visibility: hidden; }

/* 30-day clickable column chart */
#daychart { padding: 18px 0 2px; }
.dchart { position: relative; }
.dcols {
  display: grid; grid-template-columns: repeat(30, 1fr); gap: 2px;
  align-items: end; height: 76px;
  border-bottom: 1px solid var(--hairline);
}
.dcol {
  background: none; border: 0; padding: 0; margin: 0;
  height: 100%; display: flex; align-items: flex-end; justify-content: center;
  cursor: pointer; border-radius: 4px 4px 0 0;
}
.dcol:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dcol:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.dbar {
  width: min(22px, 82%);
  background: var(--accent-soft);
  border-radius: 4px 4px 0 0;
}
.dbar.zerobar { background: var(--hairline); border-radius: 0; }
.dcol:hover .dbar { filter: brightness(1.12); }
.dcol.sel .dbar { background: var(--accent); }
.dticks {
  display: grid; grid-template-columns: repeat(30, 1fr); gap: 2px;
  padding-top: 5px; margin-bottom: 2px;
  font-size: 10.5px; color: var(--text-muted);
}
.dticks div { text-align: center; white-space: nowrap; }

/* Chart tooltip — value leads, label follows */
.dtip {
  position: absolute; top: -10px; transform: translate(-50%, -100%);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  pointer-events: none; white-space: nowrap; z-index: 5;
  display: none;
}
.dtip.show { display: block; }
.dtip-value { font-size: 14px; font-weight: 650; }
.dtip-sub   { font-size: 12px; color: var(--text-secondary); }
.dtip-date  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Collapsible leaderboard */
.lb-wrap > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  padding-top: 14px; font-size: 14px; color: var(--text-secondary);
}
.lb-wrap > summary::-webkit-details-marker { display: none; }
.lb-wrap > summary:hover { color: var(--text-primary); }
.lb-wrap > summary .chev {
  font-size: 11px; color: var(--text-muted);
  transition: transform 0.15s ease;
}
.lb-wrap[open] > summary .chev { transform: rotate(90deg); }
.lb-count { margin-left: auto; color: var(--text-muted); font-size: 12px; }

/* Ranked bars — views today */
.leaderboard { padding-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.lrow {
  display: grid; grid-template-columns: minmax(90px, 150px) 1fr 56px;
  align-items: center; gap: 12px;
}
.lname {
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ltrack { height: 14px; display: flex; align-items: center; }
.lbar {
  height: 14px; background: var(--accent);
  border-radius: 0 4px 4px 0; min-width: 3px;
}
.lbar.livebar { background: var(--accent); box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 3px #0ca30c; }
.lval {
  text-align: right; font-size: 13px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.lrow.zero .lname, .lrow.zero .lval { color: var(--text-muted); font-weight: 400; }
.lrow.zero .lbar { min-width: 0; }
.lrow.zero .ltrack { border-bottom: 1px solid var(--hairline); }
.quiet { color: var(--text-muted); font-size: 12px; margin: 8px 0 0; }

/* ---- Icons ---- */
.fa-solid { color: var(--text-muted); }
h1 .fa-solid { color: var(--accent); }
.kpi .label .fa-solid, .hero .label .fa-solid { font-size: 12px; }
.ptable tbody th .fa-solid { width: 13px; text-align: center; margin-right: 2px; }
.error-banner .fa-solid { color: var(--delta-bad); }
.warn-banner .fa-solid { color: #fab219; }
.card.err .foot .fa-solid { color: var(--delta-bad); }
button.ghost .fa-solid { font-size: 12px; }
.syncing .fa-rotate { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Site cards ---- */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px 18px 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.card .site { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.card .site .name {
  font-size: 16px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: inherit; text-decoration: none;
}
a.name:hover { text-decoration: underline; }
.galink {
  color: var(--text-muted); text-decoration: none; font-size: 15px;
  flex-shrink: 0; line-height: 1;
}
.galink:hover { color: var(--accent); }
.card .site .live {
  margin-left: auto; flex-shrink: 0; white-space: nowrap;
  color: var(--text-muted); font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}
.card .site .live .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted); opacity: 0.5;
}
.card .site .live.on { color: var(--text-secondary); }
.card .site .live.on .dot { background: #0ca30c; opacity: 1; }

table.ptable { border-collapse: collapse; width: 100%; font-size: 13px; }
.ptable th, .ptable td {
  text-align: right; padding: 4px 6px;
  font-variant-numeric: tabular-nums; font-weight: 400;
}
.ptable thead th { color: var(--text-muted); font-size: 12px; border-bottom: 1px solid var(--hairline); }
.ptable tbody th { text-align: left; color: var(--text-muted); font-size: 12px; padding-left: 0; }
.ptable td { color: var(--text-primary); }
.ptable tbody td:first-of-type { font-weight: 600; }

.spark { margin-top: 2px; }
.spark svg { display: block; width: 100%; height: 44px; }
.card .foot { color: var(--text-muted); font-size: 12px; }
.card.err .foot { color: var(--delta-bad); }

.skeleton {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; height: 168px; opacity: 0.55;
  animation: pulse 1.2s ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: 0.35; } to { opacity: 0.65; } }

/* ---- Table view (accessibility fallback) ---- */
details.tableview { margin-top: 28px; color: var(--text-secondary); }
details.tableview summary { cursor: pointer; font-size: 14px; }
table { border-collapse: collapse; margin-top: 12px; width: 100%; font-size: 14px; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--hairline); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-muted); font-weight: 600; }

/* Rescan button: the dish "pings" while scanning. */
.syncing .fa-satellite-dish { animation: ping 1s ease-in-out infinite; }
@keyframes ping {
  0%, 100% { transform: scale(1);    opacity: 1; }
  50%      { transform: scale(1.15); opacity: 0.6; }
}

button.linklike {
  background: none; border: 0; padding: 0; font: inherit;
  color: var(--accent); text-decoration: underline; cursor: pointer;
}
