/* ots.gg stats -- dashboard styling.
 *
 * Colour tokens follow the `dataviz` skill's validated default palette (categorical hues
 * pass the CVD/contrast checks in both modes; see the skill's references/palette.md for
 * the underlying numbers). Light is the default; dark is picked up from
 * prefers-color-scheme, since this dashboard has no theme toggle of its own -- an admin's
 * OS setting is the only signal available, and honouring it is enough for an internal tool
 * with a handful of users.
 *
 * Every colour is a custom property, read here AND by public/dashboard.js (Chart.js
 * cannot read CSS variables itself, so dashboard.js resolves them once via
 * getComputedStyle and passes the resolved hex into the chart config).
 */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success: #006300;
  --danger: #d03b3b;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */

  --focus-ring: #2a78d6;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --success: #0ca30c;
    --danger: #e66767;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;

    --focus-ring: #3987e5;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  /* No page-level horizontal scroll at any width -- wide content (tables) scrolls inside
     its own container instead (.table-scroll below). */
  overflow-x: hidden;
}

a { color: var(--series-1); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.topnav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 4px;
  padding: 10px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.topnav a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
}
.topnav a[aria-current="page"] { color: var(--text-primary); background: var(--gridline); }
.logout-form { margin-left: auto; }
.logout-form button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font: inherit;
}

.page { max-width: 1080px; margin: 0 auto; padding: 16px; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin: 0 0 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; color: var(--text-primary); }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 0 0 16px;
}
.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}
.filter-bar input, .filter-bar select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-primary);
}
.filter-bar button {
  font: inherit;
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  background: var(--series-1);
  color: #fff;
  cursor: pointer;
}
.presets { display: flex; gap: 6px; }
.presets a {
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
}
.filter-note {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface-1);
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  font-size: 13px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}
.kpi-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kpi-label { font-size: 12px; color: var(--text-muted); }

.chart-wrap { position: relative; height: 280px; margin: 0 0 16px; }

.table-block { margin: 0; }
.csv-link {
  display: inline-block;
  margin: 0 0 8px;
  font-size: 13px;
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
/* The mobile-friendliness requirement: a wide table scrolls INSIDE this box, never the
   page. -webkit-overflow-scrolling keeps momentum scrolling smooth on iOS Safari. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 8px;
}
table { border-collapse: collapse; width: 100%; min-width: 480px; font-size: 13px; }
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
th { color: var(--text-secondary); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: none; }
.empty { color: var(--text-muted); font-size: 13px; padding: 8px 0; }

.auth-card {
  max-width: 360px;
  margin: 48px auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-card h1 { font-size: 18px; margin: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.auth-card input {
  font: inherit;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-primary);
}
.auth-card button {
  font: inherit;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--series-1);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface-1));
  color: var(--danger);
  font-size: 13px;
}
.qr-wrap { align-self: center; background: #fff; padding: 12px; border-radius: 8px; }
.qr-wrap svg { display: block; width: 200px; height: 200px; }
.secret-text { font-size: 12px; color: var(--text-secondary); word-break: break-all; }
.secret-text code { font-family: ui-monospace, monospace; }

@media (max-width: 480px) {
  .page { padding: 12px; }
  .auth-card { margin: 24px auto; padding: 18px; }
  .kpi-value { font-size: 22px; }
}
