/* ==========================================================================
   Design tokens — shared with the customer app (apps/customer-app).
   The counter uses the same palette and scale with denser controls.
   ========================================================================== */
:root {
  color-scheme: light;

  --bg: #f1f4f2;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --surface-3: #eaf0ec;
  --ink: #13201a;
  --ink-2: #4a5852;
  --ink-3: #6a7770;
  --line: #e1e7e3;
  --line-strong: #c6d1cb;

  --brand: #0b6b47;
  --brand-strong: #07573a;
  --brand-deep: #053d29;
  --brand-soft: #e2f3e9;
  --brand-ink: #064a31;

  --warn: #8a4b00;
  --warn-soft: #fff1d6;
  --warn-line: #f3cf8c;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --danger-line: #f4b8b1;
  --ok: #0b6b47;
  --ok-soft: #e2f3e9;

  --plate: #111614;
  --plate-ink: #ffffff;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --shadow-1: 0 1px 2px rgb(16 32 24 / 5%), 0 1px 3px rgb(16 32 24 / 6%);
  --shadow-2: 0 6px 20px rgb(16 32 24 / 9%);
  --shadow-3: 0 18px 48px rgb(16 32 24 / 20%);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 24px;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --tap: 44px;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0 0 var(--space-2); color: var(--ink); font-weight: 650; letter-spacing: -0.01em; line-height: 1.3; }
h1 { font-size: var(--text-xl); letter-spacing: -0.015em; }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-md); }
h4 { font-size: var(--text-md); }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
#sheet-title:focus { outline: none; }
#sheet-title:focus-visible { outline: 3px solid var(--brand); outline-offset: 4px; }

.lede, .hint, .quiet, .empty, .disclaimer { margin: 4px 0 0; color: var(--ink-2); font-size: var(--text-sm); line-height: 1.45; }
.empty {
  margin: 0;
  padding: var(--space-4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: center;
}

/* ==========================================================================
   Controls
   ========================================================================== */
button, input, select, textarea { font: inherit; color: inherit; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 var(--space-3);
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
}

input, select {
  width: 100%;
  min-height: var(--tap);
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  font-weight: 400;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder { color: var(--ink-3); }
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgb(11 107 71 / 18%); }
input[readonly] { background: var(--surface-2); color: var(--ink-2); }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: auto;
  min-height: var(--tap);
  margin: 0;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font-weight: 650;
  line-height: 1.25;
  cursor: pointer;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), transform .12s var(--ease);
}
button:hover:not(:disabled) { background: var(--brand-strong); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }

button.secondary {
  background: var(--surface);
  color: var(--brand-ink);
  border-color: var(--line-strong);
}
button.secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--ink-3); }

button.text-action {
  min-height: 32px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--brand-ink);
  font-size: var(--text-sm);
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
}
button.text-action:hover:not(:disabled) { background: transparent; color: var(--brand); }

details > summary { cursor: pointer; }

/* ==========================================================================
   Pills, plates, counts
   ========================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}
.pill::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-neutral { background: var(--surface-3); color: var(--ink-2); }

.plate {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--radius-xs);
  background: var(--plate);
  color: var(--plate-ink);
  font-size: 13px;
  font-weight: 750;
  letter-spacing: .08em;
  line-height: 1.5;
  text-transform: uppercase;
  white-space: nowrap;
}

.count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 700;
  vertical-align: 2px;
  letter-spacing: 0;
}
.count-badge:empty { display: none; }
.due-group[data-tone="warn"] .count-badge { background: var(--warn-soft); color: var(--warn); }
.due-group[data-tone="danger"] .count-badge { background: var(--danger-soft); color: var(--danger); }

.amount { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-muted { color: var(--ink-2); font-weight: 600; }

/* ==========================================================================
   Chrome: environment strip, app bar, status
   ========================================================================== */
