/* Khel Ghar admin panel.
   Two themes from one set of tokens: :root is dark, and [data-theme="light"]
   overrides it. Colours belong in the tokens, never in the rules below. */

:root {
  color-scheme: dark;
  --bg: #0e0b1f;
  --surface: #18142f;
  --surface-2: #231d42;
  --border: #2f2856;
  --text: #f1eefc;
  --muted: #a9a2c9;
  --primary: #6a58c9;
  --primary-soft: rgba(143, 127, 245, 0.16);
  --gold: #f5c542;
  --gold-ink: #f5c542;
  --accent-ink: #cfc6ff;
  --nav-active-ink: #fff;
  --page-glow: #221a4a;
  --gate-glow: #2a2058;
  --topbar-bg: rgba(14, 11, 31, 0.86);
  --hover-border: #453c7a;
  --col-hover: rgba(255, 255, 255, 0.05);
  --tip-bg: #fff;
  --tip-ink: #17132e;
  --shadow: rgba(0, 0, 0, 0.45);
  --up-ink: #4ade80;
  --on-ink: #7ee2a8;
  --warn-ink: #fbbf24;
  --danger-ink: #fca5a5;
  --info-ink: #7dd3fc;
  --banner-warn-ink: #fcd34d;
  --banner-info-ink: #bae6fd;
  --toast-ok-ink: #86efac;

  /* Charts. Checked against --surface with the palette validator: one colour
     for single-series marks, one ordered ramp for "last seen". */
  --viz-1: #8f7ff5;
  --viz-grid: #2a2450;
  --viz-axis: #3a3266;
  --viz-seg-0: #c4bbfa;
  --viz-seg-1: #a596f7;
  --viz-seg-2: #8675e8;
  --viz-seg-3: #6a58c9;
  --viz-seg-4: #4d3f9a;
  --viz-seg-0-ink: #0b0b0b;
  --viz-seg-1-ink: #0b0b0b;
  --viz-seg-2-ink: #0b0b0b;
  --viz-seg-3-ink: #fff;
  --viz-seg-4-ink: #fff;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 14px;
  --radius-sm: 8px;
  --sidebar: 232px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #f0eef9;
  --border: #e3e0f0;
  --text: #1c1836;
  --muted: #5f5a7a;
  --primary: #5b49bd;
  --primary-soft: rgba(106, 88, 201, 0.12);
  --success: #15803d;
  --warning: #b45309;
  --danger: #dc2626;
  --info: #0369a1;
  --gold-ink: #92620a;
  --accent-ink: #4d3f9a;
  --nav-active-ink: #352a73;
  --page-glow: #e8e3fb;
  --gate-glow: #e0daf9;
  --topbar-bg: rgba(246, 245, 251, 0.86);
  --hover-border: #c6c0e0;
  --col-hover: rgba(53, 42, 115, 0.06);
  --tip-bg: #1c1836;
  --tip-ink: #fff;
  --shadow: rgba(53, 42, 115, 0.18);
  --up-ink: #15803d;
  --on-ink: #166534;
  --warn-ink: #92400e;
  --danger-ink: #b91c1c;
  --info-ink: #075985;
  --banner-warn-ink: #92400e;
  --banner-info-ink: #075985;
  --toast-ok-ink: #166534;

  /* Charts. Checked against #ffffff with the palette validator. */
  --viz-1: #6a58c9;
  --viz-grid: #ecebf4;
  --viz-axis: #c6c0e0;
  --viz-seg-0: #a596f7;
  --viz-seg-1: #8675e8;
  --viz-seg-2: #6a58c9;
  --viz-seg-3: #4d3f9a;
  --viz-seg-4: #352a73;
  --viz-seg-2-ink: #fff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1100px 460px at 72% -8%, var(--page-glow) 0%, transparent 70%) no-repeat, var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.ok { color: var(--success); }
.warn { color: var(--warning); }

/* ───────────────────────────── sign in ───────────────────────────── */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(900px 500px at 50% -10%, var(--gate-glow) 0%, var(--bg) 60%);
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
}

.gate-mark { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto; }
.gate-card h1 { font-size: 20px; margin: 10px 0 6px; }
.gate-card p { margin: 0 0 20px; font-size: 13px; }
.gate-foot { margin-top: 18px !important; font-size: 12px; }

/* The "you are not an admin yet" instructions, which have to be readable
   enough that somebody can follow them without leaving the page. */
