/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --text: #17202e;
  --muted: #586478;
  --border: #d5dbe6;
  --primary: #1557b0;
  --primary-text: #ffffff;
  --primary-soft: #e3edfb;
  --ok: #17663a;
  --ok-soft: #dff3e6;
  --warn: #8a4b00;
  --warn-soft: #fdeed3;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --focus: #0b57d0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 10px;
  --tap: 44px;
  --topbar: 56px;
  --nav: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171e28; --surface-2: #1f2835; --text: #e7ecf3; --muted: #a3afc2; --border: #334052;
    --primary: #8ab4f8; --primary-text: #0b1b33; --primary-soft: #1d2f4a;
    --ok: #7fd49b; --ok-soft: #153322; --warn: #f5c26b; --warn-soft: #3a2a0c; --danger: #f2a7a1; --danger-soft: #40191a;
    --focus: #a8c7fa; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171e28; --surface-2: #1f2835; --text: #e7ecf3; --muted: #a3afc2; --border: #334052;
  --primary: #8ab4f8; --primary-text: #0b1b33; --primary-soft: #1d2f4a;
  --ok: #7fd49b; --ok-soft: #153322; --warn: #f5c26b; --warn-soft: #3a2a0c; --danger: #f2a7a1; --danger-soft: #40191a;
  --focus: #a8c7fa; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  overflow-wrap: anywhere; word-break: normal;
}
h1, h2, h3 { line-height: 1.25; margin: 0; overflow-wrap: anywhere; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .small { font-size: .875rem; }
.muted { color: var(--muted); }
a { color: var(--primary); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.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; }

/* Text links are tall enough to tap. */
.link { display: inline-flex; align-items: center; min-height: var(--tap); min-width: var(--tap); max-width: 100%; font-weight: 600; }

/* ------------------------------------------------------------------ shell */
.skip { position: absolute; left: 8px; top: -80px; z-index: 50; background: var(--surface); padding: 12px 16px; border-radius: 8px; min-height: var(--tap); display: inline-flex; align-items: center; }
.skip:focus { top: 8px; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar); display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
/* The brand name is never squeezed by the account menu; only a very long reseller name (over half the screen) is shortened. */
.brand { display: inline-block; line-height: var(--tap); min-height: var(--tap); min-width: var(--tap); max-width: 50vw; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto; }
.topbar-right { flex: 1 1 0; display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.topbar-right .combo { width: auto; max-width: 100%; min-width: var(--tap); flex: 0 1 auto; }
.topbar-right .combo-btn { border-color: transparent; background: transparent; }
.icon-btn {
  width: var(--tap); height: var(--tap); flex: 0 0 var(--tap); display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--text); font-size: 1.25rem; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.nav-toggle { display: none; }
.shell { display: grid; grid-template-columns: var(--nav) minmax(0, 1fr); min-height: calc(100vh - var(--topbar)); }
.sidenav { background: var(--surface); border-right: 1px solid var(--border); padding: 12px 8px; }
.sidenav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sidenav a {
  display: flex; align-items: center; min-height: var(--tap); padding: 8px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.sidenav a:hover { background: var(--surface-2); }
.sidenav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.nav-scrim { display: none; }
main { padding: 20px; min-width: 0; max-width: 1400px; width: 100%; }

@media (max-width: 1023.98px) {
  .nav-toggle { display: inline-flex; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidenav {
    position: fixed; z-index: 40; top: var(--topbar); bottom: 0; left: 0; width: min(300px, 86vw);
    transform: translateX(-105%); transition: transform .18s ease; overflow-y: auto; box-shadow: var(--shadow);
    visibility: hidden;
  }
  .nav-open .sidenav { transform: none; visibility: visible; }
  .nav-open .nav-scrim { display: block; position: fixed; z-index: 35; inset: var(--topbar) 0 0 0; background: rgba(0, 0, 0, .45); }
  main { padding: 16px 12px; }
}
@media (prefers-reduced-motion: reduce) { .sidenav { transition: none; } }

/* ------------------------------------------------------------------ page pieces */
.pagehead { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.pagehead > div:first-child { flex: 1 1 260px; min-width: 0; }
.pagehead .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; min-width: 0; }
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.card-head h2 { flex: 1 1 200px; min-width: 0; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); margin-bottom: 16px; }
.grid .card { margin-bottom: 0; }
.stat .label { color: var(--muted); font-size: .875rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat .hint { color: var(--muted); font-size: .875rem; }
.kv { display: grid; grid-template-columns: minmax(110px, 200px) minmax(0, 1fr); gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }
@media (max-width: 560px) { .kv { grid-template-columns: minmax(0, 1fr); } .kv dd { margin-bottom: 8px; } }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: normal; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.flash, .notice { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.flash.error, .form-error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.notice.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.form-error { border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }

.seatbar { display: grid; gap: 4px; margin-bottom: 12px; }
.seatbar .row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
progress { width: 100%; height: 10px; accent-color: var(--primary); }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); min-width: var(--tap);
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; text-align: center; max-width: 100%;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ------------------------------------------------------------------ forms */
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
.field.wide { grid-column: 1 / -1; }
.field > label, .field > .label { font-weight: 600; }
.field .help { color: var(--muted); font-size: .875rem; }
.field-error { color: var(--danger); font-size: .875rem; font-weight: 600; }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="number"], input[type="search"], input[type="file"], textarea {
  width: 100%; min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; min-width: 0;
}
textarea { min-height: 96px; resize: vertical; }
input::placeholder { color: var(--muted); opacity: 1; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 4px 0; cursor: pointer; }
.check input { width: 24px; height: 24px; flex: 0 0 24px; accent-color: var(--primary); margin: 0; }
.check span { min-width: 0; }
.checks { display: grid; gap: 2px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; margin-bottom: 12px; }
.toolbar .field { flex: 1 1 220px; }
.toolbar .btn { flex: 0 0 auto; }

/* ------------------------------------------------------------------ searchable dropdown */
select { width: 100%; min-height: var(--tap); font: inherit; }
.combo { position: relative; width: 100%; min-width: 0; }
.combo-native { position: absolute !important; inset: 0 auto auto 0; width: 1px !important; height: 1px !important; min-height: 0 !important; opacity: 0; pointer-events: none; }
.combo-btn {
  width: 100%; min-height: var(--tap); display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer; min-width: 0;
}
.combo-btn:hover { background: var(--surface-2); }
.combo-btn[disabled] { opacity: .6; cursor: not-allowed; }
.combo-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-text.is-placeholder { color: var(--muted); }
.combo-caret { flex: 0 0 auto; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid currentColor; opacity: .7; }
.combo-actions { width: auto; display: inline-block; max-width: 100%; }
.combo-actions .combo-btn { width: auto; max-width: 100%; font-weight: 600; }
.combo-pop {
  position: fixed; z-index: 100; display: flex; flex-direction: column; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); padding: 8px; overflow: hidden;
}
.combo-search { flex: 0 0 auto; margin-bottom: 6px; }
.combo-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.combo-list li { display: flex; flex-direction: column; justify-content: center; min-height: var(--tap); padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.combo-list li:hover, .combo-list li.is-active { background: var(--primary-soft); }
.combo-list li[aria-selected="true"] { font-weight: 700; }
.combo-list li.is-danger { color: var(--danger); }
.combo-list .o-sub { color: var(--muted); font-size: .8125rem; }
.combo-empty { padding: 12px 10px; color: var(--muted); }
.combo-add { flex: 0 0 auto; margin-top: 6px; min-height: var(--tap); border: 1px dashed var(--border); border-radius: 8px; background: var(--surface-2); color: var(--primary); font: inherit; font-weight: 700; cursor: pointer; text-align: left; padding: 8px 12px; }

/* ------------------------------------------------------------------ tables (stack into cards on narrow screens) */
.table-wrap { width: 100%; min-width: 0; }
table.table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; min-width: 0; }
.table th { color: var(--muted); font-size: .8125rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 700; }
.table td.num, .table th.num { text-align: right; }
.table .col-actions { width: 150px; }
.table .col-narrow { width: 110px; }
.table .col-mid { width: 18%; }
.table .col-check { width: 72px; }
.col-check .check { min-width: var(--tap); }
fieldset.field { border: 0; padding: 0; margin: 0 0 16px; }
fieldset.field > legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
.table tbody tr:last-child td { border-bottom: 0; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: .875rem; }
.empty { padding: 20px 12px; color: var(--muted); }
@media (max-width: 899.98px) {
  table.table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .table tr { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; background: var(--surface); }
  .table td { border: 0; padding: 6px 0; display: grid; grid-template-columns: minmax(84px, 34%) minmax(0, 1fr); gap: 10px; align-items: center; text-align: left; }
  .table td.num { text-align: left; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .8125rem; font-weight: 700; }
  .table td.col-actions { width: 100%; }
}

/* ------------------------------------------------------------------ dialogs */
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text);
  width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dialog-body { padding: 16px; overflow-y: auto; max-height: calc(100vh - 24px); }
.dialog-body h2 { margin-bottom: 12px; }

/* ------------------------------------------------------------------ sign-in pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; max-width: none; }
.auth-card { width: min(440px, 100%); }
.auth-brand { font-size: 1.4rem; font-weight: 800; margin-bottom: 4px; }
.auth-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.qr { display: block; width: 200px; height: 200px; max-width: 100%; background: #fff; padding: 8px; border-radius: 8px; image-rendering: pixelated; }
.secret { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 1rem; letter-spacing: .06em; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; display: block; }
.pager { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
pre.mail { white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 8px; margin: 0; font-size: .875rem; }
.list-plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.secret code { display: inline-block; font-size: 1.4rem; padding: 10px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); overflow-wrap: anywhere; user-select: all; }