.env-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 12px;
  padding: 4px 16px;
  background: var(--brand-deep);
  color: rgb(255 255 255 / 86%);
  font-size: 11px;
  line-height: 1.4;
}
.milestone, .env-note { margin: 0; }
.env-note { color: #fff; font-weight: 600; }
.stamp { display: none; }

.appbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.appbar-inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 1320px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
}
.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--brand), var(--brand-deep));
  color: #fff;
}
.brand-mark svg { width: 24px; height: 24px; }
.appbar-titles { min-width: 0; }
.kicker { margin: 0; color: var(--brand); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.appbar h1 { margin: 0; overflow: hidden; font-size: var(--text-lg); text-overflow: ellipsis; white-space: nowrap; }
.appbar .lede { flex: 1 1 auto; margin: 0 0 0 var(--space-3); padding-left: var(--space-3); border-left: 1px solid var(--line); }
.counter-signed-in .appbar .lede { display: none; }
.counter-signed-in .appbar-titles { flex: 1 1 auto; }

.staff-account { position: relative; flex-shrink: 0; margin-left: auto; }
.staff-account > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 8px 14px 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--text-sm);
  font-weight: 650;
  list-style: none;
}
.staff-account > summary::-webkit-details-marker { display: none; }
.staff-account > summary svg { width: 20px; height: 20px; color: var(--brand); }
.staff-account > summary:hover { background: var(--surface-2); }
.staff-account-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  min-width: 220px;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  animation: fade .14s var(--ease) both;
}
.staff-account-panel p { margin: 0 0 var(--space-3); color: var(--ink-2); font-size: var(--text-sm); }
.staff-account-panel button { width: 100%; }

.status { margin: 8px 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--brand-ink); font-size: var(--text-sm); font-weight: 600; }
.status:empty { display: none; }
#status:not(:empty) {
  position: fixed;
  z-index: 45;
  bottom: 20px;
  left: 50%;
  width: max-content;
  max-width: min(640px, calc(100vw - 32px));
  margin: 0;
  padding: 12px 18px 12px 16px;
  border: 0;
  border-left: 4px solid #4ade80;
  border-radius: var(--radius-sm);
  background: #13201a;
  color: #fff;
  box-shadow: var(--shadow-3);
  transform: translateX(-50%);
  animation: toast .22s var(--ease) both;
}
#status[data-tone="error"]:not(:empty) { border-left-color: #f87171; }
#sheet-status[data-tone="error"], #record-result[data-tone="error"] { background: var(--danger-soft); color: var(--danger); }
body.sheet-open #status { display: none; }

/* ==========================================================================
   Page layout and navigation
   ========================================================================== */
.sheet { max-width: 1320px; margin: 0 auto; padding: var(--space-6) var(--space-6) 96px; }

.panel {
  margin: 0 0 var(--space-4);
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}
.panel > .hint { max-width: 72ch; margin-bottom: var(--space-5); }
.panel > h2 + .hint { margin-top: -2px; }

.section-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-4); }
.section-head h2, .section-head h3 { margin: 0; }
.section-head .hint { margin-top: 4px; }

.signin {
  max-width: 420px;
  margin: var(--space-8) auto;
  padding: var(--space-8);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}
.signin h2 { margin-bottom: 0; font-size: var(--text-2xl); }
.signin > .hint:first-of-type { margin: 4px 0 var(--space-5); }
.signin-note { margin: -4px 0 var(--space-4); padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.signin button[type="submit"] { width: 100%; margin-top: var(--space-2); min-height: 48px; }

.counter-tools { display: none; margin: 0 0 var(--space-4); }
.nav-jump { margin: 0; }
.nav-jump select { min-height: 48px; font-weight: 650; }

.counter-tabs { display: flex; gap: 4px; }
.counter-tabs button {
  justify-content: flex-start;
  gap: 10px;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-2);
  font-weight: 600;
  white-space: nowrap;
}
.counter-tabs svg { flex: none; width: 20px; height: 20px; }
.counter-tabs button:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.counter-tabs button[aria-selected="true"] { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; }
.counter-tabs button[aria-selected="true"] svg { color: var(--brand); }

.counter-main { min-width: 0; }

