:root {
  --bg: #f1f5f9; --card: #fff; --ink: #0f172a; --muted: #64748b;
  --line: #e2e8f0; --accent: #2563eb; --accent-dk: #1d4ed8;
  --ok: #16a34a; --warn: #d97706; --sold: #7c3aed; --hold: #0891b2; --work: #dc2626;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h2, h3 { margin: 0 0 .4rem; }
.muted { color: var(--muted); font-size: .85rem; }
.empty { color: var(--muted); text-align: center; padding: 1rem; }
.hidden { display: none !important; }

/* ---------- header / nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; background: #0f172a; color: #fff;
  padding: .7rem 1rem calc(.7rem + env(safe-area-inset-top));
  display: flex; align-items: baseline; gap: .6rem;
}
.brand { font-weight: 800; font-size: 1.15rem; letter-spacing: .2px; }
.brand span { font-weight: 400; font-size: .8rem; color: #94a3b8; }
.topbar-sub { margin-left: auto; font-size: .75rem; color: #94a3b8; display: flex; align-items: center; gap: 5px; }
#syncDot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
#syncDot.on { background: #4ade80; box-shadow: 0 0 5px #4ade80; }
#syncDot.off { background: rgba(148,163,184,.4); }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .5rem 0 .4rem; color: var(--muted); font-size: .7rem; font-weight: 600;
}
.bottomnav a svg { width: 22px; height: 22px; fill: currentColor; }
.bottomnav a.active { color: var(--accent); }

#botFab {
  position: fixed; right: 1rem; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40;
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; box-shadow: 0 6px 18px rgba(37,99,235,.45);
  display: grid; place-items: center;
}
#botFab svg { width: 26px; height: 26px; fill: #fff; }
#botFab:active { transform: scale(.94); }

/* ---------- layout ---------- */
#view { max-width: 720px; margin: 0 auto; padding: .8rem .8rem 1rem; }
.panel, .card, .doc {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 1rem; margin-bottom: .8rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.back { display: inline-block; margin: .2rem 0 .6rem; color: var(--muted); font-weight: 600; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-bottom: .8rem; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: .7rem .3rem; text-align: center; color: var(--ink);
}
.stat b { display: block; font-size: 1.5rem; }
.stat span { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat.ok b { color: var(--ok); } .stat.warn b { color: var(--warn); } .stat.sold b { color: var(--sold); }

/* ---------- lists / cards ---------- */
.toolbar { display: flex; gap: .5rem; margin-bottom: .8rem; align-items: center; }
.toolbar input { flex: 1; }
.toolbar h2 { margin: 0; flex: 1; }
.card { display: flex; align-items: center; gap: .7rem; color: var(--ink); }
.card:active { background: #f8fafc; }
.grow { flex: 1; min-width: 0; }
.row { justify-content: space-between; }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.thumb.placeholder { display: grid; place-items: center; background: #e2e8f0; color: var(--muted); font-weight: 700; }

.chip {
  display: inline-block; padding: .18rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; background: #e2e8f0; color: #475569; white-space: nowrap;
}
.chip.bad { background: #fee2e2; color: #b91c1c; }
.st-available { background: #dcfce7; color: var(--ok); }
.st-rented { background: #fef3c7; color: var(--warn); }
.st-sold { background: #ede9fe; color: var(--sold); }
.st-onhold { background: #cffafe; color: var(--hold); }
.st-inworkshop { background: #fee2e2; color: var(--work); }
.st-pendingrego { background: #ffedd5; color: #c2410c; }
.st-directoruse { background: #e0e7ff; color: #4338ca; }
.st-courtesycar { background: #fce7f3; color: #be185d; }

/* ---------- car profile ---------- */
.car-head { display: flex; align-items: center; gap: .6rem; }
.subtitle { margin: 0 0 .8rem; color: var(--muted); }
.detailgrid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .9rem; }
.detailgrid div { background: #f8fafc; border-radius: 10px; padding: .5rem .7rem; }
.detailgrid span { display: block; font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.rowbtns { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.photostrip { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .3rem; }
.photostrip img { width: 84px; height: 84px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.addphoto {
  width: 84px; height: 84px; border-radius: 10px; flex-shrink: 0; cursor: pointer;
  border: 2px dashed var(--line); color: var(--muted); font-size: 2rem;
  display: grid; place-items: center;
}

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 3px solid var(--line); padding: .3rem 0 .9rem .8rem; position: relative; }
.timeline li::before {
  content: ''; position: absolute; left: -7px; top: .55rem;
  width: 11px; height: 11px; border-radius: 50%; background: var(--accent);
}
.timeline .time { font-size: .75rem; }
.timeline p { margin: .25rem 0; }
.timeline audio { display: block; width: 100%; max-width: 300px; height: 34px; margin: .3rem 0; }
.carref { font-weight: 700; margin-right: .4rem; }
.effects { font-size: .78rem; color: var(--ok); font-weight: 600; }

/* ---------- forms ---------- */
input, select, textarea {
  width: 100%; padding: .65rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
.form label { display: block; margin-bottom: .7rem; font-size: .85rem; font-weight: 600; color: #334155; }
.form label input, .form label select, .form label textarea { margin-top: .25rem; font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
.fieldrow { display: flex; align-items: center; gap: .5rem; }
.fieldrow label { margin: 0; white-space: nowrap; }
.fieldrow input { width: 90px; flex-shrink: 0; }
.fieldrow select { flex: 1; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
label.check input { width: auto; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dk); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; margin-top: .4rem; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { color: var(--work); border-color: #fecaca; }
.iconbtn { border: 0; background: none; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; padding: .2rem .4rem; }
.linkbtn { border: 0; background: none; color: var(--accent); font: inherit; font-size: .8rem; cursor: pointer; padding: .2rem 0; display: block; margin-top: .3rem; }
.linkbtn.danger { color: var(--work); }
.center { text-align: center; }
.center .btn { margin: .3rem; }

/* ---------- sheets / overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: #fff; width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 0; }

/* ---------- bot ---------- */
.bot-controls { display: flex; align-items: center; gap: .6rem; margin: .6rem 0; flex-wrap: wrap; }
.bot-controls audio { flex: 1; min-width: 180px; height: 36px; }
.btn.mic svg { width: 18px; height: 18px; fill: currentColor; }
.btn.mic.rec { background: var(--work); border-color: var(--work); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .6rem; }

/* ---------- contract doc ---------- */
.doc h1 { font-size: 1.35rem; margin-bottom: .1rem; }
.doc-biz { font-weight: 700; margin: 0; }
.doctable { width: 100%; border-collapse: collapse; margin: .8rem 0; }
.doctable th, .doctable td { border: 1px solid var(--line); padding: .45rem .6rem; text-align: left; font-size: .9rem; }
.doctable th { width: 7.5rem; background: #f8fafc; }
.docterms { font-size: .85rem; color: #334155; }
.ledger td, .ledger th { font-size: .8rem; padding: .3rem .45rem; }
.ledger tr.short td { background: #fef2f2; color: #b91c1c; }
.ledger tr.totals td { border-top: 2px solid #0f172a; background: #f8fafc; }
.sigrow { display: flex; gap: 2.5rem; margin-top: 2.5rem; font-size: .8rem; color: var(--muted); }
.sig { flex: 1; }
.sig span { display: block; border-bottom: 1px solid #94a3b8; height: 2.4rem; margin-bottom: .3rem; }

.attachimg { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); margin-bottom: .6rem; }
.attachimg.sig { max-height: 70px; width: auto; background: #fff; }
.gpsmap { width: 100%; height: 220px; border: 0; border-radius: 10px; margin-top: .3rem; }
/* numbered car markers on the fleet map */
.carmark-wrap { background: none; border: none; }
.carmark { display: flex; align-items: center; justify-content: center; min-width: 28px; height: 20px; padding: 0 4px; border-radius: 10px; color: #fff; font: 700 11px/1 system-ui, sans-serif; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.45); box-sizing: border-box; }
.carmark.on { color: #1a1a1a; }
.carmark.off { border-color: #fff; border-style: dashed; }

/* ---------- import ---------- */
.maptable { width: 100%; border-collapse: collapse; margin: .7rem 0; font-size: .9rem; }
.maptable th, .maptable td { text-align: left; padding: .3rem .3rem .3rem 0; }
.maptable td:first-child { font-weight: 600; white-space: nowrap; }
.preview { overflow-x: auto; margin-bottom: .7rem; }
.preview table { border-collapse: collapse; font-size: .78rem; white-space: nowrap; }
.preview th, .preview td { border: 1px solid var(--line); padding: .3rem .5rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.preview th { background: #f8fafc; }
#impFile { margin-bottom: .4rem; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  background: #0f172a; color: #fff; padding: .65rem 1.1rem; border-radius: 999px;
  font-size: .88rem; opacity: 0; transition: .25s; pointer-events: none; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--work); }

/* ---------- collections ---------- */
.daytabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: .5rem; }
.daytab { padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 999px; font-size: .8rem; color: var(--ink2); text-decoration: none; white-space: nowrap; }
.daytab.on { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.coll.paid { border-left: 4px solid #22c55e; }
.coll.failed { border-left: 4px solid #dc2626; }
.collamt { font-weight: 700; white-space: nowrap; }
.collbtns { display: flex; flex-direction: column; gap: 4px; }
.btn.ok { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.btn.danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.small { font-size: .75rem; }

/* ---------- contract picker / gaps ---------- */
.pickbox { border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; margin: -.35rem 0 .4rem; background: #f8fafc; }
.pickbox b { margin-right: .4rem; }
.btn.tiny { padding: .15rem .55rem; font-size: .72rem; border-radius: 8px; }
.gapbox { border: 1px solid #fde68a; background: #fffbeb; border-radius: 10px; padding: .6rem .8rem; margin-bottom: .7rem; font-size: .85rem; }
.gapbox.ok { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.gapbox ul { margin: .35rem 0 .3rem 1.1rem; padding: 0; }
.gapbox li { margin: .12rem 0; }
.licphotos { display: flex; gap: .6rem; margin-top: .6rem; flex-wrap: wrap; }
.licphotos figure { margin: 0; }
.licphotos img { width: 140px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.licphotos figcaption { font-size: .72rem; color: var(--ink2); text-align: center; margin-top: .15rem; }
.intakeurl { word-break: break-all; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; font-size: .8rem; margin: .6rem 0; }
.qrbox { text-align: center; margin: .5rem 0; }
.qrbox img { width: 190px; height: 190px; image-rendering: pixelated; }
.attachpdf { width: 100%; height: 70vh; min-height: 420px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.chip.rego-exp { background: #dc2626; color: #fff; }
.chip.rego-due { background: #f59e0b; color: #1e293b; }
.chip.rego-unv { background: #e2e8f0; color: #64748b; }
.chip.rego-ok { background: #16a34a; color: #fff; }

@media print {
  .topbar, .bottomnav, #botFab, .back, .noprint, #toast { display: none !important; }
  body { background: #fff; padding: 0; }
  .doc { border: 0; }
  .report { font-size: 12px; }
  .report h1 { font-size: 18px; }
  .report h2 { font-size: 14px; page-break-after: avoid; }
}
table.rpt { width: 100%; border-collapse: collapse; margin: .4rem 0 1.2rem; }
table.rpt th, table.rpt td { border: 1px solid #cbd5e1; padding: .35rem .45rem; text-align: left; font-size: 12px; vertical-align: top; }
table.rpt th { background: #f1f5f9; }
table.rpt td.act { width: 2.2rem; text-align: center; font-size: 15px; }
.red { color: #b91c1c; font-weight: 600; }
.signthumb { width: 110px; height: 80px; object-fit: cover; border: 1px solid var(--line); border-radius: 8px; }
