/* Event admin – design system and screens.
   Brand colours come from 5 theme variables set at runtime from GET /api/theme
   (--primary, --primary-dark, --accent, --bg, --text) plus --font. Defaults = ITTF.
   Every other colour is derived from them with color-mix(), or is a fixed semantic token. */

@font-face { font-family: "TeX Gyre Adventor"; src: url("../assets/fonts/tex-gyre-adventor-regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "TeX Gyre Adventor"; src: url("../assets/fonts/tex-gyre-adventor-bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }

:root {
  /* Theme (overridden by js/theme.js) */
  --primary: #005243;
  --primary-dark: #004D41;
  --accent: #DFAD3C;
  --bg: #F1F1F1;
  --text: #333333;
  --font: "TeX Gyre Adventor", "Century Gothic", "Avant Garde", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  /* Fixed semantic tokens */
  --surface: #FFFFFF;
  --on-primary: #FFFFFF;
  --danger: #B3261E;
  --danger-bg: #FCECEA;
  --warning: #8A5300;
  --warning-bg: #FFF4DC;
  --warning-border: #E9B44C;
  --success: #1E6B34;
  --success-bg: #E6F4EA;
  --info: #1F4E79;
  --info-bg: #E8F0F8;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SFMono-Regular", monospace;

  /* Scale */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --fs-xs: .75rem; --fs-sm: .8125rem; --fs: .9375rem; --fs-md: 1.0625rem; --fs-lg: 1.375rem; --fs-xl: 1.75rem;
  --header-h: 64px; --nav-w: 240px;
  --shadow-sm: 0 1px 2px var(--shadow-color);
  --shadow: 0 1px 3px var(--shadow-color), 0 6px 16px -8px var(--shadow-color);
  --shadow-lg: 0 18px 48px -12px var(--shadow-color), 0 2px 6px var(--shadow-color);
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary-dark), 0 0 0 6px var(--accent);
}

/* Derived from the theme; re-declared on .theme-scope so the theme editor preview recomputes them. */
:root, .theme-scope {
  --primary-tint: color-mix(in srgb, var(--primary) 9%, var(--surface));
  --primary-tint-2: color-mix(in srgb, var(--primary) 16%, var(--surface));
  --accent-tint: color-mix(in srgb, var(--accent) 22%, var(--surface));
  --muted: color-mix(in srgb, var(--text) 74%, var(--surface));
  --border: color-mix(in srgb, var(--text) 16%, var(--surface));
  --border-strong: color-mix(in srgb, var(--text) 34%, var(--surface));
  --panel: color-mix(in srgb, var(--text) 3%, var(--surface));
  --shadow-color: color-mix(in srgb, var(--text) 14%, transparent);
  --overlay: color-mix(in srgb, var(--text) 45%, transparent);

}
.theme-scope { color: var(--text); font-family: var(--font); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs)/1.5 var(--font); min-height: 100vh; overflow-x: hidden; }
img, svg { display: block; max-width: 100%; }
svg { width: 1.25em; height: 1.25em; flex: none; }
svg.lock { display: inline; width: 14px; height: 14px; vertical-align: -2px; color: var(--warning); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; color: var(--text); }
h1 { font-size: var(--fs-xl); letter-spacing: -.01em; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0 0 var(--s3); }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-dark); }
code, .mono { font-family: var(--mono); font-size: .92em; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--s4); top: -60px; z-index: 100; background: var(--surface); color: var(--primary); padding: var(--s2) var(--s4); border-radius: var(--r-sm); box-shadow: var(--shadow); font-weight: 700; }
.skip-link:focus { top: var(--s2); }
.noscript { padding: var(--s5); text-align: center; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.stack > * + * { margin-top: var(--s4); }
.row { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: var(--s3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.mt-0 { margin-top: 0 !important; }

/* ───────── Boot ───────── */
.app-boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--primary-tint-2); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
.spinner-sm { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── Shell ───────── */
.shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); grid-template-rows: var(--header-h) 1fr; min-height: 100vh; }
.app-header { grid-column: 1 / -1; position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s4); background: var(--surface); border-bottom: 3px solid var(--primary); box-shadow: var(--shadow-sm); }
.brand { display: flex; align-items: center; gap: var(--s3); text-decoration: none; color: var(--text); min-width: 0; }
.brand img { height: 40px; width: auto; max-width: 120px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-product { font-weight: 700; font-size: var(--fs-md); color: var(--primary); white-space: nowrap; }
.brand-name { font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-spacer { flex: 1; }
.env-pill { font-size: var(--fs-xs); font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--accent-tint); color: var(--text); letter-spacing: .04em; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--primary-tint); color: var(--primary); }
.icon-btn svg { width: 22px; height: 22px; }
.badge-count { position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--danger); color: var(--on-primary); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; box-shadow: 0 0 0 2px var(--surface); }
.nav-toggle { display: none; }