@media (min-width: 1100px) {
  #counter:not([hidden]) {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: var(--space-6);
    align-items: start;
  }
  .counter-tabs {
    position: sticky;
    top: var(--space-4);
    flex-direction: column;
    padding: var(--space-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-1);
  }
}
@media (min-width: 800px) and (max-width: 1099px) {
  .counter-tabs {
    margin: 0 0 var(--space-5);
    padding: 4px;
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    scrollbar-width: thin;
  }
  .counter-tabs button { flex: none; }
}
@media (max-width: 799px) {
  .counter-tabs { display: none; }
  .counter-tools { display: block; }
}

/* ==========================================================================
   Overview
   ========================================================================== */
.find { padding: var(--space-5) var(--space-6); }
.find h2 { font-size: var(--text-lg); }
.find-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); align-items: end; }
.find-row label { margin: 0; }
.find-row button { min-width: 96px; }
.find input { min-height: 52px; font-size: 17px; }
.find .find-row button { min-height: 52px; }
.results { display: flex; flex-direction: column; gap: var(--space-2); }
.results:not(:empty) { margin-top: var(--space-3); }

.sync-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.sync-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
#sync-status, #sync-import { margin: 0; }
#sync-status { flex: 1 1 240px; }
.sync-toolbar #sync-import { flex-basis: 100%; order: 3; }
.sync-toolbar #sync-now { margin-left: auto; background: var(--surface); color: var(--brand-ink); border-color: var(--line-strong); }
.sync-toolbar #sync-now:hover:not(:disabled) { background: var(--surface-2); }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); gap: var(--space-4); align-items: start; }
.overview-main, .overview-side { display: grid; gap: var(--space-4); min-width: 0; }
.overview-grid .panel { margin: 0; }
.overview-side h2, .overview-main h2 { font-size: var(--text-lg); }

#due-panel .section-head { margin-bottom: var(--space-2); }
.reminder-result { margin: 0 0 var(--space-3); }
.reminder-result:empty { display: none; }
.due-group { margin-top: var(--space-4); }
.due-group h3 { display: flex; align-items: center; margin-bottom: var(--space-2); color: var(--ink-2); font-size: var(--text-sm); font-weight: 700; letter-spacing: .02em; }

.callout { border-left: 4px solid #e3a008; }
.callout h2 { margin-bottom: 4px; }
#overview-link-count { margin: 0 0 var(--space-3); color: var(--ink); font-weight: 600; }

.row-list, .results, #recent-list, #quotation-list, #unassigned-list, #overview-estimates, #promotion-list { display: flex; flex-direction: column; gap: var(--space-2); }

.choice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px var(--space-3);
  width: 100%;
  min-height: 56px;
  margin: 0;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-weight: 400;
  text-align: left;
}
button.choice { cursor: pointer; }
button.choice:hover:not(:disabled) { background: var(--surface-2); border-color: var(--brand); }
.choice[aria-current="true"], #catalogue-list button[aria-current="true"] { border-color: var(--brand); background: #f3faf6; color: var(--ink); }
.row-main { display: grid; gap: 2px; flex: 1 1 220px; min-width: 0; }
.row-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-weight: 650; overflow-wrap: anywhere; }
.row-meta { color: var(--ink-2); font-size: var(--text-sm); overflow-wrap: anywhere; }
.row-side { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: none; max-width: 100%; margin-left: auto; }
.row-side .pill { white-space: normal; }
.due-row { background: var(--surface-2); }

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--line); }
.pager p { min-width: 5rem; margin: 0; color: var(--ink-2); font-size: var(--text-sm); }
.pager:not(:has(button:not([hidden]))) { border-top: 0; padding-top: 0; }

#assign-panel { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--line); }
#assign-facts, .link-state, .next-read { margin: 4px 0 var(--space-2); }
/* Estimate and overview assignment stay in the shared dialog. */
#estimate-detail:not(#record-dialog #estimate-detail),
#assign-panel:not(#record-dialog #assign-panel) { display: none !important; }

/* ==========================================================================
   Lists, records, filters
   ========================================================================== */
