/* ================================================================ tokens */
:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #111827;
  --muted: #5b6474;
  --border: #dce1e8;
  --primary: #0b5cab;
  --primary-hover: #094c8e;
  --primary-contrast: #ffffff;
  --focus: #1a73e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);

  --success: #137333;  --success-bg: #e6f4ea;
  --danger: #b3261e;   --danger-bg: #fce8e6;
  --warning: #8a4b00;  --warning-bg: #fdf0dc;
  --info: #0b57d0;     --info-bg: #e8f0fe;
  --unknown: #6a1fc2;  --unknown-bg: #f1e8fd;
  --neutral: #4b5563;  --neutral-bg: #eceff3;

  --radius: 14px;
  --radius-sm: 10px;
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f2630;
    --text: #e6edf3;
    --muted: #9aa4b2;
    --border: #2d3440;
    --primary: #4d9bf0;
    --primary-hover: #6aaef5;
    --primary-contrast: #06121f;
    --focus: #79b8ff;
    --shadow: none;

    --success: #6fd08c;  --success-bg: rgba(46, 160, 67, 0.18);
    --danger: #ff8f86;   --danger-bg: rgba(248, 81, 73, 0.18);
    --warning: #f2b55f;  --warning-bg: rgba(210, 153, 34, 0.18);
    --info: #7cb9ff;     --info-bg: rgba(56, 139, 253, 0.18);
    --unknown: #c9a8ff;  --unknown-bg: rgba(163, 113, 247, 0.2);
    --neutral: #aab3bf;  --neutral-bg: rgba(139, 148, 158, 0.18);
  }
}

/* ================================================================ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--primary); }
.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;
}
.muted { color: var(--muted); }
.center { text-align: center; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ================================================================ buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font: 600 15px/1.2 var(--font); text-decoration: none; text-align: center;
  cursor: pointer; user-select: none;
  transition: background-color .15s, border-color .15s, opacity .15s;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-lg { min-height: 52px; font-size: 17px; }
.btn-sm { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:not(:disabled):hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:not(:disabled):hover { background: var(--surface-2); }
.btn-text { background: transparent; color: var(--primary); padding-inline: 8px; }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger-outline:not(:disabled):hover { background: var(--danger-bg); }

.input, .paste, .pin-input, select.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: 16px/1.4 var(--font);
}
.input:focus, .paste:focus, .pin-input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.paste { min-height: 150px; resize: vertical; font-family: var(--mono); font-size: 15px; }
.label { font-weight: 600; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.form-error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }

/* ================================================================ layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 720px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.2; }
.user-line { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand img { border-radius: 7px; }
.mode-badge {
  flex: none; white-space: nowrap;
  font: 700 11px/1 var(--font); letter-spacing: .06em;
  padding: 5px 8px; border-radius: 999px;
  color: var(--warning); background: var(--warning-bg);
}

main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}
#view-new { padding-bottom: 76px; }
.view-title { font-size: 22px; margin: 4px 0 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.field-head .view-title { margin: 4px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.actions.grid-2 { display: grid; grid-template-columns: 1fr 1fr; }
@media (max-width: 380px) { .actions.grid-2 { grid-template-columns: 1fr; } }

.count-pill {
  display: inline-flex; min-width: 26px; height: 24px; padding: 0 8px;
  align-items: center; justify-content: center;
  border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--info-bg); color: var(--info);
}
.count-pill.warn { background: var(--warning-bg); color: var(--warning); }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .btn { margin: 4px; }
.empty-small { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }

/* ================================================================ login */
.login {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: 24px 16px;
}
.login-card {
  width: 100%; max-width: 360px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 20px; box-shadow: var(--shadow);
}
.login-logo { border-radius: 16px; margin-bottom: 12px; }
.login-card h1 { font-size: 24px; }
.login-card .muted { margin: 6px 0 18px; }
.pin-input { text-align: center; font-size: 28px; letter-spacing: .3em; min-height: 60px; margin-bottom: 14px; }
.login-card .form-error { margin: -4px 0 12px; }

