/* STRIMPORT design system — light.
   One stylesheet for the reseller panel and the owner console. On a desk they
   are dense working tools, so the scale is compact; on a phone the same markup
   restacks into cards, and dialogs and menus come up from the bottom edge where
   a thumb is. Colour is spent on state: green is live, amber wants attention,
   red is gone. Gold is the brand and marks the one number that is money —
   credits. */

:root {
  color-scheme: light;

  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --surface-3: #f0f0ec;
  --border: #e7e6e0;
  --border-strong: #d6d5ce;

  --text: #16150f;
  --text-2: #57554c;
  --text-3: #8c8a80;

  --brand: #e8b64c;
  --brand-ink: #8a5a00;
  --brand-soft: #fdf5dd;
  --brand-border: #efd48a;

  --primary: #16150f;
  --primary-hover: #2e2c23;

  --ok: #17803d;
  --ok-soft: #e8f6ed;
  --ok-border: #b9e2c6;
  --warn: #946200;
  --warn-soft: #fff4d4;
  --warn-border: #f0d489;
  --danger: #c2372c;
  --danger-soft: #fdeceb;
  --danger-border: #f2c2bd;

  --radius: 9px;
  --radius-lg: 14px;
  --shadow-xs: 0 1px 2px rgba(22, 21, 15, 0.04);
  --shadow-sm: 0 1px 3px rgba(22, 21, 15, 0.08), 0 1px 2px rgba(22, 21, 15, 0.04);
  --shadow-md: 0 8px 28px rgba(22, 21, 15, 0.12), 0 2px 6px rgba(22, 21, 15, 0.05);
  --shadow-lg: 0 28px 70px rgba(22, 21, 15, 0.22), 0 4px 12px rgba(22, 21, 15, 0.06);
  --ring: 0 0 0 3px rgba(232, 182, 76, 0.38);

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, select, label { touch-action: manipulation; }
::selection { background: #f7e2a8; }
.mono { font-family: var(--mono); font-feature-settings: normal; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.ic { flex: none; display: block; }
.grow { flex: 1; min-width: 0; }
.clip { min-width: 0; overflow: hidden; }
.strong { font-weight: 600; }
.gap-b { margin-bottom: 14px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Pieces that only one layout draws: the wide table or the stacked cards. */
.at-narrow { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-in {
  max-width: 1240px; margin: 0 auto; padding: 0 28px; height: 60px;
  display: flex; align-items: center; gap: 16px;
}
.lockup {
  display: inline-flex; align-items: center; gap: 10px; flex: none;
  font-weight: 700; font-size: 14.5px; letter-spacing: 0.085em; color: var(--text);
}
.scope {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding-left: 16px; border-left: 1px solid var(--border);
  font-size: 13px; color: var(--text-2);
}
.scope strong { color: var(--text); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.topbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }

/* ---------- page ---------- */
.page { max-width: 1240px; margin: 0 auto; padding: 28px 28px 96px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head h1 { font-size: 24px; line-height: 1.2; font-weight: 680; letter-spacing: -0.022em; }
.page-head p { color: var(--text-2); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; align-items: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 13px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 13.5px; line-height: 1; white-space: nowrap; text-decoration: none;
  cursor: pointer; box-shadow: var(--shadow-xs);
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, color 0.12s;
}
.btn:hover { background: var(--surface-2); border-color: #c8c7bf; }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
  box-shadow: 0 1px 2px rgba(22, 21, 15, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.09);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-brand { background: var(--brand); border-color: #d6a336; color: #2a1e00; }
.btn-brand:hover { background: #edc063; border-color: #d6a336; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }
.btn-danger { color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger-soft); border-color: #e7a59e; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #a92e24; border-color: #a92e24; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #136c33; border-color: #136c33; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; gap: 6px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14.5px; border-radius: 10px; }
.btn-icon { width: 32px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }
.btn-block { width: 100%; }
.btn.is-open { background: var(--surface-3); color: var(--text); }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent; opacity: 0.8;
  animation: spin 0.7s linear infinite;
}

/* ---------- form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 12.5px; font-weight: 550; color: var(--text); }
.label .opt { font-weight: 400; color: var(--text-3); }
.hint { font-size: 12.5px; color: var(--text-3); line-height: 1.45; }
.input, .select {
  width: 100%; height: 38px; padding: 0 11px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 14px; outline: none; min-width: 0;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input::placeholder { color: var(--text-3); }
.input:hover, .select:hover { border-color: #c1c0b8; }
.input:focus, .select:focus { border-color: #c99f3a; box-shadow: var(--ring); }
.input.mono { font-size: 13px; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2357554c' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
}
.input-row { display: flex; gap: 8px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--border);
}
.segmented.block { display: flex; }
.segmented button {
  flex: 1; height: 30px; padding: 0 13px; border: 0; border-radius: 7px; background: transparent;
  font-weight: 550; font-size: 13px; color: var(--text-2); cursor: pointer; white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented button:focus-visible { outline: none; box-shadow: var(--ring); }

.alert {
  display: flex; gap: 9px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius);
  font-size: 13.5px; line-height: 1.45; border: 1px solid var(--border); background: var(--surface-2);
}
.alert .ic { margin-top: 2px; }
.alert.danger { color: #8f271f; background: var(--danger-soft); border-color: var(--danger-border); }
.alert.warn { color: #6f4a00; background: var(--warn-soft); border-color: var(--warn-border); }
.alert.ok { color: #0f5c2b; background: var(--ok-soft); border-color: var(--ok-border); }

/* ---------- surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
}

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.stats.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 15px 16px 14px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.stat-ic { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.stat-v { margin-top: 12px; font-size: 28px; line-height: 1.1; font-weight: 680; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; }
.stat-c { margin-top: 4px; font-size: 12px; color: var(--text-3); }
.stat.brand { background: linear-gradient(180deg, #fff8e6, #fffdf7); border-color: var(--brand-border); }
.stat.brand .stat-ic { background: #fae3a6; color: var(--brand-ink); }
.stat.ok .stat-ic { background: var(--ok-soft); color: var(--ok); }
.stat.warn .stat-ic { background: var(--warn-soft); color: var(--warn); }
.stat.danger .stat-ic { background: var(--danger-soft); color: var(--danger); }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2);
  font-size: 12px; font-weight: 550; color: var(--text-2); white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-border); }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-border); }
.badge.danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.badge.brand { color: var(--brand-ink); background: var(--brand-soft); border-color: var(--brand-border); }
.tag {
  display: inline-block; padding: 1px 6px; border-radius: 5px; font-size: 10.5px; font-weight: 650;
  letter-spacing: 0.04em; text-transform: uppercase; background: var(--surface-3); color: var(--text-2);
}
.tag.ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- toolbar, tabs, search ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 11px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text-2);
  font-weight: 550; font-size: 13px; cursor: pointer; transition: background 0.12s, color 0.12s;
}
.tab:hover { background: var(--surface-3); color: var(--text); }
.tab:focus-visible { outline: none; box-shadow: var(--ring); }
.tab[aria-selected='true'] { background: var(--text); color: #fff; }
.tab .count {
  min-width: 18px; padding: 0 5px; border-radius: 999px; text-align: center;
  font-size: 11.5px; font-weight: 600; line-height: 18px;
  background: var(--surface-3); color: var(--text-2); font-variant-numeric: tabular-nums;
}
.tab[aria-selected='true'] .count { background: rgba(255, 255, 255, 0.2); color: #fff; }
.search { position: relative; width: 300px; max-width: 100%; }
.search .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { height: 34px; padding-left: 32px; font-size: 13.5px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 9px 14px; white-space: nowrap; font-size: 12px; font-weight: 550;
  color: var(--text-2); background: var(--surface-2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .right { text-align: right; }
.table .nowrap { white-space: nowrap; }
.table td.c-portal { max-width: 220px; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12.5px; color: var(--text-2); margin-top: 1px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }

/* The customer list: a grid, because each row opens onto its devices. */
.rows { min-width: 860px; }
.r-head, .r-row {
  display: grid; grid-template-columns: 36px minmax(0, 1.7fr) minmax(0, 1.3fr) 84px 140px 190px;
  gap: 12px; align-items: center; padding: 0 16px;
}
.r-head {
  height: 38px; font-size: 12px; font-weight: 550; color: var(--text-2);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.r-item { border-bottom: 1px solid var(--border); }
.r-item:last-child { border-bottom: 0; }
.r-row { min-height: 60px; padding-top: 10px; padding-bottom: 10px; cursor: pointer; transition: background 0.12s; }
.r-row:hover, .r-item.open > .r-row { background: var(--surface-2); }
.caret {
  width: 26px; height: 26px; display: grid; place-items: center; padding: 0; border-radius: 7px;
  border: 1px solid transparent; background: transparent; color: var(--text-3); cursor: pointer;
  transition: transform 0.16s, background 0.12s, color 0.12s;
}
.caret:hover { background: var(--surface-3); color: var(--text); }
.caret:focus-visible { outline: none; box-shadow: var(--ring); }
.r-item.open .caret { transform: rotate(90deg); color: var(--text); }

.devices { padding: 2px 16px 16px 64px; background: var(--surface-2); }
.devices-in { border: 1px solid var(--border); border-radius: 11px; background: var(--surface); overflow: hidden; }
.d-head, .d-row {
  display: grid; grid-template-columns: 112px 124px minmax(0, 1.1fr) minmax(0, 1.5fr) minmax(0, 1fr) 130px;
  gap: 12px; align-items: center; padding: 0 14px;
}
.d-head { height: 34px; font-size: 11.5px; font-weight: 550; color: var(--text-3); border-bottom: 1px solid var(--border); }
.d-row { min-height: 54px; padding-top: 9px; padding-bottom: 9px; border-bottom: 1px solid var(--border); font-size: 13px; }
.d-row:last-child { border-bottom: 0; }
.d-row.fresh { background: #f4fbf6; }
.d-ident { font-size: 12.5px; }
.d-sub { font-size: 12px; margin-top: 1px; }
.span-all { grid-column: 1 / -1; }
.code {
  display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: transparent; cursor: pointer;
  font-family: var(--mono); font-weight: 600; font-size: 13.5px; letter-spacing: 0.03em; color: var(--text);
}
.code .ic { color: var(--text-3); opacity: 0; transition: opacity 0.12s; }
.code:hover .ic, .code:focus-visible .ic { opacity: 1; }
@media (hover: none) { .code .ic { opacity: 1; } }
.code:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 5px; }

.pager {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-2);
}
.pager .btns { display: flex; gap: 6px; }

.empty { padding: 56px 24px; text-align: center; }
.empty .glyph {
  width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-3); color: var(--text-2);
}
.empty h3 { font-size: 15px; font-weight: 620; }
.empty p { max-width: 360px; margin: 6px auto 0; color: var(--text-2); font-size: 13.5px; }
.empty .btn { margin-top: 16px; }

.skeleton { height: 60px; border-bottom: 1px solid var(--border); position: relative; overflow: hidden; }
.skeleton::after {
  content: ''; position: absolute; left: 64px; top: 22px; width: 38%; height: 14px; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-3), #f7f7f4, var(--surface-3)); background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

/* ---------- popover menu ---------- */
.pop {
  position: fixed; z-index: 90; padding: 5px; max-height: 300px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow-md);
}
.pop.enter { animation: pop 0.14s ease both; }
.pop-item {
  display: flex; align-items: center; gap: 9px; width: 100%; min-height: 34px; padding: 0 9px;
  border: 0; border-radius: 7px; background: transparent; color: var(--text);
  font-size: 13.5px; text-align: left; cursor: pointer; white-space: nowrap;
}
.pop-item .ic { color: var(--text-2); }
.pop-item:hover, .pop-item:focus-visible { background: var(--surface-3); outline: none; }
.pop-item.danger, .pop-item.danger .ic { color: var(--danger); }
.pop-item.danger:hover { background: var(--danger-soft); }
.pop-item .meta { margin-left: auto; padding-left: 16px; color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.pop-sep { height: 1px; margin: 4px 2px; background: var(--border); }
.pop-row { display: flex; align-items: center; gap: 2px; }
.pop-item.mono { font-size: 12.5px; }
.pop-label { padding: 6px 9px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-3); }

/* ---------- dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(22, 21, 15, 0.38);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.overlay.enter { animation: fade 0.16s ease both; }
.modal {
  width: 100%; max-width: 480px; max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.overlay.enter .modal { animation: pop 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.modal.sm { max-width: 420px; }
.modal.wide { max-width: 720px; }
.modal.xl { max-width: 1120px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 22px 0; }
.modal-head h2 { font-size: 17px; font-weight: 650; letter-spacing: -0.012em; line-height: 1.3; }
.modal-head p { margin-top: 3px; color: var(--text-2); font-size: 13.5px; }
.modal-head .btn { margin: -4px -6px 0 auto; }
.modal-head.pad-b { padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.modal-body { display: flex; flex-direction: column; gap: 14px; padding: 18px 22px 20px; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.modal-body.flush { padding: 0; gap: 0; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.modal-foot .lead { margin-right: auto; font-size: 13px; color: var(--text-2); }
.head-icon { width: 36px; height: 36px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.head-icon.danger { background: var(--danger-soft); color: var(--danger); }
.head-icon.brand { background: var(--brand-soft); color: var(--brand-ink); }

.overlay.side { padding: 0; align-items: stretch; justify-content: flex-end; }
.drawer {
  width: 100%; max-width: 540px; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.overlay.enter .drawer { animation: slide 0.26s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.drawer .modal-head { padding-top: 22px; }
.drawer .modal-body { flex: 1; }
.section-title { font-size: 12px; font-weight: 620; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); margin-top: 4px; }
.divider { height: 1px; background: var(--border); margin: 2px 0; }

/* The code, the moment it exists. Shown once — so it is the whole panel. */
.reveal {
  padding: 22px; border-radius: var(--radius-lg); text-align: center;
  background: linear-gradient(180deg, #fff8e6, #fffdf7); border: 1px solid var(--brand-border);
}
.reveal .kicker { font-size: 12px; font-weight: 620; letter-spacing: 0.05em; text-transform: uppercase; color: var(--brand-ink); }
.reveal .big {
  margin: 12px 0 10px; font-family: var(--mono); font-weight: 700; font-size: 40px; line-height: 1.1;
  letter-spacing: 0.08em; color: var(--text); user-select: all;
}
.reveal .note { font-size: 13px; color: var(--text-2); }
.keyout {
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--brand-border); background: var(--brand-soft);
  font-family: var(--mono); font-size: 13px; word-break: break-all; user-select: all;
}

.summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 13px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13.5px; color: var(--text-2);
}
.summary strong { color: var(--text); font-weight: 620; }

/* Credit adjustment: where the balance is, what changes, where it lands. */
.balance {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 16px 18px; border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fff8e6, #fffdf7); border: 1px solid var(--brand-border);
}
.balance .k { display: block; font-size: 12px; font-weight: 550; color: var(--text-2); }
.balance .v { display: block; margin-top: 2px; font-size: 28px; line-height: 1.1; font-weight: 680; letter-spacing: -0.025em; }
.balance .after { text-align: right; }
.balance .delta {
  display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 6px 0 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-weight: 650; font-size: 13.5px;
}
.stepper { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; }
.stepper .btn { width: 44px; height: 44px; font-size: 20px; font-weight: 500; }
.stepper .input { height: 44px; text-align: center; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.stepper .input::-webkit-outer-spin-button, .stepper .input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.chips { display: flex; gap: 6px; margin-top: 2px; }
.chip {
  flex: 1; height: 32px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 13px; font-weight: 550; color: var(--text-2); cursor: pointer; font-variant-numeric: tabular-nums;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip:focus-visible { outline: none; box-shadow: var(--ring); }
.chip[aria-pressed='true'] { background: var(--text); border-color: var(--text); color: #fff; }

.ledger-stats { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--border); }
.ledger-stats > div { padding: 14px 22px; border-right: 1px solid var(--border); }
.ledger-stats > div:last-child { border-right: 0; }
.ledger-stats .k { font-size: 12px; color: var(--text-2); font-weight: 550; }
.ledger-stats .v { margin-top: 4px; font-size: 20px; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 100;
  display: flex; align-items: center; gap: 9px; max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px 10px 12px; border-radius: 11px; background: var(--text); color: #fff;
  font-size: 13.5px; box-shadow: var(--shadow-md);
}
.toast .ic { color: #7ee2a0; }
.toast.err .ic { color: #ff9c92; }
.toast.enter { animation: rise 0.22s ease both; }

/* ---------- sign-in ---------- */
.auth {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(700px 360px at 50% -80px, rgba(232, 182, 76, 0.22), transparent 70%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 392px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 22px; text-align: center; }
.auth-brand h1 { font-size: 22px; font-weight: 680; letter-spacing: -0.02em; }
.auth-brand p { color: var(--text-2); margin-top: 2px; }
.auth-card .card { padding: 22px; box-shadow: var(--shadow-sm); }
.auth-foot { margin-top: 16px; text-align: center; font-size: 12.5px; color: var(--text-3); }

/* ---------- motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes slide { from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- narrower windows ---------- */
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tablet portrait and down: the customer list stops being a table.
   Six columns do not fit, and a table that scrolls sideways hides the buttons
   that matter. Each customer becomes a card — name, then status and device
   count, then contact — and each device a short labelled list under it. */
@media (max-width: 960px) {
  .at-wide { display: none !important; }
  .at-narrow { display: revert !important; }
  .rows { min-width: 0; }
  .r-head, .d-head { display: none; }
  .r-row {
    grid-template-columns: 26px minmax(0, 1fr) auto; align-items: start;
    gap: 10px; padding: 13px 14px; min-height: 0;
  }
  .r-row .caret { margin-top: -3px; }
  .r-meta.at-narrow {
    display: flex !important; align-items: center; gap: 8px; margin-top: 6px;
    font-size: 12.5px; color: var(--text-2);
  }
  .r-meta + .cell-sub { margin-top: 5px; }
  .devices { padding: 0 12px 12px; }
  .d-row { grid-template-columns: minmax(0, 1fr) auto; gap: 7px 12px; padding: 13px 14px; min-height: 0; }
  .d-status { justify-self: end; }
  .d-row > .d-cell, .d-row > .row-actions { grid-column: 1 / -1; }
  .d-cell { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 10px; align-items: baseline; }
  .d-cell::before { content: attr(data-label); font-size: 12px; color: var(--text-3); font-family: var(--font); }
  .d-row > .row-actions { justify-content: flex-start; margin-top: 4px; }
  .skeleton::after { left: 50px; }
}

/* Phone. */
@media (max-width: 720px) {
  .phone-hide, .btn .label-wide { display: none !important; }
  .scope, .topbar-sep { display: none; }
  .topbar-in { height: 54px; padding: 0 8px 0 16px; gap: 8px; }
  .topbar-actions { gap: 0; }
  .page { padding: 18px 16px 88px; }

  /* Title and its button share a line; the description takes the next one. */
  .page-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; margin-bottom: 16px; }
  .page-head > div:first-child { display: contents; }
  .page-head h1 { font-size: 21px; }
  .page-head p { grid-column: 1 / -1; grid-row: 2; margin-top: 0; font-size: 13.5px; }

  /* Sixteen pixels in every field: anything smaller and iOS zooms the page in
     on focus and leaves it zoomed. The heights are thumb-sized for the same
     reason the desk ones are not. */
  .input, .select, .search .input { height: 44px; font-size: 16px; }
  .input.mono { font-size: 15px; }
  .btn { height: 42px; padding: 0 15px; font-size: 14.5px; }
  .btn-sm { height: 36px; padding: 0 12px; font-size: 13.5px; }
  .btn-lg { height: 48px; font-size: 15.5px; }
  .btn-icon { width: 42px; padding: 0; }
  .btn-sm.btn-icon { width: 36px; }
  .segmented button { height: 36px; font-size: 14px; }
  .grid-2 { grid-template-columns: 1fr; }
  .input-row .btn { height: 44px; }

  /* Six numbers in two tight rows rather than three tall ones. */
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
  .stats.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 11px 12px 10px; border-radius: 12px; }
  .stat-top { font-size: 12px; }
  .stat-v { margin-top: 5px; font-size: 22px; }
  .stat-ic, .stats:not(.four) .stat-c { display: none; }
  .stats.four .stat-v { margin-top: 8px; font-size: 24px; }

  /* The filters scroll sideways under the thumb instead of wrapping. */
  .toolbar { padding: 12px; gap: 10px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px; padding: 0 12px; scrollbar-width: none; max-width: calc(100% + 24px); }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; height: 34px; }
  .search { width: 100%; }
  .toolbar .input-row { width: 100%; }
  .toolbar .input-row .select { flex: 1; width: auto !important; }
  .pager { padding: 10px 12px; }

  /* Dialogs come up from the bottom edge and fill the width. */
  .overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.sm, .modal.wide, .modal.xl {
    max-width: none; max-height: 92vh; max-height: 92dvh;
    border-radius: 18px 18px 0 0; border-width: 1px 0 0;
  }
  .modal.wide, .modal.xl { height: 92vh; height: 92dvh; }
  .overlay.enter .modal { animation: sheet 0.26s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
  .drawer { max-width: none; border-left: 0; }
  .modal-head { padding: 18px 16px 0; }
  .modal-head.pad-b { padding-bottom: 14px; }
  .modal-body { padding: 16px; }
  .modal-foot { flex-wrap: wrap; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .modal-foot .btn { flex: 1 1 auto; }
  .modal-foot .lead { flex-basis: 100%; margin: 0 0 2px; }
  .ledger-stats > div { padding: 12px 16px; }
  .ledger-stats .v { font-size: 18px; }
  .reveal { padding: 20px 14px; }
  .reveal .big { font-size: 34px; letter-spacing: 0.06em; }

  /* Menus are sheets too. They keep the position the script gave them on a
     desk; here that is overridden, and the page dims behind by way of a shadow
     large enough to cover it. */
  .pop {
    left: 8px !important; right: 8px; top: auto !important; width: auto !important;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    max-height: 70vh; max-height: 70dvh; padding: 6px; border-radius: 16px;
    box-shadow: 0 0 0 100vmax rgba(22, 21, 15, 0.38), var(--shadow-lg);
  }
  .pop.enter { animation: sheet 0.22s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
  .pop-item { min-height: 46px; padding: 0 12px; font-size: 15px; gap: 12px; border-radius: 10px; }
  .pop-item.mono { font-size: 13.5px; }
  .pop-label { padding: 10px 12px 6px; font-size: 12.5px; }
  .pop-row .btn { width: 42px; height: 42px; }

  /* Up under the bar: the bottom edge is where the sheets and their buttons are. */
  .toast { top: calc(64px + env(safe-area-inset-top, 0px)); bottom: auto; }
  .auth { padding: 20px 16px; }
  .auth-card .card { padding: 18px; }
  .empty { padding: 44px 20px; }

  /* Tables, restacked. Each kind says how.
     `.cards`: a row is a card; cells that carry a label become "Label  value". */
  table.cards, table.resellers, table.ledger-table,
  .cards tbody, .resellers tbody, .ledger-table tbody { display: block; }
  .cards thead, .resellers thead, .ledger-table thead { display: none; }
  .cards td, .resellers td, .ledger-table td { display: block; padding: 0; border: 0; text-align: left; }
  .cards tr, .resellers tr, .ledger-table tr { border-bottom: 1px solid var(--border); }
  .cards tr:last-child, .resellers tr:last-child, .ledger-table tr:last-child { border-bottom: 0; }

  .cards tr { display: block; padding: 13px 16px; }
  .cards td { max-width: none !important; white-space: normal; }
  .cards td.c-head { margin-bottom: 7px; }
  .table.cards td.nowrap { white-space: normal; overflow-wrap: anywhere; }
  .cards td[data-label] { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; align-items: baseline; padding: 3px 0; }
  .cards td[data-label]::before { content: attr(data-label); font-size: 12px; color: var(--text-3); font-family: var(--font); font-weight: 400; }
  .cards .row-actions { justify-content: flex-start; }

  /* Resellers: name and status, three numbers, then the buttons full width. */
  .resellers tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; padding: 14px 16px; }
  .resellers .c-name { grid-column: 1 / 3; grid-row: 1; min-width: 0; }
  .resellers .c-status { grid-column: 3; grid-row: 1; justify-self: end; }
  .table.resellers td.c-metric { text-align: left; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
  .resellers .c-metric::before { content: attr(data-label); display: block; margin-bottom: 1px; font-size: 11.5px; font-weight: 500; letter-spacing: 0; color: var(--text-3); }
  .resellers .c-actions { grid-column: 1 / -1; }
  .resellers .c-actions .row-actions { justify-content: flex-start; }
  .resellers .c-actions .btn:not(.btn-icon) { flex: 1; }

  /* Ledger: what happened and how much, then when and against which code. */
  .ledger-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 11px 16px; }
  .ledger-table td:nth-child(2) { grid-area: 1 / 1; font-weight: 550; }
  .ledger-table td:nth-child(4) { grid-area: 1 / 2; text-align: right; }
  .ledger-table td:nth-child(1) { grid-area: 2 / 1; font-size: 12.5px; }
  .ledger-table td:nth-child(3) { grid-area: 2 / 2; text-align: right; font-size: 12.5px; }
}
@media (max-width: 380px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lockup { letter-spacing: 0.06em; }
}
