/* Back office — phone first (D15.16). One stylesheet, no external fonts, strict CSP (no inline styles). */
:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --ink: #15201b;
  --ink-2: #33423b;
  --muted: #69776f;
  --line: #dde2dc;
  --brand: #0e7a52;
  --brand-2: #0b6143;
  --brand-ink: #ffffff;
  --brand-soft: #e2f3eb;
  --ok: #117a3e;
  --warn: #9a6400;
  --warn-soft: #fff4dc;
  --danger: #b3261e;
  --danger-soft: #fde8e6;
  --info-soft: #e6effa;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.06), 0 6px 20px rgba(16, 24, 20, 0.06);
  --tab-h: 64px;
  --top-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0e1411;
    --surface: #151d19;
    --surface-2: #1c2621;
    --ink: #e8efea;
    --ink-2: #c7d3cb;
    --muted: #8fa097;
    --line: #26332c;
    --brand: #2fb981;
    --brand-2: #25a070;
    --brand-ink: #06140d;
    --brand-soft: #143325;
    --warn-soft: #3a2c10;
    --danger-soft: #3b1714;
    --info-soft: #162536;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0e1411;
  --surface: #151d19;
  --surface-2: #1c2621;
  --ink: #e8efea;
  --ink-2: #c7d3cb;
  --muted: #8fa097;
  --line: #26332c;
  --brand: #2fb981;
  --brand-2: #25a070;
  --brand-ink: #06140d;
  --brand-soft: #143325;
  --warn-soft: #3a2c10;
  --danger-soft: #3b1714;
  --info-soft: #162536;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 8px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; font-weight: 750; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 650; color: var(--ink-2); }