.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: var(--s2); border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 4px 10px 4px 4px; cursor: pointer; color: var(--text); font: inherit; max-width: 260px; }
.user-btn:hover { border-color: var(--border-strong); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: var(--fs-xs); font-weight: 700; flex: none; }
.user-btn .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-lg); padding: var(--s2); z-index: 40; }
.menu-head { padding: var(--s2) var(--s3) var(--s3); border-bottom: 1px solid var(--border); margin-bottom: var(--s2); }
.menu-head strong { display: block; overflow-wrap: anywhere; }
.menu-item { display: flex; width: 100%; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border: 0; background: none; border-radius: var(--r-sm); font: inherit; color: var(--text); text-align: left; cursor: pointer; text-decoration: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--primary-tint); color: var(--primary); }
.menu-item svg { width: 18px; height: 18px; }

.app-nav { grid-row: 2; position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto; background: var(--surface); border-right: 1px solid var(--border); padding: var(--s4) var(--s3); display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: var(--s4) var(--s3) var(--s2); }
.nav-link { position: relative; display: flex; align-items: center; gap: var(--s3); padding: 9px var(--s3); border-radius: var(--r-sm); color: var(--text); text-decoration: none; font-weight: 400; }
.nav-link svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
.nav-link:hover { background: var(--primary-tint); color: var(--primary); }
.nav-link:hover svg { color: var(--primary); }
.nav-link[aria-current="page"] { background: var(--primary-tint); color: var(--primary); font-weight: 700; }
.nav-link[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 6px; bottom: 6px; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent); }
.nav-link[aria-current="page"] svg { color: var(--primary); }
.nav-link .nav-count { margin-left: auto; font-size: var(--fs-xs); background: var(--danger); color: var(--on-primary); border-radius: 99px; padding: 0 7px; font-weight: 700; }
.nav-foot { margin-top: auto; padding: var(--s4) var(--s3) 0; font-size: var(--fs-xs); color: var(--muted); }
.nav-scrim { display: none; }