.filter-row { grid-template-columns: minmax(0, 1fr) 200px; max-width: 760px; margin-bottom: var(--space-4); }
.filter-single { max-width: 420px; margin: 0 0 var(--space-4); }
#recent-filter, #estimate-filter { max-width: 100%; }

.visit {
  margin: 0 0 var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.visit h3 { margin: 0 0 4px; font-size: var(--text-md); }
.visit p, .visit li { margin: 2px 0; }
.visit ul { margin: 6px 0 0; padding-left: 18px; }
.visit > button { margin-top: var(--space-2); }
.visit > .pill { margin: 2px 0 4px; }
.visit details > summary { padding: 4px 0; color: var(--brand-ink); font-size: var(--text-sm); font-weight: 600; }

#promotion-list > h3 { margin: var(--space-4) 0 0; color: var(--ink-2); font-size: var(--text-xs); letter-spacing: .06em; text-transform: uppercase; }
#promotion-list > h3:first-child { margin-top: 0; }
#promotion-list .visit { margin: 0; }

.catalogue article { margin: 0 0 var(--space-2); }
.catalogue article h3 { margin: 0 0 4px; }
.catalogue .section-head button { margin: 0; }

.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); margin: 0 0 var(--space-4); }
.totals div { padding: var(--space-3) var(--space-4); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.totals p { margin: 0; color: var(--ink-2); font-size: var(--text-sm); font-weight: 600; }
.totals strong { display: block; margin-top: 2px; font-size: var(--text-lg); font-variant-numeric: tabular-nums; }
.loyalty-summary { width: fit-content; margin: 0 0 var(--space-5); padding: 8px 12px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--brand-ink); font-size: var(--text-sm); font-weight: 650; }
.loyalty-summary:empty { display: none; }

.filter-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) 180px auto; gap: var(--space-3); align-items: end; margin: var(--space-5) 0; }
.filter-toolbar label { margin: 0; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--space-3); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-4); }

.settings-form { display: grid; gap: var(--space-2); max-width: 660px; }
.settings-form > button { justify-self: start; }
.settings-group { min-width: 0; margin: 0 0 var(--space-3); padding: var(--space-3) var(--space-4) var(--space-1); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.settings-group legend { padding: 0 6px; color: var(--brand-ink); font-size: var(--text-sm); font-weight: 700; }
.settings-editor { margin-top: var(--space-6); padding-top: var(--space-5); border-top: 1px solid var(--line); }
.settings-editor > summary { padding: 8px 0; color: var(--brand-ink); font-weight: 650; }
.settings-editor[open] > .hint { max-width: 72ch; margin: 8px 0 var(--space-4); }

#promotion-form { max-width: 660px; margin: 0 0 var(--space-5); padding: var(--space-5); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-2); animation: fade .18s var(--ease) both; }
#promotion-form > h3 { margin-bottom: var(--space-3); }
#promotion-form .find-row { margin-bottom: var(--space-3); }

/* ==========================================================================
   Customer workspace (docket)
   ========================================================================== */
#docket.workspace { display: grid; gap: var(--space-5); padding: var(--space-5); }
.workspace-bar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: calc(var(--space-5) * -1) calc(var(--space-5) * -1) 0;
  padding: var(--space-2) var(--space-5);
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.workspace-bar .back-link {
  gap: 4px;
  padding: 8px 10px 8px 4px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
}
.workspace-bar .back-link:hover:not(:disabled) { color: var(--brand-ink); background: var(--brand-soft); }
.back-link svg, .add-action svg { flex-shrink: 0; width: 18px; height: 18px; }
.working-plate { margin: 0; color: var(--warn); font-size: var(--text-sm); font-weight: 650; }
.working-plate:empty { display: none; }

#rider-summary-view > .rider-head, #rider-summary-view > section { margin-bottom: var(--space-6); }
.rider-head { display: grid; gap: 4px; }
.workspace #who { margin: 0; font-size: 28px; letter-spacing: -0.025em; }
.rider-head .hint, .rider-head .link-state { margin: 0; }
.rider-summary {
  width: fit-content;
  margin: 4px 0 0;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-size: var(--text-sm);
  font-weight: 650;
}
.rider-summary:empty { display: none; }

.workspace-bike .add-action { font-size: var(--text-sm); }
.bike-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: var(--space-4); align-items: stretch; }
.rider-bike {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.rider-bike:hover { border-color: var(--line-strong); box-shadow: var(--shadow-2); }
.rider-bike h4 {
  width: fit-content;
  margin: 0 0 6px;
  padding: 2px 10px;
  border-radius: var(--radius-xs);
  background: var(--plate);
  color: var(--plate-ink);
  font-size: 17px;
  font-weight: 750;
  letter-spacing: .08em;
}
.rider-bike .bike-account { margin: 0; font-weight: 600; }
.rider-bike > .hint { margin: 2px 0 0; }
.bike-facts { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin: 0; padding: 6px 0; border-top: 1px solid var(--line); color: var(--ink-2); font-size: var(--text-sm); }
.rider-bike .bike-facts:first-of-type { margin-top: var(--space-3); }
.bike-facts strong { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.service-reading-date, .next-service-date { margin: 0 0 4px !important; }
.mileage-details { margin-top: 6px; font-size: var(--text-sm); }
.mileage-details > summary { color: var(--ink-2); padding: 4px 0; }
.usage-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin: var(--space-2) 0 0; color: var(--ink-2); font-size: var(--text-sm); }
.usage-line button { min-height: 32px; padding: 2px 0; border: 0; background: transparent; color: var(--brand-ink); font-size: var(--text-sm); }
.bike-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: auto; padding-top: var(--space-4); }
.bike-actions button:not(.secondary) { flex: 1 1 auto; }

