:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --sidebar: #fafbfc;
  --text: #16181d;
  --muted: #5d6470;
  --border: #e2e5ea;
  --hover: #eef0f3;
  --accent: #0f7b5f;
  --accent-text: #ffffff;
  --accent-soft: #e3f3ee;
  --info: #1d5fc2;
  --info-soft: #e6effc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --radius: 10px;
  --sidebar-w: 260px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --sidebar: #15181d;
    --text: #e8eaed;
    --muted: #9aa1ac;
    --border: #2c3139;
    --hover: #22262d;
    --accent: #35b58f;
    --accent-text: #0b1a15;
    --accent-soft: #16322a;
    --info: #7fb0ff;
    --info-soft: #172640;
    --danger: #f97066;
    --danger-soft: #3a1a17;
    --warn: #f5c451;
    --warn-soft: #362b10;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 16px 0 8px; }
p { margin: 0; }

.muted { color: var(--muted); }
.small-text { font-size: 0.8rem; }
.strong { font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
.error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 12px 0 0; }
.ok-note { color: var(--accent); background: var(--accent-soft); padding: 8px 12px; border-radius: 8px; }
.link { color: var(--accent); font-weight: 600; }

.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.02em; white-space: nowrap; }
.brand span { color: var(--accent); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

/* ── sign in / invite ───────────────────────────────────── */
.center-view { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.narrow-card { width: 100%; max-width: 400px; display: grid; gap: 14px; }
.stack-gap { display: grid; gap: 14px; }
.no-margin { margin: 0 0 4px; }

/* ── shell: sidebar + content ───────────────────────────── */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--sidebar); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 14px;
}
.side-head { padding: 4px 8px; }

.account { position: relative; }
.account summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.account summary::-webkit-details-marker { display: none; }
.account summary:hover { background: var(--hover); }
.account summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.who { display: grid; gap: 2px; min-width: 0; flex: 1; justify-items: start; }
.who-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; font-size: 0.88rem; font-weight: 600; }
.caret { color: var(--muted); font-size: 0.8rem; }
.menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.14); padding: 6px; display: grid;
}
.menu-item {
  display: block; background: transparent; color: var(--text); text-align: left; font: inherit; font-weight: 500;
  border: 0; border-radius: 6px; padding: 9px 12px; text-decoration: none; cursor: pointer; min-height: 0;
}
.menu-item:hover { background: var(--hover); }

.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a[aria-current="page"] { background: var(--hover); color: var(--text); font-weight: 600; }
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-settings { margin-top: 10px; border-top: 1px solid var(--border); border-radius: 0 !important; padding-top: 14px !important; }

.content { padding: 40px 48px 64px; max-width: 1160px; width: 100%; margin: 0 auto; min-width: 0; }
.page-head { margin-bottom: 24px; }
.page-head.with-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.back { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 12px; font-size: 0.9rem; }
.back:hover { color: var(--text); }
.section-label { font-size: 0.95rem; font-weight: 600; color: var(--muted); margin: 28px 4px 10px; }
.page-head + .section-label { margin-top: 0; }

.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }
.wide { grid-column: 1 / -1; }

.stat-row { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 8px; }
.stat { display: grid; gap: 4px; padding: 16px; }
.stat span { font-size: 0.82rem; }
.stat strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; max-width: 420px; }

/* settings rows, v0-style */
.card.rows { padding: 0 20px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 0; border-bottom: 1px solid var(--border); }
.card.rows > .row:last-child, .card.rows > form.row:last-child { border-bottom: 0; }
.row-title { font-weight: 600; }
.row-value { text-align: right; overflow-wrap: anywhere; }
.row .muted { font-size: 0.9rem; }
.add-form { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 2fr) auto; align-items: end; }
.add-form.with-fleet { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.6fr) minmax(0, 1.4fr) auto; }
.fleet-cell { display: grid; gap: 4px; }
.pw-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.pw-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }
.pw-actions .error { margin: 0; margin-right: auto; }
.pw-actions .ok-note { margin-right: auto; }
.error.inset { margin: 12px 0; }
.link-box { align-items: flex-start; background: var(--warn-soft); margin: 12px -20px 0; padding: 14px 20px; border-bottom: 0; }
.link-value { display: block; margin-top: 8px; font-size: 0.82rem; word-break: break-all; user-select: all; color: var(--text); }
.card.rows .table-wrap { margin: 0 -20px; }
.card.rows table th:first-child, .card.rows table td:first-child { padding-left: 20px; }
.card.rows table th:last-child, .card.rows table td:last-child { padding-right: 20px; }
.card.rows tbody tr:last-child td { border-bottom: 0; }

