/* TowDesk — dispatch office styles. One file, no build step. */

:root {
  --ink: #16212e;          /* rail, headings */
  --ink-2: #263445;
  --paper: #eef1f4;        /* page */
  --surface: #ffffff;
  --line: #d6dce3;
  --line-soft: #e7ebef;
  --text: #1d2733;
  --muted: #5a6776;
  --amber: #f2a900;        /* light-bar amber: urgent + primary action only */
  --amber-ink: #3d2a00;
  --amber-soft: #fff3cf;
  --blue: #2457b8;
  --teal: #0d7d72;
  --violet: #5a4fc0;
  --green: #2f7a45;
  --gray: #7b8794;
  --red: #b42318;
  --red-soft: #fde8e6;
  --green-soft: #e5f3e9;
  --radius: 6px;
  --focus: 0 0 0 3px rgba(36, 87, 184, .35);
  font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); }
a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--ink); }
h1, h2, h3 { color: var(--ink); line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 700; }
p { margin: 0 0 .75rem; }
.num, td.num, .money { font-variant-numeric: tabular-nums; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 3px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--amber); color: var(--amber-ink); padding: .5rem .75rem; z-index: 10; }
.skip:focus { left: .5rem; top: .5rem; }

.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; background: linear-gradient(90deg, var(--ink) 232px, transparent 232px); }
.rail { background: var(--ink); color: #cfd8e2; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.rail::before { content: ""; display: block; height: 5px; background: repeating-linear-gradient(90deg, var(--amber) 0 34px, #c98c00 34px 36px); }
.rail-top { padding: 1.1rem 1rem .9rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.brand { display: flex; gap: .65rem; align-items: center; color: #fff; text-decoration: none; min-width: 0; }
.brand:hover { color: #fff; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--amber); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; left: 6px; right: 6px; top: 13px; height: 4px; border-radius: 2px; background: var(--ink); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 1.05rem; letter-spacing: -.01em; }
.brand-text small { font-size: .75rem; color: #9fb0c2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-toggle { display: none; }
.nav { display: flex; flex-direction: column; padding: .25rem .6rem 1rem; flex: 1; }
.nav a { color: #d7e0ea; text-decoration: none; padding: .5rem .65rem; border-radius: var(--radius); display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a[aria-current="page"] { background: #2c3d52; color: #fff; box-shadow: inset 3px 0 0 var(--amber); }
.nav .count { margin-left: auto; background: var(--amber); color: var(--amber-ink); font-size: .72rem; font-weight: 800; border-radius: 999px; padding: .05rem .45rem; font-variant-numeric: tabular-nums; }
.nav .nav-new { margin: .35rem 0 .6rem; justify-content: center; background: var(--amber); color: var(--amber-ink); font-weight: 700; }
.nav .nav-new:hover { background: #ffbe1a; color: var(--amber-ink); }
.nav-group { font-size: .75rem; color: #8698ab; padding: 1rem .65rem .3rem; font-weight: 600; }
.nav-foot { margin-top: auto; border-top: 1px solid #2a394b; padding-top: .75rem; display: flex; flex-direction: column; gap: .15rem; }
.nav-foot a { flex-direction: column; align-items: flex-start; gap: 0; }
.nav-foot small { color: #8698ab; font-weight: 400; font-size: .75rem; }
.link-btn { background: none; border: 0; color: #9fb0c2; font: inherit; padding: .4rem .65rem; cursor: pointer; text-align: left; }
.link-btn:hover { color: #fff; text-decoration: underline; }

.main { padding: 1.5rem 2rem 4rem; min-width: 0; max-width: 1280px; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.page-head .sub { color: var(--muted); margin: .3rem 0 0; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumb { font-size: .85rem; margin-bottom: .35rem; display: block; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .92rem; padding: .55rem .95rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover { border-color: #b6c0cb; color: var(--ink); background: #f8fafb; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #24364a; border-color: #24364a; color: #fff; }
.btn-amber { background: var(--amber); border-color: #d99800; color: var(--amber-ink); }
.btn-amber:hover { background: #ffbe1a; color: var(--amber-ink); border-color: #d99800; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-big { padding: .9rem 1rem; font-size: 1.05rem; width: 100%; }

/* ---------- Panels & layout ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line-soft); }
.panel-body { padding: 1.1rem; }
.stack > * + * { margin-top: 1rem; }
.sub { display: block; color: var(--muted); font-size: .82rem; font-weight: 400; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.cols-even { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.empty { padding: 2rem 1.1rem; text-align: center; color: var(--muted); }
.empty p { margin-bottom: .9rem; }

/* ---------- Stat strip (dashboard) ---------- */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 1rem; }
.strip > div { padding: .85rem 1.1rem; border-left: 1px solid var(--line-soft); }
.strip > div:first-child { border-left: 0; }
.strip dt { font-size: .8rem; color: var(--muted); }
.strip dd { margin: .15rem 0 0; font-size: 1.45rem; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.strip .hot dd { color: #8a5d00; }
.strip .bad dd { color: var(--red); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .55rem .85rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .count { font-size: .75rem; background: var(--line-soft); border-radius: 999px; padding: 0 .4rem; margin-left: .25rem; color: var(--ink); font-variant-numeric: tabular-nums; }

.toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 340px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: .92rem; }
.grid th { text-align: left; font-size: .78rem; font-weight: 600; color: var(--muted); padding: .55rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; background: #f8fafb; }
.grid td { padding: .65rem .75rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: #f8fafb; }
.grid .num { text-align: right; white-space: nowrap; }
.grid .nowrap { white-space: nowrap; }
.grid td.callno { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid td.callno a { color: var(--ink); text-decoration: none; }
.grid td.callno a:hover { text-decoration: underline; }
.grid .sub { display: block; color: var(--muted); font-size: .82rem; }
.row-urgent td:first-child { box-shadow: inset 4px 0 0 var(--amber); }
.row-click { cursor: pointer; }

/* ---------- Status pills ---------- */
.status { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; white-space: nowrap; background: #eef1f4; color: var(--ink); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s-waiting { background: var(--amber-soft); color: #8a5d00; }
.s-dispatched { background: #e6eefb; color: var(--blue); }
.s-en_route, .s-on_scene, .s-towing { background: #e2f3f1; color: var(--teal); }
.s-at_destination { background: #ecebfb; color: var(--violet); }
.s-completed, .s-paid { background: var(--green-soft); color: var(--green); }
.s-cancelled, .s-goa, .s-void { background: #eef0f2; color: var(--gray); }
.s-draft { background: #eef1f4; color: var(--muted); }
.s-sent { background: #e6eefb; color: var(--blue); }
.s-overdue { background: var(--red-soft); color: var(--red); }
.urgent-tag { font-size: .72rem; font-weight: 800; color: var(--amber-ink); background: var(--amber); padding: .05rem .4rem; border-radius: 3px; margin-left: .35rem; vertical-align: 1px; }

/* ---------- Forms ---------- */
label, .label { display: block; font-weight: 600; font-size: .86rem; color: var(--ink); margin-bottom: .3rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: .95rem; color: var(--text); background: #fff; border: 1px solid #c3ccd6; border-radius: var(--radius); padding: .5rem .6rem; min-height: 38px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: var(--focus); }
[aria-invalid="true"] { border-color: var(--red) !important; }
.field-error { color: var(--red); font-size: .82rem; margin: .3rem 0 0; font-weight: 500; }
.field { margin-bottom: .95rem; }
.fields { display: grid; grid-template-columns: repeat(12, 1fr); gap: 0 .85rem; }
.fields > .field { grid-column: span 12; }
.span-2 { grid-column: span 2 !important; } .span-3 { grid-column: span 3 !important; } .span-4 { grid-column: span 4 !important; }
.span-5 { grid-column: span 5 !important; } .span-6 { grid-column: span 6 !important; } .span-7 { grid-column: span 7 !important; }
.span-8 { grid-column: span 8 !important; } .span-9 { grid-column: span 9 !important; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { font-weight: 700; color: var(--ink); font-size: 1rem; padding: 0; margin-bottom: .8rem; }
.form-section { padding: 1.1rem 1.1rem .2rem; border-bottom: 1px solid var(--line-soft); }
.form-section:last-of-type { border-bottom: 0; }
.form-foot { display: flex; gap: .6rem; padding: 1rem 1.1rem; background: #f8fafb; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; flex-wrap: wrap; align-items: center; }
.form-foot .spacer { flex: 1; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: 17px; height: 17px; accent-color: var(--ink); }
.seg { display: inline-flex; border: 1px solid #c3ccd6; border-radius: var(--radius); overflow: hidden; }
.seg label { margin: 0; font-weight: 500; font-size: .88rem; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: .45rem .75rem; border-left: 1px solid #c3ccd6; }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: var(--ink); color: #fff; }
.seg input:focus-visible + span { box-shadow: inset var(--focus); }
.seg-urgent label:last-child input:checked + span { background: var(--amber); color: var(--amber-ink); font-weight: 700; }

/* ---------- Flash ---------- */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 500; border: 1px solid; }
.flash-success { background: var(--green-soft); border-color: #b9dcc3; color: #1e5631; }
.flash-error { background: var(--red-soft); border-color: #f4bdb7; color: #8d1c12; }
.flash-info { background: #e6eefb; border-color: #bfd0f0; color: #1d3f82; }

/* ---------- Call detail ---------- */
.call-hero { display: flex; align-items: flex-start; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.call-no { font-size: 2.6rem; font-weight: 800; letter-spacing: -.02em; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.call-no span { color: #9aa6b3; font-weight: 700; }
.call-hero .meta { flex: 1; min-width: 240px; padding-top: .2rem; }
.call-hero .meta .line1 { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .3rem; }
.route { display: grid; grid-template-columns: 18px 1fr; gap: .1rem .6rem; }
.route .dot { width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--ink); margin-top: .25rem; }
.route .dot.to { background: var(--ink); }
.route .bar { width: 3px; background: var(--line); margin: 0 auto; min-height: 18px; }
.route .addr { font-weight: 600; }
.route .addr-label { font-size: .78rem; color: var(--muted); font-weight: 600; display: block; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; font-size: .92rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 500; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.timeline li { display: grid; grid-template-columns: 118px 1fr; gap: .6rem; padding: .45rem 0; border-bottom: 1px dashed var(--line-soft); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.status-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .4rem; }
.status-buttons .btn[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Invoice editor ---------- */
.lines td { vertical-align: middle; }
.lines input, .lines select { min-height: 34px; padding: .35rem .45rem; font-size: .9rem; }
.lines .c-desc { min-width: 220px; }
.lines .c-qty { width: 90px; }
.lines .c-unit { width: 128px; }
.lines .c-price { width: 110px; }
.lines .c-tax { width: 50px; text-align: center; }
.lines .c-amt { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.lines .c-x { width: 40px; }
.totals { margin-left: auto; width: min(320px, 100%); font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; padding: .3rem 0; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: .3rem; padding-top: .5rem; font-weight: 800; font-size: 1.1rem; color: var(--ink); }
.totals .due { font-weight: 800; color: var(--red); }
.totals .due.zero { color: var(--green); }
.bill-to { line-height: 1.5; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin: 0; flex: 1; min-width: 120px; }

/* ---------- Driver view ---------- */
.job { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 1rem; overflow: hidden; }
.job.urgent { border-color: var(--amber); box-shadow: inset 0 4px 0 var(--amber); }
.job-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1rem .4rem; gap: .5rem; }
.job-head .call-no { font-size: 1.6rem; }
.job-body { padding: .3rem 1rem 1rem; }
.job-actions { display: grid; gap: .5rem; padding: 0 1rem 1rem; }
.job-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.job.done { opacity: .7; }

/* ---------- Sign-in & installer ---------- */
body.bare { background: var(--ink); min-height: 100vh; }
.bare-main { max-width: 420px; margin: 0 auto; padding: 8vh 1rem 2rem; }
.bare-main.wide { max-width: 640px; }
.signin { background: var(--surface); border-radius: 10px; overflow: hidden; }
.signin::before { content: ""; display: block; height: 6px; background: repeating-linear-gradient(90deg, var(--amber) 0 34px, #c98c00 34px 36px); }
.signin-body { padding: 1.6rem 1.6rem 1.2rem; }
.signin h1 { margin-bottom: .3rem; }
.signin .brand-line { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.4rem; }
.signin .brand-mark { width: 34px; height: 34px; }
.signin .brand-mark::after { top: 15px; }
.bare .flash { margin-bottom: .8rem; }
.bare-note { color: #9fb0c2; font-size: .82rem; text-align: center; margin-top: 1rem; }

/* ---------- Error page ---------- */
.error-page { max-width: 560px; padding: 2rem 0; }
.error-page .code { font-size: 3rem; font-weight: 800; color: #b6c0cb; line-height: 1; font-variant-numeric: tabular-nums; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; background: none; }
  .rail { position: sticky; height: auto; z-index: 5; }
  .rail-top { padding: .7rem 1rem; }
  .rail-toggle { display: inline-flex; background: var(--ink-2); color: #fff; border: 1px solid #34465b; border-radius: var(--radius); padding: .45rem .8rem; font: inherit; font-weight: 600; cursor: pointer; }
  .nav { display: none; }
  .nav.open { display: flex; }
  .main { padding: 1rem 1rem 3rem; }
  .cols-even { grid-template-columns: 1fr; }
  .fields > .field[class*="span-"] { grid-column: span 12 !important; }
  .fields > .field.span-2, .fields > .field.span-3, .fields > .field.span-4 { grid-column: span 6 !important; }
  .grid .hide-sm { display: none; }
  .call-no { font-size: 2rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* ---------- Print (browser print of any page) ---------- */
@media print {
  .rail, .actions, .form-foot, .btn, .flash { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .panel { border: 0; }
}
