/* Service Log prototype — design tokens + layout. Light palette first, dark
   redefines tokens only, so every colour has a definition on bare :root. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dfe3ea;
  --border-strong: #c6ccd8;
  --text: #161b26;
  --text-muted: #5c6678;
  --accent: #1f5fd6;
  --accent-soft: #e8effc;
  --accent-text: #ffffff;
  --owner: #1f5fd6;
  --system: #3a7d52;
  --external: #8a5a12;
  --danger: #b3261e;
  --warn: #9a6700;
  --ok: #1f7a45;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
  --radius-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1d222c;
    --border: #2a313d;
    --border-strong: #3b4453;
    --text: #e8ecf3;
    --text-muted: #9aa5b6;
    --accent: #6f9dff;
    --accent-soft: #1c2841;
    --accent-text: #0f1218;
    --owner: #6f9dff;
    --system: #63c58b;
    --external: #e0ae5c;
    --danger: #ef8a82;
    --warn: #e4b95e;
    --ok: #63c58b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .32);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0 0 .35em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); }
.muted { color: var(--text-muted); font-size: .875rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- shell ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  /* Installed, the app runs edge to edge — a phone held sideways is wider than the
     phone breakpoint below and still has a notch. env() is 0 everywhere else. */
  padding: calc(10px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px))
    10px calc(20px + env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; letter-spacing: -.02em; color: var(--text); text-decoration: none;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--system));
}
.brand-tag {
  font: 600 10px/1 ui-monospace, Menlo, monospace; text-transform: uppercase; letter-spacing: .08em;
  padding: 4px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent);
}
.topnav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topnav a {
  padding: 7px 12px; border-radius: var(--radius-sm); text-decoration: none;
  color: var(--text-muted); font-weight: 550; font-size: .9rem;
}
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.view { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 28px 20px 64px; outline: none; }
.view.narrow { max-width: 520px; }

