/*
 * GrossAuto — admin styles.
 *
 * Plain CSS with custom properties, per spec section 2: no framework and no
 * build step, so a stylesheet edit is visible on refresh and there is nothing
 * to keep in sync with a bundler.
 *
 * Light by default, and only light: this runs on shop-floor screens under
 * fluorescent light, where a dark UI loses contrast rather than gaining it.
 * The dark palette is kept below behind [data-theme="dark"] so it can be
 * switched back on deliberately, but nothing opts into it automatically.
 *
 * Two accents, and they mean different things. Ink (--c-primary) is the
 * neutral "act on this" colour and carries every primary button; brand red
 * (--c-brand) is the logo colour and marks position and navigation — the
 * current rail item, the active tab, links. Reds that mean trouble stay in
 * --c-danger, which is deliberately darker and duller than the brand red so
 * an error never reads as a link.
 */

:root {
  color-scheme: light;

  /* Neutrals — cool greys, tuned to sit under the graphite-and-silver logo. */
  --c-bg: #f4f6fa;
  --c-surface: #ffffff;
  --c-surface-2: #f7f9fc;
  --c-surface-3: #eef2f8;
  --c-border: #e4e9f1;
  --c-border-strong: #ccd5e2;
  --c-text: #111826;
  --c-text-muted: #5c6879;
  --c-text-subtle: #8b95a6;

  /* Ink: primary actions and focus. Calm enough to stare at for a shift. */
  --c-primary: #1a2130;
  --c-primary-hover: #2a3446;
  --c-primary-soft: #eef1f6;
  --c-primary-text: #ffffff;

  /* Brand: the red out of the logo. Position and navigation only. */
  --c-brand: #d0202b;
  --c-brand-hover: #ad1a23;
  --c-brand-soft: #fdecec;

  /* Semantic. --c-danger is kept darker than --c-brand on purpose. */
  --c-success: #1f7a4f;
  --c-success-soft: #e7f5ed;
  --c-warning: #8a5a00;
  --c-warning-soft: #fdf4e3;
  --c-danger: #92211f;
  --c-danger-soft: #fbecea;
  --c-info: #235f80;
  --c-info-soft: #e8f2f8;

  /* Typography */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-8: 3rem;

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 16px;

  /* Light UI needs soft, wide shadows; hard ones look like dirt on white. */
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 5%);
  --shadow: 0 1px 3px rgb(16 24 40 / 6%), 0 14px 32px rgb(16 24 40 / 8%);
  --shadow-lift: 0 2px 6px rgb(16 24 40 / 7%), 0 18px 40px rgb(16 24 40 / 10%);

  --ring: 0 0 0 3px rgb(26 33 48 / 12%);

  --rail-width: 252px;
  --header-height: 68px;
}

/* Opt-in only — see the file header. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --c-bg: #16171a;
  --c-surface: #1d1f23;
  --c-surface-2: #232629;
  --c-surface-3: #2a2e33;
  --c-border: #2f3237;
  --c-border-strong: #43474d;
  --c-text: #e8e8e6;
  --c-text-muted: #a5a49f;
  --c-text-subtle: #7c7a75;

  --c-primary: #e8e8e6;
  --c-primary-hover: #ffffff;
  --c-primary-soft: #262a30;
  --c-primary-text: #14161a;

  --c-brand: #e8515a;
  --c-brand-hover: #f27077;
  --c-brand-soft: #2c1a1c;

  --c-success: #6cc199;
  --c-success-soft: #17291f;
  --c-warning: #d9a441;
  --c-warning-soft: #2b2113;
  --c-danger: #e07373;
  --c-danger-soft: #2c1919;
  --c-info: #6fb0d6;
  --c-info-soft: #16262f;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow: 0 1px 3px rgb(0 0 0 / 50%), 0 4px 12px rgb(0 0 0 / 30%);
  --shadow-lift: 0 2px 6px rgb(0 0 0 / 55%), 0 16px 36px rgb(0 0 0 / 40%);
  --ring: 0 0 0 3px rgb(232 232 230 / 18%);
}

/* ---------------------------------------------------------------- reset -- */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.014em;
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p { margin: 0 0 var(--sp-3); }