/* ================================================================ new batch */
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 14px; font-size: 14px;
}
.alert { border-radius: var(--radius-sm); padding: 10px 12px; margin: 12px 0 0; font-size: 14px; background: var(--danger-bg); color: var(--danger); }
.alert.info, .notice.info { background: var(--info-bg); color: var(--info); }
.notice.warn { background: var(--warning-bg); color: var(--warning); }
.alert.warn { background: var(--warning-bg); color: var(--warning); }

.vehicle-list, .unrec-list, .item-list, .history-list { list-style: none; margin: 0; padding: 0; }
.vehicle-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 44px; padding: 0 0 0 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2);
  font: 600 15px/1.2 var(--mono); letter-spacing: .02em;
}
.chip.corrected { border-color: var(--warning); background: var(--warning-bg); }
.chip.manual { border-style: dashed; }
.chip .chip-tag { font: 600 11px/1 var(--font); color: var(--warning); margin-left: 6px; }
.chip-x {
  width: 40px; height: 42px; border: 0; background: transparent; color: var(--muted);
  font-size: 20px; line-height: 1; border-radius: 999px; cursor: pointer;
}
.chip-x:hover { color: var(--danger); }
.add-row { display: flex; gap: 8px; }
.add-row .input { flex: 1; text-transform: uppercase; font-family: var(--mono); }
.add-row .input::placeholder { text-transform: none; font-family: var(--font); }

.unrec-list li { border-top: 1px solid var(--border); padding: 12px 0; }
.unrec-list li:first-child { border-top: 0; }
.unrec-orig { font-size: 13px; color: var(--muted); margin-bottom: 6px; word-break: break-word; }
.unrec-row { display: flex; gap: 8px; }
.unrec-row .input { flex: 1; font-family: var(--mono); text-transform: uppercase; min-width: 0; }