.gate .error {
  text-align: left;
  font-size: 13px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 18px !important;
}
.gate-howto { margin-top: 10px; color: var(--text); }
.gate-howto p { margin: 0 0 8px !important; font-size: 12.5px; }
.gate-table { width: 100%; font-size: 12px; margin-bottom: 8px; }
.gate-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); }
.gate-table td:first-child { width: 68px; color: var(--muted); }
.gate-table code { word-break: break-all; }

.g-mark {
  display: inline-grid;
  place-items: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  color: #4285f4;
  font-weight: 800;
  margin-right: 8px;
}

/* ───────────────────────────── shell ───────────────────────────── */

.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; }
.brand-text { font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--gold-ink); font-weight: 600; letter-spacing: 0.04em; }

.nav-group {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 12px 6px;
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--nav-active-ink);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--gold);
}
.nav-item.active .nav-icon { color: var(--gold-ink); }
.nav-icon { display: inline-flex; flex-shrink: 0; }
.icon { display: block; flex-shrink: 0; }
.btn.only-phone { display: none; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; }
.whoami { font-size: 12px; color: var(--muted); padding: 0 8px 10px; word-break: break-all; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.topbar h2 { font-size: 19px; }
.topbar p { font-size: 12px; margin: 2px 0 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(148, 155, 171, 0.15);
}
.live-dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15); }
.live-dot.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15); }

.page { padding: 24px 28px 64px; max-width: 1480px; width: 100%; }

/* ───────────────────────────── pieces ───────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  overflow-x: auto;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card, .dash-main > .card + .card { margin-top: 0; }
.card h3 { font-size: 15px; margin-bottom: 4px; }
.card-sub { font-size: 12px; color: var(--muted); margin: 0 0 14px; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-icon {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--accent-ink);
  flex-shrink: 0;
}
.stat-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.stat-value { font-size: 30px; line-height: 1.2; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; color: var(--text); }
.delta.up { color: var(--up-ink); }
.delta.down { color: var(--danger-ink); }
.stat-note { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-note.up { color: var(--success); }
.stat.clickable { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.stat.clickable:hover,
.stat.clickable:focus-visible { border-color: var(--primary); background: var(--primary-soft); outline: none; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}
.pill.on { background: rgba(34, 197, 94, 0.15); color: var(--on-ink); }
.pill.off { background: rgba(148, 155, 171, 0.12); color: var(--muted); }
.pill.warn { background: rgba(245, 158, 11, 0.15); color: var(--warn-ink); }
.pill.danger { background: rgba(239, 68, 68, 0.15); color: var(--danger-ink); }
.pill.info { background: rgba(56, 189, 248, 0.15); color: var(--info-ink); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--hover-border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.4); color: var(--danger-ink); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-wide { width: 100%; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 84px; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.help { font-size: 12px; color: var(--muted); margin-top: 6px; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: auto; }

.search-row { display: flex; gap: 10px; margin-bottom: 16px; }
.search-row input { flex: 1; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-mark { font-size: 32px; display: block; margin-bottom: 10px; }

/* ───────────────────────────── charts ───────────────────────────── */

.dash-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; margin-top: 14px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.range { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--bg); border: 1px solid var(--border); flex-shrink: 0; }
.range button {
  border: 0; background: transparent; color: var(--muted); font: inherit;
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 6px; cursor: pointer;
}
.range button:hover { color: var(--text); }
.range button.active { background: var(--surface-2); color: var(--text); }