/* ---------- primitives ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border-strong); }
.btn-icon { padding: 6px 10px; font-size: 1.1rem; line-height: 1; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .spacer { margin-left: auto; }

label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }
.field .err { font-size: .78rem; color: var(--danger); margin-top: 4px; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.checklist .check-group h3 {
  margin: 14px 0 4px; font-size: .74rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
}
.check {
  display: flex; gap: 10px; align-items: flex-start; margin: 0; padding: 8px 10px;
  border-radius: var(--radius-sm); font-size: .9rem; font-weight: 400; color: var(--text); cursor: pointer;
}
.check:hover { background: var(--surface-2); }
.check input { width: 18px; height: 18px; flex: none; margin: 1px 0 0; padding: 0; accent-color: var(--accent); }
.check small { display: block; color: var(--text-muted); font-size: .78rem; margin-top: 2px; }
.check-other { display: grid; grid-template-columns: 1fr minmax(120px, 180px) auto; gap: 8px; margin-top: 10px; }
.due-list { list-style: none; margin: 0; padding: 0; }
.due-list li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.due-list li:first-child { border-top: 0; }
.due-list .check { flex: 1; padding: 0; }
.due-list .check:hover { background: none; }
.due-list .when { text-align: right; font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
.meter { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--border); overflow: hidden; min-width: 90px; }
.meter span { display: block; height: 100%; background: var(--ok); }
.meter.accent span { background: var(--accent); }
.meter.warn span { background: var(--warn); }
.meter.danger span { background: var(--danger); }
.pace { margin: 6px 0 4px; }
.pace input[type=range] { padding: 0; border: 0; accent-color: var(--accent); }
.pace-stops { display: flex; justify-content: space-between; font-size: .78rem; color: var(--text-muted); }
.plan-table td { vertical-align: top; }
.plan-table select { min-width: 130px; padding: 6px 8px; }
.plan-table .plan-group th { padding-top: 18px; font-size: .9rem; text-align: left; }
.plan-table .plan-group small { display: block; font-weight: 400; color: var(--text-muted); font-size: .78rem; margin-top: 2px; }
.badge.priority { padding: 1px 7px; font-size: .68rem; vertical-align: 1px; }
.item-list { margin: 6px 0 0; padding-left: 18px; font-size: .86rem; color: var(--text-muted); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 650;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.badge.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.badge.accent { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

.empty { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty h2 { color: var(--text); }
.empty .btn { margin-top: 14px; }

/* ---------- steps ---------- */
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.steps li {
  list-style: none; display: flex; align-items: center; gap: 7px;
  padding: 6px 12px 6px 8px; border-radius: 999px; font-size: .82rem; font-weight: 550;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
}
.steps li .n {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-size: .72rem; font-weight: 700; border: 1px solid var(--border);
}
.steps li.done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.steps li.done .n { background: var(--ok); color: var(--surface); border-color: transparent; }
.steps li.active { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.steps li.active .n { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* ---------- vehicles ---------- */
.vehicle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.vehicle-card {
  display: flex; flex-direction: column; gap: 4px; text-align: left; text-decoration: none;
  color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.vehicle-card:hover { border-color: var(--accent); }
.vehicle-photo {
  aspect-ratio: 16 / 9; background: var(--surface-2); display: grid; place-items: center;
  border-bottom: 1px solid var(--border); overflow: hidden;
}
.vehicle-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vehicle-photo .ph { font-size: 2rem; opacity: .35; }
.vehicle-card .body { padding: 14px 16px 16px; }
.plate {
  display: inline-block; font: 700 .82rem/1 ui-monospace, Menlo, monospace; letter-spacing: .06em;
  padding: 5px 8px; border-radius: 5px; border: 2px solid var(--border-strong); background: var(--surface-2);
  text-transform: uppercase;
}
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: .9rem; }
.kv dt { color: var(--text-muted); font-size: .82rem; }
.kv dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 14px; padding: 14px 0; border-top: 1px solid var(--border); }
.timeline li:first-child { border-top: 0; }
.timeline .when { min-width: 92px; font-size: .82rem; color: var(--text-muted); }
.timeline .what { flex: 1; min-width: 0; }
.timeline .what > strong { display: block; }
.timeline .cost { font-weight: 650; white-space: nowrap; }
/* Row-level links sit on their own line: inline after a <strong> they read as one
   word ("RideEdit"), and a phone needs something big enough to hit. */
.row-actions { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.row-actions a { font-size: .82rem; font-weight: 600; text-decoration: none; }
.row-actions a:hover { text-decoration: underline; }
.doc-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.doc-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px 5px 5px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  font-size: .78rem; color: var(--text); text-decoration: none;
}
.doc-chip img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.doc-chip .ficon { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); }
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 26px; text-align: center; color: var(--text-muted); background: var(--surface-2); cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.upload-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-top: 14px; }
.upload-item { position: relative; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.upload-item .thumb { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; font-size: 1.6rem; }
.upload-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.upload-item .meta { padding: 7px 9px; font-size: .74rem; color: var(--text-muted); word-break: break-all; }
.upload-item .rm {
  position: absolute; top: 6px; right: 6px; border: 0; border-radius: 50%; width: 24px; height: 24px;
  background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; font-size: .9rem; line-height: 1;
}
/* A file the server refused. It stays in the picker with its reason so the owner
   can remove it or try again (07 §5). */
.upload-item.invalid { border-color: var(--danger); }
.upload-item.invalid .meta { color: var(--text); }
.upload-item .err { padding: 0 9px 8px; font-size: .74rem; color: var(--danger); }

/* ---------- process panel ---------- */
.dot-live {
  width: 7px; height: 7px; border-radius: 50%; background: var(--system);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--system) 22%, transparent);
}

