:root {
  --bg: #f4f6fb; --panel: #fff; --ink: #141a2b; --muted: #5d6680; --line: #e2e6ef;
  --brand: #1f4fd1; --brand-ink: #fff; --brand-soft: #e8eefc;
  --ok: #138a4a; --ok-soft: #e4f5ec; --warn: #a86400; --warn-soft: #fff3df; --err: #c0262d; --err-soft: #fde8e9;
  --skip: #f5c518; --skip-soft: #fff6d1; --skip-ink: #3a2c00;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,26,43,.06), 0 4px 16px rgba(20,26,43,.05);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 14px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* layout */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.logo { font-weight: 800; font-size: 18px; color: var(--ink); letter-spacing: -.3px; }
.logo b { color: var(--brand); }
.topbar .spacer { flex: 1; }
.crumbs { color: var(--muted); }
.crumbs a { color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.wrap.wide { max-width: 1560px; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .editor { grid-template-columns: 1fr; } }
.sticky { position: sticky; top: 70px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card.tight { padding: 0; overflow: hidden; }
.card h2 .count { color: var(--muted); font-weight: 500; }
.tile { display: block; color: inherit; align-self: stretch; }
.grid > .card + .card { margin-top: 0; }
.tile:hover { text-decoration: none; border-color: var(--brand); }
.co-logo { width: 100px; height: 70px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.co-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.co-logo span { font-weight: 700; font-size: 20px; color: var(--muted); }
.co-crumb { display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; }
.co-crumb img { width: 24px; height: 24px; object-fit: contain; border-radius: 4px; }

/* Fixed weekly deductions: big toggle buttons with an amount under each. */
.ded-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-top: 10px; }
.ded { border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 10px; display: flex; flex-direction: column; gap: 8px; transition: border-color .15s, background .15s; }
.ded.on { border-color: var(--brand); background: var(--brand-soft); }
.ded-btn { all: unset; cursor: pointer; display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; min-height: 40px; color: var(--ink); }
.ded-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 6px; }
.ded-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #b8c0d4; flex: none; position: relative; background: #fff; }
.ded.on .ded-dot { border-color: var(--brand); background: var(--brand); }
.ded.on .ded-dot::after { content: ''; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.ded-amt { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.ded-amt input { width: 100%; text-align: right; }
.ded-add { cursor: pointer; align-items: center; justify-content: center; border-style: dashed; color: var(--brand); font-weight: 600; font-size: 15px; min-height: 96px; }
.ded-add:hover { border-color: var(--brand); }
/* Statement header: fixed deductions chips */
.hfixed { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.hfixed-label { font-weight: 600; color: var(--muted); font-size: 13px; margin-right: 4px; }
.hchip { display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--line); border-radius: 10px; padding: 4px 8px; background: #fff; }
.hchip.on { border-color: var(--brand); background: var(--brand-soft); }
.hchip-t { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; padding: 2px 4px 2px 0; }
.hchip-t[disabled] { cursor: default; }
.hchip .ded-dot { width: 18px; height: 18px; }
.hchip.on .ded-dot { border-color: var(--brand); background: var(--brand); }
.hchip.on .ded-dot::after { content: ''; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.hchip input { width: 80px; padding: 4px 6px; }
.btn.chip { border-radius: 999px; }

/* Debts */
.weeks-pick { gap: 6px; }
.sched { background: #f7f9fd; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; max-height: 220px; overflow: auto; }
.sched:empty { display: none; }
.debt-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.debt-kv { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 8px 0 4px; }
.debt-kv > div { display: flex; flex-direction: column; }
.debt-hist { margin-top: 6px; font-size: 13px; }
.debt-hist td { padding: 4px 6px; }

/* Amazon Relay import */
.relay-drop { border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; display: grid; gap: 6px; outline: none; }
.relay-drop.over, .relay-drop:focus { border-color: var(--brand); background: var(--brand-soft); }
.relay-note { background: #fff7e6; border: 1px solid #f3d38a; color: #7a5200; border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.relay-prev tr.cancelled td { opacity: .55; text-decoration: line-through; }
.relay-prev tr.cancelled td:first-child, .relay-prev tr.cancelled td:last-child { text-decoration: none; }
.relay-prev tr.off td:not(:first-child) { opacity: .6; }
.relay-prev input[type=checkbox] { width: auto; }
.relay-prev input[data-k=trip_no] { min-width: 115px; }
.relay-prev input[data-k=truck] { min-width: 80px; }
.relay-prev input[data-k=miles] { min-width: 60px; }
.relay-prev input[data-k=pickup], .relay-prev input[data-k=dropoff] { min-width: 150px; }
.relay-prev input[data-k=gross] { min-width: 90px; }
.modal.wide:has(.relay-prev) { max-width: min(1400px, 96vw); width: 96vw; }
.relay-prev .warn-in { background: #fff7e6; }
.relay-prev input.miss, .edit-table.trips input.miss { background: #fde8e8; border-color: #e5a3a3; }
.badge.bad { background: #fde8e8; color: #a32020; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 12px; cursor: pointer; font: inherit; }
.seg button.on { background: var(--brand); color: #fff; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kv > div { display: flex; flex-direction: column; gap: 2px; word-break: break-all; }
.stat { font-size: 24px; font-weight: 700; }

/* forms */
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--ink); }
.check input { width: auto; }

.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c5cbe0; text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; justify-content: center; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #e8eefc 0%, #f4f6fb 60%); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .logo { font-size: 26px; display: block; margin-bottom: 4px; }
.auth p.lead { margin: 0 0 20px; color: var(--muted); }
.steps { display: flex; gap: 8px; margin-bottom: 18px; }
.steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.steps span.on { background: var(--brand); }
.devnote { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 10px; font-size: 12px; margin-bottom: 12px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafbfe; white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8f9fd; }
.edit-table td { padding: 3px 4px; }
.edit-table input, .edit-table select { padding: 5px 6px; border-color: transparent; background: transparent; border-radius: 6px; }
.edit-table input:hover { border-color: var(--line); }
.edit-table input:focus { background: #fff; }
.edit-table input.num { text-align: right; }
.table-scroll { overflow-x: auto; }
.edit-table.trips { min-width: 1080px; }
.edit-table.items { min-width: 860px; }
.edit-table td.wide { min-width: 170px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.gray { background: #eef0f5; color: var(--muted); }

.totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .big { font-size: 20px; font-weight: 800; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.neg { color: var(--err); }

.audit { list-style: none; padding: 0; margin: 0; }
.audit li { padding: 7px 10px; border-radius: 8px; margin-bottom: 6px; font-size: 13px; }
.audit .error { background: var(--err-soft); color: var(--err); }
.audit .warn { background: var(--warn-soft); color: var(--warn); }
.audit .info { background: #eef2fb; color: #36446b; }
.audit .ok { background: var(--ok-soft); color: var(--ok); }
.ai-box { white-space: pre-wrap; font-size: 13px; background: #f6f4ff; border: 1px solid #e3ddff; border-radius: 8px; padding: 10px; margin-top: 10px; }

.empty { text-align: center; padding: 30px; color: var(--muted); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,26,43,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal .cols-2 { grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--err); }

.type-pick { display: grid; gap: 8px; }
.type-pick label { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: pointer; color: var(--ink); font-weight: 500; font-size: 13px; }
.type-pick label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.type-pick input { width: auto; margin-top: 2px; }
.type-pick b { display: block; font-size: 14px; }

/* ---------- printable statement ---------- */
.print-bar { display: flex; gap: 8px; justify-content: center; padding: 12px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.sheet { width: 8.5in; min-height: 11in; margin: 20px auto; background: #fff; padding: .45in .5in; box-shadow: var(--shadow); color: #000; font-family: Arial, Helvetica, sans-serif; font-size: 10.5px; }
.sheet .head { display: grid; grid-template-columns: 170px 1fr 170px; align-items: start; gap: 12px; margin-bottom: 14px; }
.sheet .head img { max-width: 150px; max-height: 110px; object-fit: contain; }
.sheet .head .co { text-align: center; line-height: 1.45; }
.sheet .head .co .nm { font-size: 14px; font-weight: 700; }
.sheet .head .doc { text-align: right; line-height: 1.5; }
.sheet .head .doc .t { font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.sheet .payee { display: flex; justify-content: space-between; padding: 4px 2px; font-size: 11.5px; }
.sheet table { border-collapse: collapse; width: 100%; margin-bottom: 0; }
.sheet th, .sheet td { border: 1px solid #000; padding: 4px 5px; font-size: 10px; background: none; color: #000; }
.sheet th { text-align: center; font-weight: 600; }
.sheet .sec { text-align: center; font-weight: 700; background: #f0f0f0; letter-spacing: .5px; }
.sheet td.num { text-align: right; }
.sheet td.c { text-align: center; }
.sheet .bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin-top: 10px; }
.sheet .sum td { border: 1px solid #000; }
.sheet .balance { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 6px; font-size: 18px; }
.sheet .balance b { font-size: 20px; }
.sheet .bonus th { text-align: left; font-style: italic; }
.sheet .foot { margin-top: 24px; text-align: center; color: #666; font-size: 9px; }
@media print {
  @page { size: letter; margin: 0; }
  body { background: #fff; }
  .print-bar, .topbar, .toast { display: none !important; }
  .sheet { margin: 0; box-shadow: none; width: auto; min-height: 0; }
}

/* Debt badge: red while something is owed (what, how much, installments paid), green when paid off */
.debt-pill { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; font: inherit; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 8px; border: 1px solid transparent; line-height: 1.35; text-align: left; }
.debt-pill.bad { background: var(--err); color: #fff; }
.debt-pill b { white-space: nowrap; }
.debt-pill.bad span { font-weight: 600; opacity: .92; white-space: nowrap; }
.debt-pill.bad span::before { content: '· '; }
.debt-pill.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe6cf; }
button.debt-pill { cursor: pointer; }
button.debt-pill.bad:hover { filter: brightness(1.08); }

/* Signed contracts card (driver page) */
.contracts.drop { outline: 2px dashed var(--brand); outline-offset: 2px; }
.btn.disabled { opacity: .6; pointer-events: none; }

/* Debt installment: Skip this week (editor only) */
.debt-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.btn-skip { background: var(--skip); color: var(--skip-ink); border: 1px solid #d9ab00; border-radius: 999px; padding: 3px 12px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; line-height: 1.6; }
.btn-skip:hover { filter: brightness(.95); }
.btn-skip.undo { background: var(--skip-soft); border: 1px dashed #d9ab00; font-weight: 600; }
.badge.skipped { background: var(--skip); color: var(--skip-ink); font-weight: 800; letter-spacing: .04em; }
@media print { .btn-skip { display: none; } }

/* Debt chips in the statement's Fixed deductions row */
.debt-chip { border: 1px solid transparent; border-radius: 999px; padding: 4px 11px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.debt-chip.owed { background: var(--err); color: #fff; }
.debt-chip.done { background: var(--ok); color: #fff; }
.debt-chip:hover { filter: brightness(1.08); }
.debt-edit { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.card.flash { box-shadow: 0 0 0 3px var(--skip); transition: box-shadow .3s; }
.dd-table td, .dd-table th { padding: 6px 8px; font-size: 13px; }
.dd-table input { width: 90px; padding: 4px 6px; }
.dd-types { gap: 6px; margin-bottom: 8px; }

/* Driver page "Deductions" panel (debts paid in installments): yellow so it stands out from "Fixed deductions" */
.card.ded-panel { background: #fff8d6; border: 2px solid #f5c518; color: #2b2200; }
.card.ded-panel h2 { color: #2b2200; border-left: 5px solid #f5c518; padding-left: 8px; }
.card.ded-panel .muted { color: #6b5a1a; }
.card.ded-panel .debt-card { background: #fffdf2; border-color: #f0d873; }
.card.ded-panel #addd { background: #f5c518; border-color: #d9ab00; color: #2b2200; font-weight: 700; }

/* Instant list search */
.search { position: relative; display: flex; align-items: center; gap: 8px; flex: 1; max-width: 460px; }
.search-in { padding-left: 30px !important; padding-right: 30px !important; }
.search-ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: 15px; }
.search-kbd { position: absolute; right: 70px; top: 50%; transform: translateY(-50%); font: 11px/1 ui-monospace, monospace; border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; color: var(--muted); background: #fff; pointer-events: none; }
.search-in:focus + .search-kbd, .search-in:not(:placeholder-shown) + .search-kbd { display: none; }
.search-count { white-space: nowrap; min-width: 60px; }
mark.hl { background: #ffe27a; color: inherit; padding: 0 1px; border-radius: 2px; }
.tile[hidden], tr[hidden] { display: none !important; }

/* Owner / fleet driver form */
.fleet-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; background: #fafbfe; }
.mini-form { border: 1px dashed var(--brand); border-radius: 8px; padding: 8px 10px; margin: 6px 0 10px; background: var(--brand-soft); }
.truck-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 13px; }
.truck-chip button { border: 0; background: transparent; cursor: pointer; color: var(--err); font-size: 12px; padding: 2px 6px; border-radius: 999px; }
.truck-chip button:hover { background: var(--err-soft); }
.pick-table td { padding: 7px 10px; }
.owner-tag { display: inline-block; background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }

/* Truck/Driver Assigned pickers */
.pick-box { max-height: 220px; border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; }
.pick-table tr.picked td { background: var(--brand-soft); font-weight: 600; }
tr.muted td { color: var(--muted); }