/* Content links are ink with a faint rule under them, not brand red. A table
   of forty part numbers rendered in red reads as forty errors; the underline
   is enough to say "clickable" and the red is saved for hover. */
a {
  color: var(--c-text);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--c-text) 25%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { color: var(--c-brand); text-decoration-color: currentColor; }

/* Anchors that are really controls — buttons, nav items, whole-card links —
   opt out of that entirely. */
.btn,
.rail__brand,
.rail__link,
a.stat,
.tab,
.portal-brand,
.portal-nav__link,
.logo {
  text-decoration: none;
}

img { max-width: 100%; }

/* Visible focus everywhere: this UI is heavily keyboard-driven at a counter. */
:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------- brand -- */

/* The logo is a wordmark, so it is sized by height and left to keep its own
   ratio. width:auto is what stops the intrinsic width attribute winning. */
.brand-logo,
.rail__logo,
.auth__logo,
.portal-brand__logo,
.receipt__logo,
.logo__img {
  width: auto;
  height: 40px;
  object-fit: contain;
}

/* ---------------------------------------------------------------- shell -- */

.shell {
  display: grid;
  grid-template-columns: var(--rail-width) 1fr;
  min-height: 100vh;
}

.rail {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--c-border-strong) transparent;
}

.rail__brand {
  display: flex;
  align-items: center;
  min-height: var(--header-height);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
}
.rail__brand:hover { text-decoration: none; }

.rail__logo { height: 38px; }

.rail__nav {
  padding: var(--sp-4) var(--sp-3);
  flex: 1;
}

.rail__group + .rail__group { margin-top: var(--sp-5); }

.rail__label {
  padding: 0 var(--sp-3) var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--c-text-subtle);
}

.rail__link {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  position: relative;
  margin: 1px 0;
  padding: 0.55rem var(--sp-3);
  border-radius: var(--radius);
  color: var(--c-text-muted);
  font-size: var(--text-base);
  transition: background-color 120ms ease, color 120ms ease;
}
.rail__link:hover {
  background: var(--c-surface-3);
  color: var(--c-text);
  text-decoration: none;
}
/* Current page: a red spine out of the logo, not a filled bar. On white,
   a solid highlight shouts; a 3px marker is enough to find your place. */
.rail__link[aria-current="page"] {
  background: var(--c-surface-3);
  color: var(--c-text);
  font-weight: 600;
}
.rail__link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--c-brand);
}

.rail__foot {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--c-border);
  font-size: var(--text-sm);
  color: var(--c-text-muted);
}
.rail__foot > div:first-child { font-weight: 600; color: var(--c-text); }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-5);
  background: color-mix(in srgb, var(--c-surface) 86%, transparent);
  border-bottom: 1px solid var(--c-border);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.content {
  padding: clamp(1rem, 2.4vw, 2rem);
  max-width: 1480px;
  width: 100%;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

.page-head__sub {
  margin: var(--sp-1) 0 0;
  color: var(--c-text-muted);
  font-size: var(--text-base);
}

.actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ------------------------------------------------------------- controls -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.btn:hover {
  background: var(--c-surface-2);
  border-color: var(--c-border-strong);
  box-shadow: var(--shadow-sm), var(--ring);
  text-decoration: none;
}
.btn:active { box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn--primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: var(--c-primary-text);
}
.btn--primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }

/* Brand red, for the one action a screen is really about. Used sparingly —
   if two buttons on a page are red, neither of them is the answer. */
.btn--brand {
  background: var(--c-brand);
  border-color: var(--c-brand);
  color: #fff;
}
.btn--brand:hover { background: var(--c-brand-hover); border-color: var(--c-brand-hover); }

.btn--danger { color: var(--c-danger); border-color: color-mix(in srgb, var(--c-danger) 45%, var(--c-border-strong)); background: var(--c-surface); }
.btn--danger:hover { background: var(--c-danger-soft); border-color: var(--c-danger); }