.spark polyline { fill: none; stroke: var(--viz-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark circle { fill: var(--viz-1); stroke: var(--surface); stroke-width: 2; }
.spark { flex-shrink: 0; }

.rank { display: flex; flex-direction: column; gap: 2px; }
.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 42%) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border-radius: 6px;
}
.rank-row:hover, .rank-row:focus-visible { background: var(--surface-2); outline: none; }
.rank-label { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-track { height: 10px; }
.rank-fill { height: 100%; background: var(--viz-1); border-radius: 0 4px 4px 0; }
.rank-value { min-width: 28px; text-align: right; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.seg { display: flex; gap: 2px; height: 28px; margin-top: 4px; }
.seg-part {
  display: flex; align-items: center; min-width: 3px;
  border-radius: 4px; font-size: 12px; font-weight: 700; overflow: hidden;
}
/* Padding only where there is a label: it would widen a small part past its true share. */
.seg-part.labelled { padding: 0 7px; }
.seg-part:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.seg-0 { background: var(--viz-seg-0); color: var(--viz-seg-0-ink); }
.seg-1 { background: var(--viz-seg-1); color: var(--viz-seg-1-ink); }
.seg-2 { background: var(--viz-seg-2); color: var(--viz-seg-2-ink); }
.seg-3 { background: var(--viz-seg-3); color: var(--viz-seg-3-ink); }
.seg-4 { background: var(--viz-seg-4); color: var(--viz-seg-4-ink); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; }

.cols {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 210px auto;
  column-gap: 10px;
  margin-top: 24px; /* room for the label above the tallest column */
}
.cols-y {
  display: flex; flex-direction: column; justify-content: space-between;
  font-size: 11px; color: var(--muted); text-align: right;
  font-variant-numeric: tabular-nums;
  margin: -7px 0;
}
.cols-plot { position: relative; }
.cols-grid { position: absolute; left: 0; right: 0; height: 1px; background: var(--viz-grid); }
.cols-grid:first-child { background: var(--viz-axis); }
.cols-bars { position: absolute; inset: 0; display: flex; gap: 2px; }
.cols.dense .cols-bars { gap: 1px; }
.col {
  flex: 1 1 0; min-width: 0; height: 100%;
  display: flex; align-items: flex-end; justify-content: center;
  border-radius: 4px 4px 0 0;
}
.col:hover, .col:focus-visible { background: var(--col-hover); outline: none; }
.col-bar {
  position: relative; width: 100%; max-width: 24px; min-height: 3px;
  background: var(--viz-1); border-radius: 4px 4px 0 0;
}
.cols.dense .col-bar { border-radius: 2px 2px 0 0; }
.col-peak {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  padding-bottom: 3px; font-size: 12px; font-weight: 700; color: var(--text); white-space: nowrap;
}
.cols-x {
  grid-column: 2; display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted); padding-top: 8px;
}

.viz-tip {
  position: fixed; z-index: 60; pointer-events: none;
  max-width: 260px; padding: 6px 10px; border-radius: 8px;
  background: var(--tip-bg); color: var(--tip-ink); font-size: 12px; font-weight: 600;
  box-shadow: 0 6px 22px var(--shadow);
}
.viz-table { margin-top: 12px; font-size: 12px; }
.viz-table summary { cursor: pointer; color: var(--muted); }
.viz-table summary:hover { color: var(--text); }
.viz-table table { margin-top: 8px; }
.viz-table td, .viz-table th { padding: 6px 8px; }

.facts { margin-top: 14px; border-top: 1px solid var(--border); }
.fact { display: flex; align-items: center; gap: 9px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.fact:last-child { border-bottom: 0; padding-bottom: 0; }
.fact-icon { color: var(--muted); }
.fact-label { flex: 1; color: var(--muted); }
.fact-value { font-weight: 700; font-variant-numeric: tabular-nums; }

.player-cell { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.avatar {
  position: relative; display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--surface-2); color: var(--accent-ink); font-size: 12px; font-weight: 700;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.banner { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }
.banner-warn { background: rgba(245, 158, 11, 0.12); border: 1px solid rgba(245, 158, 11, 0.35); color: var(--banner-warn-ink); }
.banner-info { background: rgba(56, 189, 248, 0.10); border: 1px solid rgba(56, 189, 248, 0.3); color: var(--banner-info-ink); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 8px 30px var(--shadow);
}
.toast.err { border-color: rgba(239, 68, 68, 0.5); color: var(--danger-ink); }
.toast.ok { border-color: rgba(34, 197, 94, 0.5); color: var(--toast-ok-ink); }

.skeleton { color: var(--muted); padding: 28px; text-align: center; }

.detail-grid { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; font-size: 13px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; word-break: break-all; }

.back-link { background: none; border: 0; color: var(--info); cursor: pointer; font: inherit; padding: 0; margin-bottom: 14px; }

@media (max-width: 1180px) {
  .dash-main { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  /* The sidebar becomes a tab bar, where a thumb can reach it. */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    height: auto; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
    z-index: 20;
  }
  .brand, .nav-group, .sidebar-foot { display: none; }
  .nav { flex-direction: row; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex: 1 0 74px; width: auto; flex-direction: column; gap: 3px;
    padding: 7px 4px; font-size: 10.5px; text-align: center; white-space: nowrap;
  }
  .nav-item.active { box-shadow: inset 0 2px 0 var(--gold); }
  .btn.only-phone { display: inline-flex; }
  .btn-label { display: none; }
  .topbar { padding-top: 14px; padding-bottom: 14px; }
  .page { padding-bottom: 96px; }
  .page, .topbar { padding-left: 16px; padding-right: 16px; }
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .stat { padding: 13px 14px; }
  .stat-value { font-size: 24px; }
  .spark { display: none; }
  .cols { grid-template-rows: 170px auto; }
  .field-row { grid-template-columns: 1fr; }
}
