:root {
  --ink: #0A0F1A;
  --ink-2: #2B3340;
  --muted: #5B6472;
  --line: #E3E6EB;
  --line-2: #C3C9D2;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --blue: #004AAD;
  --blue-dark: #00357D;
  --blue-soft: #EAF1FB;
  --accent: #F94A00;
  --good: #11622E; --good-bg: #E7F6EC;
  --watch: #8A4B00; --watch-bg: #FFF1E0;
  --urgent: #9B1C0C; --urgent-bg: #FDE8E4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 15, 26, 0.06), 0 4px 16px rgba(10, 15, 26, 0.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; }

/* ---------- shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 228px; flex: 0 0 228px; background: var(--ink); color: #fff;
  display: flex; flex-direction: column; padding: 18px 12px; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; flex-direction: column; padding: 4px 10px 18px; }
.brand b { font-size: 20px; font-weight: 900; font-stretch: 75%; letter-spacing: .02em; text-transform: uppercase; }
.brand span { font-size: 12px; color: #8A94A3; letter-spacing: .14em; font-family: 'IBM Plex Mono', monospace; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 12px; border-radius: 10px;
  color: #C7CDD6; text-decoration: none; font-weight: 700; font-size: 15px;
}
.nav a:hover { background: #141B29; color: #fff; }
.nav a.active { background: #1A2333; color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 20px; height: 20px; flex: 0 0 auto; }
.sidebar .me { margin-top: auto; border-top: 1px solid #1E2633; padding: 14px 10px 0; font-size: 14px; color: #C7CDD6; }
.sidebar .me button { background: none; border: 0; color: #8A94A3; padding: 6px 0; cursor: pointer; text-decoration: underline; }
.main { flex: 1 1 auto; min-width: 0; padding: 24px clamp(14px, 3vw, 32px) 80px; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
h1 { font-size: clamp(26px, 3vw, 34px); line-height: 1.05; margin: 0; font-weight: 900; font-stretch: 75%; text-transform: uppercase; letter-spacing: .005em; }
h2 { font-size: 20px; margin: 0; font-weight: 800; }
h3 { font-size: 16px; margin: 0; font-weight: 800; }

/* mobile nav */
.mobilebar { display: none; }
@media (max-width: 900px) {
  .sidebar { display: none; }
  .mobilebar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--ink);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); gap: 4px; justify-content: space-around;
  }
  .mobilebar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; min-height: 52px; justify-content: center;
    color: #C7CDD6; text-decoration: none; font-size: 11px; font-weight: 700; border-radius: 10px; }
  .mobilebar a.active { color: #fff; background: #1A2333; }
  .mobilebar svg { width: 22px; height: 22px; }
  .main { padding-bottom: 96px; }
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--line-2); background: #fff; color: var(--ink); font-weight: 800; font-size: 15px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--ink); }
.btn.primary:hover { background: #E04200; border-color: #E04200; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--urgent); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: .55; cursor: default; }
.iconbtn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.iconbtn:hover { background: #EEF0F3; color: var(--ink); }
.iconbtn svg { width: 18px; height: 18px; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: #fff; font-size: 16px; font-weight: 500;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
.inline-input { border-color: transparent !important; background: transparent !important; padding: 6px 8px !important; min-height: 36px !important; }
.inline-input:hover { border-color: var(--line-2) !important; background: #fff !important; }
.inline-input:focus { background: #fff !important; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card.pad0 { padding: 0; }
.card + .card { margin-top: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 999px; background: #EEF0F3; color: var(--ink-2); white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.watch { background: var(--watch-bg); color: var(--watch); }
.chip.urgent { background: var(--urgent-bg); color: var(--urgent); }
.chip.blue { background: var(--blue-soft); color: var(--blue-dark); }
.chip.accent { background: #FFF1E9; color: #9A2E00; }
.dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; background: currentColor; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.error-banner { background: var(--urgent-bg); color: var(--urgent); padding: 12px 14px; border-radius: 10px; font-weight: 600; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: calc(100vw - 32px);
}
.toast.err { background: var(--urgent); }
@media (max-width: 900px) { .toast { bottom: 92px; } }

/* ---------- board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: #EAEDF1; border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; font-weight: 800; font-size: 14px; }
.col-head .count { font-family: 'IBM Plex Mono', monospace; font-size: 12px; background: #fff; border-radius: 99px; padding: 2px 8px; }
.ro-card { display: block; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-decoration: none; color: inherit; margin-bottom: 8px; box-shadow: var(--shadow); }
.ro-card:hover { border-color: var(--blue); }
.ro-card .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.ro-card .veh { font-weight: 800; font-size: 16px; margin: 4px 0 2px; }
.ro-card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
@media (max-width: 900px) {
  .board { grid-auto-flow: row; grid-auto-columns: auto; overflow: visible; }
}

/* ---------- tables ---------- */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px; border-bottom: 1px solid #EEF0F3; vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #F8F9FB; }
.table-wrap { overflow-x: auto; }

/* ---------- RO detail ---------- */
.ro-head { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 1000px) { .ro-head { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 18px 0 14px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.tabs button { min-height: 42px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-weight: 800; cursor: pointer; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs .badge { margin-left: 6px; background: var(--accent); color: var(--ink); border-radius: 99px; padding: 1px 7px; font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.status-select { font-weight: 800; }

.insp-section { margin-bottom: 14px; }
.insp-section h3 { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.insp-item { display: grid; grid-template-columns: minmax(150px, 1.2fr) auto minmax(150px, 1.4fr) auto; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid #EEF0F3; }
.insp-item:last-child { border-bottom: 0; }
.insp-item .name { font-weight: 700; }
@media (max-width: 760px) { .insp-item { grid-template-columns: 1fr; } }
.seg { display: inline-flex; background: #EEF0F3; border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { min-height: 38px; min-width: 64px; padding: 0 10px; border: 0; border-radius: 999px; background: transparent; font-weight: 800; font-size: 13px; cursor: pointer; color: var(--muted); }
.seg button.on.good { background: var(--good); color: #fff; }
.seg button.on.watch { background: #C46A00; color: #fff; }
.seg button.on.urgent { background: #C2260F; color: #fff; }
.seg button.on.na { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.thumb { position: relative; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #EEF0F3; cursor: zoom-in; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.cam { position: relative; overflow: hidden; }
.cam input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.job { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 14px; }
.job.approved { border-left: 4px solid var(--good); }
.job.declined { border-left: 4px solid var(--line-2); background: #FAFAFB; }
.job.pending { border-left: 4px solid var(--accent); }
.job-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid #EEF0F3; }
.job-head .title { font-weight: 800; font-size: 17px; flex: 1 1 240px; }
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; text-align: left; padding: 8px 10px; }
.lines td { padding: 4px 6px; border-top: 1px solid #F1F2F5; }
.lines input, .lines select { min-height: 38px; font-size: 15px; padding: 6px 8px; }
.lines .num { width: 92px; text-align: right; }
.job-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid #EEF0F3; }
@media (max-width: 760px) {
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border-top: 1px solid #F1F2F5; }
  .lines td { border: 0; padding: 0; }
  .lines td.desc { grid-column: 1 / -1; }
  .lines .num { width: 100%; }
}
.totals { display: grid; gap: 6px; font-size: 15px; }
.totals .row { justify-content: space-between; }
.totals .grand { font-size: 26px; font-weight: 900; font-stretch: 80%; border-top: 1px solid var(--line); padding-top: 10px; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 12px 0; border-bottom: 1px solid #EEF0F3; display: grid; grid-template-columns: 150px 1fr; gap: 10px; }
@media (max-width: 600px) { .activity li { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 700; }
.kpi .value { font-size: 32px; font-weight: 900; font-stretch: 80%; line-height: 1.1; margin-top: 4px; }
.kpi .hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.chart { position: relative; }
.chart svg { width: 100%; height: 220px; display: block; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 13px; padding: 6px 10px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 15, 26, .55); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 18px; padding: 22px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal.wide { width: min(900px, 100%); }
.lightbox img { max-height: 75vh; margin: 0 auto; border-radius: 10px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--ink); }
.auth .card { width: min(440px, 100%); padding: 28px; }
.auth h1 { margin-bottom: 4px; }

/* ---------- print (invoice) ---------- */
.print-only { display: none; }
@media print {
  .sidebar, .mobilebar, .no-print, .tabs, .toast { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  .main { padding: 0; }
  .card, .job { border: 0; padding: 0; break-inside: avoid; }
}

/* estimate table sizing */
.job-head .title { width: auto; flex: 1 1 200px; min-width: 0; font-size: 17px; font-weight: 800; }
.job-head select { flex: 0 0 auto; }
.lines td:first-child select { min-width: 96px; }
.lines td.desc { min-width: 180px; }
.lines td:nth-child(3) input { min-width: 110px; }