.app-main { grid-row: 2; min-width: 0; padding: var(--s5) var(--s6) var(--s7); outline: none; }
.page { max-width: 1320px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s5); }
.page-head p { margin: var(--s1) 0 0; color: var(--muted); }
.page-head h1:focus { box-shadow: none; }
.crumbs { font-size: var(--fs-sm); margin-bottom: var(--s2); }
.crumbs a { text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.crumbs svg { width: 16px; height: 16px; }

/* ───────── Buttons ───────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 40px; padding: 0 var(--s4); border-radius: var(--r-sm); border: 1px solid transparent; font: 700 var(--fs-sm)/1 var(--font); letter-spacing: .01em; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .12s, border-color .12s, color .12s; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-dark); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--border-strong); }
.btn-secondary:hover { border-color: var(--primary); background: var(--primary-tint); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-tint); }
.btn-danger { background: var(--danger); color: var(--on-primary); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, var(--text)); color: var(--on-primary); }
.btn-danger-outline { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, var(--surface)); }
.btn-danger-outline:hover { background: var(--danger-bg); color: var(--danger); }
.btn-sm { min-height: 32px; padding: 0 var(--s3); font-size: var(--fs-xs); }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.is-busy { pointer-events: none; }
.btn.is-busy .spinner { border-color: color-mix(in srgb, currentColor 30%, transparent); border-top-color: currentColor; }
.btn-ms { background: var(--surface); color: var(--text); border-color: var(--border-strong); min-height: 44px; font-size: var(--fs); }
.btn-ms:hover { background: var(--panel); border-color: var(--text); color: var(--text); }
.btn-ms .ms-logo { width: 20px; height: 20px; }

/* ───────── Forms ───────── */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label, fieldset > legend { font-weight: 700; font-size: var(--fs-sm); color: var(--text); }
.req { color: var(--danger); margin-left: 2px; }
.hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger); font-weight: 700; display: flex; gap: 4px; align-items: center; }
.input, select.input, textarea.input { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs); }
textarea.input { min-height: 84px; resize: vertical; line-height: 1.45; }
select.input { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input:hover { border-color: var(--text); }
.input:focus-visible { border-color: var(--primary); }
.input[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-bg); }
.input:disabled { background: var(--panel); color: var(--muted); }
.input-search { padding-left: 38px; background-image: none; }
.search-wrap { position: relative; min-width: 220px; flex: 1 1 260px; max-width: 420px; }
.search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--s4); }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; } .col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset > legend { padding: 0; margin-bottom: var(--s2); }
.check { display: flex; align-items: flex-start; gap: var(--s2); cursor: pointer; padding: 6px 0; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 var(--s4); }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-sm); overflow: hidden; flex-wrap: wrap; }
.segmented label { position: relative; padding: 8px 14px; cursor: pointer; font-size: var(--fs-sm); border-right: 1px solid var(--border); background: var(--surface); }
.segmented label:last-child { border-right: 0; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.segmented label:has(input:checked) { background: var(--primary); color: var(--on-primary); font-weight: 700; }
.segmented label:has(input:focus-visible) { box-shadow: inset 0 0 0 2px var(--accent); }
.form-actions { display: flex; gap: var(--s3); justify-content: flex-end; flex-wrap: wrap; margin-top: var(--s5); }
.toolbar { display: flex; gap: var(--s3); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--s4); }
.toolbar .field { min-width: 160px; }
.toolbar .field.grow { flex: 1 1 240px; }

/* ───────── Chips & badges ───────── */
.chip { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 99px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; border: 1px solid transparent; background: var(--panel); color: var(--text); line-height: 1; }
.chip svg { width: 12px; height: 12px; }
.chip-neutral { background: var(--panel); border-color: var(--border); color: var(--muted); }
.chip-primary { background: var(--primary-tint); color: var(--primary); }
.chip-test { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, var(--surface)); }
.chip-unpub { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--surface)); }
.chip-archived { background: color-mix(in srgb, var(--text) 10%, var(--surface)); color: var(--text); }
.chip-retained { background: var(--text); color: var(--surface); }
.chip-hold { background: var(--accent); color: var(--text); }
.chip-success { background: var(--success-bg); color: var(--success); }
.chip-warn { background: var(--warning-bg); color: var(--warning); }
.chip-danger { background: var(--danger-bg); color: var(--danger); }
.chip-info { background: var(--info-bg); color: var(--info); }
.chip-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-running::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.code-pill { font-family: var(--mono); font-size: 11px; padding: 2px 6px; border-radius: 4px; background: var(--panel); border: 1px solid var(--border); color: var(--text); white-space: nowrap; }
.lock { display: inline-flex; vertical-align: -2px; margin-left: 4px; color: var(--warning); }
.lock svg { width: 14px; height: 14px; }

