/* ==========================================================================
   MIAS Pro design system
   Tokens -> primitives -> layout -> components.  No CSS framework: the
   console, the scoreboard and the public site share one vocabulary so a
   result table looks the same everywhere it appears.
   ========================================================================== */

:root {
  /* Brand: deep competition blue with a gold accent for medals and podium. */
  --brand-900: #0b1f3a;
  --brand-800: #12305a;
  --brand-700: #1a4480;
  --brand-600: #2258a5;
  --brand-500: #2f6fc4;
  --brand-100: #e5eefa;
  --brand-050: #f2f7fd;

  --gold: #c8962c;
  --silver: #8c98a4;
  --bronze: #a56a3a;

  --ink-900: #0f1720;
  --ink-700: #2c3946;
  --ink-500: #5a6875;
  --ink-400: #7d8a97;
  --ink-300: #aab4bf;
  --ink-200: #d8dee5;
  --ink-100: #eaeef2;
  --ink-050: #f5f7f9;
  --surface: #ffffff;
  --canvas: #f4f6f9;

  --ok-700: #146c43; --ok-100: #d9f2e4;
  --warn-700: #96650a; --warn-100: #fdf1d6;
  --err-700: #b02a2a; --err-100: #fbe3e3;
  --info-700: #1a5c9e; --info-100: #dceafa;
  --live-500: #e0392b;

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 32, .07);
  --shadow: 0 2px 8px rgba(15, 23, 32, .09);
  --shadow-lg: 0 12px 32px rgba(15, 23, 32, .16);

  --sidebar-w: 246px;
  --topbar-h: 58px;

  --font: "Segoe UI", Inter, system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "SF Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-900);
  background: var(--canvas);
}

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.175rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono, .tabular { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.muted { color: var(--ink-500); }
.small { font-size: .8125rem; }
.tiny { font-size: .72rem; }
.strong { font-weight: 650; }
.upper { text-transform: uppercase; letter-spacing: .06em; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.mb0 { margin-bottom: 0 !important; }
.mt1 { margin-top: 1rem; }

/* ------------------------------------------------------------ app shell -- */

.app { min-height: 100vh; }

.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 40;
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem;
  background: linear-gradient(100deg, var(--brand-900), var(--brand-700));
  color: #fff; box-shadow: var(--shadow);
}
.topbar a { color: #fff; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; letter-spacing: -.02em; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center;
  background: var(--gold); color: var(--brand-900); font-weight: 800; font-size: .82rem;
}
.brand small { display: block; font-size: .62rem; font-weight: 500; opacity: .75; letter-spacing: .1em; text-transform: uppercase; }
.topbar-spacer { flex: 1; }

.games-pill {
  display: inline-flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.2);
  padding: .3rem .7rem; border-radius: 999px; font-size: .8125rem; color: #fff;
}
.games-pill:hover { background: rgba(255,255,255,.22); text-decoration: none; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--gold); color: var(--brand-900); font-weight: 700; font-size: .78rem;
}

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 30;
  background: var(--brand-900); color: #cfd9e6; overflow-y: auto; padding-bottom: 2rem;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 4px; }