.btn--sm { padding: var(--sp-1) var(--sp-3); font-size: var(--text-sm); }
.btn--ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn--ghost:hover { background: var(--c-surface-3); box-shadow: none; }

.input,
.select,
.textarea {
  width: 100%;
  min-height: 42px;
  padding: 0.58rem var(--sp-3);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input::placeholder, .textarea::placeholder { color: var(--c-text-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: color-mix(in srgb, var(--c-primary) 30%, var(--c-border-strong)); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--c-primary);
  outline: none;
  box-shadow: var(--ring);
}
.textarea { min-height: 5rem; resize: vertical; }

/* Numeric input aligns right and uses tabular figures: money columns that do
   not line up are genuinely harder to scan for errors. */
.input--num { text-align: right; font-variant-numeric: tabular-nums; }

.field { margin-bottom: var(--sp-4); }
.field__label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--c-text);
}
.field__hint { margin: var(--sp-1) 0 0; font-size: var(--text-sm); color: var(--c-text-muted); }
.field__error { margin: var(--sp-1) 0 0; font-size: var(--text-sm); color: var(--c-danger); font-weight: 550; }
.field--required .field__label::after { content: " *"; color: var(--c-danger); }

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* --------------------------------------------------------------- cards --- */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
}
.card__title { font-size: var(--text-md); font-weight: 650; }
.card__body { padding: var(--sp-5); }
.card__body--flush { padding: 0; }

.stat {
  display: block;
  padding: var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
a.stat:hover {
  border-color: color-mix(in srgb, var(--c-brand) 32%, var(--c-border));
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
  text-decoration: none;
}
.stat__label {
  font-size: var(--text-sm);
  color: var(--c-text-muted);
  margin-bottom: var(--sp-2);
}
.stat__value {
  font-size: var(--text-2xl);
  font-weight: 650;
  letter-spacing: -0.024em;
  font-variant-numeric: tabular-nums;
}
.stat__meta { margin-top: var(--sp-1); font-size: var(--text-sm); color: var(--c-text-subtle); }
.stat--warning .stat__value { color: var(--c-warning); }
.stat--danger .stat__value { color: var(--c-danger); }
.stat--success .stat__value { color: var(--c-success); }

/* -------------------------------------------------------------- tables --- */

.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }

.table th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
  background: var(--c-surface-2);
}

.table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}

.table tbody tr { transition: background-color 100ms ease; }
.table tbody tr:hover { background: var(--c-surface-2); }
.table tbody tr:last-child td { border-bottom: none; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .mono { font-family: var(--font-mono); font-size: var(--text-sm); }

/* -------------------------------------------------------------- badges --- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge--neutral { background: var(--c-surface-3); color: var(--c-text-muted); border-color: var(--c-border); }
.badge--success { background: var(--c-success-soft); color: var(--c-success); border-color: color-mix(in srgb, var(--c-success) 22%, transparent); }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); border-color: color-mix(in srgb, var(--c-warning) 22%, transparent); }
.badge--danger { background: var(--c-danger-soft); color: var(--c-danger); border-color: color-mix(in srgb, var(--c-danger) 22%, transparent); }
.badge--info { background: var(--c-info-soft); color: var(--c-info); border-color: color-mix(in srgb, var(--c-info) 22%, transparent); }

/* -------------------------------------------------------------- alerts --- */

/* A left rule rather than a full outline: the tone is legible at a glance and
   the box stays quiet enough to live above a form. */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--c-border);
  border-left: 3px solid;
  border-radius: var(--radius);
  margin-bottom: var(--sp-4);
  font-size: var(--text-base);
}
.alert--error { background: var(--c-danger-soft); border-left-color: var(--c-danger); color: var(--c-danger); }
.alert--success { background: var(--c-success-soft); border-left-color: var(--c-success); color: var(--c-success); }
.alert--info { background: var(--c-info-soft); border-left-color: var(--c-info); color: var(--c-info); }
.alert--warning { background: var(--c-warning-soft); border-left-color: var(--c-warning); color: var(--c-warning); }