/* ───────── Cards ───────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card-pad { padding: var(--s5); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: var(--fs-md); }
.card-body { padding: var(--s5); }
.card-body > :last-child { margin-bottom: 0; }
.card-foot { padding: var(--s3) var(--s5); border-top: 1px solid var(--border); background: var(--panel); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.cards { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid-2 { display: grid; gap: var(--s5); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main-side { display: grid; gap: var(--s5); grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); align-items: start; }
.stats { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: var(--s5); }
.stat { padding: var(--s4) var(--s5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary); }
.stat .stat-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.stat .stat-value { font-size: 1.9rem; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.stat .stat-sub { font-size: var(--fs-xs); color: var(--muted); }
.action-card { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s5); }
.action-card h3 { display: flex; align-items: center; gap: var(--s2); }
.action-card h3 svg { width: 20px; height: 20px; color: var(--primary); }
.action-card p { color: var(--muted); font-size: var(--fs-sm); margin: 0; flex: 1; }
.action-card .row { margin-top: auto; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px var(--s4); margin: 0; font-size: var(--fs-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.danger-card { border-color: color-mix(in srgb, var(--danger) 40%, var(--surface)); }
.danger-card .card-head { background: var(--danger-bg); border-radius: var(--r-lg) var(--r-lg) 0 0; border-color: color-mix(in srgb, var(--danger) 25%, var(--surface)); }
.danger-card .card-head h2, .danger-card .card-head h3 { color: var(--danger); }

/* ───────── Event header ───────── */
.event-hero { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s5); margin-bottom: var(--s4); box-shadow: var(--shadow-sm); border-top: 4px solid var(--primary); }
.event-hero h1 { font-size: var(--fs-lg); margin-top: var(--s2); }
.event-meta { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); margin-top: var(--s3); color: var(--muted); font-size: var(--fs-sm); }
.event-meta span { display: inline-flex; align-items: center; gap: 6px; }
.event-meta svg { width: 16px; height: 16px; }

