/* =========================================================================
   FamilySehat — Admin design system
   Tokens → base → shell → components → pages. Light + dark themes.
   ========================================================================= */

:root {
  color-scheme: light;
  --bg: #F5F7F6;
  --surface: #FFFFFF;
  --surface-2: #F8FAF9;
  --surface-3: #EFF3F1;
  --border: #E4EAE7;
  --border-strong: #D2DBD6;
  --text: #0F1C16;
  --text-2: #4B5B53;
  --text-3: #7D8B84;

  --primary: #1F7A4D;
  --primary-hover: #17643F;
  --primary-soft: #E6F3EC;
  --primary-soft-2: #CFE8DA;
  --primary-text: #145A37;
  --ring: rgba(31, 122, 77, .28);

  --success: #1F7A4D;  --success-soft: #E6F3EC;  --success-text: #145A37;
  --warning: #B7791F;  --warning-soft: #FDF4E3;  --warning-text: #8A5A12;
  --danger:  #D14343;  --danger-soft:  #FDECEC;  --danger-text:  #A12D2D;
  --info:    #2F6FDB;  --info-soft:    #EAF1FD;  --info-text:    #1F4FA3;
  --neutral-soft: #EEF2F0; --neutral-text: #56655D;

  --sidebar-bg: #0D2219;
  --sidebar-bg-2: #12301F;
  --sidebar-text: #A9C0B4;
  --sidebar-text-strong: #F1F7F4;
  --sidebar-muted: #6F8B7D;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(110, 214, 155, .14);
  --sidebar-accent: #6ED69B;
  --sidebar-border: rgba(255, 255, 255, .08);

  --chart-1: #1F7A4D; --chart-2: #6ED69B; --chart-3: #2F6FDB; --chart-4: #E0A100; --chart-5: #9B5DE5;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --shadow-xs: 0 1px 2px rgba(15, 28, 22, .05);
  --shadow-sm: 0 1px 2px rgba(15, 28, 22, .04), 0 1px 3px rgba(15, 28, 22, .06);
  --shadow: 0 4px 12px -2px rgba(15, 28, 22, .08), 0 2px 4px -2px rgba(15, 28, 22, .05);
  --shadow-lg: 0 24px 48px -12px rgba(15, 28, 22, .25);
  --sidebar-w: 256px;
  --topbar-h: 60px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0A120E;
  --surface: #101B16;
  --surface-2: #13211A;
  --surface-3: #18291F;
  --border: #213229;
  --border-strong: #2C4237;
  --text: #E6EFEA;
  --text-2: #A5B7AE;
  --text-3: #74877D;

  --primary: #3DB878;
  --primary-hover: #52C98A;
  --primary-soft: rgba(61, 184, 120, .13);
  --primary-soft-2: rgba(61, 184, 120, .22);
  --primary-text: #7EDCA9;
  --ring: rgba(61, 184, 120, .35);

  --success: #3DB878;  --success-soft: rgba(61, 184, 120, .13);  --success-text: #7EDCA9;
  --warning: #E3A33B;  --warning-soft: rgba(227, 163, 59, .14);  --warning-text: #F0C27A;
  --danger:  #F06A6A;  --danger-soft:  rgba(240, 106, 106, .14); --danger-text:  #F7A1A1;
  --info:    #5B92F0;  --info-soft:    rgba(91, 146, 240, .14);  --info-text:    #A3C2F7;
  --neutral-soft: rgba(165, 183, 174, .12); --neutral-text: #A5B7AE;

  --sidebar-bg: #08110D;
  --sidebar-bg-2: #0C1913;
  --sidebar-border: rgba(255, 255, 255, .06);

  --chart-1: #3DB878; --chart-2: #8BE3B2; --chart-3: #5B92F0; --chart-4: #E3A33B; --chart-5: #B58AF0;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .25);
  --shadow: 0 4px 12px -2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01";
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
h1, h2, h3, h4 { margin: 0; color: var(--text); letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 700; line-height: 1.25; letter-spacing: -.02em; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 12px; }
code, .mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.icon { flex-shrink: 0; display: inline-block; vertical-align: middle; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.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; }
::selection { background: var(--primary-soft-2); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-text); border-right: 1px solid var(--sidebar-border);
  transition: transform .25s var(--ease);
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; height: var(--topbar-h); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, #3DB878 0%, #1F7A4D 100%); color: #fff;
  box-shadow: 0 4px 12px -4px rgba(61, 184, 120, .6), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.brand-name { color: var(--sidebar-text-strong); font-weight: 700; font-size: 15px; letter-spacing: -.01em; line-height: 1.15; }
.brand-sub { color: var(--sidebar-muted); font-size: 11.5px; font-weight: 500; }
.sidebar-close { margin-left: auto; display: none; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 12px 16px; }
.nav-section { margin-top: 18px; }
.nav-section:first-child { margin-top: 6px; }
.nav-label { padding: 0 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--sidebar-muted); }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; margin: 1px 0; border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-weight: 500; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-link .icon { opacity: .85; }
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
.nav-link.active { background: var(--sidebar-active); color: var(--sidebar-text-strong); }
.nav-link.active .icon { color: var(--sidebar-accent); opacity: 1; }
.nav-link.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--sidebar-accent);
}