#bike-form { margin-top: var(--space-4); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-2); animation: fade .18s var(--ease) both; }
#bike-form h4 { margin: 0 0 var(--space-3); }
#bike-form .bike-actions { margin-top: var(--space-2); padding-top: 0; }

.workspace-history h3 { margin-bottom: var(--space-3); }
.compact-fold { margin: 0; }
.compact-fold > summary { padding: 8px 0; color: var(--brand-ink); font-weight: 650; }
#summary-estimates, #summary-vouchers { padding-top: var(--space-2); border-top: 1px solid var(--line); }
.earlier-services { margin-top: var(--space-2); }
.earlier-services > summary { padding: 6px 0; color: var(--brand-ink); font-weight: 600; }
.visit-summary { margin: 0; color: var(--ink-2); }
.new-visit {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11px;
  font-weight: 700;
}
.next-editor > summary, .service-assignment-details > summary { padding: 6px 0; color: var(--brand-ink); font-size: var(--text-sm); font-weight: 600; }
.next-editor form { padding-top: 10px; }
.service-assignment-details { margin-top: var(--space-2); }
.service-assignment-details + .hint:empty { display: none; }
.service-assignment { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-2); margin-top: var(--space-3); }
.service-assignment label { flex: 1 1 180px; margin: 0; }
.service-assignment .hint { flex-basis: 100%; }

.leave-panel {
  position: fixed;
  z-index: 60;
  top: 16px;
  left: 50%;
  display: grid;
  gap: var(--space-3);
  width: min(460px, calc(100% - 24px));
  padding: var(--space-4);
  border: 1px solid var(--warn-line);
  border-left: 4px solid #e3a008;
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform: translateX(-50%);
}
.leave-panel p { margin: 0; font-weight: 600; }
.leave-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ==========================================================================
   Service sheet
   ========================================================================== */