/* ───────── Tables ───────── */
.table-wrap { position: relative; overflow: auto; max-height: min(70vh, 760px); border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.table-wrap.no-max { max-height: none; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
table.data caption { text-align: left; padding: var(--s3) var(--s4); font-weight: 700; }
table.data th { position: sticky; top: 0; z-index: 2; background: var(--primary); color: var(--on-primary); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; padding: 10px var(--s3); white-space: nowrap; }
table.data td { padding: 10px var(--s3); border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:nth-child(even) td { background: var(--panel); }
table.data tbody tr:hover td { background: var(--primary-tint); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tr.is-clickable { cursor: pointer; }
table.data .t-right { text-align: right; }
table.data .t-actions { text-align: right; white-space: nowrap; width: 1%; }
table.data a.row-link { font-weight: 700; text-decoration: none; color: var(--primary); }
table.data a.row-link:hover { text-decoration: underline; }
.cell-sub { display: block; font-size: var(--fs-xs); color: var(--muted); }
.score { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.score b { color: var(--primary); }
.winner { font-weight: 700; }
.games-line { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.table-meta { display: flex; justify-content: space-between; align-items: center; margin: var(--s2) 2px 0; font-size: var(--fs-xs); color: var(--muted); }

/* ───────── Tabs ───────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: var(--s5); overflow-x: auto; scrollbar-width: thin; }
.tab { position: relative; padding: 12px var(--s4); border: 0; background: none; font: 700 var(--fs-sm) var(--font); color: var(--muted); cursor: pointer; white-space: nowrap; border-radius: var(--r-sm) var(--r-sm) 0 0; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--primary); background: var(--primary-tint); }
.tab[aria-selected="true"] { color: var(--primary); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: var(--s3); right: var(--s3); bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); }
.tab.tab-danger { color: var(--danger); }
.tab svg { width: 16px; height: 16px; }
.tabpanel:focus-visible { box-shadow: none; }

/* ───────── Callouts ───────── */
.callout { display: flex; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r); border: 1px solid; font-size: var(--fs-sm); align-items: flex-start; }
.callout svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.callout p { margin: 0; }
.callout strong { display: block; }
.callout-warn { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.callout-error { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 45%, var(--surface)); color: var(--danger); }
.callout-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 30%, var(--surface)); color: var(--info); }
.callout-success { background: var(--success-bg); border-color: color-mix(in srgb, var(--success) 35%, var(--surface)); color: var(--success); }
.callout + .callout { margin-top: var(--s2); }
.callout ul { margin: 4px 0 0; padding-left: 18px; }

/* ───────── Empty, skeleton ───────── */
.empty { text-align: center; padding: var(--s7) var(--s5); color: var(--muted); }
.empty svg { width: 44px; height: 44px; margin: 0 auto var(--s3); color: var(--primary); opacity: .55; }
.empty h3 { color: var(--text); margin-bottom: var(--s1); }
.empty p { max-width: 420px; margin: 0 auto var(--s4); font-size: var(--fs-sm); }
.skel { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--panel) 25%, var(--primary-tint) 37%, var(--panel) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; }
.skel + .skel { margin-top: 10px; }
.skel-lg { height: 28px; width: 40%; }
.skel-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: var(--s4); padding: 14px var(--s4); border-bottom: 1px solid var(--border); }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ───────── Dialog ───────── */
dialog.dlg { border: 0; padding: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); color: var(--text); background: var(--surface); overflow: hidden; }
dialog.dlg.dlg-wide { width: min(860px, calc(100vw - 24px)); }
dialog.dlg.dlg-sm { width: min(460px, calc(100vw - 24px)); }
dialog.dlg[open] { display: flex; flex-direction: column; animation: dlg-in .16s ease-out; }
dialog.dlg::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.dlg-head h2 { font-size: var(--fs-md); padding-top: 8px; }
.dlg-head .dlg-sub { font-size: var(--fs-sm); color: var(--muted); margin: 2px 0 0; }
.dlg-body { padding: var(--s5); overflow-y: auto; flex: 1 1 auto; }
.dlg-body > * + * { margin-top: var(--s4); }
.dlg-foot { display: flex; justify-content: flex-end; gap: var(--s3); padding: var(--s3) var(--s5); border-top: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.summary-list { margin: 0; padding: 0; list-style: none; }
.summary-list li { position: relative; padding: 4px 0 4px 22px; }
.summary-list li::before { content: ""; position: absolute; left: 4px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.changes-table td.before { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.changes-table td.after { font-weight: 700; color: var(--success); }
.progress-panel { display: flex; align-items: center; gap: var(--s4); padding: var(--s5); border-radius: var(--r); background: var(--primary-tint); }
.progress-steps { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.progress-steps .sep { width: 18px; height: 2px; background: var(--border-strong); }

/* ───────── Toasts ───────── */
.toasts { position: fixed; right: var(--s4); bottom: var(--s4); z-index: 1000; display: flex; flex-direction: column; gap: var(--s2); width: min(400px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: var(--s3); align-items: flex-start; background: var(--surface); color: var(--text); border-radius: var(--r); box-shadow: var(--shadow-lg); padding: var(--s3) var(--s4); border-left: 5px solid var(--primary); animation: toast-in .2s ease-out; font-size: var(--fs-sm); }
.toast svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.toast .toast-msg { flex: 1; }
.toast .toast-msg strong { display: block; }
.toast-success { border-left-color: var(--success); } .toast-success svg { color: var(--success); }
.toast-error { border-left-color: var(--danger); } .toast-error svg { color: var(--danger); }
.toast-warn { border-left-color: var(--warning-border); } .toast-warn svg { color: var(--warning); }
.toast .icon-btn { width: 28px; height: 28px; margin: -4px -8px 0 0; }
.toast .icon-btn svg { width: 16px; height: 16px; color: var(--muted); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ───────── Sign-in ───────── */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: var(--s5) var(--s4);
  background: radial-gradient(1200px 600px at 110% -10%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 60%),
              radial-gradient(900px 500px at -10% 110%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%), var(--bg); }
.auth-card { width: min(440px, 100%); background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); overflow: hidden; border-top: 4px solid var(--primary); }
.auth-card .auth-head { padding: var(--s6) var(--s6) var(--s4); text-align: center; }
.auth-card .auth-head img { height: 64px; width: auto; max-width: 180px; margin: 0 auto var(--s4); object-fit: contain; }
.auth-card .auth-head h1 { font-size: var(--fs-lg); color: var(--primary); }
.auth-card .auth-head p { color: var(--muted); margin: var(--s1) 0 0; font-size: var(--fs-sm); }
.auth-card .auth-body { padding: 0 var(--s6) var(--s6); }
.auth-card .auth-body form > * + * { margin-top: var(--s4); }
.divider { display: flex; align-items: center; gap: var(--s3); color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; margin: var(--s5) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-foot { text-align: center; font-size: var(--fs-xs); color: var(--muted); padding: var(--s3); background: var(--panel); border-top: 1px solid var(--border); }
.pw-rules { list-style: none; padding: 0; margin: 0; font-size: var(--fs-xs); display: grid; gap: 4px; }
.pw-rules li { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.pw-rules li svg { width: 14px; height: 14px; }
.pw-rules li.ok { color: var(--success); }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 76px; }
.pw-wrap .pw-toggle { position: absolute; right: 4px; top: 4px; min-height: 32px; }

/* ───────── Stepper (import) ───────── */
.stepper { display: flex; gap: var(--s2); list-style: none; padding: 0; margin: 0 0 var(--s5); counter-reset: step; flex-wrap: wrap; }
.stepper li { flex: 1 1 160px; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: var(--fs-sm); font-weight: 700; counter-increment: step; }
.stepper li::before { content: counter(step); display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border-strong); font-size: var(--fs-xs); flex: none; }
.stepper li[aria-current="step"] { border-color: var(--primary); color: var(--primary); box-shadow: inset 0 -3px 0 var(--accent); }
.stepper li[aria-current="step"]::before { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.stepper li.done { color: var(--text); }
.stepper li.done::before { content: "✓"; background: var(--success-bg); border-color: var(--success); color: var(--success); }
.upload-slot { display: grid; grid-template-columns: auto 1fr auto; gap: var(--s4); align-items: center; padding: var(--s4) var(--s5); border: 1px dashed var(--border-strong); border-radius: var(--r); background: var(--surface); }
.upload-slot + .upload-slot { margin-top: var(--s3); }
.upload-slot.has-file { border-style: solid; border-color: var(--primary); background: var(--primary-tint); }
.upload-slot .slot-num { width: 44px; height: 44px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--primary); color: var(--on-primary); font-weight: 700; }
.upload-slot .slot-title { font-weight: 700; }
.upload-slot .slot-file { font-size: var(--fs-sm); overflow-wrap: anywhere; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-input:focus-visible + .btn { box-shadow: var(--focus); }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--r); padding: var(--s5); text-align: center; background: var(--panel); }
.dropzone > svg { width: 36px; height: 36px; margin: 0 auto var(--s2); color: var(--primary); }
.dropzone .slot-file { margin-top: var(--s2); }
.dropzone.has-file { border-color: var(--primary); background: var(--primary-tint); }

/* ───────── Games editor ───────── */
.games-editor { display: grid; grid-template-columns: auto 1fr auto 1fr auto; gap: var(--s2) var(--s3); align-items: center; max-width: 340px; }
.games-editor .g-label { font-size: var(--fs-xs); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.games-editor .g-head { font-size: var(--fs-xs); font-weight: 700; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.games-editor .input { text-align: center; font-variant-numeric: tabular-nums; min-height: 38px; padding: 6px; }
.games-editor .g-dash { color: var(--muted); }
.games-editor .g-state { width: 22px; height: 22px; display: grid; place-items: center; }
.games-editor .g-state svg { width: 18px; height: 18px; }
.g-ok { color: var(--success); } .g-bad { color: var(--danger); }
.match-vs { display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--s3); align-items: center; padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--panel); border: 1px solid var(--border); }
.match-vs .side { min-width: 0; }
.match-vs .side strong { display: block; overflow-wrap: anywhere; }
.match-vs .side-a { text-align: right; }
.match-vs .vs { font-size: var(--fs-xs); color: var(--muted); font-weight: 700; }
.result-line { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--primary-tint); font-weight: 700; }

/* ───────── Notifications ───────── */
.notes { list-style: none; margin: 0; padding: 0; }
.note { display: grid; grid-template-columns: 14px 1fr auto; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); align-items: start; }
.note:last-child { border-bottom: 0; }
.note .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: transparent; border: 2px solid var(--border-strong); }
.note.unread { background: color-mix(in srgb, var(--primary) 4%, var(--surface)); }
.note.unread .dot { background: var(--primary); border-color: var(--primary); }
.note.unread .note-subject { font-weight: 700; }
.note-subject { overflow-wrap: anywhere; }
.note-body { color: var(--muted); font-size: var(--fs-sm); margin: 2px 0 6px; overflow-wrap: anywhere; }
.note-meta { font-size: var(--fs-xs); color: var(--muted); display: flex; gap: var(--s3); flex-wrap: wrap; align-items: center; }