/* ---------------------------------------------------------------- misc --- */

.empty {
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  color: var(--c-text-muted);
}
.empty__title { font-weight: 650; color: var(--c-text); margin-bottom: var(--sp-1); font-size: var(--text-md); }

.toolbar {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface-2);
}
.toolbar .input, .toolbar .select { width: auto; min-width: 180px; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--c-border);
  font-size: var(--text-sm);
  color: var(--c-text-muted);
}

.search { flex: 1; max-width: 520px; position: relative; }
.search .input { padding-left: var(--sp-8); border-radius: 999px; background: var(--c-surface-2); }
.search .input:focus { background: var(--c-surface); }
.search__icon {
  position: absolute;
  left: var(--sp-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-subtle);
  pointer-events: none;
}

.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--c-border); margin-bottom: var(--sp-4); }
.tab {
  padding: var(--sp-2) var(--sp-4);
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--c-text-muted);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}
.tab:hover { color: var(--c-text); }
.tab[aria-selected="true"] { color: var(--c-text); border-bottom-color: var(--c-brand); font-weight: 650; }

.dl { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: var(--sp-2) var(--sp-4); margin: 0; }
.dl dt { color: var(--c-text-muted); font-size: var(--text-sm); }
.dl dd { margin: 0; font-variant-numeric: tabular-nums; }

.muted { color: var(--c-text-muted); }
.mono { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: var(--sp-4); }
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); }
.right { text-align: right; }

/* HTMX shows this while a swap is in flight. */
.htmx-indicator { opacity: 0; transition: opacity 150ms ease; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---------------------------------------------------------------- auth --- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background:
    radial-gradient(circle at 12% 8%, rgb(208 32 43 / 7%), transparent 38%),
    radial-gradient(circle at 88% 92%, rgb(26 33 48 / 7%), transparent 34%),
    var(--c-bg);
}
.auth__card {
  width: 100%;
  max-width: 420px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  padding: clamp(1.5rem, 4vw, 2.5rem);
}

.auth__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-5);
}
.auth__logo { height: 72px; }

.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  padding: 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
}
.nav-toggle span { display: block; height: 2px; margin: 4px 0; border-radius: 2px; background: var(--c-text); }
.rail-backdrop { display: none; }
.user-chip {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: var(--c-primary);
  color: var(--c-primary-text);
  font-weight: 700;
  font-size: var(--text-sm);
}

/* ------------------------------------------------------------- portal --- */

.portal {
  min-height: 100vh;
  background:
    radial-gradient(circle at 92% 0%, rgb(208 32 43 / 5%), transparent 26rem),
    var(--c-bg);
}
.portal-head {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--c-border);
  background: color-mix(in srgb, var(--c-surface) 90%, transparent);
  backdrop-filter: blur(14px);
}
.portal-head__inner {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  width: min(1180px, calc(100% - 2rem));
  min-height: 72px;
  margin: 0 auto;
}
.portal-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--c-text);
  white-space: nowrap;
}
.portal-brand:hover { text-decoration: none; }
.portal-brand__logo { height: 36px; }
/* The wordmark carries the brand, so this only has to say which door you
   came in by. Set apart with a rule rather than repeating the name. */