body.sheet-open { overflow: hidden; }
#service-backdrop { position: fixed; inset: 0; z-index: 25; background: rgb(10 20 15 / 50%); animation: fade .18s var(--ease) both; }
.service-sheet {
  position: fixed;
  z-index: 26;
  display: block;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  color: var(--ink);
}
.service-sheet-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.service-sheet-bar h2 {
  width: fit-content;
  margin: 2px 0 0;
  padding: 2px 12px;
  border-radius: var(--radius-xs);
  background: var(--plate);
  color: var(--plate-ink);
  font-size: 20px;
  font-weight: 750;
  letter-spacing: .08em;
}
.service-sheet-bar .hint { margin: 0; }
#sheet-status { flex-basis: 100%; margin: 0; }
#sheet-status:empty { display: none; }
.service-sheet-body { padding: var(--space-5); }
.service-sheet-body > section { min-width: 0; }
.service-sheet-body > section > h3, .sheet-pos .section-head h3 { font-size: var(--text-lg); }
.sheet-next, .sheet-pos, .sheet-checkout { padding: var(--space-5); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.sheet-checkout { background: var(--surface-2); }

.service-summary { display: grid; gap: 6px; margin: 0 0 var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); background: var(--brand-soft); }
.service-summary p { display: flex; flex-wrap: wrap; gap: 4px var(--space-3); margin: 0; }
.service-summary span { min-width: 9rem; color: var(--brand-ink); font-size: var(--text-sm); font-weight: 600; }
.service-summary strong { font-variant-numeric: tabular-nums; }
.summary-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0 0 var(--space-3); }
.follow-up-offer { margin: 4px 0 var(--space-3); color: var(--brand-ink); }
.service-mode, .service-group { min-width: 0; margin: 0 0 var(--space-3); padding: var(--space-2) var(--space-4) var(--space-1); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.service-mode { display: flex; flex-wrap: wrap; gap: 4px var(--space-4); }
.service-mode legend, .service-group legend { padding: 0 6px; color: var(--brand-ink); font-size: var(--text-sm); font-weight: 700; }
.service-choice { flex-direction: row; align-items: center; gap: 8px; width: auto; margin: 0; color: var(--ink); font-size: var(--text-md); font-weight: 600; }
.service-choice input { width: 20px; min-height: var(--tap); accent-color: var(--brand); }
.next-vehicle { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.service-sheet input, .service-sheet select, .service-sheet button, .service-sheet summary,
.sheet-pos, .sheet-next, .sheet-checkout { scroll-margin-top: 220px; }

#pos-search { margin: var(--space-3) 0; padding: var(--space-4); border-radius: var(--radius-sm); background: var(--surface-2); }
#pos-search .find-row { margin-bottom: var(--space-2); }
#pos-results { display: grid; gap: 6px; }
#pos-preview { margin-top: var(--space-3); padding: var(--space-3); border: 1px solid var(--brand); border-radius: var(--radius-sm); background: #f3faf6; }
#pos-preview p { margin: 0 0 4px; }
.link-state:not(:empty) { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: var(--text-sm); font-weight: 600; }

.invoice-list { display: grid; gap: 6px; }
.invoice-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 2px;
  padding: 0 10px 0 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.invoice-row.assigned-invoice { grid-template-columns: minmax(0, 1fr); padding-left: 12px; }
.invoice-row > details { min-width: 0; }
.invoice-row summary { display: flex; align-items: baseline; gap: 8px; min-width: 0; padding: 8px 0; }
.invoice-row summary::-webkit-details-marker { display: none; }
.invoice-row summary::marker { content: ""; }
.invoice-row summary::before { content: "▸"; flex: 0 0 auto; color: var(--brand-ink); font-size: 12px; transition: transform .15s var(--ease); }
.invoice-row details[open] > summary::before { content: "▾"; }
.invoice-doc { flex: 0 0 auto; font-weight: 650; }
.invoice-state { flex: 0 0 auto; color: var(--ink-2); font-size: var(--text-sm); }
.invoice-state[data-assigned="true"] { color: var(--ink); }
.invoice-meta { min-width: 0; overflow: hidden; color: var(--ink-2); font-size: var(--text-sm); text-overflow: ellipsis; white-space: nowrap; }
.invoice-body { padding: 0 0 8px 18px; }
.assigned-invoices { margin-top: var(--space-4); }
.assigned-invoices h4 { margin: 0 0 6px; color: var(--ink-2); font-size: var(--text-sm); font-weight: 700; }
.attention-check { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.attention-check input { width: 18px; min-height: var(--tap); accent-color: var(--brand); }
.attention-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
#assign-selected { margin: 0 0 0 auto; }
#assign-selected:disabled, .attention-actions button:disabled, .bulk-assignment button:disabled { opacity: .45; }
.assignment-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding: var(--space-3) 0; }
#assignment-count { color: var(--brand-ink); font-size: var(--text-sm); font-weight: 700; }
.assignment-confirmation { margin-bottom: var(--space-3); padding: var(--space-4); border: 1px solid var(--warn-line); border-radius: var(--radius-sm); background: var(--warn-soft); }
.assignment-confirmation p { margin: 0 0 var(--space-3); }
.assignment-confirmation button + button { margin-left: 8px; }
.bulk-assignment { display: grid; gap: var(--space-2); margin: 0 0 var(--space-4); padding: var(--space-3); border: 1px solid var(--warn-line); border-radius: var(--radius-sm); background: var(--warn-soft); }
.bulk-assignment p { margin: 0; }
.bulk-assignment button { justify-self: start; }

@media (min-width: 800px) {
  .service-sheet { inset: 28px; border-radius: var(--radius-lg); box-shadow: var(--shadow-3); animation: fade .18s var(--ease) both; }
  .service-sheet-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .8fr); gap: var(--space-5); align-items: start; }
  .sheet-checkout { grid-column: 1 / -1; }
}
@media (max-width: 799px) {
  .service-sheet { inset: 0; }
  .service-sheet-body { display: grid; gap: var(--space-4); padding: var(--space-4); }
  .sheet-next, .sheet-pos, .sheet-checkout { padding: var(--space-4); }
}