/* ───────── Theme editor ───────── */
.color-row { display: grid; grid-template-columns: 44px 1fr; gap: var(--s2); align-items: center; }
.color-row input[type="color"] { width: 44px; height: 40px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 2px; background: var(--surface); cursor: pointer; }
.preview-frame { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); box-shadow: var(--shadow); }
.preview-frame .pv-header { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--surface); border-bottom: 3px solid var(--primary); }
.preview-frame .pv-header img { height: 34px; width: auto; max-width: 100px; object-fit: contain; }
.preview-frame .pv-body { padding: var(--s4); display: grid; gap: var(--s3); }
.preview-frame .pv-nav { display: flex; gap: var(--s2); flex-wrap: wrap; }
.preview-frame .pv-nav span { padding: 6px 10px; border-radius: var(--r-sm); font-size: var(--fs-sm); }
.preview-frame .pv-nav span.on { background: var(--primary-tint); color: var(--primary); font-weight: 700; box-shadow: inset 0 -3px 0 var(--accent); }
.contrast-list { display: grid; gap: 6px; font-size: var(--fs-sm); margin: 0; padding: 0; list-style: none; }
.contrast-list li { display: flex; justify-content: space-between; gap: var(--s3); align-items: center; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--border); vertical-align: -2px; margin-right: 6px; }
.logo-preview { display: flex; align-items: center; gap: var(--s4); padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.logo-preview img { height: 48px; width: auto; max-width: 140px; object-fit: contain; }

.supervisor-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s2); }
.supervisor-list .check { border: 1px solid var(--border); border-radius: var(--r); padding: var(--s3); background: var(--surface); }
.supervisor-list .check:has(input:checked) { border-color: var(--primary); background: var(--primary-tint); }

