:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #191919;
  --text-2: #5f6368;
  --border: #dfe3e8;
  --accent: #1b64be;
  --accent-ink: #ffffff;
  --danger: #c62828;
  --good: #0b7a1c;
  --warn: #a15c00;
  --series-1: #257de0;
  --series-2: #f47230;
  --grid: #e8eaed;
  --radius: 12px;
  --tabs-h: 64px;
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111214;
    --surface: #1c1d20;
    --surface-2: #26282c;
    --text: #efefef;
    --text-2: #a0a4aa;
    --border: #33363b;
    --accent: #4b9bf0;
    --accent-ink: #0b1220;
    --danger: #ef6b6b;
    --good: #4cc463;
    --warn: #f0a640;
    --series-1: #338ced;
    --series-2: #e76624;
    --grid: #2c2f33;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; margin: 18px 0 6px; }
a { color: var(--accent); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.25rem; }
.sync {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-2); border-radius: 999px; padding: 5px 12px; font-size: 0.8rem; cursor: pointer;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-2); }
.dot.ok { background: var(--good); }
.dot.busy { background: var(--warn); }
.dot.err { background: var(--danger); }

main { max-width: 760px; margin: 0 auto; padding: 12px; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabs a { display: flex; align-items: center; justify-content: center; text-decoration: none; color: var(--text-2); font-weight: 600; font-size: 0.9rem; }
.tabs a.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.tabs a.add { color: var(--accent-ink); background: var(--accent); margin: 10px 4px; border-radius: 999px; }

/* Forms */
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
textarea { min-height: 0; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.money { font-variant-numeric: tabular-nums; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.group { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 0 0 12px; background: var(--surface); }
.group legend, .group summary { font-weight: 700; font-size: 0.9rem; padding: 0 4px; cursor: pointer; }
details.group[open] summary { margin-bottom: 10px; }
#jobForm { background: var(--surface); border-radius: var(--radius); padding: 14px; border: 1px solid var(--border); }
#jobForm .group { background: var(--bg); }
.hint { color: var(--text-2); font-size: 0.85rem; margin: 6px 0; }
.hint.warn, .error { color: var(--danger); }
.ok-line { color: var(--good); font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; min-height: 0; }

button, .button {
  font: inherit; font-weight: 600; font-size: 0.92rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); text-decoration: none;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.ghost { background: transparent; }
button.small { min-height: 34px; padding: 0 10px; font-size: 0.82rem; }
button.link { background: none; border: 0; color: var(--accent); padding: 0; min-height: 32px; }
button:disabled { opacity: 0.6; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .primary { flex: 1 1 auto; }
.actions.secondary button { flex: 1 1 30%; }
form.inline { display: flex; gap: 8px; align-items: flex-end; }
form.inline .field { flex: 1; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

/* Jobs list */
.toolbar { margin-bottom: 10px; }
.month { margin-bottom: 16px; }
.month > header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 6px 4px; flex-wrap: wrap; }
.month > header span { color: var(--text-2); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.job {
  display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none;
}
.job small { display: block; color: var(--text-2); font-size: 0.8rem; }
.job-main { min-width: 0; }
.job-main strong { display: block; overflow-wrap: anywhere; }
.job-money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 1px 8px; margin: 4px 4px 0 0; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.chip.due { color: var(--warn); }
.empty { text-align: center; color: var(--text-2); padding: 32px 12px; }

/* Lists in settings */
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-row small { display: block; color: var(--text-2); font-size: 0.8rem; }
.pair-code { font: 700 2rem/1.2 ui-monospace, monospace; letter-spacing: 0.08em; text-align: center; margin: 12px 0; }

/* Trends */
.filters, .seg { display: flex; gap: 6px; flex-wrap: wrap; }
.filters { margin-bottom: 12px; }
.filters button, .seg button { min-height: 36px; padding: 0 12px; border-radius: 999px; font-size: 0.85rem; }
.filters button.on, .seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi span { display: block; font-size: 0.8rem; color: var(--text-2); font-weight: 600; }
.kpi strong { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi small { color: var(--text-2); font-size: 0.78rem; }
.kpi small.up { color: var(--good); }
.kpi small.down { color: var(--danger); }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--text-2); stroke-width: 1; }
.chart .axis { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit.on { fill: var(--text); fill-opacity: 0.05; }
.legend { display: flex; gap: 14px; font-size: 0.82rem; color: var(--text-2); margin-bottom: 6px; }
.legend i, .tip-row i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; align-items: center; gap: 10px; padding: 2px 0; }
.hbar-label { font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 14px; }
.hbar-fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-value { font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--text); }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.table th, .table td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--text-2); font-weight: 600; font-size: 0.8rem; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; min-width: 160px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 0.82rem; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
.tooltip strong { display: block; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 4px; }
.tip-row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }

/* Toast + modal */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 0.9rem;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 30; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
dialog { border: 0; border-radius: 16px; padding: 0; width: min(440px, 92vw); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal-form { padding: 18px; }
.modal-form h2 { margin-bottom: 10px; }

@media (min-width: 900px) {
  .tabs { top: 0; bottom: auto; left: auto; right: 16px; width: 520px; height: 56px; border: 0; background: transparent; padding: 0; }
  .topbar { padding-right: 560px; }
  body { padding-bottom: 24px; }
  #toast { bottom: 24px; }
}

/* Operating costs + computed net profit */
.cost-row { display: flex; gap: 8px; align-items: flex-end; }
.cost-row .field { flex: 1; margin-bottom: 8px; }
.cost-row .remove-cost { margin-bottom: 8px; min-height: 46px; }
.cost-add { display: flex; gap: 16px; flex-wrap: wrap; }
input.reg { text-transform: uppercase; letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.net-field input { background: var(--surface-2); font-weight: 700; font-variant-numeric: tabular-nums; cursor: default; }
.net-field input.neg { color: var(--danger); }
.net-field input:focus { outline: none; }
.chip.type { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent); }
.reg-row { display: flex; align-items: center; gap: 10px; }
.reg-row input.reg { flex: 0 0 9.5em; min-width: 0; }
.vehicle-info { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vehicle-info.muted { font-weight: 400; color: var(--text-2); }
.week-pick { display: flex; align-items: flex-end; gap: 12px; margin: 0 0 12px; }
.week-pick .field { flex: 1; margin: 0; }
.date-filter { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.date-filter .field { margin: 0; }
.date-quick { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 4px; }
#filterSummary { margin: 6px 0 0; font-weight: 600; color: var(--text); }
