:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --border: #e6e5e0;
  --text: #2b312d;
  --muted: #767c78;
  --brand: #5b7f6c;
  --brand-dark: #4c6e5c;
  --brand-soft: #eef3f0;
  --accent: #5b7f6c;
  --blue: #4a6f8f;   --blue-soft: #eef3f8;
  --amber: #8f6a2c;  --amber-soft: #faf4e8;
  --red: #a4524d;    --red-soft: #f8ecea;
  --green: #4f7d5f;  --green-soft: #edf5ef;
  --gray: #737974;   --gray-soft: #f0efec;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(31, 42, 36, 0.04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a.card { color: inherit; }
a.card:hover { text-decoration: none; border-color: #cfcabe; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); color: var(--text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: var(--text); }
.logo-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand-soft); display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--brand); letter-spacing: 0.02em; }
.logo-text { font-weight: 600; font-size: 14px; line-height: 1.15; }
.logo-text span { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: #4a514c; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-dark); }
.nav svg { width: 17px; height: 17px; flex: none; opacity: 0.7; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 6px; }
.sidebar .new-quote { margin: 0 4px 12px; justify-content: center; }
.sidebar .logout { margin: auto 4px 0; justify-content: center; }

/* Login */
body.logged-out .app { display: none; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; padding: 24px; display: flex; flex-direction: column; gap: 10px; }
.login-card .login-logo { width: 100%; height: auto; margin: 0 0 10px; }
.login-card .alert { margin: 0; }
.login-card .btn { justify-content: center; }
.main { padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); gap: 12px; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.warn .value { color: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.filter-row th { padding: 6px 8px 8px; vertical-align: top; font-weight: 400; white-space: normal; }
.filter-row input, .filter-row select { display: block; padding: 4px 6px; font-size: 12px; min-width: 88px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: #f7f8f5; }
tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500; white-space: nowrap; text-transform: capitalize; }
.b-quote, .b-open { background: var(--blue-soft); color: var(--blue); }
.b-accepted, .b-partial, .b-hold { background: var(--amber-soft); color: var(--amber); }
.b-scheduled { background: #f2f0f7; color: #6d6391; }
.b-fulfilled, .b-paid, .b-credit { background: var(--green-soft); color: var(--green); }
.b-overdue { background: var(--red-soft); color: var(--red); }
.b-cancelled, .b-void, .b-cash, .b-neutral { background: var(--gray-soft); color: var(--gray); }
.b-delivery { background: #f8f1ea; color: #8a6446; }
.b-pickup, .b-counter { background: var(--gray-soft); color: var(--gray); }
.job-meta .late-date { color: var(--red); font-weight: 600; }
.b-homeowner { background: #f3eef6; color: #74508a; }
.b-contractor { background: #eaf0f6; color: #3c5f80; }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 13px; border-radius: 6px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.accent { background: var(--brand-soft); border-color: #d6e2da; color: var(--brand-dark); }
.btn.accent:hover { background: #e3ece6; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.icon { padding: 4px 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid #d3cfc5; border-radius: 6px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47, 93, 70, 0.25); border-color: var(--brand); }
textarea { resize: vertical; min-height: 60px; }
input[type="checkbox"] { width: auto; }
.field { margin-bottom: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; color: var(--text); margin: 8px 0; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"] { max-width: 280px; }
.toolbar select { width: auto; }
.toolbar input[type="date"] { width: auto; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; overflow-y: hidden; }
.tabs a { padding: 8px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { font-size: 11px; background: var(--gray-soft); border-radius: 999px; padding: 1px 6px; margin-left: 4px; }

.seg { display: inline-flex; border: 1px solid #d3cfc5; border-radius: 6px; overflow: hidden; }
.seg button { border: none; background: var(--surface); padding: 7px 12px; font: inherit; font-weight: 550; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid #d3cfc5; }
.seg button.on { background: var(--brand-soft); color: var(--brand-dark); }
/* Segmented control, demo style (Pickups & Delivery page). */
.seg.soft { gap: 2px; padding: 2px; background: var(--gray-soft); border: 1px solid var(--border); border-radius: 8px; overflow: visible; }
.seg.soft button { height: 30px; background: none; padding: 0 12px; border-radius: 6px; font-size: 13px; white-space: nowrap; }
.seg.soft button + button { border-left: none; }
.seg.soft button:hover { color: var(--text); background: rgba(255, 255, 255, 0.6); }
.seg.soft button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(40, 37, 35, 0.12), 0 0 0 1px rgba(40, 37, 35, 0.05); }

/* ---------- Alerts ---------- */
.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert.warn { background: var(--amber-soft); color: #6f4a0c; }
.alert.error { background: var(--red-soft); color: #7d2420; }
.alert.ok { background: var(--green-soft); color: #1f5a37; }
.alert.info { background: var(--blue-soft); color: #214a6b; }

/* ---------- Dashboard ---------- */
.aging-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--gray-soft); gap: 2px; }
.aging-bar div { min-width: 3px; }
.aging-legend { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.stack .aging-legend { grid-template-columns: 1fr 1fr; }
.aging-legend .l { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.aging-legend .v { font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row .title { font-weight: 550; }
a.list-row { color: inherit; }
a.list-row:hover { background: #f7f8f5; text-decoration: none; }
.job-row { border-bottom: 1px solid var(--border); padding: 8px 16px; cursor: pointer; }
.job-row:last-child { border-bottom: none; }
.job-row:hover { background: #f7f8f5; }
.job-line { display: grid; grid-template-columns: minmax(0, 1fr) 78px 76px 96px; align-items: center; gap: 12px; min-height: 26px; }
.job-line .title { color: var(--text); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-line .kind { font-size: 12.5px; color: var(--muted); }
.job-line .when { text-align: right; font-size: 12.5px; white-space: nowrap; }
.job-row .item-list { margin: 6px 0 4px; cursor: auto; }
.chev { width: 14px; height: 14px; flex: none; }
[aria-expanded="true"] > .chev { transform: rotate(180deg); }
.warn-text { color: var(--red); font-weight: 600; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); }
/* Every card header: green tint, black text. */
.card-head { background: var(--green-soft); border-radius: var(--radius) var(--radius) 0 0; }
.card-head, .card-head h2, .card-head .muted, .card-head a { color: #000; }
.items-toggle { display: inline-flex; align-items: center; gap: 3px; background: none; border: none; padding: 2px 0; font: inherit; font-size: 12.5px; font-weight: 550; color: var(--brand); cursor: pointer; white-space: nowrap; }
.items-toggle:hover { text-decoration: underline; text-underline-offset: 2px; }
.icon-inline { width: 14px; height: 14px; vertical-align: -2px; flex: none; color: var(--muted); }
.item-list { width: 100%; font-size: 13px; border: 1px solid var(--border); border-radius: 6px; border-collapse: separate; border-spacing: 0; background: var(--surface-2); }
.item-list td { padding: 5px 10px; border-bottom: 1px solid var(--border); }
.item-list tr:last-child td { border-bottom: none; }
.item-list td.num { width: 1%; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.item-list td:nth-child(2) { width: 1%; white-space: nowrap; color: var(--muted); }

/* ---------- Order builder ---------- */
.picker { position: relative; }
.picker-results { border: 1px solid var(--border); border-radius: 6px; margin-top: 6px; max-height: 300px; overflow-y: auto; background: var(--surface); }
.picker-results button { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left; border: none; border-bottom: 1px solid var(--border); background: none; padding: 8px 12px; font: inherit; cursor: pointer; }
.picker-results button:last-child { border-bottom: none; }
.picker-results button:hover, .picker-results button:focus { background: var(--brand-soft); outline: none; }
.picker-results .meta { font-size: 12px; color: var(--muted); }
.lines td { padding: 6px 8px; }
.lines input { padding: 5px 8px; }
.lines .qty { width: 90px; text-align: right; }
.lines .price { width: 100px; text-align: right; }
.stock-warn { color: var(--amber); font-size: 11.5px; font-weight: 600; }
.totals { width: 100%; }
.totals td { padding: 5px 0; border: none; }
.totals tr.grand td { font-size: 17px; font-weight: 600; border-top: 1px solid var(--border); padding-top: 10px; }
.customer-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-top: 10px; font-size: 13px; }
.customer-card .kv { display: flex; justify-content: space-between; padding: 2px 0; }

/* ---------- Stepper ---------- */
.stepper { display: flex; gap: 0; margin: 4px 0 18px; overflow-x: auto; }
.step { flex: 1; min-width: 110px; position: relative; padding-top: 22px; font-size: 12px; color: var(--muted); text-align: center; }
.step::before { content: ""; position: absolute; top: 7px; left: 0; right: 0; height: 3px; background: var(--border); }
.step:first-child::before { left: 50%; }
.step:last-child::before { right: 50%; }
.step .pip { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 17px; height: 17px; border-radius: 50%; background: var(--surface); border: 3px solid var(--border); z-index: 1; }
.step.done { color: var(--text); font-weight: 600; }
.step.done::before { background: var(--brand); }
.step.done .pip { background: var(--brand); border-color: var(--brand); }
.step.current .pip { border-color: var(--brand); }
.step .when { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }

/* ---------- Schedule ---------- */
.day { margin-bottom: 20px; }
.day-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.day-head h2 { font-size: 15px; }
.day-head.today h2 { color: var(--text); }
.day-head.today h2::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); margin-left: 8px; vertical-align: 2px; }
.day-head.late h2 { color: var(--red); }
.job { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; padding: 16px 16px; border-bottom: 1px solid var(--border); }
.job:last-child { border-bottom: none; }
.job-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.job-meta { display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.job-meta .addr { display: inline-flex; align-items: center; gap: 4px; color: #4a4542; }
.job .item-list { grid-column: 1 / -1; margin-top: 2px; }
.job .actions .btn.primary { min-width: 124px; }

/* ---------- Analytics ---------- */
.analytics-filters label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.analytics-filters select, .analytics-filters input { width: auto; color: var(--text); }
.text-warn { color: var(--amber); }
.distance-info { margin-top: 6px; line-height: 1.45; }
.distance-info .distance-credit { font-size: 11px; margin-top: 2px; }
.back-bar { margin-bottom: 14px; }
.back-bar:hover { text-decoration: none; background: var(--gray-soft); }
.analytics-sort { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 500; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.chart-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.rev-chart { position: relative; min-height: 280px; }
.rev-chart svg { display: block; overflow: visible; }
.rev-chart .grid-line { stroke: var(--border); stroke-width: 1; }
.rev-chart .grid-line.zero { stroke: #cfccc4; }
.rev-chart .axis-text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.rev-chart .hover-band { fill: transparent; }
.rev-chart .bar-label { font-size: 10px; fill: var(--text); font-variant-numeric: tabular-nums; pointer-events: none; }
.rev-chart .bar-group { outline: none; }
.rev-chart .bar-group:hover .hover-band, .rev-chart .bar-group:focus .hover-band { fill: var(--gray-soft); }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08); padding: 8px 10px; font-size: 12.5px; min-width: 170px; z-index: 5; }
.chart-tip .tip-title { font-weight: 600; margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 8px; padding: 1px 0; }
.chart-tip .tip-row strong { font-variant-numeric: tabular-nums; }
.chart-tip .key { width: 10px; height: 2px; border-radius: 1px; flex: none; }

/* Delivery address check (app.js addressCheckHtml / addressStatusHtml). */
.addr-ok { color: var(--green); }
.addr-suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 4px; }

/* Column help: headings with data-tip get a dotted underline and show .hover-tip on hover or focus (app.js). */
th.has-tip { cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-color: var(--border); }
th.has-tip:hover, th.has-tip:focus-visible { color: var(--text); text-decoration-color: var(--muted); outline: none; }
.hover-tip { position: fixed; z-index: 50; max-width: 280px; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1); padding: 8px 10px;
  font-size: 12.5px; font-weight: 400; line-height: 1.45; text-align: left; white-space: normal; }
.chart-table { margin-top: 10px; font-size: 13px; }
.chart-table summary { cursor: pointer; color: var(--brand); font-size: 12.5px; }
.chart-table table { margin-top: 8px; }

/* ---------- Modal & toast ---------- */
/* The backdrop covers the part of the screen that is actually visible (--vvt / --vvh are kept current by app.js from
   window.visualViewport), so with an on-screen keyboard open the dialog sits above it. The body scrolls; the
   heading and the action buttons stay put. */
.modal-backdrop { position: fixed; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100vh); background: rgba(20, 28, 24, 0.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 520px; max-height: calc(var(--vvh, 100vh) - 40px); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
.modal.wide { max-width: 720px; }
.modal-head { flex: none; padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-body { padding: 18px 20px; overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.modal-foot { flex: none; padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 10px 10px; }
.x { border: none; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 60; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); animation: fade 0.2s; }
.toast.error { background: var(--red); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Printable documents ---------- */
.doc-toolbar { max-width: 820px; margin: 0 auto 12px; display: flex; justify-content: space-between; }
.doc { max-width: 820px; margin: 0 auto; background: #fff; padding: 44px 48px; border: 1px solid var(--border); border-radius: 4px; }
.doc-top { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.doc-title { text-align: right; }
.doc-title h1 { font-size: 26px; font-weight: 500; letter-spacing: 0.08em; color: var(--brand); }
.doc-meta { display: grid; grid-template-columns: auto auto; gap: 2px 14px; margin-top: 8px; font-size: 13px; justify-content: end; }
.doc-meta dt { color: var(--muted); text-align: right; }
.doc-meta dd { margin: 0; font-weight: 600; text-align: right; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; font-size: 13px; }
.doc table th { background: none; border-bottom: 2px solid var(--text); color: var(--text); }
.doc-totals { margin-left: auto; width: 280px; margin-top: 14px; }
.doc-totals td { padding: 4px 0; border: none; }
.doc-totals .grand td { border-top: 2px solid var(--text); font-weight: 700; font-size: 16px; padding-top: 8px; }
.doc-foot { margin-top: 36px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.paid-stamp { display: inline-block; border: 3px solid var(--green); color: var(--green); padding: 2px 12px; font-weight: 800; letter-spacing: 0.1em; transform: rotate(-4deg); margin-top: 8px; }

body.print-mode .sidebar, body.print-mode .topbar { display: none; }
body.print-mode .app { grid-template-columns: 1fr; }

/* ---------- Roles, and who is signed in ---------- */
/* Manager-only links and buttons. The API refuses the action for anyone else whatever the screen shows. */
body:not(.is-manager) .manager-only { display: none !important; }
body.is-manager .staff-only { display: none; }
.nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 4px 0; border-top: 1px solid var(--border); }
.sidebar-user .who { min-width: 0; padding-left: 6px; line-height: 1.25; }
.who-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .logout { margin: 0 0 0 auto; }
.login-form { display: flex; flex-direction: column; gap: 10px; }
.login-or { text-align: center; }
input[type="radio"] { width: auto; }
select { max-width: 100%; }
.linklike { border: none; background: none; padding: 0; font: inherit; color: var(--brand); cursor: pointer; text-decoration: underline; }
.radio-note { margin: -4px 0 6px 28px; }
.b-posted, .b-active { background: var(--green-soft); color: var(--green); }
.b-off { background: var(--gray-soft); color: var(--gray); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px; font: inherit; font-weight: 550; color: var(--muted); cursor: pointer; white-space: nowrap; }
.chip:hover { color: var(--text); }
.chip.on { background: var(--brand-soft); border-color: #d6e2da; color: var(--brand-dark); }
.th-sort { border: none; background: none; padding: 0; font: inherit; font-weight: 600; color: inherit; cursor: pointer; white-space: nowrap; }
.th-sort:hover { color: var(--text); }
.stock-negative .title, .stock-negative strong { color: var(--red); }

/* ---------- Yard count (pages/count.js) ---------- */
.progress { height: 10px; border-radius: 6px; background: var(--gray-soft); overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--brand); border-radius: 6px; transition: width 0.3s; }
.count-progress { margin-bottom: 14px; }
.count-progress-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.count-live { margin-left: auto; }
.count-intro { max-width: 760px; }
.count-intro p { margin: 10px 0 0; }
.count-name { max-width: 520px; }
.count-name p { margin: 6px 0 12px; }
.count-name-row { display: flex; gap: 8px; }
.count-enter { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.count-enter > * { min-width: 0; }
.count-who { margin-bottom: 8px; }
.count-picker > input[type="search"] { font-size: 16px; padding: 10px 12px; }
.count-picker .chips { margin-top: 10px; }
.chip-toggle { margin-left: auto; }
.count-results { margin-top: 10px; border: 1px solid var(--border); border-radius: 6px; max-height: 56vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.count-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; text-align: left; border: none; border-bottom: 1px solid var(--border); background: none; padding: 9px 12px; font: inherit; color: inherit; cursor: pointer; }
.count-row:last-child { border-bottom: none; }
.count-row:hover, .count-row:focus-visible { background: var(--brand-soft); outline: none; }
.count-row-name { display: flex; flex-direction: column; min-width: 0; }
.count-row .meta { font-size: 12px; color: var(--muted); }
.count-state { font-size: 12.5px; text-align: right; flex: none; max-width: 46%; }
.count-state.done { color: var(--green); font-weight: 600; }
.count-state.sending { color: var(--amber); font-weight: 600; }
.count-more { padding: 10px 12px; }
.count-entry { margin-top: 10px; border: 1px solid #d6e2da; background: var(--brand-soft); border-radius: 8px; padding: 12px; }
.count-entry-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.count-entry-head .title { font-weight: 600; font-size: 15px; }
.count-entry .row { grid-template-columns: 1fr 1fr; }
.count-entry input:disabled { background: var(--gray-soft); cursor: not-allowed; }
.count-qty input { font-size: 20px; font-weight: 600; padding: 10px 12px; }
.count-conv { margin: -6px 0 10px; }
.count-entry-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.count-entry-actions .btn { flex: 1 1 150px; justify-content: center; }
.count-mine-row.voided .title { text-decoration: line-through; color: var(--muted); }
.count-mine-act { flex: none; }
.count-people { margin-bottom: 14px; }
.count-people-list { display: flex; flex-wrap: wrap; gap: 8px 28px; padding: 12px 16px; }
.count-person { display: flex; flex-direction: column; }
.seg.soft.count-filter { display: flex; flex-wrap: wrap; }
.count-filter .n { font-size: 11px; background: rgba(0, 0, 0, 0.06); border-radius: 999px; padding: 1px 6px; margin-left: 2px; }
.count-sort { display: none; align-items: center; gap: 6px; margin: 0; }
.count-sort select { width: auto; }
.diff-up { color: var(--green); }
.diff-down { color: var(--red); }
.post-plan { margin: 0 0 8px; padding-left: 18px; }
.post-plan li { margin: 4px 0; }
.count-result ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- People and audit log (pages/people.js) ---------- */
.people-role { width: auto; min-width: 110px; }
.audit-detail { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; max-width: 420px; }
.audit-action { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; }
.load-more { display: flex; justify-content: center; padding: 12px; border-top: 1px solid var(--border); }

/* ---------- Money: deposits, payments, returns, pallets (app.js and pages/money.js) ---------- */
.credit-text { color: var(--green); }
.kv-line { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
a.kv-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); color: inherit; }
a.kv-row:last-of-type { border-bottom: none; }
.kpi-actions { display: inline-flex; gap: 14px; flex-wrap: wrap; }
.linklike.small { font-size: 12px; }
input.bad { border-color: var(--red); background: var(--red-soft); }
.check.disabled { color: var(--muted); }

/* Order and invoice lines: pallet deposits are a group of their own. */
tr.group-row td { background: var(--surface-2); font-size: 12px; font-weight: 600; padding: 7px 12px; }
.totals tr.deposit-total td { color: var(--text); }
.doc tr.group-row td { background: none; border-top: 1px solid var(--text); }
.doc-note { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* Quote builder: the pallet deposit lines under the materials. */
.deposits { border-top: 1px solid var(--border); padding: 14px 16px 16px; }
.deposits-head { display: flex; align-items: baseline; gap: 4px 12px; flex-wrap: wrap; margin-bottom: 10px; }
.deposit-hint { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.deposit-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px 96px auto; gap: 4px 10px; align-items: end; padding: 8px 0 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.deposit-row .dep-total { align-self: center; padding-top: 16px; }
.deposit-row .dep-remove { align-self: center; margin-top: 16px; }
.deposit-row .dep-note { grid-column: 1 / -1; }
.deposit-row input { text-align: right; }

/* Paged lists. */
.pager { border-top: 1px solid var(--border); padding: 12px 16px; }
.pager .alert { margin: 0 0 10px; }
.pager-row { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; min-height: 32px; }

/* Voided payments, refunds and credit memos stay on record, struck through. */
tr.voided td { color: var(--muted); }
tr.voided td:first-child, tr.voided s { text-decoration: line-through; }
.void-note { color: var(--red); text-decoration: none; }
.credit-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* Materials: the per-row Actions button that stands in for Receive / Adjust / Edit on small screens. */
.row-menu { display: none; }
.row-menu-cell { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.action-sheet { display: grid; gap: 8px; }
.action-sheet .btn { justify-content: center; padding: 12px; font-size: 15px; }

/* The payment form: one row per unpaid invoice with the amount going toward it. */
.apply-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 6px 0 6px; }
.apply-list { border: 1px solid var(--border); border-radius: 6px; }
.apply-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.apply-row:last-child { border-bottom: none; }
.apply-amt input { text-align: right; }
.apply-left { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 2px 4px; font-size: 14px; }
.apply-left strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.apply-left.over { color: var(--red); }
.settle { margin-top: 4px; }
.settle .totals td { padding: 4px 0; }

/* Material returns. */
.return-lines { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 12px; }
.return-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 6px 12px; align-items: end; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.return-row:last-child { border-bottom: none; }
.return-row .ret-info { align-self: start; }
.return-row .ret-qty input { text-align: right; }
.return-row .ret-stock { grid-column: 1 / -1; margin: 0; }

/* Pallet returns. */
.pallet-find { max-width: 640px; }
.cust-picker .cust-q { font-size: 16px; padding: 10px 12px; }
.cust-picker .cust-hint { margin-top: 6px; }
.pallet-customer-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pallet-customer-top strong { font-size: 16px; }
.pallet-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px 16px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.pallet-facts strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.pallet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.pallet-row:last-child { border-bottom: none; }
.pallet-info { min-width: 0; }
.stepper { display: flex; align-items: stretch; gap: 6px; flex: none; }
.stepper input { width: 64px; text-align: center; font-size: 18px; font-weight: 600; }
.stepper .btn { width: 44px; min-height: 44px; justify-content: center; font-size: 20px; padding: 0; }
.how-seg { display: flex; flex-wrap: wrap; }
.how-seg button { flex: 1 1 auto; }
.pallet-go { width: 100%; justify-content: center; padding: 12px; font-size: 15px; margin-top: 6px; }

/* ---------- Small screens ---------- */
/* Up to 900px wide (phones, an iPad held upright) the sidebar becomes a top bar: a menu button that opens the
   navigation as a drawer, and "+ New quote". */
.topbar, .nav-backdrop { display: none; }

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .doc-toolbar, .toast { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .doc { border: none; padding: 0; max-width: none; }
}

@media (max-width: 1100px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .count-enter { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  /* A wide table scrolls sideways inside its own card, with its first column pinned. */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .table-wrap > table:not(.lines) > * > tr > :first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
  .table-wrap > table:not(.lines) > thead > tr > th:first-child, .table-wrap > table:not(.lines) > tfoot > tr > td:first-child { background: var(--surface-2); }
  .table-wrap > table:not(.lines) > tbody > tr.link:hover > td:first-child { background: #f7f8f5; }
  /* The widest lists (orders, invoices, customers, materials) keep room for names instead of one word per line. */
  .table-wrap > table:not(.lines):not(.stack-sm):has(> thead th:nth-child(6)) { min-width: 720px; }
  .table-wrap > table:not(.lines):not(.stack-sm):has(> thead th:nth-child(8)) { min-width: 1000px; }
  /* Quote builder: Cancel / Save stay in reach while the page scrolls. */
  .page-head.sticky-head { position: sticky; z-index: 5; background: var(--bg); margin: -8px 0 10px; padding: 8px 0; }
  .app { display: block; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .topbar-brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; color: var(--text); font-weight: 600; }
  .topbar-brand:hover { text-decoration: none; }
  .topbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-btn { width: 44px; height: 44px; padding: 0; justify-content: center; flex: none; }
  .menu-btn svg { width: 22px; height: 22px; }
  .topbar-new { flex: none; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 41; width: min(300px, 86vw); height: auto; overflow-y: auto; padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-105%); visibility: hidden; transition: transform 0.18s ease, visibility 0.18s; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2); }
  body.nav-open .sidebar { transform: none; visibility: visible; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(20, 28, 24, 0.45); }
  .sidebar .new-quote { display: none; }
  .nav { overflow-y: visible; flex: none; }
  .sidebar-user { margin-top: auto; }
  .main { padding: 16px 16px 60px; }
  .page-head.sticky-head { top: calc(61px + env(safe-area-inset-top)); }
  .seg { max-width: 100%; }
  .seg.soft { flex-wrap: wrap; }
  /* Materials: Receive / Adjust / Edit move from the far-right column into an Actions button on the pinned name. */
  .row-menu { display: inline-flex; flex: none; }
  .col-actions { display: none; }
}

/* Touch screens: every control is at least 44px tall, and 16px text in fields stops iOS zooming in on focus. */
@media (max-width: 900px), (pointer: coarse) {
  .btn, .chip, .seg button, .seg.soft button, .nav a, .items-toggle, .x, .th-sort, .linklike { min-height: 44px; }
  .seg.soft button { height: auto; }
  .btn.small { padding: 4px 12px; }
  .x { min-width: 44px; }
  .tabs a { display: inline-flex; align-items: center; min-height: 44px; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea { min-height: 44px; font-size: 16px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; flex: none; }
  .check { min-height: 44px; margin: 0; }
  .filter-row input, .filter-row select { font-size: 16px; min-width: 104px; }
  .picker-results button, .count-row { min-height: 48px; }
  a.list-row, .job-row { min-height: 44px; }
}

@media (max-width: 760px) {
  .grid-2, .grid-3, .row, .doc-parties { grid-template-columns: minmax(0, 1fr); }
  .aging-legend { grid-template-columns: repeat(2, 1fr); }
  .job-line { grid-template-columns: minmax(0, 1fr) auto auto; }
  .job-line .kind { display: none; }
  .doc { padding: 20px; overflow-x: auto; }
  .doc-top { flex-direction: column; }
  .doc-title { text-align: left; }
  .doc-meta { justify-content: start; }
  .doc-meta dt, .doc-meta dd { text-align: left; }
}

@media (max-width: 700px) {
  /* Tables marked stack-sm (the count board, people, the audit log) become one card per row. Cells carry their
     column name in data-label. */
  table.stack-sm, table.stack-sm > tbody { display: block; }
  table.stack-sm > thead { display: none; }
  table.stack-sm > tbody > tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  table.stack-sm > tbody > tr:last-child { border-bottom: none; }
  table.stack-sm > tbody > tr > td { display: block; padding: 0; border: none; text-align: left; white-space: normal; min-width: 0; }
  .table-wrap > table.stack-sm > tbody > tr > td:first-child { grid-column: 1 / -1; position: static; box-shadow: none; background: none; }
  table.stack-sm td.wide { grid-column: 1 / -1; }
  table.stack-sm td.blank { display: none; }
  table.stack-sm td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
  .count-sort { display: flex; }

  /* Quote builder lines: one card per line, the quantity, unit and price side by side. */
  table.lines, table.lines > tbody { display: block; }
  table.lines > thead { display: none; }
  table.lines tr { display: block; }
  table.lines tr[data-i] { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr); gap: 8px; align-items: end; padding: 12px; border-bottom: 1px solid var(--border); }
  table.lines td { display: block; padding: 0; border: none; text-align: left; }
  table.lines tr[data-i] > td:first-child { grid-column: 1 / -1; min-width: 0 !important; }
  table.lines .qty, table.lines .price, table.lines .sold-by, table.lines .unit { width: 100% !important; text-align: left; }
  table.lines tr[data-i] > td:nth-child(2)::before { content: "Qty"; }
  table.lines tr[data-i] > td:nth-child(3)::before { content: "Unit"; }
  table.lines tr[data-i] > td:nth-child(4)::before { content: "Unit price"; }
  table.lines tr[data-i] > td:nth-child(n+2):nth-child(-n+4)::before { display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
  table.lines tr[data-i] > td.line-total { grid-column: 1 / 3; align-self: center; font-weight: 600; font-size: 15px; }
  table.lines tr[data-i] > td.line-total::before { content: "Line total  "; font-size: 12px; font-weight: 400; color: var(--muted); }
  table.lines tr[data-i] > td:last-child { justify-self: end; }
}

@media (max-width: 600px) {
  h1 { font-size: 20px; }
  .toolbar input[type="search"] { max-width: none; flex: 1 1 100%; }
  .picker-bar { flex-wrap: wrap; }
  .picker-bar select { width: 100% !important; }
  .job { grid-template-columns: 1fr; }
  .card-head { flex-wrap: wrap; }
  .analytics-filters label { max-width: 100%; min-width: 0; }
  .analytics-filters select { min-width: 0; flex: 1 1 auto; }
  .table-wrap > table:not(.lines):not(.stack-sm) > * > tr > :first-child { max-width: 44vw; white-space: normal; overflow-wrap: break-word; }
  /* A table with many columns keeps a workable width and scrolls in its card, rather than squeezing every name
     down to one word per line. */
  .table-wrap > table:not(.lines):not(.stack-sm):has(> thead th:nth-child(6)) > * > tr > :first-child { min-width: 150px; }
  .totals { width: 100% !important; }
  .count-name-row { flex-wrap: wrap; }
  .count-name-row .btn { flex: 1 1 100%; justify-content: center; }
  .chip-toggle { margin-left: 0; }
  /* Category chips: one row that scrolls sideways, so the list and the entry form stay near the top. */
  .count-picker .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; }
  .count-picker .chips::-webkit-scrollbar { display: none; }
  .count-picker .chip { flex: none; }
  /* Quote builder header: one slim row under the top bar. */
  .page-head.sticky-head { flex-wrap: nowrap; }
  .page-head.sticky-head .sub { display: none; }
  .page-head.sticky-head h1 { font-size: 17px; }
  .page-head.sticky-head .actions { flex-wrap: nowrap; }
  .count-results { max-height: 46vh; }
  /* Money screens on a phone. */
  .deposit-row { grid-template-columns: minmax(0, 1fr) 84px auto; }
  .deposit-row .dep-type { grid-column: 1 / -1; }
  .deposit-row .dep-qty { grid-column: 1; max-width: 140px; }
  .deposit-row .dep-total { grid-column: 2; text-align: right; }
  .deposit-row .dep-remove { grid-column: 3; }
  .apply-row { grid-template-columns: minmax(0, 1fr) 104px; }
  .return-row { grid-template-columns: minmax(0, 1fr); }
  .return-row .ret-qty input { text-align: left; }
  .pallet-row { flex-wrap: wrap; }
  .pallet-row .stepper { margin-left: auto; }
  .how-seg button { flex: 1 1 45%; }
  .how-seg button + button { border-left: none; box-shadow: -1px 0 0 #d3cfc5, 0 -1px 0 #d3cfc5; }
  /* At the top on phones, so a message never covers the buttons at the bottom of a dialog. */
  .toast { left: 12px; right: 12px; bottom: auto; top: calc(68px + env(safe-area-inset-top)); text-align: center; }
  /* Dialogs: a sheet fixed to the bottom of the visible screen, full width, buttons side by side. */
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal, .modal.wide { max-width: none; max-height: calc(var(--vvh, 100vh) - 12px); border-radius: 14px 14px 0 0; }
  .modal-head { padding: 8px 8px 8px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-radius: 0; }
  .modal-foot .btn { flex: 1; justify-content: center; }
}