.process-panel[hidden] { display: none; }
.process-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(660px, 100%);
  display: flex; flex-direction: column; z-index: 30;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -18px 0 48px rgba(16, 24, 40, .16);
}
.pp-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.pp-head h2 { margin: 0; }
.pp-head .btn { margin-left: auto; }
.pp-tabs { display: flex; gap: 6px; padding: 12px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pp-tabs button {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-muted); font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
}
.pp-tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.pp-diagram { flex: 1; overflow: auto; padding: 16px 18px; min-height: 220px; }
.pp-diagram svg { width: 100%; height: auto; display: block; }
@media (min-width: 1240px) {
  body.panel-open .app { margin-right: min(660px, 52vw); }
}
.pp-log { border-top: 1px solid var(--border); padding: 12px 18px 16px; max-height: 34%; overflow: auto; background: var(--surface-2); }
.log-list { list-style: none; margin: 0; padding: 0; font-size: .8rem; }
.log-list li { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.log-list .t { color: var(--text-muted); font-family: ui-monospace, Menlo, monospace; font-size: .72rem; }
.log-list .lane { font-weight: 650; }
.log-list .lane.system { color: var(--system); }
.log-list .lane.smtp { color: var(--external); }
.log-list .empty-note { color: var(--text-muted); }

/* BPMN svg */
.bpmn-lane { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.5; }
.bpmn-lane-head { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 1.5; }
.bpmn-lane-label { fill: var(--text-muted); font: 600 12px sans-serif; }
.bpmn-task { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 1.5; }
.bpmn-task-label { fill: var(--text); font: 500 11px sans-serif; }
.bpmn-event { fill: var(--surface); stroke: var(--text-muted); stroke-width: 2; }
.bpmn-event.end { stroke-width: 4; }
.bpmn-edge { fill: none; stroke: var(--border-strong); stroke-width: 1.5; }
.bpmn-node.visited .bpmn-task { fill: color-mix(in srgb, var(--ok) 14%, transparent); stroke: var(--ok); }
.bpmn-node.visited .bpmn-event { stroke: var(--ok); }
.bpmn-node.current .bpmn-task { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.5; }
.bpmn-node.current .bpmn-task-label { fill: var(--accent); font-weight: 700; }
.bpmn-node.current .bpmn-event { stroke: var(--accent); stroke-width: 3; }

/* ---------- misc ---------- */
.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  padding: 10px 16px; border-radius: 999px; background: var(--text); color: var(--surface);
  font-size: .86rem; font-weight: 550; box-shadow: var(--shadow); max-width: 92vw;
}
.toast.err { background: var(--danger); color: #fff; }
.mail {
  border: 1px solid var(--border); border-left: 4px solid var(--external);
  border-radius: var(--radius-sm); padding: 14px 16px; background: var(--surface-2);
}
.note {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--text); font-size: .86rem; border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.note .ico { flex: none; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
th { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- installed ----------
   Launched from the home screen there is no browser chrome around the page, so it
   should stop behaving like one: no pull-to-refresh bounce dragging the top bar
   down, and no grey flash on every tap. */
@media (display-mode: standalone) {
  html, body { overscroll-behavior-y: none; }
  body { -webkit-tap-highlight-color: transparent; }
}

/* ---------- phone ----------
   This is the primary device: a bike is serviced in a garage with a phone in a
   pocket. Everything below is about that, not about a narrow desktop window. */
@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    padding: 10px 16px;
    /* The bar is sticky, so it owns the notch rather than sliding under it. */
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }
  .topnav { order: 3; width: 100%; margin-left: 0; }
  .topnav a { padding: 9px 12px; }

  .view {
    padding: 18px 16px 56px;
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  /* iOS Safari zooms the whole page when a focused control is under 16px, which
     leaves the form half off-screen. 16px is the fix; nothing else here matters
     if every tap on an input jerks the page sideways. */
  input, select, textarea { font-size: 16px; padding: 11px 12px; }

  /* 44px is the smallest thing a thumb hits reliably. */
  .btn { min-height: 44px; padding: 11px 16px; }
  .btn-icon { min-height: 40px; }

  /* Actions stack and fill the width instead of wrapping into orphans. */
  .page-head { gap: 12px; margin-bottom: 16px; }
  .page-head .spacer { display: none; }
  .page-head > .btn-row, .page-head > .btn, .page-head > a.btn { width: 100%; }
  .btn-row > .btn { flex: 1 1 auto; }
  form .btn-row > .btn { flex-basis: 100%; }

  h1 { font-size: 1.35rem; }
  .card { padding: 16px; border-radius: 10px; }
  .card + .card { margin-top: 12px; }

  /* A three-column row at 320px gives every column about 90px. Stack it: the date
     becomes a heading and the hours sit under it, which is how a list reads. */
  .timeline li { flex-wrap: wrap; gap: 4px 12px; padding: 16px 0; }
  .timeline .when { min-width: 0; flex: 1 1 auto; order: 1; }
  .timeline .cost { order: 2; }
  .timeline .what { order: 3; flex: 1 1 100%; }
  .row-actions a { padding: 6px 0; }

  /* max-content labels push the values off the right edge on a narrow screen. */
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .check-other { grid-template-columns: 1fr auto; }
  .check-other input { grid-column: 1 / -1; }
  .kv dd { margin-bottom: 10px; }
  .kv dd:last-child { margin-bottom: 0; }

  /* One card per row reads better than two cramped ones. */
  .vehicle-grid { grid-template-columns: 1fr; }
  .upload-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .upload-item .rm { width: 32px; height: 32px; font-size: 1.1rem; }
  .dropzone { padding: 20px 14px; }

  /* The wizard steps are a progress indicator, not navigation — shrink, don't wrap
     into three tall rows. */
  .steps { gap: 4px; margin-bottom: 16px; }
  .steps li { font-size: .74rem; padding: 5px 8px; }

  .process-panel {
    box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .pp-log { max-height: 30%; }

  .toasts { bottom: calc(22px + env(safe-area-inset-bottom, 0px)); width: max-content; }
}

/* Very narrow — small phones, and a phone in a split view. */
@media (max-width: 380px) {
  .view { padding-left: 12px; padding-right: 12px; }
  .card { padding: 14px; }
  .btn { padding: 11px 12px; font-size: .86rem; }
  .grid-2 { grid-template-columns: 1fr; }
}
