/*
 * PottyPal admin dashboard.
 *
 * Colour roles come from the validated data-viz palette: the three categorical
 * series slots clear the CVD and normal-vision floors in both light and dark
 * mode on the surfaces declared here. Charts are written against the role
 * variables, never raw hex, so the two modes swap in one place.
 *
 * Light-mode aqua (--series-3) sits at 2.74:1 against the light surface, below
 * the 3:1 bar. The relief for that is mandatory, not optional: every chart
 * ships a legend, direct end labels, and a table view, so identity is never
 * carried by colour alone.
 */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;

  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;

  --gridline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  /* Ordinal ramp for the funnel. Starts at step 250, the lightest step that
     still clears 2:1 on the light surface. */
  --ordinal-1: #86b6ef;
  --ordinal-2: #5598e7;
  --ordinal-3: #2a78d6;
  --ordinal-4: #1c5cab;

  --good: #006300;
  --critical: #d03b3b;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --surface-1: #1a1a19;
    --page: #0d0d0d;

    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;

    --gridline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;

    /* Dark ordinal ramp runs the other way and stops at step 600, the darkest
       step still clearing 2:1 on the dark surface. */
    --ordinal-1: #184f95;
    --ordinal-2: #256abf;
    --ordinal-3: #3987e5;
    --ordinal-4: #6da7ec;

    --good: #0ca30c;
    --critical: #d03b3b;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --surface-1: #1a1a19;
  --page: #0d0d0d;

  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;

  --gridline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;

  --ordinal-1: #184f95;
  --ordinal-2: #256abf;
  --ordinal-3: #3987e5;
  --ordinal-4: #6da7ec;

  --good: #0ca30c;
  --critical: #d03b3b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- Sign in ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-title { margin: 0 0 4px; font-size: 20px; }
.login-sub { margin: 0 0 24px; color: var(--text-secondary); font-size: 14px; }

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="search"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
}

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

.btn {
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  background: var(--series-1);
  color: #ffffff;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
  width: auto;
}

.btn-ghost:hover { color: var(--text-primary); }
.btn:disabled { opacity: 0.55; cursor: default; }

.error {
  margin: 14px 0 0;
  color: var(--critical);
  font-size: 14px;
}

/* ---------- Shell ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand { font-weight: 650; }

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.range-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.range-btn {
  padding: 7px 12px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  cursor: pointer;
}

.range-btn.is-active {
  background: var(--series-1);
  color: #ffffff;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 10px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  cursor: pointer;
}

.tab.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--series-1);
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
}

.status-line {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: 14px;
  min-height: 1.5em;
}

/* ---------- Stat tiles ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-label {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-value {
  margin: 0;
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.stat-meta {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

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

/* ---------- Cards & charts ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.card-title { margin: 0; font-size: 16px; }

.card-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 62ch;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

.card-grid .card { margin-bottom: 0; }

.chart { position: relative; }

.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 10px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

.empty {
  padding: 28px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Tooltip. Positioned by script; pointer-events off so it never eats a hover. */
.tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  min-width: 130px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
}

.tooltip-title {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.tooltip-row b { font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

th {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

tbody tr:hover { background: var(--gridline); }

.row-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--series-1);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-row input { flex: 1 1 260px; width: auto; }
.search-row .btn { width: auto; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.detail-item .detail-label {
  margin: 0 0 2px;
  font-size: 12px;
  color: var(--text-secondary);
}

.detail-item .detail-value { margin: 0; font-size: 14px; }

@media (max-width: 640px) {
  .card-head { flex-direction: column; }
  .topbar { align-items: flex-start; }
}
