/* UserBus Fleet. System font, one accent, light and dark.
   The theme is the server-rendered `data-theme` on <html>: `light` and `dark` are fixed, `auto` (and a
   page without the attribute) follows prefers-color-scheme. The dark palette is written twice below
   because CSS cannot share one block between a media query and an attribute selector.
   No third-party request of any kind: this file, app.js and the favicon are the page's assets. */

:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #5d6470;
  --line: #e3e6eb;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --good: #15803d;
  --bad: #b42318;
  --idle: #8a919c;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a20;
  --text: #e8eaed;
  --muted: #9aa1ac;
  --line: #2a2f38;
  --accent: #8b93ff;
  --accent-text: #0f1115;
  --accent-soft: #23264a;
  --good: #4ade80;
  --bad: #f97066;
  --idle: #6b7280;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a20;
    --text: #e8eaed;
    --muted: #9aa1ac;
    --line: #2a2f38;
    --accent: #8b93ff;
    --accent-text: #0f1115;
    --accent-soft: #23264a;
    --good: #4ade80;
    --bad: #f97066;
    --idle: #6b7280;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 10; }

/* The top bar */

.top {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.top-in {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand span { color: var(--accent); font-weight: 600; }
.brand:hover { text-decoration: none; }

.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }

.nav a {
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
  font-weight: 500;
}

.nav a:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--accent-soft); }

.menu { position: relative; margin-left: auto; }

.menu summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
}

.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover, .menu[open] summary { background: var(--bg); color: var(--text); }

.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
}

