:root {
  --bg: #f2f2f3; --panel: #fff; --ink: #141414; --muted: #6b6b70; --line: #e2e2e4;
  --side: #0b0b0c; --side-ink: #c4c4c6; --accent: #e20b11; --accent-dark: #b1080d; --silver: #b4b4b4;
  --good: #2f9e44; --warn: #f08c00; --bad: #e03131; --info: #1971c2;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); display: flex; min-height: 100vh; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

.sidebar { width: 230px; flex: none; background: var(--side); color: var(--side-ink); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: #fff; padding: 20px 18px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  border-bottom: 1px solid transparent; border-image: linear-gradient(90deg, transparent, #8d8d8d, #e9e9e9, #8d8d8d, transparent) 1; }
.brand-logo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px #2a2a2a, 0 6px 18px rgba(226, 11, 17, .25); }
#shop-name { font-weight: 800; font-size: 15px; letter-spacing: .06em; text-transform: uppercase; font-style: italic; }
.sidebar nav a { display: block; color: var(--side-ink); padding: 8px 18px; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: #1b1b1d; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: linear-gradient(90deg, rgba(226, 11, 17, .22), transparent); color: #fff; border-left-color: var(--accent); }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--silver); opacity: .7; padding: 16px 18px 4px; }

main { flex: 1; padding: 24px 28px 60px; min-width: 0; }
h1 { margin: 0; font-size: 22px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }
.sub { color: var(--muted); }

.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 7px 13px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; }

.pipeline { display: flex; gap: 0; margin-bottom: 18px; overflow-x: auto; }
.pipeline a { flex: 1; min-width: 130px; background: var(--panel); border: 1px solid var(--line); padding: 14px 16px; color: var(--ink); position: relative; }
.pipeline a:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.pipeline a:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.pipeline a + a { border-left: none; }
.pipeline a:hover { background: #fff2f2; text-decoration: none; }
.pipeline .n { font-size: 26px; font-weight: 700; color: var(--accent); }
.pipeline .t { font-size: 12px; color: var(--muted); }

table.list { width: 100%; border-collapse: collapse; background: var(--panel); }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #fafbfc; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.num { text-align: right; white-space: nowrap; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #e9ecef; color: #495057; text-transform: capitalize; white-space: nowrap; }
.badge.new, .badge.draft, .badge.scheduled, .badge.open { background: #e7f0fd; color: #1864ab; }
.badge.sent, .badge.waiting_parts, .badge.partial { background: #fff3bf; color: #8a5a00; }
.badge.approved, .badge.ready, .badge.completed, .badge.paid, .badge.done { background: #d3f9d8; color: #2b8a3e; }
.badge.in_progress { background: #ffe8cc; color: #c2410c; }
.badge.declined, .badge.void, .badge.overdue { background: #ffe3e3; color: #c92a2a; }
.badge.converted, .badge.invoiced, .badge.archived { background: #e9ecef; color: #495057; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 12px; cursor: pointer; font: inherit; font-size: 13px; text-transform: capitalize; }
.tabs button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.subnav { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.subnav button { border: none; background: none; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav button.on { color: var(--ink); border-bottom-color: var(--accent); }
input.search { padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; min-width: 220px; }

/* workflow stepper */
.stepper { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.stepper .step { flex: 1; min-width: 110px; padding: 8px 12px; border-radius: 8px; background: #fff; border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.stepper .step b { display: block; font-size: 13px; color: var(--ink); }
.stepper .step.done { border-color: #b2f2bb; background: #ebfbee; }
.stepper .step.current { border-color: var(--accent); background: #fff1f1; }

/* forms */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 25, 35, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; padding: 20px 22px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.field.full { grid-column: 1 / -1; }
.field input, .field select, .field textarea, .inline-input { font: inherit; font-weight: 400; color: var(--ink); padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; width: 100%; }
.field input[type=checkbox] { width: auto; }
.field textarea { resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.vin-row { display: flex; gap: 6px; }

/* line items */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-size: 12px; color: var(--muted); text-align: left; padding: 6px; border-bottom: 1px solid var(--line); }
table.lines td { padding: 4px; border-bottom: 1px solid var(--line); }
table.lines input, table.lines select { font: inherit; padding: 5px 7px; border: 1px solid transparent; border-radius: 6px; width: 100%; background: transparent; }
table.lines input:hover, table.lines select:hover { border-color: var(--line); }
table.lines input:focus, table.lines select:focus { border-color: var(--info); outline: none; background: #fff; }
table.lines .kind-labor { color: var(--info); }
table.lines .kind-part { color: var(--good); }
.totals { margin-left: auto; max-width: 300px; margin-top: 12px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 17px; font-weight: 700; border-top: 2px solid var(--ink); padding-top: 6px; margin-top: 4px; }
.add-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; }

/* schedule */
.week { display: grid; grid-template-columns: repeat(7, minmax(130px, 1fr)); gap: 8px; overflow-x: auto; }
.day { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 260px; padding: 8px; }
.day.today { border-color: var(--accent); }
.day h4 { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.job { display: block; border-left: 4px solid var(--info); background: #f7f9fc; border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; font-size: 12px; color: var(--ink); }
.job:hover { text-decoration: none; background: #eef3fa; }
.job.in_progress { border-left-color: var(--accent); }
.job.waiting_parts { border-left-color: var(--warn); }
.job.ready, .job.completed { border-left-color: var(--good); }
.job.invoiced { border-left-color: #adb5bd; opacity: .7; }

/* inspection */
.insp-row { display: grid; grid-template-columns: minmax(180px, 1.2fr) auto 110px 1.5fr; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.insp-row:last-child { border-bottom: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 5px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on.good { background: var(--good); color: #fff; }
.seg button.on.attention { background: var(--warn); color: #fff; }
.seg button.on.urgent { background: var(--bad); color: #fff; }
.seg button.on.na { background: #868e96; color: #fff; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot.good { background: var(--good); } .dot.attention { background: var(--warn); } .dot.urgent { background: var(--bad); } .dot.na { background: #adb5bd; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 99; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }
.loading { color: var(--muted); padding: 30px; }
.muted { color: var(--muted); }
.row-actions { display: flex; gap: 6px; }

/* print */
.print-page { background: #fff; max-width: 820px; margin: 0 auto; padding: 36px 40px; border: 1px solid var(--line); }
.print-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid var(--ink); padding-bottom: 14px; margin-bottom: 18px; }
.print-head .shop { font-size: 20px; font-weight: 700; }
.print-head .doc { text-align: right; }
.print-head .doc .t { font-size: 22px; font-weight: 700; text-transform: uppercase; }
.print-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 18px; }
.print-page table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.print-page th { text-align: left; border-bottom: 1px solid var(--ink); padding: 5px 4px; font-size: 12px; }
.print-page td { padding: 5px 4px; border-bottom: 1px solid #eee; }
.sig { margin-top: 40px; display: flex; gap: 30px; }
.sig div { flex: 1; border-top: 1px solid var(--ink); padding-top: 4px; font-size: 12px; color: var(--muted); }
body.printing .sidebar { display: none; }
@media print {
  body { background: #fff; }
  .sidebar, .no-print { display: none !important; }
  main { padding: 0; }
  .print-page { border: none; padding: 0; max-width: none; }
}
/* Phone layout: top bar, slide-out menu, bottom tabs. Hidden on wide screens. */
.mbar, .tabbar, .scrim { display: none; }
@media (max-width: 800px) {
  body { display: block; }
  .mbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; background: var(--side); color: #fff;
    padding: calc(env(safe-area-inset-top) + 8px) 12px 10px; border-bottom: 2px solid var(--accent); }
  .mbar-menu { background: none; border: 0; color: #fff; padding: 6px; margin-left: -6px; display: flex; }
  #mbar-title { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar { position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; width: 280px; height: auto; transform: translateX(-105%);
    transition: transform .22s ease; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .5); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45); }
  .sidebar nav a { padding: 12px 20px; font-size: 15px; }
  .brand-logo { width: 72px; height: 72px; }
  main { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); }
  .tabbar { display: flex; position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; background: #0b0b0c; border-top: 1px solid #262628;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: #9a9aa0; background: none; border: 0;
    font: inherit; font-size: 11px; padding: 4px 0; text-decoration: none; }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar svg circle[r="1.5"] { fill: currentColor; }
  .tabbar a.active { color: #fff; }
  .tabbar a.active svg { stroke: var(--accent); }
  body.auth-mode .mbar, body.auth-mode .tabbar, body.printing .mbar, body.printing .tabbar { display: none; }
  .page-head { gap: 8px; }
  .page-head h1 { display: none; }  /* the top bar already shows the page title */
  .page-head .sub { width: 100%; }
  .page-head .spacer { display: none; }
  .btn { min-height: 40px; padding: 8px 14px; }
  .btn.sm { min-height: 34px; }
  input, select, textarea, .inline-input, input.search { font-size: 16px !important; }  /* stops iPhone zooming into fields */
  input.search { min-width: 0; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .insp-row { grid-template-columns: 1fr; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal { max-width: 100% !important; border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .stepper .step { min-width: 90px; }
  .row-actions { flex-wrap: wrap; }
  #toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
}
/* Install tip and phone extras */
.install-tip { position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(86px + env(safe-area-inset-bottom)); background: #141416; color: #fff;
  border: 1px solid #333; border-radius: 14px; padding: 14px 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); font-size: 14px; }
.install-tip b { color: #fff; }
.install-tip .x { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: #aaa; font-size: 20px; }
.share-ico { display: inline-block; width: 16px; height: 16px; vertical-align: -3px; }
.scan-overlay { position: fixed; inset: 0; z-index: 90; background: #000; display: flex; flex-direction: column; }
.scan-overlay video { flex: 1; width: 100%; object-fit: cover; }
.scan-frame { position: absolute; left: 8%; right: 8%; top: 38%; height: 18%; border: 3px solid var(--accent); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35); pointer-events: none; }
.scan-bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center; background: linear-gradient(transparent, rgba(0, 0, 0, .85)); color: #fff; }
.scan-bar span { flex: 1; font-size: 14px; }
.scan-top { position: absolute; top: 0; left: 0; right: 0; padding: calc(env(safe-area-inset-top) + 14px) 16px 14px; color: #fff; text-align: center; font-weight: 700; background: linear-gradient(rgba(0, 0, 0, .7), transparent); }

/* sending, activity, branding */
.hidden { display: none !important; }
.warn { background: #fff4e6; border: 1px solid #ffd8a8; color: #8a4b00; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-top: 10px; }
.activity { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: center; }
.act-sig { display: flex; gap: 14px; align-items: center; }
.act-sig img { max-height: 54px; max-width: 200px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.logo-row { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.logo-box { width: 200px; height: 90px; border: 1px dashed var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; background: #fafbfc; }
.logo-box img { max-width: 190px; max-height: 80px; object-fit: contain; }
.field input[type=color] { height: 38px; padding: 3px; }

/* Velocity Motors theme touches */
h1 { letter-spacing: -.01em; }
.page-head h1::after { content: ""; display: block; width: 38px; height: 3px; margin-top: 6px; background: var(--accent); border-radius: 2px; }
.stat .v { color: var(--ink); }
.stat { border-top: 3px solid var(--silver); }
.btn.primary { box-shadow: 0 1px 0 rgba(0, 0, 0, .15); }

/* sign in */
body.auth-mode .sidebar, body.auth-mode main { display: none; }
.auth-bg { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 50% 20%, #2a0a0b, #0b0b0c 60%); }
.auth-card { background: #fff; width: 100%; max-width: 380px; border-radius: 14px; padding: 28px 26px; display: flex; flex-direction: column; gap: 12px;
  border-top: 4px solid var(--accent); box-shadow: 0 24px 60px rgba(0, 0, 0, .5); text-align: center; }
.auth-card .field { text-align: left; }
.auth-card h1 { font-size: 20px; }
.auth-card p { margin: 0 0 4px; font-size: 13px; }
.auth-logo { width: 110px; height: 110px; border-radius: 50%; object-fit: cover; margin: 0 auto; }
.auth-go { padding: 10px; font-size: 15px; }
.auth-err { color: var(--bad); font-weight: 600; font-size: 13px; min-height: 1em; }
.nav-me { margin: 18px 18px 20px; padding-top: 12px; border-top: 1px solid #262628; font-size: 12px; color: var(--silver); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.nav-me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-signout { background: none; border: 1px solid #3a3a3d; color: #ddd; border-radius: 6px; padding: 3px 8px; font: inherit; cursor: pointer; }
.nav-signout:hover { border-color: var(--accent); color: #fff; }
body.booting .sidebar, body.booting main { visibility: hidden; }

/* roles */
body.role-team .admin-only { display: none !important; }
body.role-team [data-del]:not(#lines [data-del]), body.role-team [data-delpay] { display: none !important; }
#me { color: var(--side-ink); }
#me:hover { color: #fff; }
.role-chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.chip-owner { background: #141414; color: #fff; }
.chip-admin { background: #ffe3e3; color: #a30a0e; }
.chip-team { background: #e9ecef; color: #495057; }
.perm-table td:not(:first-child), .perm-table th:not(:first-child) { text-align: center; width: 120px; }
.perm-yes { color: var(--good); font-weight: 800; }
.perm-no { color: #adb5bd; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; flex-wrap: wrap; }
.auth-ok { color: var(--good); font-weight: 600; font-size: 13px; }
.auth-ok:empty, .auth-err:empty { display: none; }

/* email settings */
.email-status { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: #fff4e6; color: #8a4b00; margin-bottom: 12px; font-size: 13px; }
.email-status.on { background: #ebfbee; color: #2b8a3e; }
.smtp-alt { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.smtp-alt summary { cursor: pointer; color: var(--muted); font-size: 13px; }