/* ───────── Responsive ───────── */
@media (max-width: 1100px) {
  .app-main { padding: var(--s5) var(--s5) var(--s7); }
  .grid-main-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-grid; }
  .app-nav { position: fixed; top: var(--header-h); left: 0; bottom: 0; width: min(290px, 86vw); height: auto; z-index: 50; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-lg); visibility: hidden; }
  .shell.nav-open .app-nav { transform: none; visibility: visible; }
  .shell.nav-open .nav-scrim { display: block; position: fixed; inset: var(--header-h) 0 0 0; background: var(--overlay); z-index: 45; }
  .app-main { grid-column: 1; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  :root { --header-h: 58px; }
  .app-header { padding: 0 var(--s2) 0 var(--s1); gap: var(--s1); }
  .brand img { height: 34px; }
  .brand-name, .env-pill { display: none; }
  .user-btn { padding: 3px; border: 0; }
  .user-btn .who, .user-btn .chev { display: none; }
  .app-main { padding: var(--s4) var(--s4) var(--s7); }
  h1 { font-size: var(--fs-lg); }
  .page-head { margin-bottom: var(--s4); }
  .form-grid > * { grid-column: span 12; }
  .card-body, .card-pad, .action-card { padding: var(--s4); }
  .card-head { padding: var(--s3) var(--s4); }
  .dlg-body { padding: var(--s4); }
  .dlg-head, .dlg-foot { padding-left: var(--s4); padding-right: var(--s4); }
  .dlg-foot .btn { flex: 1 1 auto; }
  .search-wrap { max-width: none; min-width: 0; flex-basis: 100%; }
  .toolbar .field { flex: 1 1 140px; min-width: 0; }
  .event-hero { padding: var(--s4); }
  .upload-slot { grid-template-columns: auto 1fr; }
  .upload-slot > :last-child { grid-column: 1 / -1; justify-self: start; }
  .note { padding: var(--s3) var(--s4); grid-template-columns: 14px 1fr; }
  .note > :last-child { grid-column: 2; }
  .auth-card .auth-head { padding: var(--s5) var(--s5) var(--s3); }
  .auth-card .auth-body { padding: 0 var(--s5) var(--s5); }

  /* Tables become cards */
  .table-wrap.cards-sm { max-height: none; overflow: visible; border: 0; background: transparent; }
  .cards-sm table.data, .cards-sm table.data tbody, .cards-sm table.data tr, .cards-sm table.data td { display: block; width: 100%; }
  .cards-sm table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .cards-sm table.data tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); margin-bottom: var(--s3); padding: var(--s2) 0; box-shadow: var(--shadow-sm); }
  .cards-sm table.data tbody tr td, .cards-sm table.data tbody tr:nth-child(even) td, .cards-sm table.data tbody tr:hover td { background: transparent; }
  .cards-sm table.data td { display: grid; grid-template-columns: 38% 1fr; gap: var(--s3); border: 0; padding: 6px var(--s4); text-align: left; overflow-wrap: anywhere; }
  .cards-sm table.data td::before { content: attr(data-label); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding-top: 2px; }
  .cards-sm table.data td.t-primary { grid-template-columns: 1fr; font-size: var(--fs); padding-bottom: var(--s2); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
  .cards-sm table.data td.t-primary::before { display: none; }
  .cards-sm table.data td.t-actions { width: 100%; text-align: left; grid-template-columns: 1fr; padding-top: var(--s2); }
  .cards-sm table.data td.t-actions::before { display: none; }
  .cards-sm table.data td.t-empty::before { display: none; }
  .cards-sm table.data td.t-empty { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
@media print {
  .app-header, .app-nav, .toasts { display: none !important; }
  .shell { display: block; }
}

.auth-narrow { max-width: 480px; }
.h3 { font-size: var(--fs-md); }
@media (max-width: 720px) {
  .cards-sm table.data td > * { min-width: 0; }
  .cards-sm .code-pill, .cards-sm .mono { white-space: normal; overflow-wrap: anywhere; }
}

/* Layout fixes after visual review */
.field > .search-wrap { flex: none; max-width: 520px; width: 100%; min-width: 0; }
.toolbar .field.grow { flex: 1 1 280px; }
.note > div { min-width: 0; }
.note-meta > * { overflow-wrap: anywhere; }
@media (min-width: 721px) {
  .cell-sub.mono { white-space: nowrap; font-size: 11px; }
  table.data td.t-primary { min-width: 200px; }
  table.data th:first-child, table.data td:first-child { padding-left: var(--s4); }
}
.col-5 { grid-column: span 5; }
.swatch { width: 20px; height: 20px; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; vertical-align: middle; }