.portal-brand__tag {
  padding-left: var(--sp-3);
  border-left: 1px solid var(--c-border-strong);
  color: var(--c-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.portal-nav { display: flex; align-self: stretch; align-items: stretch; gap: var(--sp-1); }
.portal-nav__link {
  display: flex;
  align-items: center;
  padding: 0 var(--sp-3);
  border-bottom: 2px solid transparent;
  color: var(--c-text-muted);
  font-weight: 550;
}
.portal-nav__link:hover { color: var(--c-text); text-decoration: none; }
.portal-nav__link.is-active { border-bottom-color: var(--c-brand); color: var(--c-text); font-weight: 650; }
.portal-user { display: flex; align-items: center; gap: var(--sp-3); margin-left: auto; }
.portal-user__name { max-width: 180px; overflow: hidden; color: var(--c-text-muted); text-overflow: ellipsis; white-space: nowrap; }
.portal-page { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) 0 4rem; }
.portal-page > .page__title:first-child { margin-bottom: var(--sp-2); }
.portal .auth { min-height: calc(100vh - 72px); padding-top: 0; }
.portal .auth__card > h1, .portal .auth__card > p { text-align: center; }
.portal .auth__card > p { margin-bottom: var(--sp-5); }
.portal .thumb__img { height: 210px; margin-bottom: var(--sp-3); border-radius: var(--radius); }

/* --------------------------------------------------------------- POS ---- */

.pos-setup, .pos-shift-open { max-width: 720px; }
.pos-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: var(--sp-5); align-items: start; }
.pos-main { min-width: 0; }
.pos-side { display: grid; gap: var(--sp-4); position: sticky; top: calc(var(--header-height) + var(--sp-4)); }
.pos-shift-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: var(--sp-4);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  background: var(--c-border);
  box-shadow: var(--shadow-sm);
}
.pos-shift-strip > div { display: grid; gap: 2px; padding: var(--sp-3) var(--sp-4); background: var(--c-surface); }
.pos-shift-strip span { color: var(--c-text-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; }
.pos-search { display: flex; gap: var(--sp-2); padding: var(--sp-4); border-bottom: 1px solid var(--c-border); background: var(--c-surface-2); }
.pos-search .input { font-size: var(--text-md); }
.pos-search .select { max-width: 380px; }
.pos-customer { display: grid; grid-template-columns: 130px minmax(220px, 420px); align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--c-border); }
.pos-customer label { font-weight: 600; }
.pos-lines .select { min-width: 260px; }
.pos-lines tfoot td { padding: var(--sp-4); border-top: 2px solid var(--c-border-strong); }
.pos-total { color: var(--c-text); font-size: var(--text-xl); font-weight: 750; }
.pos-tenders { display: grid; gap: var(--sp-2); padding: var(--sp-5); border-top: 1px solid var(--c-border); background: var(--c-surface-2); }
.pos-tenders h3 { margin-bottom: var(--sp-2); }
.pos-tender { display: grid; grid-template-columns: 100px minmax(160px, 1fr) 130px 130px; gap: var(--sp-2); align-items: center; }
.pos-tender > label { font-weight: 650; }
.pos-change { display: flex; justify-content: flex-end; gap: var(--sp-4); padding-top: var(--sp-2); color: var(--c-text-muted); }
.pos-change strong { min-width: 130px; color: var(--c-success); text-align: right; font-size: var(--text-lg); }
.pos-actions { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--c-border); }
.pos-park-label { max-width: 230px; margin-left: auto; }
.key-hint { padding: 1px 5px; border: 1px solid currentColor; border-radius: 4px; font-size: 0.65rem; opacity: .72; }
.pos-parked-list { display: grid; }
.pos-parked { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2); align-items: center; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--c-border); }
.pos-parked:last-child { border-bottom: 0; }
.pos-parked div { min-width: 0; }
.pos-parked strong, .pos-parked small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos-parked small { color: var(--c-text-muted); }
.pos-parked .btn { grid-column: 1 / -1; }
.receipt { width: min(100%, 680px); margin: 0 auto; padding: clamp(1rem, 4vw, 2.5rem); border: 1px solid var(--c-border); border-radius: var(--radius-lg); background: var(--c-surface); box-shadow: var(--shadow); }
.receipt__head { display: flex; align-items: center; gap: var(--sp-4); padding-bottom: var(--sp-5); border-bottom: 1px dashed var(--c-border-strong); }
.receipt__head > div { display: grid; flex: 1; }
.receipt__head small { color: var(--c-text-muted); }
.receipt__logo { height: 44px; }
.receipt__number { padding: var(--sp-4) 0; font-family: var(--font-mono); text-align: center; }
.receipt__totals { display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2) var(--sp-5); padding-top: var(--sp-5); border-top: 1px dashed var(--c-border-strong); text-align: right; }

/* ----------------------------------------------------------- fitment ---- */