.kv-summary { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.kv-summary dt { color: var(--muted); }
.kv-summary dd { margin: 0; font-weight: 600; word-break: break-word; }

.sticky-cta {
  position: fixed; left: 0; right: 0; z-index: 15;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 10px 16px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.sticky-cta .btn { max-width: 688px; margin: 0 auto; display: flex; box-shadow: 0 4px 14px rgba(0,0,0,.15); }

/* ================================================================ progress */
.job-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.job-title { font-weight: 700; font-size: 17px; }
.badge {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
.progress { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 16px 0 8px; }
.progress-fill { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .35s ease; }
.progress-text { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 600; }
.progress-text .muted { font-weight: 500; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.stat { border-radius: var(--radius-sm); padding: 10px 4px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.stat-num { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; font-weight: 600; }
.s-success { background: var(--success-bg); color: var(--success); }
.s-failed { background: var(--danger-bg); color: var(--danger); }
.s-skipped { background: var(--warning-bg); color: var(--warning); }
.s-pending { background: var(--neutral-bg); color: var(--neutral); }

.summary-text {
  width: 100%; margin-top: 10px; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font: 14px/1.45 var(--font);
}

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; scrollbar-width: none; }
.filter {
  flex: none; min-height: 36px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 600 13px/1 var(--font); cursor: pointer;
}
.filter[aria-selected="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }

.item-list li {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.item-list li:first-child { border-top: 0; }
.item-n { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.item-vehicle { font: 700 15px/1.2 var(--mono); letter-spacing: .02em; }
.item-msg { grid-column: 2 / 4; font-size: 13px; color: var(--muted); word-break: break-word; }
.item-msg.msg-skipped { font-size: 14px; font-weight: 600; color: var(--warning); }
.item-msg.msg-failed, .item-msg.msg-error { color: var(--danger); }
.item-msg.msg-unknown { color: var(--unknown); }
.item-ref { font: 12px var(--mono); color: var(--muted); }
.item-list li.is-running { background: var(--info-bg); margin: 0 -16px; padding-inline: 16px; }

.st-success { background: var(--success-bg); color: var(--success); }
.st-failed, .st-error { background: var(--danger-bg); color: var(--danger); }
.st-skipped { background: var(--warning-bg); color: var(--warning); }
.st-unknown { background: var(--unknown-bg); color: var(--unknown); }
.st-running, .st-queued { background: var(--info-bg); color: var(--info); }
.st-pending, .st-cancelled, .st-completed-neutral { background: var(--neutral-bg); color: var(--neutral); }
.st-completed { background: var(--success-bg); color: var(--success); }
.st-interrupted { background: var(--unknown-bg); color: var(--unknown); }

.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.5s; }
  .progress-fill { transition: none; }
}

/* ================================================================ history */
.history-list li + li { margin-top: 10px; }
.history-item {
  display: block; width: 100%; text-align: left; color: inherit; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.history-item:hover { border-color: var(--primary); }
.history-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.history-date { font-weight: 700; }
.history-counts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mini { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }

/* ================================================================ tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tab {
  position: relative; flex: 1; max-width: 180px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--primary); }
.tab-dot {
  position: absolute; top: 10px; left: calc(50% + 10px);
  width: 9px; height: 9px; border-radius: 50%; background: var(--info);
  box-shadow: 0 0 0 2px var(--surface);
}

/* ================================================================ dialog & toast */
.dialog {
  width: min(420px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dialog-body { padding: 20px; }
.dialog h2 { font-size: 20px; margin-bottom: 8px; }
.confirm-count { font-size: 17px; margin: 0 0 14px; }
.confirm-count strong { font-size: 22px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 84px);
  max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--surface); font-size: 15px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.error { background: var(--danger); color: var(--bg); }

@media (min-width: 900px) {
  .view-title { font-size: 26px; }
}

/* ================================================================ login extras & defaults step */
.field { margin-bottom: 14px; text-align: left; }
.field .label { display: block; margin-bottom: 6px; font-size: 14px; }
.input-lg { min-height: 52px; font-size: 17px; }
.password-row { position: relative; }
.password-row .input { padding-right: 72px; }
.password-row .btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.hint.small { font-size: 12px; margin-top: 14px; }
.mode-note { font-size: 13px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--warning-bg); color: var(--warning); margin: -8px 0 16px; }
.spinner.big { width: 32px; height: 32px; border-width: 3px; color: var(--primary); }

.defaults { min-height: 100vh; min-height: 100dvh; display: flex; justify-content: center; padding: 24px 16px 40px; }
.defaults-card {
  width: 100%; max-width: 480px; align-self: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 22px 18px; box-shadow: var(--shadow);
}
.defaults-card h1 { font-size: 24px; }
.defaults-card > .muted { margin: 6px 0 18px; }
.steps { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.steps i { width: 24px; height: 2px; background: var(--border); }
.step { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.step.done { background: var(--success-bg); color: var(--success); }
.step.current { background: var(--primary); color: var(--primary-contrast); }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 20px 0; }
#defaults-btn { margin-top: 8px; }

.picker-btn {
  width: 100%; min-height: 56px; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 15px/1.35 var(--font); cursor: pointer;
}
.picker-btn:hover { border-color: var(--primary); }
.picker-btn svg { flex: none; width: 22px; height: 22px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.picker-value { flex: 1; }
.picker-value.placeholder { color: var(--muted); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.segmented button {
  min-height: 46px; border: 0; border-radius: 9px; background: transparent; color: var(--text);
  font: 600 15px/1.2 var(--font); cursor: pointer;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.15); outline: 1px solid var(--border); }

/* ================================================================ permit summary on New / Account */
.lock-note { font-size: 12px; color: var(--muted); white-space: nowrap; }
.permit-card .kv-summary { grid-template-columns: 1fr; gap: 2px; }
.permit-card .kv-summary dt { font-size: 12px; margin-top: 6px; }
.permit-card .kv-summary dt:first-child { margin-top: 0; }
.credits-line { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--border); font-size: 14px; display: flex; justify-content: space-between; }
.credits-line strong { font-variant-numeric: tabular-nums; }
.list-title { margin-bottom: 10px; }

/* ================================================================ bottom sheet */
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; max-height: 88dvh;
  margin: auto auto 0; padding: 0; border: 0; border-radius: 18px 18px 0 0;
  background: var(--surface); color: var(--text); box-shadow: 0 -10px 40px rgba(0,0,0,.3);
  display: none; flex-direction: column;
}
.sheet[open] { display: flex; }
.sheet::backdrop { background: rgba(0, 0, 0, .5); }
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 18px; } }
.sheet-head { padding: 8px 16px 12px; border-bottom: 1px solid var(--border); }
.sheet-head h2 { font-size: 18px; }
.sheet-head .field-head { margin: 4px 0 8px; }
.sheet-grip { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 6px; }
.option-list { list-style: none; margin: 0; padding: 8px 8px calc(16px + var(--safe-bottom)); overflow-y: auto; }
.option {
  width: 100%; display: flex; gap: 12px; align-items: flex-start; text-align: left;
  padding: 14px 12px; min-height: 56px; border: 0; border-radius: 12px;
  background: transparent; color: var(--text); font: 15px/1.4 var(--font); cursor: pointer;
}
.option:hover { background: var(--surface-2); }
.option[aria-selected="true"] { background: var(--info-bg); color: var(--info); font-weight: 600; }
.option .check { flex: none; width: 20px; text-align: center; }
.option-empty { padding: 20px; text-align: center; color: var(--muted); }

/* ================================================================ app accounts & wallet */
.mono { font-family: var(--mono); }
.btn-danger { background: var(--danger); color: var(--bg); }
.btn-danger:not(:disabled):hover { filter: brightness(1.08); }
.dialog-msg { margin: 0 0 6px; color: var(--muted); }
.copy-helper { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.toast.success { background: var(--success); color: var(--bg); }
.login-card .field .hint { margin-top: 4px; font-size: 12px; }
.defaults-card .notice { margin: 0 0 16px; text-align: left; }

.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.balance-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); text-decoration: none; font: 700 15px/1 var(--font); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.balance-pill svg { width: 18px; height: 18px; fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.balance-pill:hover { border-color: var(--primary); }
.balance-pill.low { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.balance-pill.low svg { stroke: currentColor; }

.small-inline { font-size: 12px; }
.wallet-line-amount { font-weight: 700; text-decoration: none; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wallet-line-amount.low { color: var(--danger); }
#wallet-line { gap: 10px; align-items: baseline; }
.permit-card #credits-line:not([hidden]) + #wallet-line { border-top: 0; padding-top: 0; margin-top: 6px; }

/* confirm dialog cost */
.cost-box { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; margin: 0 0 12px; }
.cost-row { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; padding: 2px 0; }
.cost-row strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cost-row.cost-total strong { font-size: 18px; }
.cost-row.cost-low strong { color: var(--danger); }
.cost-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
#confirm-wallet-alert { margin: 0 0 12px; }
.dialog .kv-summary { margin-bottom: 4px; }

/* progress: wallet */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
}
.banner.warn { background: var(--danger-bg); color: var(--danger); }
.banner-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 200px; }
.banner-text strong { font-size: 16px; }
.banner-text span { font-size: 14px; }
.charged-line {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 12px 0 0;
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 14px;
}
.charged-line strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.charged-sub { color: var(--muted); font-size: 13px; margin-left: auto; }
.item-vehicle { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.charge-chip {
  font: 700 12px/1 var(--font); padding: 4px 7px; border-radius: 999px;
  background: var(--info-bg); color: var(--info); letter-spacing: 0;
}
.charge-chip.refunded { background: var(--success-bg); color: var(--success); }
.charged-sub-inline { color: var(--muted); font-size: 13px; }
.st-charged { background: var(--info-bg); color: var(--info); }

/* wallet view */
.balance-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 22px 16px; }
.balance-label { font-size: 14px; color: var(--muted); font-weight: 600; }
.balance-big { font-size: 42px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.01em; overflow-wrap: anywhere; }
.balance-big.low, .balance-big.neg { color: var(--danger); }
.balance-sub { font-size: 14px; color: var(--muted); }
.balance-sub:empty { display: none; }
.warn-text { color: var(--danger); font-weight: 600; }
.redeem-row { display: flex; gap: 8px; margin-top: 12px; }
.redeem-row .input { flex: 1; min-width: 0; }
.coupon-input { text-transform: uppercase; letter-spacing: .06em; }
.coupon-input::placeholder { text-transform: none; letter-spacing: normal; }
@media (max-width: 380px) { .redeem-row { flex-direction: column; } }

.txn-list { list-style: none; margin: 0; padding: 0; }
.txn { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.txn:first-child { border-top: 0; }
.txn-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.txn-title { font-weight: 700; overflow-wrap: anywhere; }
.txn-title.mono { font-size: 15px; }
.txn-meta { font-size: 12px; color: var(--muted); }
.txn-note { font-size: 13px; color: var(--text); background: var(--surface-2); border-radius: 8px; padding: 4px 8px; margin-top: 2px; align-self: flex-start; overflow-wrap: anywhere; }
.txn-link { font-size: 13px; font-weight: 600; align-self: flex-start; padding: 4px 0; }
.txn-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; text-align: right; }
.txn-amount { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.txn-amount.pos { color: var(--success); }
.txn-amount.neg { color: var(--text); }
.txn-bal { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty.compact { padding: 20px 8px; }
.empty.compact p { margin: 4px 0; }

/* account */
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.status-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-dot.ok { color: var(--success); }
.subsection { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.card-subtitle { font-size: 15px; }

/* 5 tabs on small phones */
@media (max-width: 380px) { .tab { font-size: 11px; } }

/* ================================================================ admin panel */
.admin-main { max-width: 720px; }
.admin .tabbar-inner { display: contents; }
.admin-badge { font: 700 11px/1 var(--font); letter-spacing: .06em; padding: 5px 8px; border-radius: 999px; background: var(--info-bg); color: var(--info); }
form.card > .card-title { margin-bottom: 12px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.view-head .view-title { margin: 4px 0; }

.stat-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.stat-card-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-card-value { font-size: 24px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-card-sub { font-size: 13px; color: var(--muted); }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row .input { flex: 1; min-width: 0; }

/* responsive table: cards on phones, a real table on desktop */
.rtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.rtable thead { display: none; }
.rtable tbody { display: flex; flex-direction: column; gap: 10px; }
.rtable tr {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px;
}
.rtable tr.clickable { cursor: pointer; }
.rtable tr.clickable:hover { border-color: var(--primary); }
.rtable td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; text-align: right; min-width: 0; }
.rtable td::before { content: attr(data-label); color: var(--muted); font-weight: 600; text-align: left; flex: none; }
.rtable td.cell-main { display: block; text-align: left; padding: 0 0 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.rtable td.cell-main::before, .rtable td.cell-actions::before { content: none; }
.rtable td.cell-actions { justify-content: flex-end; padding-top: 8px; }
.cell-title { font: 700 16px/1.3 var(--font); color: var(--text); background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.cell-sub { display: block; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.cell-wrap { overflow-wrap: anywhere; }
.tag { display: inline-block; font: 700 11px/1 var(--font); padding: 3px 6px; border-radius: 999px; margin-left: 6px; vertical-align: middle; background: var(--neutral-bg); color: var(--neutral); }
.tag.custom { background: var(--warning-bg); color: var(--warning); }
.st-active { background: var(--success-bg); color: var(--success); }
.st-disabled, .st-expired { background: var(--danger-bg); color: var(--danger); }
.st-used { background: var(--neutral-bg); color: var(--neutral); }
.st-admin { background: var(--info-bg); color: var(--info); }
.st-user { background: var(--neutral-bg); color: var(--neutral); }
.code-btn {
  font: 700 15px/1.2 var(--mono); letter-spacing: .03em; color: var(--text);
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: 8px;
  padding: 8px 10px; min-height: 40px; cursor: pointer; max-width: 100%; text-align: left; overflow-wrap: anywhere;
}
.code-btn:hover { border-color: var(--primary); }
.table-empty { text-align: center; color: var(--muted); padding: 30px 16px; }

.money-field { position: relative; }
.money-field::before { content: "₹"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; pointer-events: none; }
.money-field .input { padding-left: 28px; font-variant-numeric: tabular-nums; }
.inline-row { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-row .input { flex: 1 1 160px; min-width: 0; }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.check-row input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; margin: 0; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 14px; }
@media (min-width: 600px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .form-grid .span-2 { grid-column: 1 / -1; } }
.success-box { background: var(--success-bg); color: var(--success); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 12px; }
.success-box strong { display: block; margin-bottom: 4px; }
.cred-box { font: 15px/1.5 var(--mono); background: var(--surface-2); color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; }

.code-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; max-height: 320px; overflow-y: auto; }
.code-list .code-btn { width: 100%; }

/* bottom sheet with a scrolling body */
.sheet.sheet-wide { max-width: 640px; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(24px + var(--safe-bottom)); }
.sheet-section { padding: 16px 0; border-top: 1px solid var(--border); }
.sheet-section:first-child { border-top: 0; }
.sheet-section h3 { font-size: 16px; margin-bottom: 10px; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.item-list .item-actions { grid-column: 2 / 4; justify-self: end; }
.batch-kv { margin-top: 12px; }

@media (min-width: 900px) {
  .admin .topbar { position: static; }
  .admin .topbar-inner, .admin-main { max-width: 1100px; }
  .admin .tabbar {
    position: sticky; top: 0; bottom: auto; height: auto; padding: 0 16px;
    border-top: 0; border-bottom: 1px solid var(--border); justify-content: center;
  }
  .admin .tabbar-inner { width: 100%; max-width: 1068px; display: flex; gap: 4px; }
  .admin .tab { flex: none; max-width: none; flex-direction: row; gap: 8px; padding: 14px 16px; font-size: 15px; border-bottom: 3px solid transparent; }
  .admin .tab svg { width: 20px; height: 20px; }
  .admin .tab[aria-current="page"] { border-bottom-color: var(--primary); }
  .admin main { padding-bottom: 40px; }
  .admin .toast { bottom: 32px; }

  .stat-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .quick-actions { display: flex; }

  .rtable { display: table; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); border-collapse: separate; border-spacing: 0; overflow: hidden; }
  .rtable thead { display: table-header-group; }
  .rtable tbody { display: table-row-group; }
  .rtable tr { display: table-row; border: 0; border-radius: 0; box-shadow: none; padding: 0; background: transparent; }
  .rtable th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
  .rtable td, .rtable td.cell-main, .rtable td.cell-actions { display: table-cell; text-align: left; padding: 10px 12px; border-top: 1px solid var(--border); border-bottom: 0; margin: 0; vertical-align: middle; }
  .rtable tbody tr:first-child td { border-top: 0; }
  .rtable td::before { content: none; }
  .rtable tr.clickable:hover td { background: var(--surface-2); }
  .rtable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .rtable th.num { text-align: right; }
  .rtable td.cell-actions { text-align: right; }
}

/* ================================================================ Revision 2: port day, reconnect, paused & multiple jobs, resilience */
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; max-width: 320px; }
.boot-inner p { margin: 0; }

/* "Connection lost — retrying…" pill: non-blocking, never covers the tab bar */
.net-pill {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  display: inline-flex; align-items: center; gap: 8px; max-width: calc(100vw - 32px);
  padding: 8px 14px; border-radius: 999px; font: 600 14px/1.2 var(--font); white-space: nowrap;
  background: var(--warning-bg); color: var(--warning); border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
  box-shadow: 0 6px 18px rgba(0,0,0,.18); pointer-events: none;
}
@supports not (background: color-mix(in srgb, red 50%, blue)) { .net-pill { border-color: var(--warning); } }
.net-pill .spinner { width: 12px; height: 12px; }

/* persistent reconnect strip under the top bar */
.reconnect-banner { background: var(--warning-bg); color: var(--warning); border-top: 1px solid var(--border); }
.reconnect-inner { max-width: 720px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 10px; }
.reconnect-text { flex: 1; min-width: 0; font-size: 13px; line-height: 1.3; }
.reconnect-inner .btn { flex: none; }

/* port day line */
.portday-line { margin: 0 0 10px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.portday-line:empty { display: none; }
.portday-line strong { color: var(--text); font-weight: 700; }
.date-mode .portday-line { margin: 10px 0 0; }

/* start date mode radio cards */
fieldset.field { border: 0; padding: 0; min-width: 0; }
fieldset.field legend { padding: 0; }
.radio-card {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px; margin-bottom: 8px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--info-bg); }
.radio-card input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
.radio-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.radio-text strong { font-size: 15px; }
.hint-inline { font-size: 13px; color: var(--muted); }
.start-date-wrap { margin: 0 0 4px 32px; }

/* banners */
.banner.amber { background: var(--warning-bg); color: var(--warning); }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.st-paused { background: var(--warning-bg); color: var(--warning); }

/* active batch switcher */
.switcher .card-title { margin-bottom: 8px; }
.switcher-list { list-style: none; margin: 0; padding: 0; }
.switcher-list li + li { border-top: 1px solid var(--border); }
.switch-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center;
  padding: 10px 8px; margin: 0 -8px; border-radius: var(--radius-sm); color: inherit; text-decoration: none;
}
.switch-item:hover { background: var(--surface-2); }
.switch-item[aria-current="true"] { background: var(--info-bg); }
.switch-title { font-weight: 700; font-size: 14px; }
.switch-sub { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.item-date { font: 600 12px/1 var(--font); padding: 4px 7px; border-radius: 999px; background: var(--warning-bg); color: var(--warning); letter-spacing: 0; }

/* action bar (e.g. "Run remaining N trucks" after a coupon) */
.action-bar {
  position: fixed; z-index: 45; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  width: min(560px, calc(100vw - 24px));
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 10px 10px 14px; border-radius: 14px;
  background: var(--text); color: var(--surface); box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.action-bar-text { flex: 1 1 160px; font-weight: 600; font-size: 14px; }
.action-bar-btns { display: flex; gap: 4px; margin-left: auto; }
.action-bar .btn-text { color: var(--surface); }
.admin .system-card .stat-card-sub + .stat-card-sub { margin-top: -2px; }
.coupon-created .code-btn { font-size: 20px; padding: 12px 14px; width: 100%; text-align: center; }
.used-by { font-size: 13px; }
.status-dot.warn { color: var(--warning); }
.system-card { margin-top: 14px; }
form.card > .form-intro { margin: -6px 0 12px; }
.coupon-created .hint { margin-bottom: 0; }
.item-msg.item-lasterror { font-size: 12px; color: var(--muted); font-style: italic; }
.segmented.is-locked button:disabled { cursor: not-allowed; opacity: .75; }
.picker-btn:disabled { cursor: not-allowed; opacity: .75; }
.picker-btn:disabled:hover { border-color: var(--border); }
select.input:disabled { opacity: .75; }
.tab-dot.warn { background: var(--warning); }
.notice-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 6px; }
#reconnect-soon { margin: 0 0 12px; }
.port-conn { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.port-conn .mono { font-size: 13px; }