.sidebar-foot { border-top: 1px solid var(--sidebar-border); padding: 12px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius); }
.user-card .who { min-width: 0; flex: 1; }
.user-card .name { color: var(--sidebar-text-strong); font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card .role { color: var(--sidebar-muted); font-size: 11.5px; }
.sidebar-actions { display: flex; gap: 4px; margin-top: 4px; }
.sidebar-actions a, .sidebar-actions button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 8px; border-radius: var(--radius-sm); border: 1px solid var(--sidebar-border);
  background: transparent; color: var(--sidebar-text); font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.sidebar-actions a:hover, .sidebar-actions button:hover, .sidebar-actions a.active { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
.sidebar-actions form { flex: 1; display: flex; margin: 0; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 32px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(10px); -webkit-backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--border);
}
.menu-toggle { display: none; }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; color: var(--text-3); }
.crumbs a { color: var(--text-2); font-weight: 500; }
.crumbs a:hover { color: var(--text); }
.crumbs .current { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs .icon { color: var(--text-3); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.content { width: 100%; max-width: 1360px; margin: 0 auto; padding: 28px 32px 56px; flex: 1; }
.app-footer { padding: 16px 32px 24px; color: var(--text-3); font-size: 12px; max-width: 1360px; width: 100%; margin: 0 auto; }

.sidebar-backdrop { display: none; }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-header .titles { min-width: 0; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); margin-bottom: 6px; display: inline-flex; align-items: center; gap: 6px; }
.page-sub { margin: 6px 0 0; color: var(--text-2); font-size: 14px; max-width: 72ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-weight: 500; font-size: 13px; margin-bottom: 10px; }
.back-link:hover { color: var(--text); }

/* ---------- Layout helpers ---------- */
.stack { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.tight { gap: 6px; }
.spacer { flex: 1; }
.grid { display: grid; gap: 20px; }
.grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.c-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs); min-width: 0;
}
.card + .card { margin-top: 20px; }
.grid > .card + .card, .stack > .card + .card { margin-top: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-header.plain { border-bottom: 0; padding-bottom: 4px; }
.card-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; }
.card-title .icon { color: var(--text-3); }
.card-desc { color: var(--text-3); font-size: 13px; margin-top: 2px; font-weight: 400; }
.card-body { padding: 20px; }
.card-body.tight { padding: 12px 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card.flush > .table-wrap { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* KPI */
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.kpi-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi-icon.info { background: var(--info-soft); color: var(--info); }
.kpi-icon.warning { background: var(--warning-soft); color: var(--warning); }
.kpi-icon.violet { background: color-mix(in srgb, var(--chart-5) 14%, transparent); color: var(--chart-5); }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-value .unit { font-size: 15px; font-weight: 600; color: var(--text-3); margin-left: 3px; }
.kpi-foot { font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.kpi-plain { padding: 14px 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.kpi-plain .kpi-label { font-size: 12.5px; }
.kpi-plain .kpi-value { font-size: 22px; margin-top: 4px; }

/* Charts */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.chart-box.lg { height: 320px; }

/* ---------- Buttons ---------- */
.btn, button {
  --btn-bg: var(--primary); --btn-fg: #fff; --btn-bd: var(--primary); --btn-hover: var(--primary-hover);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--btn-bd); background: var(--btn-bg); color: var(--btn-fg);
  font: inherit; font-size: 13.5px; font-weight: 600; line-height: 1; white-space: nowrap;
  cursor: pointer; text-decoration: none; user-select: none;
  box-shadow: var(--shadow-xs);
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:hover, button:hover { background: var(--btn-hover); border-color: var(--btn-hover); color: var(--btn-fg); }
.btn:active, button:active { transform: translateY(1px); }
.btn:focus-visible, button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn[disabled], button[disabled] { opacity: .6; cursor: not-allowed; transform: none; }

.btn.secondary, button.secondary { --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border-strong); --btn-hover: var(--surface-3); }
.btn.secondary:hover, button.secondary:hover { border-color: var(--border-strong); }
.btn.ghost, button.ghost { --btn-bg: transparent; --btn-fg: var(--text-2); --btn-bd: transparent; --btn-hover: var(--surface-3); box-shadow: none; }
.btn.ghost:hover, button.ghost:hover { color: var(--text); }
.btn.danger, button.danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); --btn-hover: color-mix(in srgb, var(--danger) 86%, #000); }
.btn.danger-outline, button.danger-outline { --btn-bg: var(--surface); --btn-fg: var(--danger-text); --btn-bd: color-mix(in srgb, var(--danger) 35%, var(--border)); --btn-hover: var(--danger-soft); }
.btn.danger-outline:hover, button.danger-outline:hover { border-color: var(--danger); }
.btn.success-soft, button.success-soft { --btn-bg: var(--success-soft); --btn-fg: var(--success-text); --btn-bd: transparent; --btn-hover: var(--primary-soft-2); box-shadow: none; }
.btn.sm, button.sm { height: 30px; padding: 0 10px; font-size: 12.5px; gap: 5px; border-radius: 7px; }
.btn.lg, button.lg { height: 42px; padding: 0 18px; font-size: 14.5px; }
.btn.block, button.block { width: 100%; }
.btn.icon-only, button.icon-only { width: 36px; padding: 0; }
.btn.icon-only.sm, button.icon-only.sm { width: 30px; }
.btn.is-loading, button.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after, button.is-loading::after {
  content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-right-color: transparent; animation: spin .7s linear infinite;
}
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.link-btn { background: none; border: 0; padding: 0; height: auto; color: var(--primary); font-weight: 600; box-shadow: none; cursor: pointer; }
.link-btn:hover { background: none; color: var(--primary-hover); text-decoration: underline; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
.field-label .opt { font-weight: 400; color: var(--text-3); }
.field-hint { font-size: 12.5px; color: var(--text-3); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); cursor: pointer; }
.check input[type=checkbox] { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--primary); cursor: pointer; }
label { font-size: 13px; font-weight: 600; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], input[type=url], input:not([type]), select, textarea {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
  box-shadow: var(--shadow-xs);
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; }
input::placeholder { color: var(--text-3); }
input:hover, select:hover { border-color: color-mix(in srgb, var(--border-strong) 60%, var(--text-3)); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input[type=date], input[type=datetime-local] { padding-right: 8px; }
:root[data-theme="dark"] input[type=date]::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type=datetime-local]::-webkit-calendar-picker-indicator { filter: invert(.8); }
select {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237D8B84' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}

.input-group { position: relative; display: flex; align-items: center; }
.input-group > .icon { position: absolute; left: 11px; color: var(--text-3); pointer-events: none; }
.input-group > .icon ~ input { padding-left: 36px; }
.input-group > .suffix { position: absolute; right: 12px; color: var(--text-3); font-size: 13px; pointer-events: none; }
.input-group > input.has-suffix { padding-right: 52px; }
.input-group > .reveal {
  position: absolute; right: 4px; height: 30px; width: 30px; padding: 0; border: 0; box-shadow: none;
  background: transparent; color: var(--text-3);
}
.input-group > .reveal:hover { background: var(--surface-3); color: var(--text); }
.input-group > input.has-reveal { padding-right: 40px; }
.input-lg { height: 42px !important; font-size: 15px !important; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 16px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .input-group { flex: 1 1 260px; max-width: 380px; }
.toolbar select { width: auto; min-width: 150px; }
.toolbar .meta { margin-left: auto; color: var(--text-3); font-size: 13px; }

/* Settings rows */
.settings-section { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 32px; padding: 28px 0; border-bottom: 1px solid var(--border); }
.settings-section:first-of-type { padding-top: 4px; }
.settings-section h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.settings-section h2 .icon { color: var(--primary); }
.settings-section .section-desc { color: var(--text-2); font-size: 13.5px; margin-top: 6px; }
.save-bar {
  position: sticky; bottom: 16px; z-index: 10; margin-top: 24px;
  display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-3);
  font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
  padding-top: 10px; padding-bottom: 10px;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions, th.actions { text-align: right; white-space: nowrap; width: 1%; }
td.actions .btn-group { justify-content: flex-end; flex-wrap: nowrap; }
.cell-user { display: flex; align-items: center; gap: 11px; min-width: 180px; }
.cell-user .meta { min-width: 0; }
.cell-user .primary { font-weight: 600; color: var(--text); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-user a.primary:hover { color: var(--primary); }
.cell-user .secondary { font-size: 12.5px; color: var(--text-3); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.na { color: var(--text-3); }

/* Definition list */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 0; margin: 0; }
.dl dt, .dl dd { padding: 11px 0; border-bottom: 1px solid var(--border); margin: 0; }
.dl dt { color: var(--text-3); font-size: 13px; padding-right: 24px; }
.dl dd { color: var(--text); font-weight: 500; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.dl dt:last-of-type, .dl dd:last-of-type { border-bottom: 0; }

/* ---------- Badges, avatars, chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral-text);
}
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.success { background: var(--success-soft); color: var(--success-text); }
.badge.warning { background: var(--warning-soft); color: var(--warning-text); }
.badge.danger { background: var(--danger-soft); color: var(--danger-text); }
.badge.info { background: var(--info-soft); color: var(--info-text); }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-2); }
.badge .icon { width: 12px; height: 12px; }

.avatar {
  --h: 150;
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 700; letter-spacing: .01em;
  background: hsl(var(--h) 55% 92%); color: hsl(var(--h) 45% 30%);
}
:root[data-theme="dark"] .avatar { background: hsl(var(--h) 35% 22%); color: hsl(var(--h) 60% 80%); }
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }
.avatar.xl { width: 72px; height: 72px; font-size: 24px; }
.avatar.on-dark { background: rgba(255, 255, 255, .1); color: var(--sidebar-text-strong); }

.code-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 4px 0 12px;
  border-radius: var(--radius-sm); background: var(--surface-3); border: 1px solid var(--border);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; font-weight: 600; letter-spacing: .04em;
}
.code-chip.lg { height: 44px; font-size: 18px; padding: 0 6px 0 16px; letter-spacing: .08em; }
.code-chip button { height: 26px; width: 26px; padding: 0; background: transparent; border: 0; color: var(--text-3); box-shadow: none; }
.code-chip.lg button { height: 34px; width: 34px; }
.code-chip button:hover { background: var(--surface); color: var(--text); }
.code-chip.inactive { opacity: .6; text-decoration: line-through; }

/* Progress */
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.progress.warning > span { background: var(--warning); }
.progress.danger > span { background: var(--danger); }
.progress.lg { height: 8px; }
.usage { display: flex; align-items: center; gap: 10px; min-width: 140px; }
.usage .progress { flex: 1; }
.usage .label { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Alerts / callouts ---------- */
.alert {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px;
  border-radius: var(--radius); border: 1px solid transparent; font-size: 13.5px; margin-bottom: 16px;
}
.alert .icon { margin-top: 1px; }
.alert.ok, .alert.success { background: var(--success-soft); color: var(--success-text); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.alert.err, .alert.danger { background: var(--danger-soft); color: var(--danger-text); border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.alert.warning { background: var(--warning-soft); color: var(--warning-text); border-color: color-mix(in srgb, var(--warning) 22%, transparent); }
.alert.info { background: var(--info-soft); color: var(--info-text); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.alert b { font-weight: 650; }

.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border-strong); color: var(--text-2); font-size: 13px; }
.callout .icon { color: var(--text-3); margin-top: 1px; }

/* Credential reveal */
.credential { border: 1px solid color-mix(in srgb, var(--success) 30%, var(--border)); background: linear-gradient(180deg, var(--success-soft), var(--surface) 70%); border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.credential-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.credential-head .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--success); color: #fff; }
.credential-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.credential-field { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.credential-field .k { font-size: 11.5px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.credential-field .v { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; font-weight: 600; word-break: break-all; }
.credential-field .grow { flex: 1; min-width: 0; }
.credential-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--warning-text); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 10px; width: min(400px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 14px 14px 16px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: toast-in .3s var(--ease);
}
.toast .ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.toast.success .ico { background: var(--success-soft); color: var(--success); }
.toast.error .ico { background: var(--danger-soft); color: var(--danger); }
.toast .body { flex: 1; min-width: 0; padding-top: 3px; }
.toast .title { font-weight: 600; font-size: 13.5px; }
.toast .msg { color: var(--text-2); font-size: 13px; margin-top: 2px; word-wrap: break-word; }
.toast .close { height: 26px; width: 26px; padding: 0; background: transparent; border: 0; box-shadow: none; color: var(--text-3); }
.toast .close:hover { background: var(--surface-3); color: var(--text); }
.toast.leaving { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Dialogs ---------- */
dialog.modal {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius-xl);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.modal.wide { width: min(760px, calc(100vw - 32px)); }
dialog.modal.narrow { width: min(440px, calc(100vw - 32px)); }
dialog.modal[open] { display: flex; flex-direction: column; animation: dialog-in .22s var(--ease); }
dialog.modal::backdrop { background: rgba(8, 17, 13, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade-in .2s ease; }
dialog.modal > form { display: flex; flex-direction: column; min-height: 0; flex: 1; margin: 0; }
.modal-header { display: flex; align-items: flex-start; gap: 14px; padding: 20px 22px 4px; }
.modal-header .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--primary-soft); color: var(--primary); }
.modal-header .ico.danger { background: var(--danger-soft); color: var(--danger); }
.modal-header .ico.warning { background: var(--warning-soft); color: var(--warning); }
.modal-header h2 { font-size: 17px; }
.modal-header p { margin: 4px 0 0; color: var(--text-2); font-size: 13.5px; }
.modal-header .x { margin-left: auto; height: 32px; width: 32px; padding: 0; background: transparent; border: 0; box-shadow: none; color: var(--text-3); }
.modal-header .x:hover { background: var(--surface-3); color: var(--text); }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.modal-footer .left { margin-right: auto; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
body.modal-open { overflow: hidden; }

/* ---------- Pager ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager .summary { color: var(--text-3); font-size: 13px; }
.pager .summary b { color: var(--text); font-weight: 600; }
.pager .pages { display: flex; gap: 4px; align-items: center; }
.pager .pg {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  color: var(--text-2); font-weight: 500; font-size: 13px; border: 1px solid transparent;
}
.pager a.pg:hover { background: var(--surface-3); color: var(--text); }
.pager .pg.current { background: var(--primary); color: #fff; font-weight: 600; }
.pager .pg.disabled { color: var(--text-3); opacity: .5; }
.pager .pg.gap { min-width: 20px; }

/* ---------- Tabs / segmented ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: -1px;
  color: var(--text-2); font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary-text); border-bottom-color: var(--primary); font-weight: 600; }
:root[data-theme="dark"] .tabs a.active { color: var(--primary); }
/* Label in front of a group of tabs (e.g. one game's pages); every group after the first gets a divider. */
.tabs .tabs-group {
  display: inline-flex; align-items: center; padding: 10px 4px 10px 14px; color: var(--text-3);
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap;
}
.tabs .tabs-group + a { padding-left: 8px; }
.tabs a + .tabs-group { margin-left: 8px; border-left: 1px solid var(--border); }

/* Radio group styled as a segmented switch: <div class="segmented"><label><input type="radio">…</label>…</div> */
.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius); }
.segmented.block { display: flex; }
.segmented label {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px;
  border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.segmented.block label { flex: 1; }
.segmented label:hover { color: var(--text); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.segmented label:has(input:checked) .icon { color: var(--primary); }
.segmented label:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--ring); }

[data-when][hidden] { display: none !important; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty .ico { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-3); margin-bottom: 8px; }
.empty .ico.success { background: var(--success-soft); color: var(--success); }
.empty h3 { font-size: 15px; }
.empty p { color: var(--text-3); max-width: 44ch; margin: 0; font-size: 13.5px; }
.empty .row { margin-top: 14px; justify-content: center; }
.empty.sm { padding: 28px 16px; }

/* ---------- List rows ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; display: block; }
.list .sub { color: var(--text-3); font-size: 12.5px; display: block; }

/* ---------- Leaderboards / podium ---------- */
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: end; }
.podium-place {
  position: relative; text-align: center; padding: 22px 16px 18px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.podium-place.first { padding-top: 30px; padding-bottom: 26px; border-color: color-mix(in srgb, #E0A100 40%, var(--border)); background: linear-gradient(180deg, color-mix(in srgb, #E0A100 10%, var(--surface)), var(--surface)); }
.podium-place .medal { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #fff; position: absolute; top: -14px; box-shadow: var(--shadow-sm); }
.medal.gold { background: linear-gradient(135deg, #F5C542, #D49B0B); }
.medal.silver { background: linear-gradient(135deg, #C9D1D6, #8F9BA3); }
.medal.bronze { background: linear-gradient(135deg, #E3A577, #B06A3A); }
.podium-place .name { font-weight: 650; }
.podium-place .val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.podium-place .metric { color: var(--text-3); font-size: 12px; margin-top: -6px; }

.rank-list { list-style: none; margin: 0; padding: 6px 0; }
.rank-list li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 8px 20px; }
.rank-list .rk { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--surface-3); color: var(--text-2); font-variant-numeric: tabular-nums; }
.rank-list li:nth-child(1) .rk { background: #FDF0C7; color: #8A6400; }
.rank-list li:nth-child(2) .rk { background: #E8ECEF; color: #4E5A62; }
.rank-list li:nth-child(3) .rk { background: #F6E1D2; color: #8A4B22; }
:root[data-theme="dark"] .rank-list li:nth-child(-n+3) .rk { background: var(--surface-3); color: var(--text); }
.rank-list .nm { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-list .vl { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.rank-list .bar { grid-column: 2 / 4; height: 4px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.rank-list .bar > span { display: block; height: 100%; background: var(--primary); border-radius: inherit; opacity: .8; }

.pct-cell { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; min-width: 110px; }
.pct-cell .progress { width: 56px; }
.pct-cell .icon { color: var(--success); }

/* ---------- Danger zone ---------- */
.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.danger-zone .card-header { border-bottom-color: color-mix(in srgb, var(--danger) 18%, var(--border)); }
.danger-zone .card-title, .danger-zone .card-title .icon { color: var(--danger-text); }
.danger-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.danger-row .t { font-weight: 600; }
.danger-row .d { color: var(--text-2); font-size: 13px; }

/* ---------- Profile header ---------- */
.profile { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.profile .info { min-width: 0; flex: 1; }
.profile h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.profile .meta { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 6px; color: var(--text-2); font-size: 13.5px; }
.profile .meta span { display: inline-flex; align-items: center; gap: 6px; }
.profile .meta .icon { color: var(--text-3); }

/* ---------- Auth ---------- */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-brand {
  position: relative; overflow: hidden; color: #E9F5EE; padding: 48px 56px;
  display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(1200px 600px at -10% -10%, rgba(110, 214, 155, .28), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(47, 111, 219, .18), transparent 60%),
    linear-gradient(160deg, #0D2219 0%, #123A27 55%, #0B1D15 100%);
}
.auth-brand::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: radial-gradient(rgba(255, 255, 255, .08) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
}
.auth-brand > * { position: relative; z-index: 1; }
.auth-brand .logo { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 17px; color: #fff; }
.auth-brand .logo .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
.auth-hero h2 { color: #fff; font-size: 34px; line-height: 1.15; font-weight: 700; letter-spacing: -.025em; max-width: 16ch; }
.auth-hero p { color: #A9C9B8; font-size: 15px; margin-top: 14px; max-width: 42ch; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; display: flex; flex-direction: column; gap: 12px; }
.auth-points li { display: flex; align-items: center; gap: 12px; color: #D5E8DD; font-size: 14px; }
.auth-points .pt { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: rgba(255, 255, 255, .08); color: #6ED69B; border: 1px solid rgba(255, 255, 255, .08); }
.auth-brand .fine { color: #6F8B7D; font-size: 12.5px; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--surface); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .mobile-logo { display: none; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 28px; }
.auth-card h1 { font-size: 26px; }
.auth-card .lead { color: var(--text-2); margin: 8px 0 28px; }
.auth-card .form-stack { gap: 18px; }
.auth-card .between-label { display: flex; justify-content: space-between; align-items: baseline; }
.auth-card .between-label a { font-size: 13px; font-weight: 600; }
.auth-foot { margin-top: 28px; text-align: center; color: var(--text-3); font-size: 13px; }
.auth-foot a { font-weight: 600; }
.steps { display: flex; gap: 8px; margin-bottom: 24px; }
.steps .st { flex: 1; height: 4px; border-radius: 999px; background: var(--surface-3); }
.steps .st.on { background: var(--primary); }
.otp-input { font-family: "JetBrains Mono", ui-monospace, monospace !important; letter-spacing: .5em; text-align: center; font-size: 20px !important; height: 48px !important; font-weight: 600; }
.auth-theme { position: fixed; top: 16px; right: 16px; z-index: 5; }

/* Error page */
.error-page { min-height: 60vh; display: grid; place-items: center; text-align: center; }
.error-page .code { font-size: 64px; font-weight: 800; letter-spacing: -.04em; background: linear-gradient(135deg, var(--primary), var(--chart-2)); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1; }

/* Theme toggle icons */
.theme-toggle .when-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .when-dark { display: inline-block; }
:root[data-theme="dark"] .theme-toggle .when-light { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .grid.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .25s var(--ease), visibility 0s linear .25s; }
  body.sidebar-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow-lg); transition: transform .25s var(--ease); }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(8, 17, 13, .5); animation: fade-in .2s ease; }
  body.sidebar-open { overflow: hidden; }
  .sidebar-close { display: inline-flex; }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 20px; }
  .content { padding: 22px 20px 48px; }
  .app-footer { padding: 12px 20px 20px; }
  .grid.c2, .grid.c-2-1, .grid.c-1-2 { grid-template-columns: minmax(0, 1fr); }
  .settings-section { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .auth-shell { grid-template-columns: minmax(0, 1fr); }
  .auth-brand { display: none; }
  .auth-card .mobile-logo { display: flex; }
}
@media (max-width: 640px) {
  .grid.k4, .grid.k3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .page-header { align-items: flex-start; }
  h1 { font-size: 21px; }
  .podium { grid-template-columns: minmax(0, 1fr); }
  .podium-place.first { order: -1; }
  .toolbar .input-group { max-width: none; }
  .toolbar .meta { margin-left: 0; width: 100%; }
  .kpi-value { font-size: 24px; }
  th, td { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Tanker Escape ---------- */
.board-mini {
  --cell: 9px; --gap: 1px; --pad: 3px;
  position: relative; display: grid; grid-template-columns: repeat(6, var(--cell)); grid-auto-rows: var(--cell); gap: var(--gap);
  width: max-content; padding: var(--pad); border-radius: 6px; background: #2B2F2C;
}
.board-mini.lg { --cell: 22px; --gap: 2px; --pad: 6px; border-radius: 10px; }
.board-mini i { border-radius: 2px; background: rgba(255, 255, 255, .06); }
.board-mini i.t { background: var(--primary); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.board-mini i.w { background: repeating-linear-gradient(45deg, #5d625e 0 2px, #474b48 2px 4px); }
.board-mini i.v0 { background: var(--chart-3); }
.board-mini i.v1 { background: var(--chart-4); }
.board-mini i.v2 { background: var(--chart-5); }
.board-mini i.v3 { background: #C2563A; }
.board-mini i.v4 { background: #2A9AA8; }
.board-mini i.v5 { background: #8A8F55; }
/* Exit gate on the right edge of row 2 */
.board-mini::after {
  content: ""; position: absolute; right: -2px; width: 3px; height: var(--cell); border-radius: 2px; background: var(--warning);
  top: calc(var(--pad) + 2 * (var(--cell) + var(--gap)));
}
.stars { color: var(--warning); letter-spacing: 1px; white-space: nowrap; }
.stock-row { display: grid; grid-template-columns: 104px minmax(0, 1fr) 84px; align-items: center; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.stock-row:last-child { border-bottom: 0; }
.stock-row .progress { height: 10px; }
.stock-row .count { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-2); }
.recent-games { display: flex; flex-wrap: wrap; gap: 6px; }
.recent-games .chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.stock-row .band-range { white-space: nowrap; }
.rank-medal { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-weight: 800; font-size: 12px; color: #fff; }
.game-head .secondary { white-space: normal; }
.games-table td.game { min-width: 190px; }
@media (max-width: 640px) {
  .grid.flag-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stock-row { grid-template-columns: 92px minmax(0, 1fr) 70px; gap: 10px; padding: 12px 16px; }
}
.recent-games .chip.flagged { background: var(--warning-soft); color: var(--warning-text); }

/* ---------- Fuel Line ---------- */
/* Board preview: one <i> per tile, a <b> per pipe arm (n/e/s/w); .r refinery, .p pump, .l locked. */
.pipe-mini {
  --cell: 10px; --pipe: 3px; --pad: 3px;
  display: grid; grid-template-columns: repeat(var(--cols), var(--cell)); grid-auto-rows: var(--cell);
  width: max-content; padding: var(--pad); border-radius: 6px; background: #1C2B36;
  background-image: linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
  background-size: var(--cell) var(--cell); background-position: var(--pad) var(--pad);
}
.pipe-mini.lg { --cell: 24px; --pipe: 6px; --pad: 6px; border-radius: 10px; }
.pipe-mini.wrap { outline: 2px dashed rgba(143, 211, 255, .45); outline-offset: -2px; }
.pipe-mini i { position: relative; }
.pipe-mini i.l { background: rgba(255, 255, 255, .08); }
.pipe-mini b { position: absolute; background: #9FB3C0; border-radius: 1px; }
.pipe-mini b.n, .pipe-mini b.s { left: calc(50% - var(--pipe) / 2); width: var(--pipe); height: 50%; }
.pipe-mini b.e, .pipe-mini b.w { top: calc(50% - var(--pipe) / 2); height: var(--pipe); width: 50%; }
.pipe-mini b.n { top: 0; }
.pipe-mini b.s { bottom: 0; }
.pipe-mini b.e { right: 0; }
.pipe-mini b.w { left: 0; }
.pipe-mini i::after { content: ""; position: absolute; inset: calc(50% - var(--pipe) / 2); border-radius: 1px; background: #9FB3C0; }
.pipe-mini i.r::after { inset: 18%; border-radius: 3px; background: var(--warning); }
.pipe-mini i.p::after { inset: 26%; border-radius: 50%; background: #8FD3FF; }
/* Admin home: one block of figures per game */
.game-figures h3 { font-size: 14px; font-weight: 600; margin: 0 0 10px; }
.game-figures section + section { border-left: 1px solid var(--border); padding-left: 20px; }
.grid.game-kpis { gap: 14px; }
@media (max-width: 900px) { .game-figures section + section { border-left: 0; padding-left: 0; border-top: 1px solid var(--border); padding-top: 16px; } }