/* ==========================================================================
   Catalogue editor
   ========================================================================== */
#catalogue-search-form { display: grid; grid-template-columns: minmax(0, 1fr) 200px auto; gap: var(--space-3); align-items: end; margin-top: var(--space-3); }
#catalogue-search-form label { margin: 0; }
#catalogue-list { display: grid; gap: 0; margin-top: var(--space-4); border-top: 1px solid var(--line); }
.catalogue-editor {
  display: grid;
  grid-template-columns: 80px minmax(130px, 1fr) minmax(200px, 1.6fr) 140px;
  align-items: start;
  gap: 8px 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.catalogue-editor-heading { grid-column: 2; grid-row: 1; }
.catalogue-editor-heading h3 { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.catalogue-editor-heading .hint { margin: 2px 0 0; font-variant-numeric: tabular-nums; }
.visibility-state { display: inline-flex; align-items: center; gap: 5px; margin: 6px 0 0; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--surface-3); color: var(--ink-2); font-size: 11px; font-weight: 700; }
.visibility-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.visibility-state[data-visible="true"] { background: var(--brand-soft); color: var(--brand-ink); }
.catalogue-photo-controls { grid-column: 1; grid-row: 1; min-width: 0; }
.catalogue-copy-controls { grid-column: 3; grid-row: 1; min-width: 0; }
.catalogue-thumbnail { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 4px; overflow: hidden; border-radius: var(--radius-sm); background: var(--surface-3); color: var(--ink-3); font-size: 10px; text-align: center; }
.catalogue-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.image-upload { position: relative; display: inline-flex; flex-direction: row; align-items: center; min-height: 28px; margin: 0; color: var(--brand-ink); font-size: 12px; font-weight: 650; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.image-upload:focus-within { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.catalogue-editor input[type="file"] { position: absolute; inset: 0; width: 100%; min-height: 0; padding: 0; opacity: 0; cursor: pointer; }
.catalogue-editor textarea { width: 100%; height: 58px; min-height: 58px; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); color: var(--ink); font-size: 13px; line-height: 1.5; resize: vertical; }
.catalogue-editor label { margin-bottom: 2px; font-size: 12px; }
.catalogue-editor button.text-action { display: block; min-height: 28px; margin: 0; font-size: 12px; text-align: left; }
.catalogue-photo-controls details { margin-top: 2px; font-size: 11px; overflow-wrap: anywhere; }
.catalogue-photo-controls summary { padding: 4px 0; color: var(--ink-2); white-space: nowrap; }
.catalogue-photo-controls details[open] { position: relative; z-index: 1; width: 200px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow-2); }
.catalogue-photo-controls details label { margin-top: 8px; }
.row-actions { grid-column: 4; grid-row: 1; display: flex; flex-direction: column; gap: 6px; padding-top: 20px; }
.catalogue-editor .row-actions button { width: 100%; min-height: 36px; margin: 0; padding: 6px 8px; font-size: 12px; }
.row-result { grid-column: 2 / -1; margin: 0; color: var(--brand-ink); font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.row-result:empty { display: none; }
.image-preview { min-height: 96px; margin: 0 0 8px; }
.image-preview img { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; background: var(--brand-soft); }

/* ==========================================================================
   Record dialog
   ========================================================================== */
#record-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: var(--shadow-3);
  overscroll-behavior: contain;
}
#record-dialog[open] { animation: fade .18s var(--ease) both; }
#record-dialog::backdrop { background: rgb(10 20 15 / 50%); }
.record-dialog-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.record-dialog-header h2 { margin: 0; font-size: var(--text-lg); overflow-wrap: anywhere; }
.record-dialog-header .status { flex-basis: 100%; margin: 0; }
#record-dialog-body { padding: var(--space-5); }
#record-dialog-body > section { margin: 0; }
#record-dialog-body h3 { font-size: var(--text-lg); }
#estimate-body p { margin: 0 0 6px; }
#estimate-open { margin-top: var(--space-3); }
.record-loading { padding: var(--space-5); color: var(--ink-2); }

/* ==========================================================================
   Motion
   ========================================================================== */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes toast { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (min-width: 800px) {
  #view-settings:not([hidden]) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); align-items: start; }
  #view-settings .panel { margin: 0; }
}

@media (max-width: 1099px) {
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 800px) {
  .catalogue-editor { grid-template-columns: 64px minmax(0, 1fr); gap: 8px 12px; }
  .catalogue-editor-heading { grid-column: 2; grid-row: 1; }
  .catalogue-photo-controls { grid-column: 1; grid-row: 1 / 3; }
  .catalogue-copy-controls { grid-column: 2; grid-row: 2; }
  .row-actions { grid-column: 2; grid-row: 3; flex-direction: row; flex-wrap: wrap; padding-top: 0; }
  .catalogue-editor .row-actions button { width: auto; }
}

@media (max-width: 799px) {
  .appbar-inner { padding: var(--space-3) var(--space-4); }
  .appbar .lede { display: none; }
  .sheet { padding: var(--space-4) var(--space-3) 96px; }
  .panel { padding: var(--space-4); }
  .find { padding: var(--space-4); }
  .signin { margin: var(--space-4) auto; padding: var(--space-6) var(--space-5); }
  .filter-row, .filter-toolbar { grid-template-columns: minmax(0, 1fr) auto; }
  .filter-toolbar > label:first-child { grid-column: 1 / -1; }
  .totals { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .totals div { padding: 10px; }
  .totals strong { font-size: var(--text-md); overflow-wrap: anywhere; }
  .assignment-toolbar #assign-selected { width: 100%; margin-left: 0; }
  .settings-form > button, #sync-now { width: 100%; }
  .sync-toolbar #sync-now { margin-left: 0; }
  #docket.workspace { padding: var(--space-4); }
  .workspace-bar { margin: calc(var(--space-4) * -1) calc(var(--space-4) * -1) 0; padding: var(--space-2) var(--space-4); }
  .workspace #who { font-size: var(--text-2xl); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  #due-panel .section-head > button { width: 100%; }
}

@media (max-width: 600px) {
  #catalogue-search-form { grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); }
  #catalogue-search-form > label:first-child { grid-column: 1 / -1; }
  #record-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .staff-account > summary span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .staff-account > summary { padding: 8px 10px; }
}