.menu-item {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.menu-item:hover { background: var(--bg); }
a.menu-item { display: block; }
a.menu-item:hover { text-decoration: none; }

/* The page */

.main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }
.main:focus { outline: none; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.mono { font-family: var(--mono); }
.num { text-align: right; white-space: nowrap; }

.unknown { color: var(--muted); cursor: help; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.link { font-size: 13px; font-weight: 500; }

.note { color: var(--muted); margin: 0 0 16px; }

.empty { color: var(--muted); margin: 4px 0; }

.alert { color: var(--bad); margin: 0 0 12px; }

/* Figures */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stat[data-stat="available"] .stat-value, .stat[data-stat="earned"] .stat-value { color: var(--accent); }

/* The chart */

.chart { margin: 0; }
.chart svg { display: block; width: 100%; height: 150px; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { opacity: 0.8; }
.chart .bar-unknown { fill: var(--idle); }
.chart .axis { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-top { font-size: 12px; margin-bottom: 4px; }
.chart-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Activity: two series per chart, told apart by colour and named in the legend */

.chart .bar-received { fill: var(--accent); }
.chart .bar-completed { fill: var(--good); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .line-p50 { stroke: var(--accent); }
.chart .line-p95 { stroke: var(--idle); stroke-dasharray: 5 4; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--accent-soft); fill-opacity: 0.5; }
.chart g:hover .bar { opacity: 0.85; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.swatch-received { background: var(--accent); }
.swatch-completed { background: var(--good); }
.swatch-p50, .swatch-p95 { background: none; height: 0; border-radius: 0; width: 16px; }
.swatch-p50 { border-top: 2px solid var(--accent); }
.swatch-p95 { border-top: 2px dashed var(--idle); }

.filters { display: grid; gap: 14px; margin-bottom: 16px; }
.filter-dates { display: grid; grid-template-columns: repeat(2, minmax(0, 12rem)); gap: 12px; }
.filter-group { border: 0; margin: 0; padding: 0; min-width: 0; }
.filter-group legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 14px; cursor: pointer; background: var(--surface); max-width: 100%; }
.check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check input { accent-color: var(--accent); margin: 0; }
.filters .form-foot { gap: 8px; margin-top: 0; align-items: center; flex-wrap: wrap; }
.filters .form-foot p { margin: 0 auto 0 0; }

/* Tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th.num { text-align: right; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions > * { margin-left: 6px; }
.machine-rename { display: flex; align-items: center; gap: 6px; }
.machine-rename .input { width: 12rem; }

/* Machines */

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}

.chip-name { font-weight: 600; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; display: inline-block; }
[data-machine-state="online"] .dot { background: var(--good); }
[data-machine-state="revoked"] .dot, [data-machine-state="no_credential"] .dot { background: var(--bad); }

.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--bg); border: 1px solid var(--line); }
.badge-paid { color: var(--good); }
.badge-failed { color: var(--bad); }

/* Controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  line-height: 1;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { border-color: var(--accent); opacity: 0.92; }
.btn-danger { color: var(--bad); }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-wide { width: 100%; padding: 12px 14px; }
.btn.disabled { opacity: 0.45; cursor: default; }

form.inline { display: inline; margin: 0; }

.input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
  width: 100%;
}

.input:focus { border-color: var(--accent); outline: none; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field.grow { flex: 1; }

.add-form, .rate-form, .payout-form, .schedule { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.payout-form .field { min-width: 160px; }

.choice { border: 0; margin: 0; padding: 0; font-size: 14px; }
.choice legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 10px; }
.choice label { margin-right: 14px; white-space: nowrap; }

.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; margin-bottom: 16px; }
.segmented a { padding: 6px 14px; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 14px; }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }

/* The settings tab bar: never wider than the page - on a narrow screen it scrolls sideways. */
.segmented-tabs { display: flex; width: max-content; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.segmented-tabs a { flex: 0 0 auto; white-space: nowrap; }

.segmented-buttons { margin-bottom: 0; align-self: flex-start; }
.segmented-buttons button { font: inherit; font-size: 14px; font-weight: 500; padding: 6px 16px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.segmented-buttons button:hover { color: var(--text); }
.segmented-buttons button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

/* Settings */

.settings-form { margin: 0; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.field-grid .wide { grid-column: 1 / -1; }
.field .input[readonly] { color: var(--muted); background: var(--bg); }
.field.has-error .input { border-color: var(--bad); }
.field-error { color: var(--bad); font-size: 12px; }
.form-foot { display: flex; justify-content: flex-end; margin-top: 14px; }
.saved { color: var(--good); font-size: 13px; font-weight: 500; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }

/* A machine's prices: one form per model; the currency is a symbol beside the amount, not a field */

.price-list { list-style: none; margin: 0; padding: 0; }
.price-row { border-bottom: 1px solid var(--line); padding: 10px 0; }
.price-row:first-child { padding-top: 0; }
.price-row:last-child { border-bottom: 0; padding-bottom: 0; }
.price-form { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin: 0; }
.price-form-new { align-items: flex-end; }
.price-model { flex: 1 1 180px; min-width: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; overflow-wrap: anywhere; }
.price-field { flex: 0 1 260px; }
.price-input { display: flex; align-items: center; gap: 6px; padding: 0 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.price-input:focus-within { border-color: var(--accent); }
.price-input .input { flex: 1; width: auto; min-width: 4em; border: 0; padding: 8px 0; background: transparent; text-align: right; }
.price-affix { color: var(--text); font-weight: 600; }
.price-unit { color: var(--muted); font-size: 13px; white-space: nowrap; }
.field.has-error .price-input { border-color: var(--bad); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (max-width: 720px) {
  .price-field { flex: 1 1 100%; }
  .price-form .btn { width: 100%; }
}

/* The credential */

.secret { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; margin: 8px 0; }

.secret pre {
  margin: 0;
  white-space: pre-wrap;
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
  user-select: all;
}

/* Sign-in and notices */

.signin, .notice { max-width: 420px; margin: 48px auto; text-align: center; padding: 28px 24px; }
.signin h1, .notice h1 { margin-bottom: 6px; }
.signin .btn { margin-top: 16px; }
.notice p { margin: 12px 0 0; }

/* Native machine enrollment: the same Fleet card, accent and control language as the provider pages. */
.machine-enrol {
  max-width: 560px;
  margin: 32px auto 48px;
  padding: 32px;
}

.machine-enrol-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--accent-soft);
}

.machine-enrol-mark span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
}

.machine-enrol h1 { margin: 0; font-size: 28px; }
.machine-enrol-lead { margin: 10px 0 24px; color: var(--muted); font-size: 16px; }

.machine-enrol-details {
  display: grid;
  gap: 0;
  margin: 0 0 20px;
  border-top: 1px solid var(--line);
}

.machine-enrol-details div {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.machine-enrol-details dt { color: var(--muted); font-size: 13px; }
.machine-enrol-details dd { margin: 0; overflow-wrap: anywhere; font-weight: 550; }
.machine-enrol-details dd span { color: var(--muted); font-weight: 400; }

.machine-enrol-note {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin: 0 0 24px;
  padding: 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--muted);
  font-size: 13px;
}

.machine-enrol-note span { color: var(--accent); line-height: 1.4; }
.machine-enrol-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.machine-enrol-actions .btn-primary { min-width: 190px; }

@media (max-width: 720px) {
  .machine-enrol { margin: 16px 0 32px; padding: 24px 20px; }
  .machine-enrol h1 { font-size: 24px; }
  .machine-enrol-details div { grid-template-columns: 1fr; gap: 3px; }
  .machine-enrol-actions { align-items: stretch; }
  .machine-enrol-actions .btn { width: 100%; }
}

/* Phones */

@media (max-width: 720px) {
  .top-in { flex-wrap: wrap; gap: 0 12px; padding-top: 8px; }
  .nav { order: 3; flex-basis: 100%; margin: 4px -8px 6px; padding: 0 0 2px; gap: 0; }
  .nav a { padding: 8px 9px; font-size: 14px; }
  .menu { margin-left: auto; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-value { font-size: 20px; }
  .main { padding-top: 16px; }
  .table { font-size: 13px; }
  .table th, .table td { padding: 8px 6px; }
  .add-form .btn, .rate-form .btn, .payout-form .btn, .schedule .btn { width: 100%; }
  .rate-form .field, .payout-form .field, .schedule .field { flex: 1 1 100%; }
  .field-grid { grid-template-columns: minmax(0, 1fr); }
  .form-foot .btn { width: 100%; }
  .filter-dates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .legend { font-size: 12px; }
  .filters .form-foot p { flex-basis: 100%; }
  .filters .form-foot .btn { flex: 1; width: auto; }
}
