/* Traffic Tracker — committed dark theme */
:root {
  color-scheme: dark;
  --page: #0a0f17;
  --surface: #121926;
  --surface-2: #1a2333;
  --border: rgba(146, 178, 230, 0.12);
  --ink: #f2f6fc;
  --ink-2: #bac6d8;
  --muted: #7e8ba0;
  --grid: #1f2937;
  --accent: #4d9bf5;
  --accent-soft: rgba(77, 155, 245, 0.14);
  --good: #2fbf58;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e05252;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; color: var(--ink); }
body {
  background:
    radial-gradient(900px 420px at 15% -10%, rgba(77, 155, 245, 0.08), transparent 60%),
    radial-gradient(800px 400px at 95% 0%, rgba(93, 82, 224, 0.06), transparent 55%),
    var(--page);
  background-attachment: fixed;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 20px; }
h2 { font-size: 15px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }

/* ---- shell ---- */
.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 0 28px; height: 58px;
  background: rgba(16, 22, 33, 0.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 8px 14px; border-radius: 8px; font-size: 13.5px; color: var(--ink-2);
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a .pill {
  background: var(--critical); color: #fff; border-radius: 99px;
  font-size: 10.5px; padding: 1px 7px; margin-left: 6px; font-weight: 700;
}
.topbar .spacer { flex: 1; }
.syncbox { display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: var(--muted); }
.scan-times { display: flex; flex-direction: column; line-height: 1.45; font-size: 11.5px; white-space: nowrap; }
.btn {
  background: linear-gradient(180deg, #55a3f7, #3d88e0); color: #fff; border: none; border-radius: 8px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
  box-shadow: 0 2px 8px rgba(61, 136, 224, 0.35);
}
.btn:hover { filter: brightness(1.1); }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); box-shadow: none; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 26px 28px 60px; }
.pagehead { display: flex; align-items: baseline; gap: 14px; margin-bottom: 20px; }
.pagehead .sub { color: var(--muted); font-size: 13px; }

/* ---- cards & tiles ---- */
.card {
  background: linear-gradient(180deg, #141d2c 0%, #111826 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  overflow-x: auto;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px rgba(3, 8, 18, 0.35);
}
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px; }
@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .tiles { grid-template-columns: 1fr; } }
.tile {
  background: linear-gradient(180deg, #151f30 0%, #111826 100%);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 6px 18px rgba(3, 8, 18, 0.3);
  display: block; color: inherit;
}
a.tile { cursor: pointer; transition: border-color 0.15s, transform 0.15s, background 0.15s, box-shadow 0.15s; }
a.tile:hover {
  background: linear-gradient(180deg, #1e2c44 0%, #17223a 100%);
  border-color: rgba(77, 155, 245, 0.55);
  transform: translateY(-2px);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset, 0 10px 26px rgba(20, 60, 130, 0.35);
}
.tile .label { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.tile .delta { font-size: 12.5px; margin-top: 3px; font-weight: 600; }
.tile.accent .value { color: var(--accent); }
.tile.good .value { color: var(--good); }
.tile.serious .value { color: var(--serious); }
.tile.critical .value { color: var(--critical); }

.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---- charts ---- */
.chartbox { position: relative; height: 300px; margin-top: 12px; }
.chartbox.tall { height: 340px; }
.rangebtns { display: flex; gap: 6px; }
.rangebtns button {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 7px; padding: 4px 11px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.rangebtns button.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.cardhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; color: var(--muted); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap; user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--ink-2); }
th .arrow { font-size: 9px; margin-left: 3px; }
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.025); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.sitelink { font-weight: 600; color: var(--ink); }
.sitelink:hover { color: var(--accent); }
.subtext { color: var(--muted); font-size: 11.5px; }

/* status badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.good { color: var(--good); background: rgba(47, 191, 88, 0.12); }
.badge.accent { color: var(--accent); background: var(--accent-soft); }
.badge.serious { color: var(--serious); background: rgba(236, 131, 90, 0.12); }
.badge.critical { color: var(--critical); background: rgba(224, 82, 82, 0.14); }
.badge.muted { color: var(--muted); }

.delta-up { color: var(--good); font-weight: 600; }
.delta-down { color: var(--critical); font-weight: 600; }
.delta-flat { color: var(--muted); }

/* dead view: hide the Today column (dead sites have no clicks today) */
#sites-table.dead-view .col-today { display: none; }

/* sparklines */
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.spark.flat polyline { stroke: var(--muted); }
.spark.bad polyline { stroke: var(--critical); }

/* ---- filters ---- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filters input[type="search"], .filters select {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; font-family: inherit; outline: none;
}
.filters input[type="search"] { width: 260px; }
.filters input:focus, .filters select:focus { border-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: transparent; color: var(--ink-2);
  border-radius: 99px; padding: 5px 13px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.count-note { color: var(--muted); font-size: 12.5px; margin-left: auto; }

/* ---- alerts ---- */
.alert-item {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 0;
  border-bottom: 1px solid var(--grid); font-size: 13.5px;
}
.alert-item input[type="checkbox"], .alerts-toolbar input[type="checkbox"] {
  width: 15px; height: 15px; margin-top: 3px; accent-color: var(--accent); cursor: pointer;
}
.alerts-toolbar {
  display: flex; align-items: center; gap: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.alerts-toolbar .selectall { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.alerts-toolbar .btn { margin-left: auto; background: linear-gradient(180deg, #e05252, #c43d3d); box-shadow: 0 2px 8px rgba(224,82,82,0.3); }
.alerts-toolbar .btn[disabled] { opacity: 0.4; }
.alert-item:last-child { border-bottom: none; }
.alert-icon { font-size: 15px; line-height: 1.3; }
.alert-item .when { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.empty { color: var(--muted); font-size: 13.5px; padding: 18px 0; text-align: center; }

/* ---- forms ---- */
.formrow { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.formrow input {
  background: var(--page); border: 1px solid var(--border); color: var(--ink);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; font-family: inherit;
}
.formrow input:focus { border-color: var(--accent); outline: none; }
.notice {
  background: var(--accent-soft); border: 1px solid rgba(57, 135, 229, 0.35); color: var(--accent);
  padding: 10px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
}
code.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--ink-2); }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 34px 34px 28px; width: 340px; box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.login-card label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 14px; }
.login-card input {
  display: block; width: 100%; margin-top: 6px;
  background: var(--page); border: 1px solid var(--border); color: var(--ink);
  border-radius: 8px; padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.login-card input:focus { border-color: var(--accent); outline: none; }
.login-error {
  background: rgba(208,59,59,0.14); border: 1px solid rgba(208,59,59,0.4); color: #ff8a8a;
  border-radius: 8px; padding: 9px 13px; font-size: 12.5px; margin-bottom: 14px;
}

/* sync progress */
#sync-progress { display: none; align-items: center; gap: 8px; }
#sync-progress .bar { width: 120px; height: 5px; background: var(--grid); border-radius: 99px; overflow: hidden; }
#sync-progress .bar i { display: block; height: 100%; background: var(--accent); width: 0%; transition: width 0.6s; }
