:root {
  --bg: #0b0d14;
  --panel: #12151f;
  --panel-2: #181c28;
  --line: #262b3b;
  --fg: #e7e9f0;
  --muted: #9aa1b5;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
  --mono: ui-monospace, 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { overflow-x: hidden; }
body { overflow-wrap: break-word; }
img, svg { max-width: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.55 -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif; }
a { color: var(--accent-2); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.brk { overflow-wrap: anywhere; word-break: break-word; }
.strong { font-weight: 650; }
.nb { white-space: nowrap; }
.hidden { display: none; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }
.mt6 { margin-top: 6px; } .mt10 { margin-top: 10px; } .mt12 { margin-top: 12px; } .mt14 { margin-top: 14px; } .mb14 { margin-bottom: 14px; }
.toolbar { margin-bottom: 12px; }
.w90 { width: 90px; }
.self-end { align-self: flex-end; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-width: 0; }
.row > input, .row > select, .row > label { max-width: 100%; min-width: 0; }
.row > .muted { min-width: 0; }
.grow { flex: 1 1 auto; }
.right { margin-left: auto; }

/* layout */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; font-size: 15px; }
.brand span { font-size: 11px; color: var(--muted); }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--muted); cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.nav:hover { background: var(--panel-2); color: var(--fg); }
.nav.on { background: linear-gradient(90deg, rgba(124,92,255,.22), rgba(34,211,238,.06)); color: var(--fg); box-shadow: inset 2px 0 0 var(--accent); }
.nav .ico { width: 18px; text-align: center; }
.brand { flex: none; }
/* login and logout: pinned to the bottom of the sidebar, never covered by the menu */
.side .foot { flex: none; margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--line); background: var(--panel); }
.main { padding: 26px 30px 60px; max-width: 1400px; width: 100%; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head h1 { font-size: 21px; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card + .card { margin-top: 14px; }
.card h2 { font-size: 15px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
.grid > * { min-width: 0; }
.card { min-width: 0; }
.stat .v { overflow-wrap: anywhere; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.stat .s { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* table: compact, wrapping; the script (TableCtl) switches a wrapper to .cards when the table cannot fit its container */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); max-width: 100%; min-width: 0; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.02); }
td.wrap, td.c-act, th.c-act { white-space: normal; overflow-wrap: anywhere; }
td.wrap { vertical-align: middle; }
.c-sel { width: 1%; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.c2a { line-height: 1.35; }
.c2b { font-size: 12px; line-height: 1.35; margin-top: 2px; }
.badges, .acts { display: inline-flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.route-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; max-width: 100%; }
.route-list > .badge { justify-self: start; min-width: 0; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.acts { gap: 6px; }

/* cards mode: one card per row, label above value, actions at the bottom, checkbox top-right */
.tbl-wrap.cards { overflow-x: hidden; }
.cards table, .cards tbody, .cards tr { display: block; width: 100%; }
.cards thead { display: block; }
.cards thead tr { display: flex; }
.cards th { display: none; }
.cards th.c-sel { display: flex; align-items: center; gap: 8px; width: auto; padding: 8px 14px; background: transparent; border: 0; position: static; }
.cards th.c-sel::after { content: '全选'; font-size: 12px; color: var(--muted); }
.cards tbody tr { position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: 10px 14px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.cards tbody tr:last-child { border-bottom: 0; }
.cards td { display: block; padding: 0; border: 0; white-space: normal; overflow-wrap: anywhere; min-width: 0; text-align: left; vertical-align: top; }
.cards td.num { text-align: left; }
.cards td.wrap { min-width: 0 !important; grid-column: 1 / -1; }
.cards td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; font-weight: 600; }
.cards td.blank { display: none; }
.cards td.c-sel { position: absolute; top: 12px; right: 14px; width: auto; }
.cards td.c-sel + td, .cards tr > td:first-child:not(.c-sel) { grid-column: 1 / -1; padding-right: 30px; }
.cards td.c-act { grid-column: 1 / -1; order: 99; padding-top: 10px; border-top: 1px dashed var(--line); }
.cards .acts { display: flex; }
.cards .c2a { font-size: 14px; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 7px 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { border-color: #3a4157; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b8cff); border-color: transparent; color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=search], input[type=number], input[type=password], input[type=datetime-local], select, textarea {
  background: #0e1119; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.18); }
textarea { width: 100%; max-width: 100%; resize: vertical; min-height: 80px; font-family: var(--mono); font-size: 12.5px; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); min-width: 0; }
label.f > input, label.f > select, label.f > textarea { width: 100%; }
select { max-width: 100%; }
label.f > input, label.f > select, label.f > textarea { color: var(--fg); font-size: 14px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 12px 14px; min-width: 0; }
.form > * { min-width: 0; }
.form .full { grid-column: 1 / -1; }
.check { display: inline-flex; gap: 7px; align-items: center; font-size: 13px; color: var(--fg); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.section-t { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-2); margin-top: 6px; border-top: 1px dashed var(--line); padding-top: 12px; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; border: 1px solid var(--line); }
.badge.ok { color: var(--ok); border-color: rgba(52,211,153,.35); background: rgba(52,211,153,.08); }
.badge.warn { color: var(--warn); border-color: rgba(251,191,36,.35); background: rgba(251,191,36,.08); }
.badge.bad { color: var(--bad); border-color: rgba(248,113,113,.35); background: rgba(248,113,113,.08); }
.badge.info { color: var(--accent-2); border-color: rgba(34,211,238,.35); background: rgba(34,211,238,.08); }
.badge.off { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(154,161,181,.5); }
/* state modes */
.mode-line { display: grid; grid-template-columns: 5.5em minmax(0, 1fr); gap: 4px 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.mode-line:last-of-type { border-bottom: 0; }
.mode-line > b { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.mode-sum .badges { display: flex; }

/* modal */
/*
 * Every dialog is a column of three parts: title, body, buttons. The dialog never grows past the visible viewport and
 * only the body scrolls, so the title (with its close button) and the buttons (save, confirm) are always on screen,
 * however long the content is. `dvh` is the viewport that is really visible on phones (it shrinks while the browser's
 * address bar or the on-screen keyboard is showing); `vh` is the fallback for browsers without it.
 */
.modal-bg { position: fixed; inset: 0; background: rgba(4,6,12,.66); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: hidden; backdrop-filter: blur(3px); }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(860px, 100%); max-width: 100%; max-height: calc(100vh - 12vh); max-height: calc(100dvh - 12vh); box-shadow: 0 30px 80px rgba(0,0,0,.5); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.modal.wide { width: min(1100px, 100%); }
/* full: fills the viewport width (minus a margin) and height */
.modal.full { width: min(1500px, 100%); max-height: calc(100vh - 6vh - 24px); max-height: calc(100dvh - 6vh - 24px); }
.modal-bg:has(.modal.full) { padding: 3vh 16px 12px; }
.modal .mh, .modal .mf { flex: 0 0 auto; }
.modal .mb { overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
/* the page behind an open dialog stays where it is */
html.modal-open, html.modal-open body { overflow: hidden; }
html.modal-open body { position: fixed; left: 0; right: 0; width: 100%; }
.modal-bg.under { background: transparent; backdrop-filter: none; }
.modal-bg.under > .modal { filter: brightness(.6); pointer-events: none; }
.modal .mh { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 12px; }
.modal .mh h3 { font-size: 16px; overflow-wrap: anywhere; min-width: 0; flex: 1 1 auto; }
.modal .mb { padding: 18px; min-width: 0; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* channel model list: grid rows that reflow to cards on narrow screens (no horizontal scrolling) */
.cm { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cm-bar { display: flex; gap: 10px 14px; align-items: center; flex-wrap: wrap; }
.cm-search { flex: 1 1 220px; display: flex; min-width: 0; }
.cm-search input { width: 100%; }
.cm-bar .btn.primary { margin-left: auto; }
.cm-list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cm-row { display: grid; grid-template-columns: 28px minmax(220px, 2.2fr) minmax(150px, 1.2fr) minmax(200px, 1.8fr) auto; gap: 6px 14px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); min-width: 0; }
.cm-row:last-child { border-bottom: 0; }
.cm-row > * { min-width: 0; }
.cm-row:not(.cm-head):hover { background: rgba(255,255,255,.02); }
.cm-row.done { opacity: .72; }
.cm-head { background: var(--panel-2); font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; z-index: 1; }
.cm-id .mono { overflow-wrap: anywhere; font-weight: 600; }
.cm-match { margin-top: 3px; font-size: 12px; overflow-wrap: anywhere; }
.cm-price { display: flex; gap: 4px 12px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.cm-price small { color: var(--muted); font-size: 11px; }
.cm-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12px; align-items: baseline; }
.cm-caps { overflow-wrap: anywhere; }
.cm-act { justify-self: end; }
@media (max-width: 1100px) {
  .cm-row { grid-template-columns: 28px minmax(0, 1fr) auto; grid-template-areas: 'sel id act' 'sel price act' 'sel meta meta'; gap: 4px 12px; }
  .cm-head { display: none; }
  .cm-sel { grid-area: sel; align-self: start; padding-top: 2px; }
  .cm-id { grid-area: id; }
  .cm-price { grid-area: price; }
  .cm-meta { grid-area: meta; }
  .cm-act { grid-area: act; align-self: start; }
}
@media (max-width: 560px) {
  .cm-row { grid-template-columns: 24px minmax(0, 1fr); grid-template-areas: 'sel id' 'sel price' 'sel meta' 'sel act'; }
  .cm-act { justify-self: start; }
}
.x { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; margin-left: auto; flex: none; }

/* toasts */
#toasts { position: fixed; right: 18px; bottom: 18px; max-width: calc(100vw - 36px); align-items: flex-end; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--ok); padding: 10px 14px; border-radius: 9px; min-width: min(240px, 100%); max-width: min(420px, calc(100vw - 36px)); overflow-wrap: anywhere; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--bad); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% -10%, rgba(124,92,255,.25), transparent), radial-gradient(900px 500px at 110% 110%, rgba(34,211,238,.15), transparent); }
.login .card { width: min(380px, 92vw); padding: 28px; }
.login h1 { font-size: 20px; margin: 12px 0 4px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

.codes { width: 100%; min-height: 220px; }
.warn-card { border-color: rgba(245, 158, 11, .6); background: rgba(245, 158, 11, .08); }
.tfa { display: flex; flex-direction: column; gap: 8px; }
.tfa ol { margin: 0; padding-left: 18px; }
.tfa-qr { align-self: center; width: 200px; height: 200px; image-rendering: pixelated; background: #fff; padding: 6px; border-radius: 8px; }
.bar { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.bar div { flex: 1; background: linear-gradient(180deg, var(--accent), rgba(124,92,255,.25)); border-radius: 3px 3px 0 0; min-height: 2px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; color: var(--muted); font-size: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: minmax(70px, 140px) minmax(0, 1fr); gap: 6px 14px; font-size: 13px; overflow-wrap: anywhere; }
.kv > :nth-child(odd) { color: var(--muted); }
.tabs { display: flex; gap: 6px; margin: 14px 0 10px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: none; cursor: pointer; color: var(--muted); }
.tab.on { color: var(--fg); border-color: var(--accent); }

/* ------------------------------------------------------------------ parts shared by every width */
input[type=search] { -webkit-appearance: none; appearance: none; }
.row.nowrap { flex-wrap: nowrap; }
/* row actions that stay on one line while the table is a table (they wrap freely inside a card) */
.tbl-wrap:not(.cards) .acts.nw { flex-wrap: nowrap; white-space: nowrap; }
.tb-q > input { width: 250px; }
.row.nowrap > input { flex: 1 1 auto; }
/* the menu takes the space between brand and footer; when it does not fit, it scrolls inside that space */
.navs { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.navs > .nav { flex: none; }
.topbar, .scrim, .selbar, td.c-cc { display: none; }

/* list toolbar: on a desktop its groups dissolve into the one row it always was */
.tb-q, .tb-f { display: contents; }
.tb-f > * { order: 1; }
.tb-q > .btn { order: 2; }
.tb-a { order: 3; }

/* collapsible record sections of the license dialog */
details.sec { margin-top: 12px; border-top: 1px dashed var(--line); }
details.sec > summary { display: flex; align-items: center; gap: 8px; padding: 12px 0 10px; cursor: pointer; list-style: none; font-size: 12px; letter-spacing: .08em; color: var(--accent-2); user-select: none; -webkit-user-select: none; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after { content: '▸'; margin-left: auto; color: var(--muted); font-size: 14px; }
details.sec[open] > summary::after { content: '▾'; }
.sec-n { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; letter-spacing: 0; }

/* balance adjustment */
.adj { display: grid; grid-template-columns: auto minmax(110px, 170px) minmax(0, 1fr) auto; grid-template-areas: 'seg amt note go' 'chips chips chips chips'; gap: 10px; align-items: center; margin-top: 10px; }
.adj .seg { grid-area: seg; } .adj-amt { grid-area: amt; } .adj-note { grid-area: note; } .adj-go { grid-area: go; justify-content: center; } .adj-chips { grid-area: chips; }
.adj-amt, .adj-note { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-b { border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg-b + .seg-b { border-left: 1px solid var(--line); }
.seg-b.on { background: rgba(52,211,153,.14); color: var(--ok); font-weight: 600; }
.seg-b.neg.on { background: rgba(248,113,113,.14); color: var(--bad); }
.btn.primary.neg { background: linear-gradient(135deg, #ef4444, #f87171); }
.adj-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 3px 12px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.chip:hover { color: var(--fg); border-color: #3a4157; }

/* compact phone card */
.cc { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.cc-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; min-width: 0; }
.cc-h > .badge { flex: none; }
.cc-t { font-size: 14px; font-weight: 600; min-width: 0; }
button.cc-t { border: 0; background: none; padding: 0; text-align: left; cursor: pointer; color: inherit; }
.cc-l { display: flex; flex-wrap: wrap; gap: 2px 16px; font-variant-numeric: tabular-nums; }
.cc-m { font-size: 12.5px; line-height: 1.4; min-width: 0; }
.cc small, .cc-l small { color: var(--muted); font-size: 11.5px; margin-right: 5px; }

/* ------------------------------------------------------------------ tablets and phones */
@media (max-width: 860px) {
  .shell { display: block; }
  .head { display: none; }
  .main { padding: 14px max(14px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }

  /* top bar: stays on screen; menu, page title, refresh */
  .topbar { display: flex; align-items: center; gap: 6px; position: sticky; top: 0; z-index: 30; background: rgba(18,21,31,.94); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
    padding: calc(6px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left)); }
  .tb-btn { width: 44px; height: 44px; flex: none; border: 0; background: none; border-radius: 10px; font-size: 20px; line-height: 1; cursor: pointer; color: var(--fg); }
  .tb-btn:active { background: var(--panel-2); }
  .tb-title { flex: 1 1 auto; min-width: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* navigation drawer */
  .side { position: fixed; top: 0; bottom: 0; left: 0; z-index: 41; width: min(290px, 84vw); height: auto; transform: translateX(-102%); transition: transform .18s ease; overflow: hidden;
    padding: calc(14px + env(safe-area-inset-top)) 10px calc(14px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); border-right: 1px solid var(--line); box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .nav-open .side { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(4,6,12,.6); }
  .nav { min-height: 46px; font-size: 15px; }
  .side .foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 8px 0; margin-top: 8px; }
  .side .foot .mt6 { margin: 0 0 0 auto; }

  /* touch sizes; 16px inputs so iOS does not zoom the page when one is focused */
  input[type=text], input[type=search], input[type=number], input[type=password], input[type=datetime-local], select, textarea,
  label.f > input, label.f > select, label.f > textarea { font-size: 16px; min-height: 44px; }
  textarea { font-size: 14px; }
  .btn { min-height: 44px; padding: 8px 14px; }
  .btn.sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }
  input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
  .check { min-height: 36px; }
  .check input { width: 22px; height: 22px; }
  .x { width: 44px; height: 44px; font-size: 24px; margin-right: -10px; }
  .tab { min-height: 40px; }
  .chip { min-height: 36px; padding: 4px 14px; font-size: 14px; }
  .seg-b { min-height: 44px; padding: 8px 14px; flex: 1 1 0; }

  /* toolbars */
  .toolbar > input, .toolbar > select { flex: 1 1 140px; }
  .tb { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .tb-q { display: flex; gap: 8px; }
  .tb-q > input { flex: 1 1 auto; min-width: 0; }
  .tb-f { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tb-f > select { width: 100%; }
  .tb-a { margin-left: 0; gap: 8px; }
  .tb-a > .btn { flex: 1 1 auto; justify-content: center; }
  .tb-a > .bulk { display: none; }

  /* cards */
  .cards tbody tr { padding: 12px; gap: 8px 12px; }
  .cards td.c-sel { top: 0; right: 0; padding: 10px 12px; }
  .cards th.c-sel { padding: 10px 12px; }
  .cards td.c-sel + td, .cards tr > td:first-child:not(.c-sel) { padding-right: 36px; }
  .cards.has-cc td:not(.c-sel):not(.c-act):not(.c-cc) { display: none; }
  .cards.has-cc td.c-cc { display: block; grid-column: 1 / -1; }
  .cards.has-cc td.c-sel ~ td.c-cc .cc-h { padding-right: 36px; }
  .cards.has-cc td.c-act { padding-top: 8px; }
  .cards .acts .btn { flex: 1 1 auto; justify-content: center; }
  .pager { justify-content: space-between; font-size: 13px; }

  /* bulk actions: a bar at the bottom of the screen while rows are ticked */
  .selbar { display: flex; align-items: center; gap: 10px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; background: var(--panel-2); border-top: 1px solid var(--accent);
    padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); box-shadow: 0 -10px 30px rgba(0,0,0,.45); }
  .selbar.off { display: none; }
  .selbar-n { flex: 1 1 auto; min-width: 0; font-size: 13px; }
  .selbar .acts { flex: none; flex-wrap: nowrap; }

  /* messages appear under the top bar, clear of the buttons at the bottom */
  #toasts { top: calc(62px + env(safe-area-inset-top)); bottom: auto; left: 12px; right: 12px; max-width: none; align-items: stretch; }
  .toast { max-width: none; }

  .card { padding: 14px; }
  .stat .v { font-size: 22px; }
  button.cc-t { min-height: 36px; display: flex; align-items: center; margin: -7px 0; }
  .drag-handle { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  /* a form's save button stays at the bottom of the screen while the form is scrolled */
  .savebar { position: sticky; bottom: 0; z-index: 5; margin: 14px -14px -14px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
  .savebar > .btn { flex: 1 1 auto; justify-content: center; }
  .kv { grid-template-columns: minmax(70px, 110px) minmax(0, 1fr); }
}

/* ------------------------------------------------------------------ phones: dialogs are sheets */
@media (max-width: 640px), (max-height: 520px) and (max-width: 960px) {
  /* laid out inside the visible viewport: above the on-screen keyboard, below the notch */
  .modal-bg, .modal-bg:has(.modal.full) { inset: auto; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100vh); padding: 0; align-items: flex-end; }
  .modal, .modal.wide, .modal.full { width: 100%; max-height: 100%; border-radius: 16px 16px 0 0; border-width: 1px 0 0; }
  .modal .mh { padding: calc(6px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 6px max(14px, env(safe-area-inset-left)); }
  .modal .mb { padding: 14px max(14px, env(safe-area-inset-right)) 18px max(14px, env(safe-area-inset-left)); }
  .modal .mf { padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); flex-wrap: nowrap; background: var(--panel); }
  .modal .mf .btn { flex: 1 1 0; justify-content: center; min-width: 0; white-space: nowrap; }
  .modal .mf .btn.primary { flex: 2 1 0; }
  .prewrap { max-height: none; }
}
@media (max-width: 640px) {
  .form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form > .f:has(> textarea), .form > .f:has(> .row), .form > .check { grid-column: 1 / -1; }
  .adj { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'seg' 'amt' 'chips' 'note' 'go'; }
  .adj .seg { display: flex; }
  .adj-chips .chip { flex: 1 1 auto; }
}
/* a phone held sideways, small tablets: the list toolbar fits in two rows, dialogs keep a compact title and button bar */
@media (min-width: 641px) and (max-width: 860px) {
  .tb { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
  .tb-a { grid-column: 1 / -1; }
  .tb-a > .btn { flex: 0 1 auto; }
}
@media (max-height: 520px) and (max-width: 960px) {
  .modal .mh { padding-top: 2px; padding-bottom: 2px; }
  .modal .mh h3 { font-size: 15px; }
  .modal .mf { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .modal .mf .btn { min-height: 40px; }
  .topbar { padding-top: calc(2px + env(safe-area-inset-top)); padding-bottom: 2px; }
}
@media (max-width: 380px) {
  .form { grid-template-columns: minmax(0, 1fr); }
  .tb-btn { width: 40px; }
}


/* security center */
.meter { height: 8px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; margin: 8px 0 6px; }
.meter-fill { height: 100%; background: linear-gradient(90deg, var(--ok), var(--accent-2)); border-radius: 99px; }
.meter.warn .meter-fill { background: linear-gradient(90deg, var(--warn), #f59e0b); }
.meter.bad .meter-fill { background: linear-gradient(90deg, var(--bad), #ef4444); }
.meter-fill.w0 { width: 0%; }
.meter-fill.w5 { width: 5%; }
.meter-fill.w10 { width: 10%; }
.meter-fill.w15 { width: 15%; }
.meter-fill.w20 { width: 20%; }
.meter-fill.w25 { width: 25%; }
.meter-fill.w30 { width: 30%; }
.meter-fill.w35 { width: 35%; }
.meter-fill.w40 { width: 40%; }
.meter-fill.w45 { width: 45%; }
.meter-fill.w50 { width: 50%; }
.meter-fill.w55 { width: 55%; }
.meter-fill.w60 { width: 60%; }
.meter-fill.w65 { width: 65%; }
.meter-fill.w70 { width: 70%; }
.meter-fill.w75 { width: 75%; }
.meter-fill.w80 { width: 80%; }
.meter-fill.w85 { width: 85%; }
.meter-fill.w90 { width: 90%; }
.meter-fill.w95 { width: 95%; }
.meter-fill.w100 { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip-ev { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
label.f .hint { font-size: 11px; color: var(--muted); opacity: .85; }
label.f.inline { flex-direction: row; align-items: center; gap: 6px; }
label.f.inline input { width: 90px; }
h3.sub { font-size: 13px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }
.mt { margin-top: 14px; }

code { font-family: var(--mono); font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; overflow-wrap: anywhere; }

.prewrap { white-space: pre-line; max-height: 60vh; overflow: auto; }

/* models page: drag-to-sort */
.drag-handle { all: unset; box-sizing: border-box; cursor: grab; padding: 4px 8px; border-radius: 8px; font-size: 18px; line-height: 1; color: var(--muted); touch-action: none; user-select: none; -webkit-user-select: none; }
.drag-handle:hover, .drag-handle:focus-visible { color: var(--text, #e8eaf0); background: rgba(255,255,255,.07); }
.drag-handle:focus-visible { outline: 2px solid var(--accent-2); }
tr.dragging { background: rgba(34,211,238,.10); box-shadow: 0 6px 22px rgba(0,0,0,.45); position: relative; z-index: 2; }
tr.dragging .drag-handle { cursor: grabbing; }
body.dragging-rows, body.dragging-rows * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
tr.inactive > td { opacity: .5; }
tr.inactive:hover { background: transparent; }
tr.grp-sep > td { padding: 8px 14px; font-size: 12px; color: var(--muted); background: rgba(255,255,255,.03); border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); white-space: normal; }
.cards tbody tr.grp-sep { display: block; padding: 0; }
.cards tbody tr.grp-sep > td { display: block; }