p { margin: 0.4rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.path { font: 0.8rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.voidform { display: flex; gap: 8px; padding: 0 14px 12px; }
.voidform input { flex: 1; min-width: 0; }
.money, .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.exact { display: block; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell ---------- */
.devbar { background: #1d2b24; color: #d7f5e6; text-align: center; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; padding: 3px 8px; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top-h);
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .back { font-size: 1.4rem; line-height: 1; padding: 6px 8px 6px 0; color: var(--ink); }
.topbar h1 { flex: 1; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wallet-chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: 999px; padding: 7px 12px; font: inherit; font-weight: 650; font-size: 0.95rem; cursor: pointer;
}
.wallet-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
main { padding: 14px 14px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.stack > * + * { margin-top: 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 0.72rem; font-weight: 600; min-width: 0; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current='page'] { color: var(--brand); }
.tabbar a.fab { position: relative; top: -14px; }
.tabbar a.fab span.ic { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); box-shadow: 0 8px 18px color-mix(in srgb, var(--brand) 45%, transparent); }
.tabbar a.fab span.ic svg { width: 26px; height: 26px; }
.sidebar { display: none; }

@media (min-width: 900px) {
  body { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
  .devbar { grid-column: 1 / -1; }
  .sidebar { display: flex; flex-direction: column; gap: 4px; padding: 18px 12px; border-right: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; height: 100vh; }
  .sidebar .brand { font-weight: 800; font-size: 1.05rem; padding: 6px 10px 16px; }
  .sidebar a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 600; }
  .sidebar a svg { width: 20px; height: 20px; }
  .sidebar a[aria-current='page'] { background: var(--brand-soft); color: var(--brand); }
  .sidebar .grow { flex: 1; }
  .tabbar { display: none; }
  .shell { min-width: 0; }
  main { padding: 22px 28px 40px; }
  .topbar { padding: 0 28px; }
}

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.flat { box-shadow: none; }
.card h2 + * { margin-top: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head > .rowitem { flex: 1; min-width: 0; } /* a long name/chain line ellipsizes instead of widening the page */
.hero { background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%); color: var(--brand-ink); border: none; }
.hero .label { opacity: 0.85; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.hero .big { font-size: 2.1rem; font-weight: 800; letter-spacing: -0.02em; margin: 2px 0 8px; }
.hero .row2 { display: flex; gap: 18px; flex-wrap: wrap; font-size: 0.9rem; }
.hero .row2 b { display: block; font-size: 1.05rem; }
.hero .actions { display: flex; gap: 8px; margin-top: 14px; }
.hero .btn { background: rgba(255, 255, 255, 0.18); color: inherit; border-color: transparent; }
.hero .btn.primary { background: var(--brand-ink); color: var(--brand); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .hero .btn.primary { background: #06140d; color: var(--brand); } }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.kpi .k { color: var(--muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .v { font-size: 1.25rem; font-weight: 750; margin-top: 2px; }

/* list rows (cards on a phone — the template's weak spot, D15.16) */
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rows > li + li { border-top: 1px solid var(--line); }
.rowlink, .rowitem { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--ink); min-height: 64px; }
a.rowlink:active { background: var(--surface-2); }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 0.85rem; background: var(--brand-soft); color: var(--brand); }
.avatar.r-CITY { background: #e7ecfb; color: #2c4db3; }
.avatar.r-SUPER { background: #f3e8fb; color: #7a3db3; }
.avatar.r-AGENT { background: #fbeee2; color: #a4541a; }
.avatar.r-PLAYER { background: var(--surface-2); color: var(--ink-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .avatar.r-CITY, :root:not([data-theme='light']) .avatar.r-SUPER, :root:not([data-theme='light']) .avatar.r-AGENT { background: var(--surface-2); } }
.rowmain { flex: 1; min-width: 0; }
.rowmain .t { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowmain .s { color: var(--muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowend { text-align: right; flex: none; }
.rowend .t { font-weight: 700; }
.chev { color: var(--muted); flex: none; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; background: var(--surface-2); color: var(--ink-2); vertical-align: middle; }
.badge.ok { background: var(--brand-soft); color: var(--brand); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: 0.85rem; }
.kv dd { margin: 0; text-align: right; font-weight: 600; }

.crumbs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; font-size: 0.85rem; padding-bottom: 2px; }
.crumbs a, .crumbs span { flex: none; padding: 5px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); }
.crumbs span[aria-current] { background: var(--brand-soft); color: var(--brand); border-color: transparent; font-weight: 700; }

.seg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.seg a { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); font-weight: 650; font-size: 0.9rem; }
.seg a[aria-current='page'] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--info-soft); color: var(--ink-2); font-size: 0.82rem; font-weight: 600; }
.chip a { color: var(--muted); font-weight: 800; }
.toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.banner { border-radius: var(--radius-sm); padding: 10px 14px; font-weight: 600; font-size: 0.92rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.ok { background: var(--brand-soft); color: var(--brand); }
.banner.info { background: var(--info-soft); color: var(--ink-2); }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty .big { font-size: 2rem; }

/* ---------- forms ---------- */
.field { display: block; }
.field + .field { margin-top: 12px; }
.field > span { display: block; font-size: 0.82rem; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; }
.field .hint { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 5px; font-weight: 400; }
input[type='text'], input[type='password'], input[type='date'], input[type='search'], input:not([type]), select, textarea {
  width: 100%; min-height: 48px; padding: 12px 14px; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input.amount { font-size: 1.8rem; font-weight: 750; text-align: center; letter-spacing: -0.01em; min-height: 64px; }
input.code { font-size: 1.6rem; letter-spacing: 0.35em; text-align: center; font-variant-numeric: tabular-nums; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 0.85rem; border-radius: 10px; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.sticky { position: sticky; bottom: calc(var(--tab-h) + 10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); padding-top: 18px; }
@media (min-width: 900px) { .actions.sticky { bottom: 10px; } }
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.radio-cards label { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); cursor: pointer; }
.radio-cards input { margin-right: 6px; }
.radio-cards label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.radio-cards small { display: block; color: var(--muted); margin-top: 2px; }

/* ---------- transfer confirm ---------- */
.flow { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: stretch; }
.flow .side { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; min-width: 0; }
.flow .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow .arrow { display: grid; place-items: center; color: var(--brand); font-size: 1.4rem; font-weight: 800; }
.flow .before { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }
.flow .after { font-weight: 750; font-size: 1.05rem; }
.amount-hero { text-align: center; padding: 8px 0 4px; }
.amount-hero .big { font-size: 2.4rem; font-weight: 800; letter-spacing: -0.02em; }
.secret { font: 600 1.2rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.06em; word-break: break-all; background: var(--surface-2); border-radius: 12px; padding: 12px; text-align: center; user-select: all; }
.qr { display: grid; place-items: center; background: #fff; border-radius: 14px; padding: 14px; width: min(260px, 100%); margin: 0 auto; }
.qr svg { width: 100%; height: auto; display: block; }

/* ---------- tables (desktop) + report rows ---------- */
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.t th { text-align: left; color: var(--muted); font-weight: 650; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t td.r, table.t th.r { text-align: right; }
.only-desktop { display: none; }
@media (min-width: 900px) { .only-desktop { display: block; } .only-phone { display: none; } }

/* ---------- sheets (native <dialog>): bottom sheet on a phone, side drawer on desktop ---------- */
dialog.sheet { border: none; padding: 0; margin: 0; max-width: none; width: 100%; max-height: 88vh; background: var(--surface); color: var(--ink); border-radius: 20px 20px 0 0; position: fixed; inset: auto 0 0 0; }
dialog.sheet::backdrop { background: rgba(8, 14, 11, 0.45); }
dialog.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 2px; }
dialog.sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 4px; }
dialog.sheet .sheet-body { padding: 8px 16px 16px; overflow: auto; max-height: calc(88vh - 120px); }
dialog.sheet .sheet-foot { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
dialog.sheet .sheet-foot .btn { flex: 1; }
@media (min-width: 900px) {
  dialog.sheet { inset: 0 0 0 auto; width: 420px; max-height: 100vh; height: 100vh; border-radius: 20px 0 0 20px; }
  dialog.sheet .grab { display: none; }
  dialog.sheet .sheet-body { max-height: calc(100vh - 130px); }
}

/* ---------- auth screens ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
body.auth-body { display: block; }
.auth .card { width: min(420px, 100%); }
.auth .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.auth .logo .mark { width: 42px; height: 42px; border-radius: 12px; background: var(--brand); display: grid; place-items: center; color: var(--brand-ink); font-weight: 900; }
.steps { display: flex; gap: 6px; margin: 4px 0 14px; }
.steps i { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.steps i.on { background: var(--brand); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); z-index: 50; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 650; box-shadow: var(--shadow); max-width: calc(100% - 28px); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }

/* utilities (the CSP forbids inline style attributes) */
.grow { flex: 1; min-width: 0; }
.p0 { padding: 0; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.w6 { width: 6rem; }
.fig { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.01em; }

/* player record: level bar + league badge */
.levelwrap { display: grid; gap: 6px; }
.levelhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.levelbar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.levelbar i { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.levelbar i.w0 { width: 2%; } .levelbar i.w5 { width: 5%; } .levelbar i.w10 { width: 10%; } .levelbar i.w15 { width: 15%; }
.levelbar i.w20 { width: 20%; } .levelbar i.w25 { width: 25%; } .levelbar i.w30 { width: 30%; } .levelbar i.w35 { width: 35%; }
.levelbar i.w40 { width: 40%; } .levelbar i.w45 { width: 45%; } .levelbar i.w50 { width: 50%; } .levelbar i.w55 { width: 55%; }
.levelbar i.w60 { width: 60%; } .levelbar i.w65 { width: 65%; } .levelbar i.w70 { width: 70%; } .levelbar i.w75 { width: 75%; }
.levelbar i.w80 { width: 80%; } .levelbar i.w85 { width: 85%; } .levelbar i.w90 { width: 90%; } .levelbar i.w95 { width: 95%; }
.levelbar i.w100 { width: 100%; }
.badge.league { background: var(--brand-soft); color: var(--brand-2); }
.badge.league.l1 { background: var(--surface-2); color: var(--ink-2); }
.badge.league.l5 { background: var(--warn-soft); color: var(--warn); }
.big { font-size: 1.6rem; font-weight: 800; }