.nav-group { padding: .9rem 0 .2rem; }
.nav-group > .label {
  padding: 0 1rem .35rem; font-size: .66rem; text-transform: uppercase;
  letter-spacing: .12em; color: #7b8ea8; font-weight: 700;
}
.sidebar a.nav-item {
  display: flex; align-items: center; gap: .65rem; padding: .5rem 1rem;
  color: #cfd9e6; font-size: .875rem; border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.sidebar a.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar a.nav-item.active { background: rgba(47,111,196,.28); border-left-color: var(--gold); color: #fff; font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; opacity: .85; }
.nav-item .count {
  margin-left: auto; background: rgba(255,255,255,.14); border-radius: 999px;
  padding: .05rem .45rem; font-size: .7rem; font-variant-numeric: tabular-nums;
}

.content { margin-left: var(--sidebar-w); padding: calc(var(--topbar-h) + 1.25rem) 1.5rem 3rem; }

.page-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 260px; }
.page-head h1 { margin-bottom: .15rem; }
.page-head .sub { color: var(--ink-500); font-size: .875rem; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.breadcrumb { font-size: .78rem; color: var(--ink-400); margin-bottom: .3rem; }
.breadcrumb a { color: var(--ink-500); }

/* ------------------------------------------------------------- surfaces -- */

.card {
  background: var(--surface); border: 1px solid var(--ink-200);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 1.25rem;
}
.card-head {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .8rem 1rem; border-bottom: 1px solid var(--ink-100);
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.card-body { padding: 1rem; }
.card-body.tight { padding: .5rem; }
.card-foot { padding: .65rem 1rem; border-top: 1px solid var(--ink-100); background: var(--ink-050); font-size: .8125rem; }

.grid { display: grid; gap: 1.25rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.tight { gap: .35rem; }
.spacer { flex: 1; }

/* ------------------------------------------------------------ stat tiles-- */

.stat {
  background: var(--surface); border: 1px solid var(--ink-200); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--brand-500); }
.stat.ok::before { background: var(--ok-700); }
.stat.warn::before { background: var(--warn-700); }
.stat.err::before { background: var(--err-700); }
.stat.gold::before { background: var(--gold); }
.stat .k { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-500); font-weight: 650; }
.stat .v { font-size: 1.65rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .d { font-size: .78rem; color: var(--ink-500); }

/* --------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-500); font-weight: 700; padding: .55rem .75rem;
  border-bottom: 1px solid var(--ink-200); background: var(--ink-050); white-space: nowrap;
}
table.data td { padding: .6rem .75rem; border-bottom: 1px solid var(--ink-100); vertical-align: middle; }
table.data tbody tr:hover { background: var(--brand-050); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
table.data.compact td, table.data.compact th { padding: .35rem .5rem; }
table.data tr.is-medal-1 { background: #fdf6e3; }
table.data tr.is-medal-2 { background: #f3f5f7; }
table.data tr.is-medal-3 { background: #faf0e6; }

.rank { font-family: var(--mono); font-weight: 700; font-variant-numeric: tabular-nums; }
.rank-1 { color: var(--gold); }
.rank-2 { color: var(--silver); }
.rank-3 { color: var(--bronze); }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-400); }
.empty .big { font-size: 2rem; opacity: .35; display: block; margin-bottom: .35rem; }

/* --------------------------------------------------------------- badges -- */

.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .5rem;
  border-radius: 999px; font-size: .72rem; font-weight: 650; line-height: 1.5;
  background: var(--ink-100); color: var(--ink-700); white-space: nowrap;
}
.badge.ok { background: var(--ok-100); color: var(--ok-700); }
.badge.warn { background: var(--warn-100); color: var(--warn-700); }
.badge.err { background: var(--err-100); color: var(--err-700); }
.badge.info { background: var(--info-100); color: var(--info-700); }
.badge.brand { background: var(--brand-100); color: var(--brand-700); }
.badge.gold { background: #f8eed4; color: #7a5a12; }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge.live { background: var(--live-500); color: #fff; }
.badge.live::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* -------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .42rem .85rem; border-radius: var(--radius-sm); border: 1px solid var(--ink-200);
  background: var(--surface); color: var(--ink-900); font-size: .8125rem; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: background .15s, border-color .15s, box-shadow .15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--ink-050); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 1px; }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.btn.primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn.danger { background: var(--err-700); border-color: var(--err-700); color: #fff; }
.btn.danger:hover { filter: brightness(.92); }
.btn.success { background: var(--ok-700); border-color: var(--ok-700); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand-600); }
.btn.ghost:hover { background: var(--brand-050); }
.btn.sm { padding: .25rem .55rem; font-size: .75rem; }
.btn.lg { padding: .6rem 1.2rem; font-size: .9rem; }
.btn.block { width: 100%; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ---------------------------------------------------------------- forms -- */

.field { margin-bottom: .9rem; }
.field > label, label.field-label {
  display: block; font-size: .75rem; font-weight: 650; color: var(--ink-700);
  margin-bottom: .25rem; text-transform: uppercase; letter-spacing: .04em;
}
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=time], input[type=search],
input[type=url], input[type=tel], select, textarea {
  width: 100%; padding: .45rem .6rem; font-family: inherit; font-size: .875rem;
  color: var(--ink-900); background: var(--surface);
  border: 1px solid var(--ink-300); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(47,111,196,.16);
}
input[disabled], select[disabled], textarea[disabled] { background: var(--ink-050); color: var(--ink-400); }
textarea { min-height: 84px; resize: vertical; }
.help { font-size: .75rem; color: var(--ink-500); margin-top: .2rem; }
.error-text { font-size: .75rem; color: var(--err-700); margin-top: .2rem; }
.field.has-error input, .field.has-error select { border-color: var(--err-700); }
.check { display: flex; align-items: center; gap: .45rem; font-size: .875rem; }
.check input { width: auto; }
.filters { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.filters .field { margin-bottom: 0; min-width: 150px; }

/* --------------------------------------------------------------- alerts -- */

.alert {
  display: flex; gap: .6rem; padding: .7rem .9rem; border-radius: var(--radius);
  border: 1px solid; font-size: .875rem; margin-bottom: 1rem;
}
.alert.info { background: var(--info-100); border-color: #b9d4f0; color: var(--info-700); }
.alert.ok { background: var(--ok-100); border-color: #b5e2ca; color: var(--ok-700); }
.alert.warn { background: var(--warn-100); border-color: #f0dcae; color: var(--warn-700); }
.alert.err { background: var(--err-100); border-color: #f0bfbf; color: var(--err-700); }

/* ---------------------------------------------------------------- tabs --- */

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--ink-200); margin-bottom: 1.1rem; overflow-x: auto; }
.tabs a {
  padding: .5rem .85rem; font-size: .8125rem; font-weight: 600; color: var(--ink-500);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--brand-600); text-decoration: none; }
.tabs a.active { color: var(--brand-700); border-bottom-color: var(--brand-600); }

/* -------------------------------------------------------------- modals --- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(11,31,58,.55); z-index: 60;
  display: grid; place-items: center; padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(620px, 100%); max-height: 88vh; overflow: auto;
}
.modal-head { padding: 1rem 1.15rem; border-bottom: 1px solid var(--ink-100); display: flex; align-items: center; }
.modal-body { padding: 1.15rem; }
.modal-foot { padding: .85rem 1.15rem; border-top: 1px solid var(--ink-100); display: flex; gap: .5rem; justify-content: flex-end; }

/* --------------------------------------------------------------- misc ---- */

.timeline { border-left: 2px solid var(--ink-200); margin-left: .5rem; padding-left: 1rem; }
.timeline .item { position: relative; padding-bottom: .9rem; font-size: .8125rem; }
.timeline .item::before {
  content: ""; position: absolute; left: -1.32rem; top: .35rem; width: 9px; height: 9px;
  border-radius: 50%; background: var(--brand-500); border: 2px solid var(--surface);
}
.timeline .item.sev-ALERT::before { background: var(--err-700); }
.timeline .item.sev-WARNING::before { background: var(--warn-700); }

.progress { height: 6px; background: var(--ink-100); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand-500); }

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: .35rem .9rem; font-size: .875rem; }
.kv dt { color: var(--ink-500); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }
.kv dd { margin: 0; }

.avatar-lg {
  width: 92px; height: 92px; border-radius: var(--radius); object-fit: cover;
  background: var(--ink-100); display: grid; place-items: center; color: var(--ink-400);
}

.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ------------------------------------------------------------ responsive - */

@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  .content { margin-left: 0; padding-left: 1rem; padding-right: 1rem; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-flex !important; }
}
.nav-toggle {
  display: none; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.2);
  color: #fff; border-radius: var(--radius-sm); padding: .3rem .55rem; cursor: pointer; font-size: 1rem;
}

@media print {
  .topbar, .sidebar, .page-actions, .btn { display: none !important; }
  .content { margin: 0; padding: 0; }
  .card { border: none; box-shadow: none; }
}
