/* MatchDay shared design tokens + components (refresh 2026-07-13).
   Broadcast-scoreboard identity: near-blacks carry a deliberate green
   undertone (not neutral grey), pitch-green brand accent kept separate
   from a brighter "live" status green, tabular monospace for every
   score/timer/count. Single dark theme — see chat design discussion.
   Loaded by every operator page; nav.js also reads these tokens. */

:root {
  --bg: #0a0e0c;
  --surface: #131917;
  --surface-2: #1a221e;
  --border: #232c27;
  --text: #eef2ef;
  --text-dim: #8b9791;
  --text-faint: #55625b;
  --accent: #17b872;
  --accent-strong: #22e08a;
  --info: #4da3ff;
  --status-live: #22e08a;
  --status-pre: #f0a83c;
  --status-final: #6b7670;
  --status-danger: #ff6259;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px;

  --radius: 10px;
  --radius-sm: 6px;

  --rail-width: 232px;
  --rail-compact-width: 64px;
  --rail-breakpoint: 900px;

  --page-gutter: clamp(12px, 3vw, 20px);
  --touch-target: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100%; }
html { overflow-x: clip; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}
::selection { background: var(--accent); color: #06110b; }

/* Scoreboard digit treatment — every score/timer/count uses this */
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, [tabindex]:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
button:hover { border-color: var(--text-faint); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #06120c; }
button.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button.ghost { background: transparent; }
button.danger { color: var(--status-danger); }
button.danger:hover { border-color: var(--status-danger); }
button.icon { padding: 8px; width: 34px; height: 34px; display: grid; place-items: center; flex-shrink: 0; }

input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { max-width: 100%; }
img, video, iframe { max-width: 100%; }

/* Shared responsive primitives. Pages can opt into these without needing a
   component build step. */
.responsive-form, .responsive-actions {
  display: flex;
  align-items: end;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.responsive-form > .field, .responsive-form > input, .responsive-form > select { flex: 1 1 180px; min-width: 0; }
.responsive-actions { align-items: center; }
.scroll-region { min-width: 0; overflow: auto; overscroll-behavior: contain; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Page shell ---------- */
/* nav.js docks its rail via body.md-rail-open at desktop widths — that
   rule lives in nav.js itself (not here), so pages loading nav.js without
   this stylesheet (the sport scoring plugin pages) still shift correctly. */

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
  gap: var(--sp-3);
}
.page-head h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.page-head .sub { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

/* ---------- Status chip ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.chip.live { background: rgba(34,224,138,0.12); color: var(--status-live); }
.chip.live .dot { background: var(--status-live); animation: md-pulse 1.8s ease-in-out infinite; }
.chip.pre { background: rgba(240,168,60,0.12); color: var(--status-pre); }
.chip.pre .dot { background: var(--status-pre); }
.chip.final { background: rgba(107,118,112,0.16); color: var(--text-dim); }
.chip.final .dot { background: var(--status-final); }
.chip.view { background: rgba(77,163,255,0.12); color: var(--info); }
.chip.operate { background: rgba(23,184,114,0.12); color: var(--accent); }

@keyframes md-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,224,138,0.5); }
  50% { opacity: 0.55; box-shadow: 0 0 0 4px rgba(34,224,138,0); }
}
@media (prefers-reduced-motion: reduce) {
  .chip .dot { animation: none; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
}
.stripe { border-left: 3px solid var(--status-final); }
.stripe.live { border-left-color: var(--status-live); }
.stripe.pre { border-left-color: var(--status-pre); }

/* ---------- Tiles ---------- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-3);
}
.tile {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}
.tile:hover { border-color: var(--accent); transform: translateY(-2px); background: var(--surface-2); text-decoration: none; }
.tile .glyph { font-size: 19px; opacity: 0.95; }
.tile .label { font-weight: 700; font-size: 13.5px; }
.tile.primary { background: var(--accent); color: #06120c; border-color: var(--accent); }
.tile.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

/* ---------- Section ---------- */
.section { margin-bottom: var(--sp-7); }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}
.section-head h2 {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0;
}

/* ---------- List rows ---------- */
.list { display: flex; flex-direction: column; gap: var(--sp-2); }
.row {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4);
  flex-wrap: wrap;
}
.row .scoreline { display: flex; align-items: baseline; gap: var(--sp-2); min-width: 190px; font-weight: 700; }
.row .scoreline .score { font-size: 18px; }
.row .scoreline .vs { color: var(--text-faint); font-weight: 400; margin: 0 2px; }
.row .name { font-weight: 700; min-width: 140px; }
.row .meta { color: var(--text-faint); font-size: 12px; flex: 1; min-width: 120px; }
.row .row-actions { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; }
.row .row-actions a, .row .row-actions button { font-size: 12.5px; }
.row input[type=checkbox] { width: 16px; height: 16px; flex-shrink: 0; }

.owner-tag { font-size: 11px; color: var(--text-faint); }
.owner-tag b { color: var(--text-dim); }

.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--status-final); flex-shrink: 0; }
.conn-dot.on { background: var(--status-live); box-shadow: 0 0 0 3px rgba(34,224,138,0.15); }