/* The make / model / year / engine row. Auto-fit rather than a fixed column
   count: the same component sits in a page-wide hero and in a narrow card
   beside a product, and neither should get its own breakpoint. */
.vehicle-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0 var(--sp-3);
  align-items: start;
}
.vehicle-fields .field { margin-bottom: var(--sp-3); }

.year-range { display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--sp-2); align-items: center; }
.year-range span { color: var(--c-text-subtle); }

/* One fitment per line, with its remove button pinned right. */
.fitment-list { display: grid; gap: 0; margin: 0 0 var(--sp-4); padding: 0; list-style: none; }
.fitment-list > li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--c-border);
}
.fitment-list > li:last-child { border-bottom: 0; }
.fitment-list form { margin: 0; }

/* The POS bar is one flex row, so the year keeps a hand-sized fixed width
   instead of stretching like the search box next to it. */
.pos-year { width: 5.5rem; flex: none; }


.fitment-hero {
  margin-bottom: var(--sp-5);
  padding: clamp(1rem, 3vw, 1.75rem);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--c-surface-3), var(--c-surface) 65%);
  box-shadow: var(--shadow-sm);
}
.fitment-hero form { display: grid; gap: var(--sp-3); }
.fitment-hero .btn { justify-self: start; }
.fitment-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(260px, .8fr)); gap: var(--sp-5); align-items: start; margin-top: var(--sp-5); }
.disclosure { overflow: hidden; border: 1px solid var(--c-border); border-radius: var(--radius-lg); background: var(--c-surface); box-shadow: var(--shadow-sm); }
.disclosure > summary { padding: var(--sp-4) var(--sp-5); cursor: pointer; font-size: var(--text-md); font-weight: 650; }
.disclosure > summary:hover { background: var(--c-surface-2); }
.disclosure[open] > summary { border-bottom: 1px solid var(--c-border); }
.disclosure__body { padding: var(--sp-4); }
.compact-form { display: grid; grid-template-columns: minmax(110px, .75fr) repeat(auto-fit, minmax(110px, 1fr)) auto; gap: var(--sp-2); align-items: center; }
.compact-form + .compact-form { padding-top: var(--sp-3); border-top: 1px solid var(--c-border); }
.fitment-garage-list { margin-top: var(--sp-5); }

/* -------------------------------------------------------- collections --- */