/* ── forms ──────────────────────────────────────────────── */
label { display: grid; gap: 4px; font-size: 0.88rem; font-weight: 500; }
label small { font-weight: 400; }
input[type="email"], input[type="password"], input[type="number"], input[type="text"], input[type="search"], select {
  /* 16px stops iOS Safari zooming into the field on focus. */
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%; min-height: 42px;
}
input[readonly] { color: var(--muted); }
select { cursor: pointer; }
select.compact { width: auto; min-height: 34px; padding: 5px 8px; font-size: 0.88rem; }
input:focus-visible, button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; margin: 12px 0 0; }
.check input { margin-top: 4px; }
#tariff-form .primary { margin-top: 14px; }

button {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 9px 16px; cursor: pointer;
  border: 1px solid transparent; min-height: 42px;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: 0 1px 2px rgb(0 0 0 / 0.05); }
.secondary:hover, .ghost:hover { background: var(--hover); }
.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.danger { background: var(--danger); color: #fff; }
.danger-text { color: var(--danger); }
.small { padding: 5px 10px; font-size: 0.82rem; min-height: 34px; }
.block { width: 100%; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.preview { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--bg); color: var(--muted); font-size: 0.88rem; }
.preview:empty { display: none; }

/* ── current tariff ─────────────────────────────────────── */
.price { font-size: 2.2rem; font-weight: 700; line-height: 1.1; margin-bottom: 14px; }
.price small { font-size: 0.9rem; font-weight: 500; color: var(--muted); margin-left: 6px; }
.facts { display: grid; gap: 8px; margin: 0 0 8px; }
.facts div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--border); padding-bottom: 6px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); background: var(--warn-soft); padding: 12px; border-radius: 8px; }