/* One primary action per row; the rest live behind a single overflow
   menu — a row is scanned, not read, and stacking five inline links
   defeats that. */
.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); min-width: 168px; padding: 5px;
  display: none; flex-direction: column; gap: 1px; z-index: 30;
  box-shadow: 0 10px 28px rgba(0,0,0,0.45);
}
.menu-panel.open { display: flex; }
.menu-item {
  text-align: left; background: transparent; border: none;
  color: var(--text-dim); padding: 8px 10px; border-radius: 4px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.menu-item:hover { background: var(--surface); color: var(--text); border-color: transparent; }
.menu-item.danger { color: var(--status-danger); }

/* ---------- Bulk-select bar ---------- */
.bulk-bar {
  display: none; align-items: center; gap: var(--sp-3);
  padding: 10px 14px; margin-bottom: var(--sp-3);
  background: rgba(255,98,89,0.08); border: 1px solid rgba(255,98,89,0.3);
  border-radius: var(--radius-sm); font-size: 12.5px; color: var(--status-danger);
}
.bulk-bar.show { display: flex; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4,6,5,0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  z-index: 1600;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.modal h3 { margin: 0; font-size: 15px; font-weight: 800; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-faint); }
.field input, .field select { width: 100%; }
.modal-actions { display: flex; gap: var(--sp-2); }
.modal-actions button { flex: 1; }
.share-list { display: flex; flex-direction: column; gap: var(--sp-2); border-top: 1px solid var(--border); padding-top: var(--sp-3); }
.share-list .grant { display: flex; align-items: center; gap: var(--sp-2); font-size: 12.5px; }
.share-list .grant .who { flex: 1; color: var(--text-dim); }
.share-list .grant .revoke { color: var(--status-danger); font-size: 11.5px; cursor: pointer; }

.empty { font-size: 12.5px; color: var(--text-faint); padding: var(--sp-3) 0; }
.msg { font-size: 12.5px; color: var(--status-danger); min-height: 16px; margin-bottom: var(--sp-2); }

@media (pointer: coarse) {
  button, input, select, .menu-item { min-height: var(--touch-target); }
  input[type="checkbox"], input[type="radio"] { min-height: 20px; min-width: 20px; }
}

@media (max-width: 640px) {
  .page-head { align-items: stretch; margin-bottom: var(--sp-5); }
  .page-head > * { min-width: 0; }
  .page-head > a, .page-head > button, .page-head > label { flex: 1 1 100%; }
  .page-head > a > button, .page-head > label > button { width: 100%; }

  .card { padding: var(--sp-4); }
  .row { align-items: stretch; gap: var(--sp-3); }
  .row .name, .row .scoreline, .row .meta { min-width: 0; }
  .row .meta { flex-basis: 100%; }
  .row .row-actions { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .row .row-actions > a, .row .row-actions > button { flex: 1 1 auto; }
  .row .row-actions > a > button { width: 100%; }
  .bulk-bar { flex-wrap: wrap; }

  .responsive-form, .responsive-actions { align-items: stretch; }
  .responsive-form > *, .responsive-actions > * { flex: 1 1 100%; min-width: 0; }

  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: none;
    max-height: calc(100dvh - var(--safe-top) - 12px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: var(--radius) var(--radius) 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: var(--sp-5) max(var(--sp-4), var(--safe-right)) max(var(--sp-5), var(--safe-bottom)) max(var(--sp-4), var(--safe-left));
  }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions button { min-width: min(120px, 100%); }

  .menu-panel {
    position: fixed;
    left: max(8px, var(--safe-left));
    right: max(8px, var(--safe-right));
    top: auto;
    bottom: max(8px, var(--safe-bottom));
    width: auto;
    max-height: min(70dvh, 520px);
    overflow-y: auto;
    padding: var(--sp-2);
    border-radius: var(--radius);
    z-index: 1700;
  }
  .menu-item { padding: 11px 12px; }
}

@media (max-width: 350px) {
  .tile-grid { grid-template-columns: 1fr; }
  .modal-actions button { flex-basis: 100%; }
}