.collections-stats { margin-bottom: var(--sp-5); }
.collections-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--sp-5); align-items: start; }
.collections-bottom { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr); gap: var(--sp-5); align-items: start; margin-top: var(--sp-5); }
.block { display: block; }
.text-sm { font-size: var(--text-sm); }
.check { display: flex; align-items: center; gap: var(--sp-2); margin: var(--sp-3) 0; color: var(--c-text-muted); }
.check input { width: 1rem; height: 1rem; accent-color: var(--c-primary); }
.template-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-4); }
.case-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: var(--sp-5);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  background: var(--c-border);
  box-shadow: var(--shadow-sm);
}
.case-summary > div { display: grid; gap: var(--sp-1); padding: var(--sp-4); background: var(--c-surface); }
.case-summary span:first-child { color: var(--c-text-muted); font-size: var(--text-xs); letter-spacing: .04em; text-transform: uppercase; }
.case-summary strong { font-size: var(--text-md); }
.case-layout { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: var(--sp-5); align-items: start; margin-bottom: var(--sp-5); }
.case-actions { position: sticky; top: calc(var(--header-height) + var(--sp-4)); }
.case-actions form { display: grid; gap: var(--sp-3); }
.timeline { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.timeline > li { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: var(--sp-3); position: relative; min-height: 84px; }
.timeline > li:not(:last-child)::before { content: ""; position: absolute; top: 16px; bottom: -2px; left: 5px; width: 2px; background: var(--c-border); }
.timeline__dot { position: relative; z-index: 1; width: 12px; height: 12px; margin-top: 3px; border: 3px solid var(--c-brand-soft); border-radius: 50%; background: var(--c-brand); }
.timeline time { margin-left: auto; color: var(--c-text-muted); font-size: var(--text-xs); }
.timeline p { margin: var(--sp-2) 0; white-space: pre-wrap; }

/* -------------------------------------------------------------- mobile --- */

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(84vw, var(--rail-width));
    height: 100vh;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow-lift);
  }
  .nav-open .rail { transform: translateX(0); }
  .rail-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    border: 0;
    background: rgb(16 24 40 / 44%);
    backdrop-filter: blur(3px);
  }
  .nav-open .rail-backdrop { display: block; }
  .nav-toggle { display: block; flex: none; }
  .content { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); gap: var(--sp-2); }
  .topbar .select { width: 70px; }
  .user-chip { display: none; }
  .portal-head__inner { flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-3) 0; }
  .portal-nav { order: 3; width: 100%; overflow-x: auto; }
  .portal-nav__link { min-height: 42px; white-space: nowrap; }
  .portal-user__name { display: none; }
  .pos-workspace { grid-template-columns: 1fr; }
  .pos-side { position: static; }
  .pos-shift-strip { grid-template-columns: repeat(2, 1fr); }
  .pos-tender { grid-template-columns: 90px 1fr; }
  .pos-tender .input { width: 100%; }
  .fitment-grid { grid-template-columns: 1fr; }
  .collections-layout, .collections-bottom, .case-layout { grid-template-columns: 1fr; }
  .case-actions { position: static; }
  .case-summary { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .search { max-width: none; }
  .topbar > form.row { display: none; }
  .page-head { margin-bottom: var(--sp-4); }
  .card__head, .card__body { padding: var(--sp-4); }
  .toolbar .input, .toolbar .select { width: 100%; min-width: 0; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .portal-page { width: min(100% - 1.25rem, 1180px); }
  .portal-brand__tag { display: none; }
  .pos-customer { grid-template-columns: 1fr; }
  .pos-actions { align-items: stretch; flex-direction: column; }
  .pos-actions > * { width: 100%; max-width: none; }
  .pos-search { flex-direction: column; }
  .pos-search .select { max-width: none; }
  .pos-park-label { margin-left: 0; }
  .compact-form { grid-template-columns: 1fr; }
  .vehicle-fields { grid-template-columns: 1fr; }
  .case-summary { grid-template-columns: 1fr; }
}

@media print {
  .rail, .topbar, .actions, .toolbar, .pagination { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .card { border: none; box-shadow: none; }
  body { background: #fff; }
  .content { max-width: none; padding: 0; }
  .receipt { width: 80mm; border: 0; box-shadow: none; }
  /* The mark is the only branding on a printed receipt, so it must survive
     the browser's "do not print backgrounds" default. */
  .receipt__logo { height: 34px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* ------------------------------------------------------- media thumbs --- */

.thumb {
  margin: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--c-surface-2);
}
/* Fixed box with contain: product photos arrive at every aspect ratio, and a
   grid that reflows per image is harder to scan than letterboxing. */
.thumb__img {
  display: block;
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: var(--c-surface);
}
.thumb__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-2);
}

/* --------------------------------------------------------- error page --- */

.errpage {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}
.errpage__card {
  width: min(100%, 460px);
  text-align: center;
}
.errpage__brand { display: inline-flex; }
.errpage__brand:hover { text-decoration: none; }
.errpage__logo { width: auto; height: 52px; object-fit: contain; }
/* Large but quiet: the number identifies the failure, it is not the message. */
.errpage__status {
  margin: 1.75rem 0 0;
  font-size: 3.25rem;
  font-weight: 750;
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--c-border-strong);
  font-variant-numeric: tabular-nums;
}
.errpage__title { margin: 0.75rem 0 0; }
.errpage__message { margin: 0.6rem 0 1.75rem; color: var(--c-text-muted); }
/* The two strings worth quoting in a bug report, and nothing else. */
.errpage__meta {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1.75rem 0 0;
  font-size: 0.75rem;
  color: var(--c-text-subtle);
}
.errpage__meta .mono { font-family: var(--font-mono); }