/* ── tables ─────────────────────────────────────────────── */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head h2, .section-head h3 { margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td { font-variant-numeric: tabular-nums; }
td.note { max-width: 280px; }
td.row-actions { text-align: right; }
.empty-cell { text-align: center; padding: 24px 10px; }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover { background: var(--hover); }
.row-link { color: inherit; text-decoration: none; }
.who-cell { display: grid; }
.invite-row td { background: color-mix(in srgb, var(--warn-soft) 40%, transparent); }

.badge { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.off { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.push-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 0.88rem; }
.push-list li { display: flex; justify-content: space-between; gap: 12px; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: 460px; width: calc(100% - 32px); padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h3 { margin-top: 0; }
dialog form { display: grid; gap: 12px; }
dialog .check { margin: 0; }

.compare { font-size: 0.9rem; }
.compare th, .compare td { padding: 7px 8px; }
.compare tbody th { color: var(--muted); font-weight: 500; white-space: normal; }
.compare tr.changed td:last-child { color: var(--accent); font-weight: 700; }
.compare tr.changed td:nth-child(2) { text-decoration: line-through; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 0.9rem;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgb(0 0 0 / 0.2); z-index: 30;
}

/* ── payments / data / import ────────────────────────────── */
.segmented { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 16px; border-radius: 10px; background: var(--hover); border: 1px solid var(--border); max-width: 100%; overflow-x: auto; }
.segmented button { min-height: 36px; padding: 6px 14px; background: transparent; color: var(--muted); border-radius: 8px; white-space: nowrap; }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.stat-row:empty { display: none; }
#pay-stats { margin-bottom: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 12px; }
.filters input[type="search"] { flex: 1 1 220px; max-width: 360px; }
.inline-label { display: flex; align-items: center; gap: 8px; font-weight: 500; white-space: nowrap; }
.inline-label select, .inline-label input { width: auto; min-height: 38px; padding: 6px 10px; }
input[type="date"] {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 4px 10px; }
.label-row .section-label { margin: 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.import-panel { margin-bottom: 16px; border-color: color-mix(in srgb, var(--info) 40%, var(--border)); }
.import-rows { max-height: 420px; overflow-y: auto; }
.import-actions { margin-top: 14px; }
.spacer { flex: 1; }
.data-wrap { max-height: 70vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.data-table { font-size: 0.8rem; }
.data-table th { position: sticky; top: 0; background: var(--surface); z-index: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.data-table td { white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; padding: 7px 10px; }
.data-table tbody tr:hover { background: var(--hover); }

/* ── verification codes ─────────────────────────────────── */
.code-chip {
  display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700;
  font-size: 1.05rem; letter-spacing: 0.08em; padding: 3px 10px; margin-left: 6px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--info); color: var(--info); white-space: nowrap; user-select: all;
}
.code-banner {
  display: grid; gap: 8px; margin-bottom: 20px; padding: 12px 16px; border-radius: var(--radius);
  background: var(--info-soft); border: 1px solid color-mix(in srgb, var(--info) 35%, transparent);
}
.code-banner-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.code-banner-text { flex: 1 1 260px; font-size: 0.92rem; }
.code-banner .code-chip { margin-left: 0; font-size: 1.2rem; }
.code-step { display: grid; gap: 12px; padding: 14px; border-radius: 8px; background: var(--info-soft); }
.code-step p { margin: 0; }
#invite-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.3rem; letter-spacing: 0.2em; text-align: center; }

/* ── tablet ─────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .content { padding: 32px 28px 56px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ── phone: sidebar becomes a top bar with tabs ─────────── */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar {
    position: sticky; height: auto; overflow: visible; z-index: 10;
    display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; align-content: start; gap: 10px;
    padding: 10px 16px 0; padding-top: max(10px, env(safe-area-inset-top));
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .side-head { padding: 0; }
  .account { justify-self: end; max-width: 100%; min-width: 0; }
  .account summary { padding: 5px 8px; gap: 8px; }
  .avatar { width: 26px; height: 26px; font-size: 0.8rem; }
  .who { display: flex; align-items: center; gap: 6px; }
  .who-email { min-width: 0; flex: 0 1 auto; }
  .who .badge { flex: none; }
  .who-email { max-width: 18ch; font-weight: 500; }
  .menu { left: auto; min-width: 200px; }
  .nav { grid-column: 1 / -1; display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 8px; }
  .nav a { border-radius: 0; padding: 10px 12px; border-bottom: 2px solid transparent; white-space: nowrap; }
  .nav a[aria-current="page"] { background: transparent; color: var(--accent); border-bottom-color: var(--accent); }
  .nav svg { display: none; }
  .nav-settings { margin: 0 0 0 auto; border-top: 0; padding-top: 10px !important; }
  .content { padding: 20px 16px 48px; }
  h1 { font-size: 1.35rem; }
  .card { padding: 16px; }
  .card.rows { padding: 0 16px; }
  .card.rows .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .link-box { margin: 12px -16px 0; padding: 14px 16px; }
  .add-form, .pw-form { grid-template-columns: minmax(0, 1fr); }
  .page-head.with-actions .actions { justify-content: flex-start; }
  .filters .inline-label { flex: 1 1 140px; justify-content: space-between; }
  .filters .inline-label input, .filters .inline-label select { flex: 1; }
  .row { flex-wrap: wrap; }
}

@media (max-width: 520px) {
  .fields { grid-template-columns: minmax(0, 1fr); }
  .who-email { max-width: 12ch; }
  .stat-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

/* Phones: each table row becomes a card, each cell a "label  value" line. */
@media (max-width: 640px) {
  .table-wrap { overflow: visible; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; margin-bottom: 10px; }
  table.stack td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border-bottom: 1px dashed var(--border); padding: 8px 0 !important; text-align: right;
  }
  table.stack td:last-child { border-bottom: 0; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-weight: 600; text-align: left; flex-shrink: 0; }
  table.stack td[data-label=""]::before { content: none; }
  table.stack td.row-actions { justify-content: flex-end; }
  table.stack td.row-actions:has(> div:empty) { display: none; }
  table.stack td.note { max-width: none; }
  table.stack td.empty-cell { justify-content: center; }
  .card.rows table.stack tbody tr:last-child td { border-bottom: 1px dashed var(--border); }
  .card.rows table.stack tbody tr:last-child td:last-child { border-bottom: 0; }
  .invite-row td { background: transparent; }
  .invite-row { background: color-mix(in srgb, var(--warn-soft) 40%, transparent); }
}

/* Riders: fleet filter above the summary tiles */
.fleet-bar select { width: auto; min-width: 180px; }
