/* TS Price List design system (01-UI-SPEC). Later plans append page sections below. */
:root {
  --sp-xs: 4px; --sp-sm: 8px; --sp-md: 16px; --sp-lg: 24px; --sp-xl: 32px; --sp-2xl: 48px; --sp-3xl: 64px;
  --fs-body: 16px; --fs-label: 12px; --fs-heading: 20px; --fs-display: 28px;
  --fw-regular: 400; --fw-semibold: 600;
  --c-page: #f3f4f6; --c-surface: #ffffff; --c-nav: #1f2937; --c-border: #e5e7eb;
  --c-text: #374151; --c-muted: #6b7280; --c-accent: #1d4ed8;
  --c-danger: #b91c1c; --c-danger-bg: #fef2f2;
  --c-ok: #15803d; --c-ok-bg: #f0fdf4;
  --c-review: #b45309; --c-review-bg: #fffbeb;
  --c-skipped: #4b5563; --c-skipped-bg: #f3f4f6;
  --c-rejected: #b91c1c; --c-rejected-bg: #fef2f2;
  --c-row: #f9fafb;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--c-page); color: var(--c-text);
  font-family: var(--font); font-size: var(--fs-body); font-weight: var(--fw-regular); line-height: 1.5;
}
a { color: var(--c-accent); }
h1, h2, h3 { margin: 0 0 var(--sp-md); }
.heading { font-size: var(--fs-heading); font-weight: var(--fw-semibold); line-height: 1.2; }
.display { font-size: var(--fs-display); font-weight: var(--fw-semibold); line-height: 1.2; }
.meta { font-size: var(--fs-label); color: var(--c-muted); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.skip-link {
  position: absolute; left: var(--sp-sm); top: -100px; background: var(--c-surface); padding: var(--sp-sm) var(--sp-md);
  z-index: 100; border: 1px solid var(--c-border);
}
.skip-link:focus { top: var(--sp-sm); }

/* Layout shell */
.topnav { background: var(--c-nav); color: #fff; }
.topnav-inner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-md);
  padding: 0 var(--sp-md); min-height: 56px; flex-wrap: wrap;
}
.brand { color: #fff; font-weight: var(--fw-semibold); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.nav-menu summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; list-style: none; }
.nav-menu summary::-webkit-details-marker { display: none; }
.nav-links { display: flex; align-items: center; gap: var(--sp-md); flex-wrap: wrap; }
.nav-link {
  color: #fff; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center;
  border-bottom: 2px solid transparent; padding: 0 var(--sp-xs);
}
.nav-link:hover { border-bottom-color: #9ca3af; }
.nav-link.is-active { border-bottom-color: var(--c-accent); box-shadow: 0 2px 0 #fff inset; }
.nav-user { font-size: var(--fs-label); color: #d1d5db; }
.nav-logout { margin: 0; }
@media (min-width: 720px) {
  .nav-menu summary { display: none; }
}
@media (max-width: 719px) {
  .nav-menu { width: 100%; }
  .nav-links { flex-direction: column; align-items: stretch; padding-bottom: var(--sp-md); }
}
.container { max-width: 1200px; margin: 0 auto; padding: var(--sp-lg) var(--sp-md); }
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px; padding: var(--sp-lg); margin-bottom: var(--sp-xl); }
.empty-state { text-align: center; padding: var(--sp-3xl) var(--sp-lg); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-sm);
  min-height: 44px; padding: 0 var(--sp-md); border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-weight: var(--fw-semibold); cursor: pointer; text-decoration: none;
  transition: background-color 100ms, color 100ms, border-color 100ms;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--c-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1e40af; }
.btn-secondary { background: var(--c-surface); color: var(--c-text); border-color: #d1d5db; }
.btn-secondary:hover:not(:disabled) { background: var(--c-row); }
.btn-secondary.btn-on-dark { background: transparent; color: #fff; border-color: #9ca3af; }
.btn-secondary.btn-on-dark:hover:not(:disabled) { background: #374151; }
.btn-destructive { background: var(--c-danger); color: #fff; }
.btn-destructive:hover:not(:disabled) { background: #991b1b; }
.btn-text { background: none; color: var(--c-accent); padding: 0 var(--sp-sm); }
.btn-text.is-danger { color: var(--c-danger); }
.btn-block { width: 100%; }

/* Forms */
.field { margin-bottom: var(--sp-md); }
.field label { display: block; font-size: var(--fs-label); font-weight: var(--fw-semibold); margin-bottom: var(--sp-xs); }
input[type="text"], input[type="password"], input[type="search"], input[type="number"], input[type="file"], select, textarea {
  width: 100%; min-height: 44px; padding: var(--sp-sm) 12px; font: inherit; color: var(--c-text);
  background: var(--c-surface); border: 1px solid #d1d5db; border-radius: 6px;
}
.password-row { display: flex; gap: var(--sp-sm); align-items: center; }
.helper { font-size: var(--fs-label); color: var(--c-muted); margin-top: var(--sp-xs); }

/* Login */
.login-wrap { display: flex; justify-content: center; padding: var(--sp-3xl) var(--sp-md); }
.login-card { width: 100%; max-width: 400px; }
.alert-box {
  background: var(--c-danger-bg); color: var(--c-danger); border: 1px solid var(--c-danger);
  border-radius: 6px; padding: var(--sp-sm) var(--sp-md); margin-bottom: var(--sp-md);
}

/* Flash */
.flash { border-radius: 6px; padding: var(--sp-sm) var(--sp-md); margin-bottom: var(--sp-md); border: 1px solid; }
.flash-success { background: var(--c-ok-bg); color: var(--c-ok); border-color: var(--c-ok); }
.flash-error { background: var(--c-danger-bg); color: var(--c-danger); border-color: var(--c-danger); }

/* Badges */
.badge {
  display: inline-block; font-size: var(--fs-label); font-weight: var(--fw-semibold); line-height: 1.5;
  padding: 0 var(--sp-sm); border-radius: 4px; border: 1px solid currentColor;
}
.badge-ok { color: var(--c-ok); background: var(--c-ok-bg); }
.badge-review { color: var(--c-review); background: var(--c-review-bg); }
.badge-skipped { color: var(--c-skipped); background: var(--c-skipped-bg); }
.badge-rejected { color: var(--c-rejected); background: var(--c-rejected-bg); }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: var(--sp-sm) var(--sp-md); border-bottom: 1px solid var(--c-border); text-align: left; vertical-align: top; }
.table th[scope] { font-size: var(--fs-label); font-weight: var(--fw-semibold); background: var(--c-border); }
.table td.num { text-align: right; }

/* Dialog */
dialog { border: 1px solid var(--c-border); border-radius: 8px; padding: var(--sp-lg); max-width: 480px; color: var(--c-text); }
dialog::backdrop { background: rgba(31, 41, 55, .5); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Users (S2) */
.users-create-title { font-weight: var(--fw-semibold); cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.field-error { color: var(--c-danger); font-size: var(--fs-label); margin-top: var(--sp-xs); }
.secret-box { border: 2px solid var(--c-ok); background: var(--c-ok-bg); border-radius: 8px; padding: var(--sp-md); margin-bottom: var(--sp-lg); }
.secret-value { font-family: ui-monospace, monospace; font-size: 18px; margin-right: var(--sp-md); word-break: break-all; }
.table-scroll { overflow-x: auto; }
.row-disabled td { color: var(--c-muted); }
.row-actions { display: flex; gap: var(--sp-sm); flex-wrap: wrap; }
.row-actions form { margin: 0; }
.confirm-dialog .dialog-buttons { display: flex; gap: var(--sp-md); margin-top: var(--sp-lg); }
.confirm-dialog .dialog-buttons form { margin: 0; }
@media (min-width: 768px) { .users-create[open] .users-create-title { pointer-events: none; } }

/* Browse grid (S6) */
.container-wide { max-width: none; }
.cat-tabs { display: flex; gap: var(--sp-md); border-bottom: 1px solid var(--c-border); margin-bottom: var(--sp-md); }
.cat-tab { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--sp-sm); color: var(--c-text); text-decoration: none; border-bottom: 3px solid transparent; }
.cat-tab.is-active { border-bottom-color: var(--c-accent); font-weight: var(--fw-semibold); color: var(--c-accent); }
.grid-meta { margin: 0 0 var(--sp-md); }
.grid-toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-md); align-items: flex-end; }
.grid-toolbar .field { margin-bottom: 0; }
.grid-search { flex: 1 1 260px; }
.grid-nomatch { text-align: center; padding: var(--sp-xl) var(--sp-md); }
.is-hidden { display: none !important; }
.grid-scroll { overflow: auto; max-height: calc(100vh - 220px); background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px; }
.grid-table { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
.grid-table th, .grid-table td { padding: var(--sp-sm); border-bottom: 1px solid var(--c-border); vertical-align: top; text-align: left; background: var(--c-surface); }
.grid-table thead th { position: sticky; top: 0; z-index: 3; min-width: 96px; font-size: var(--fs-label); font-weight: var(--fw-semibold); background: var(--c-border); }
.grid-table .col-size { position: sticky; left: 0; z-index: 2; width: 120px; min-width: 120px; max-width: 120px; box-shadow: 2px 0 4px -2px rgba(0, 0, 0, .2); font-weight: var(--fw-semibold); }
.grid-table thead .col-size { z-index: 4; }
.grid-table td { min-width: 96px; }
.grid-table tr.band-row th { background: #e5e7eb; font-size: var(--fs-heading); font-weight: var(--fw-semibold); }
.band-label { position: sticky; left: var(--sp-sm); }
.size-sub { margin-top: var(--sp-xs); }
.entry + .entry { border-top: 1px solid var(--c-border); margin-top: var(--sp-xs); padding-top: var(--sp-xs); }
.entry-price { text-align: right; }
.price { font-size: var(--fs-body); font-weight: var(--fw-semibold); }
.entry-sub { font-size: var(--fs-label); color: var(--c-muted); overflow-wrap: anywhere; text-align: right; }
.entry-brand { font-weight: var(--fw-semibold); }
mark.hl { background: #fef9c3; color: inherit; }
/* Desktop: brand names sit centred over centred prices and patterns; the size column stays left */
@media (min-width: 720px) {
  .grid-table thead th:not(.col-size), .entry-price, .entry-sub { text-align: center; }
}
/* Desktop: every second size row that is showing is shaded, so a row is easy to follow across. Counted
   over visible rows only, so the stripes stay even when a search or filter hides rows. */
@media (min-width: 720px) {
  .grid-table tbody tr:nth-child(even of :not(.is-hidden, .band-row)) td,
  .grid-table tbody tr:nth-child(even of :not(.is-hidden, .band-row)) th { background: #e9edf3; }
}
@media (hover: hover) and (min-width: 720px) {
  .grid-table tbody tr:not(.band-row):hover td, .grid-table tbody tr:not(.band-row):hover th { background: #dbe6fb; }
}
/* Phones: one card per size, brands listed down the card (no sideways scroll). */
@media (max-width: 719px) {
  .topnav { position: relative; }
  .topnav-inner { flex-wrap: nowrap; }
  .nav-menu { width: auto; }
  .nav-menu summary { padding: 0 var(--sp-sm); }
  .nav-links { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: var(--c-nav); padding: 0 var(--sp-md) var(--sp-md); }
  .container-wide { padding-top: var(--sp-sm); }
  .grid-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .cat-tabs { margin-bottom: var(--sp-sm); }
  .cat-tab { flex: 1 1 auto; justify-content: center; white-space: nowrap; }
  .grid-meta { margin-bottom: var(--sp-sm); }
  .grid-toolbar { position: sticky; top: 0; z-index: 5; background: var(--c-page); gap: var(--sp-sm); padding: var(--sp-sm) 0; }
  .grid-toolbar .field { flex: 1 1 0; min-width: 0; }
  .grid-toolbar .grid-search { flex-basis: 100%; }
  .grid-toolbar .grid-clear { flex: 0 0 auto; }
  .grid-toolbar label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .grid-scroll { max-height: none; overflow: visible; background: none; border: 0; border-radius: 0; }
  .grid-table, .grid-table tbody, .grid-table tr, .grid-table th, .grid-table td { display: block; }
  .grid-table thead { display: none; }
  .grid-table tbody tr:not(.band-row) { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px; margin-bottom: var(--sp-sm); overflow: hidden; }
  .grid-table tr.band-row th { background: none; border: 0; padding: var(--sp-md) 0 var(--sp-sm); }
  .grid-table .col-size { position: static; width: auto; min-width: 0; max-width: none; box-shadow: none; background: var(--c-row); font-size: 18px; }
  .size-sub { display: inline-block; margin: 0 0 0 var(--sp-sm); }
  .grid-table td { display: flex; flex-wrap: wrap; gap: 0 var(--sp-md); min-width: 0; padding: var(--sp-sm) 12px; }
  .grid-table td:empty { display: none; }
  .grid-table tr td:last-child { border-bottom: 0; }
  .grid-table td::before { content: attr(data-label); flex: 0 0 104px; font-size: 14px; font-weight: var(--fw-semibold); padding-top: 2px; }
  .grid-table td .entry { flex: 0 0 calc(100% - 104px - var(--sp-md)); margin-left: auto; display: flex; justify-content: space-between; align-items: baseline; gap: 0 var(--sp-sm); }
  .entry-sub { order: -1; flex: 1 1 0; text-align: left; font-size: 14px; }
  .entry-price { flex: 0 0 auto; }
}

/* Import (S3) */
.subheading { font-size: var(--fs-heading); font-weight: var(--fw-semibold); line-height: 1.2; margin: var(--sp-lg) 0 var(--sp-md); }
.import-card .subheading { margin-top: 0; }
.import-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-md); margin-bottom: var(--sp-xl); }
.import-tiles .tile { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px; padding: var(--sp-md); }
.import-tiles .tile-num { font-size: var(--fs-display); font-weight: var(--fw-semibold); line-height: 1.2; margin: 0; }
.import-tiles .tile-label { font-size: var(--fs-label); color: var(--c-muted); margin: 0; }

/* Import review (S4) */
.review-page { padding-bottom: 140px; }
.review-progress { width: 100%; height: 10px; margin-bottom: var(--sp-lg); }
.review-group { margin-bottom: var(--sp-lg); }
.review-group > summary { cursor: pointer; }
.review-item {
  display: grid; grid-template-columns: minmax(220px, 1fr) minmax(320px, 2fr); gap: var(--sp-lg);
  background: var(--c-surface); border: 1px solid var(--c-border); border-left: 4px solid var(--c-review);
  border-radius: 8px; padding: var(--sp-md); margin-bottom: var(--sp-md);
}
.review-item.is-confirmed { border-left-color: var(--c-ok); }
.review-item.is-rejected { border-left-color: var(--c-rejected); }
.review-item .label { font-size: var(--fs-label); font-weight: var(--fw-semibold); color: var(--c-muted); margin: 0 0 var(--sp-xs); }
.ri-raw {
  background: var(--c-row); border: 1px solid var(--c-border); border-radius: 6px; padding: var(--sp-sm) 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; white-space: pre-wrap;
}
.ri-refs { margin: var(--sp-sm) 0 var(--sp-xs); }
.ri-tyre { border-top: 1px dashed var(--c-border); padding-top: var(--sp-sm); margin-top: var(--sp-sm); }
.ri-tyre:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.ri-row { display: flex; gap: var(--sp-md); flex-wrap: wrap; }
.ri-row .field { flex: 2 1 160px; }
.ri-row .ri-price { flex: 1 1 100px; }
.ri-row .ri-tt { flex: 0 1 90px; }
.ri-radio { display: flex; gap: var(--sp-sm); align-items: center; min-height: 44px; }
.ri-radio input { width: 20px; height: 20px; flex: none; }
.ri-choices { border: 1px solid var(--c-border); border-radius: 6px; margin: 0 0 var(--sp-md); padding: var(--sp-sm) var(--sp-md); }
.ri-actions { display: flex; gap: var(--sp-sm); align-items: center; margin-top: var(--sp-sm); }
.ri-actions form { margin: 0; }
.field-error { color: var(--c-danger); font-size: var(--fs-label); margin: var(--sp-xs) 0 0; }
.review-item [aria-invalid="true"] { border-color: var(--c-danger); }
[data-new-brand] { margin-top: var(--sp-sm); }
.review-footer {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--c-surface); border-top: 1px solid var(--c-border);
  padding: var(--sp-sm) var(--sp-md); z-index: 20;
}
.review-footer-inner { display: flex; gap: var(--sp-md); align-items: center; justify-content: flex-end; flex-wrap: wrap; min-height: 56px; }
.review-footer-inner form { margin: 0; }
.review-footer-progress { margin-right: auto; font-size: var(--fs-label); min-width: 160px; }
.review-footer-progress progress { display: block; width: 100%; height: 8px; }
.review-footer .helper { margin: 0; text-align: right; }
.dialog-actions { display: flex; gap: var(--sp-sm); justify-content: flex-end; margin-top: var(--sp-md); }
@media (max-width: 720px) {
  .review-item { grid-template-columns: 1fr; }
  .review-footer-inner .btn { min-width: 0; }
  .review-page { padding-bottom: 220px; }
}

/* Reconciliation (S5) */
.recon-status { display: flex; gap: var(--sp-sm); align-items: center; margin: 0 0 var(--sp-sm); }
.recon-toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-md); align-items: center; justify-content: space-between; margin: var(--sp-lg) 0 var(--sp-md); }
.recon-toolbar .chips { display: flex; flex-wrap: wrap; gap: var(--sp-sm); }
.recon-toolbar .chip { display: inline-block; padding: var(--sp-xs) var(--sp-md); border: 1px solid var(--c-border); border-radius: 999px; text-decoration: none; color: inherit; }
.recon-toolbar .chip.is-active { background: var(--c-border); font-weight: var(--fw-semibold); }
.ri-raw-cell { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; white-space: pre-wrap; }
.pager { display: flex; gap: var(--sp-md); align-items: center; margin: var(--sp-md) 0; }

/* Re-import groups */
.rerun-tiles { margin-top: calc(-1 * var(--sp-md)); }
.ri-conflict .ri-card { border: 1px solid var(--c-border); border-radius: 6px; padding: var(--sp-sm) var(--sp-md); margin-bottom: var(--sp-sm); }
.ri-conflict .ri-card:has(input:checked) { border-color: var(--c-accent); font-weight: var(--fw-semibold); }
.missing-list { list-style: none; margin: var(--sp-sm) 0 var(--sp-md); padding: 0; }
.missing-row { display: flex; gap: var(--sp-md); align-items: center; border-bottom: 1px solid var(--c-border); }
.decided-earlier > summary { color: var(--c-muted); }
.decided-row { display: flex; gap: var(--sp-md); align-items: center; justify-content: space-between; padding: var(--sp-sm) 0; border-bottom: 1px solid var(--c-border); }
.decided-row form { margin: 0; }

/* Phase 2: grid editing (admin only; every class here starts with ed- or sits under .grid-admin) */
.ed-hint { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--sp-sm); margin: 0 0 var(--sp-xs); font-size: var(--fs-label); color: var(--c-muted); }
.ed-hint-text { margin: 0; }
.ed-keys summary { cursor: pointer; color: var(--c-accent); text-decoration: underline; }
.ed-keys[open] { flex-basis: 100%; }
.ed-keys-table { border-collapse: collapse; margin: var(--sp-xs) 0 var(--sp-sm); color: var(--c-text); }
.ed-keys-table th, .ed-keys-table td { text-align: left; font-size: var(--fs-label); padding: var(--sp-xs) var(--sp-md) var(--sp-xs) 0; border-bottom: 1px solid var(--c-border); }
.ed-keys-table th { font-weight: var(--fw-semibold); white-space: nowrap; }
.ed-phone-note { margin: 0 0 var(--sp-sm); font-size: var(--fs-label); color: var(--c-muted); }
.ed-strip { margin: 0 0 var(--sp-sm); font-size: var(--fs-label); }
.ed-strip-line { margin: 0; color: var(--c-muted); }
.ed-problems { list-style: none; margin: var(--sp-xs) 0 0; padding: var(--sp-sm) var(--sp-md); border: 1px solid var(--c-danger); border-radius: 6px; background: var(--c-danger-bg); color: var(--c-danger); }
.ed-problems li + li { margin-top: var(--sp-xs); }
.ed-mark { display: inline-flex; flex: 0 0 16px; width: 16px; height: 16px; margin-right: auto; }
.ed-mark svg { width: 16px; height: 16px; }
.ed-mark.is-saved { color: var(--c-ok); }
.ed-mark.is-failed { color: var(--c-danger); }
.ed-mark.is-saving { color: var(--c-muted); }
/* width 0 + min-width 100%: the box fills its cell but never makes the column wider (no layout shift) */
.grid-admin input.ed-input {
  display: block; width: 0; min-width: 100%; height: 32px; min-height: 32px; margin: 0; padding: 0 var(--sp-xs);
  border: 2px solid var(--c-accent); border-radius: 4px; background: #fff; color: var(--c-text);
  font: inherit; font-size: var(--fs-body); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; text-align: center;
}
.grid-admin input.ed-input:focus, .grid-admin input.ed-input:focus-visible { outline: none; }
.ed-prompt { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: var(--sp-sm) var(--sp-md); background: var(--c-surface); border-top: 1px solid var(--c-border); }
.ed-prompt-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-md); min-height: 56px; }
.ed-prompt-text { margin: 0 auto 0 0; }
/* Patterns (plan 02-03): placeholder for a blank pattern and the "Only tyres with no pattern" pass */
.ed-blank { font-size: var(--fs-label); font-weight: var(--fw-regular, 400); color: var(--c-muted); border-bottom: 1px dashed var(--c-muted); }
.ed-sep { white-space: pre; }
.ed-blankrow { display: flex; flex: 1 0 100%; flex-wrap: wrap; align-items: center; gap: 0 var(--sp-md); min-height: 44px; }
.ed-blankonly { display: inline-flex; align-items: center; gap: var(--sp-sm); min-height: 44px; margin: 0; cursor: pointer; }
.ed-blankonly input { width: 20px; height: 20px; flex: none; margin: 0; }
.ed-blankcount { font-size: var(--fs-label); color: var(--c-muted); }
@media (min-width: 720px) {
  .ed-phone-note { display: none; }
  .grid-admin .grid-scroll { max-height: calc(100vh - 280px); scroll-padding-top: 40px; scroll-padding-left: 120px; }
  .grid-admin .entry-price { position: relative; display: flex; align-items: center; justify-content: center; gap: var(--sp-xs); min-height: 32px; }
  /* The saved mark is taken out of the flow so the price stays centred under the brand name */
  .grid-admin .entry-price .ed-mark { position: absolute; left: 0; top: 8px; margin: 0; }
  .grid-admin .entry-price:has(.is-editing) .ed-mark { visibility: hidden; }
  .grid-admin [data-ed] { display: block; flex: 0 1 auto; min-width: 0; padding: 0 var(--sp-xs); line-height: 32px; border-radius: 4px; cursor: cell; }
  .grid-admin [data-ed]:focus, .grid-admin [data-ed]:focus-visible { outline: 2px solid var(--c-accent); outline-offset: -2px; }
  .grid-admin [data-ed].is-editing { flex: 1 1 auto; padding: 0; outline: none; }
  .grid-admin .grid-table tbody tr:not(.band-row) td.is-failed { background: var(--c-danger-bg); }
  .grid-admin .entry-sub { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; min-height: 24px; }
  .grid-admin .ed-blank { white-space: nowrap; }
  .grid-admin .entry-sub .entry-brand { flex: 0 0 auto; }
  .grid-admin [data-ed="pattern"] { line-height: 24px; }
  .grid-admin [data-ed="pattern"].ed-blank { border-radius: 4px 4px 0 0; }
  .grid-admin input.ed-input.ed-input-pattern { height: 24px; min-height: 24px; font-size: var(--fs-label); font-weight: 400; }
  /* The pattern pass uses its own classes, never is-hidden, so it combines with the size, brand and group filters.
     A tyre filled in during the pass (ed-keep) stays in view until the box is unticked: nothing jumps while typing. */
  .ed-blank-only .entry:not([data-blank]):not(.ed-keep), .ed-blank-only tr.ed-noblank { display: none; }
  .ed-blank-only .entry { border-top: 0; margin-top: 0; padding-top: 0; }
  /* Add and remove (plan 02-04). One .ed-tools and one .ed-add exist; grid-edit.js moves them under the pointer.
     Hidden means visibility: hidden (never transparent), so a hidden control cannot be clicked. */
  .grid-admin .grid-table tbody td { position: relative; }
  .grid-admin .entry { position: relative; }
  .grid-admin td.ed-empty { cursor: cell; }
  .grid-admin td.ed-empty:focus, .grid-admin td.ed-empty:focus-visible { outline: 2px solid var(--c-accent); outline-offset: -2px; }
  .grid-admin td.ed-empty:empty:hover::after, .grid-admin td.ed-empty:empty:focus::after {
    content: 'Add price'; display: block; text-align: center; line-height: 32px; font-size: var(--fs-label); color: var(--c-muted);
  }
  .ed-tools, .ed-add { position: absolute; left: 0; visibility: hidden; }
  /* Three controls share the 32px strip on the left of a cell, stacked so none sits on another and none
     covers a price: remove, history (plan 02-07), then "+" at the foot of the cell. Each is 32 x 24. */
  .ed-tools { top: calc(-1 * var(--sp-sm)); display: flex; flex-direction: column; }
  .entry + .entry > .ed-tools { top: calc(-1 * var(--sp-xs)); }
  .ed-add { left: var(--sp-sm); bottom: 0; }
  .ed-add, .ed-remove, .ed-history {
    display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 24px; min-height: 24px; margin: 0; padding: 0;
    border: 1px solid var(--c-border); border-radius: 4px; background: var(--c-surface); color: var(--c-muted); cursor: pointer;
  }
  .ed-add svg, .ed-remove svg, .ed-history svg { width: 16px; height: 16px; pointer-events: none; }
  .ed-history:hover { color: var(--c-accent); border-color: var(--c-accent); }
  .ed-add:hover { color: var(--c-accent); border-color: var(--c-accent); }
  .ed-remove:hover { color: var(--c-danger); border-color: var(--c-danger); }
  .entry:hover > .ed-tools, td:hover > .ed-add { visibility: visible; }
  /* Nothing may cover the box while a value is being typed */
  .entry:has(.is-editing) > .ed-tools, td:has(.is-editing) > .ed-add { visibility: hidden; }
  .ed-blank-only .ed-tools, .ed-blank-only .ed-add, .ed-blank-only .ed-draft { display: none; }
  .grid-admin .ed-draft { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-xs); }
  .entry + .ed-draft { border-top: 1px solid var(--c-border); margin-top: var(--sp-xs); padding-top: var(--sp-xs); }
  .grid-admin .ed-draft input.ed-input-pattern { text-align: center; }
  .grid-admin select.ed-brandpick {
    display: block; width: 0; min-width: 100%; height: 32px; min-height: 32px; margin: 0; padding: 0 var(--sp-xs);
    border: 2px solid var(--c-accent); border-radius: 4px; background: #fff; color: var(--c-text); font: inherit; font-size: var(--fs-label);
  }
}
/* Last changed and price history (plan 02-07, admin only) */
.row-changed { margin-top: var(--sp-xs); font-size: var(--fs-label); font-weight: var(--fw-regular, 400); line-height: 1.5; color: var(--c-muted); white-space: nowrap; }
.ed-history-dialog { width: calc(100% - 2 * var(--sp-md)); max-width: 560px; }
.ed-history-now { margin: 0 0 var(--sp-md); }
.ed-history-scroll { max-height: 50vh; overflow: auto; }
.ed-history-scroll .table { font-variant-numeric: tabular-nums; }
.ed-history-status { margin: var(--sp-sm) 0 0; min-height: 18px; }
.ed-history-note, .history-note { display: block; font-size: var(--fs-label); color: var(--c-muted); }
.history-table { font-variant-numeric: tabular-nums; }
.history-now { margin: 0 0 var(--sp-md); }
.history-links { margin-top: var(--sp-md); }
.log-history { margin-left: var(--sp-xs); font-size: var(--fs-label); white-space: nowrap; }
@media (max-width: 719px) {
  .ed-addnew { display: none; }
  /* the one admin extra in a card: the read-only "Changed" line, right-aligned beside the size */
  .grid-admin .grid-table tbody .col-size { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--sp-sm); }
  .grid-admin .col-size .row-changed { margin: 0 0 0 auto; }
  .ed-hint, .ed-strip, .ed-prompt, .ed-mark, .ed-blankrow { display: none; }
  .ed-tools, .ed-add, .ed-draft, .ed-empty::after { display: none; }
  /* a blank pattern looks exactly as in Phase 1 on a phone: no placeholder, no dangling dot, no empty line */
  .ed-blank { display: none; }
  .grid-admin .entry[data-blank] .ed-sep { display: none; }
  .grid-admin td:not([data-others]) .entry[data-blank] .entry-sub { display: none; }
}


/* Phase 2: Add size or brand form (S7, admin only) */
.tn-card { max-width: 640px; }
.tn-intro { margin: 0 0 var(--sp-md); }
.tn-group { border: 0; padding: 0; margin: 0 0 var(--sp-md); min-width: 0; }
.tn-group legend { padding: 0; font-size: var(--fs-label); font-weight: var(--fw-semibold); margin-bottom: var(--sp-xs); }
.tn-radios { display: flex; flex-wrap: wrap; gap: 0 var(--sp-lg); }
.tn-radio { display: inline-flex; align-items: center; gap: var(--sp-sm); min-height: 44px; cursor: pointer; }
.tn-radio input { width: 20px; height: 20px; flex: none; margin: 0; }
.tn-price { display: flex; align-items: center; gap: var(--sp-sm); }
.tn-price input { max-width: 200px; }
.tn-prefix { color: var(--c-muted); }
.tn-only { border-top: 1px solid var(--c-border); padding-top: var(--sp-md); }
.tn-only-note { margin: 0 0 var(--sp-sm); }
.tn-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-md); margin-top: var(--sp-lg); }
.tn-card .flash a { color: inherit; font-weight: var(--fw-semibold); }
@media (max-width: 719px) {
  .tn-actions .btn { width: 100%; }
}

/* Phase 2: change log (S9, admin only) */
.log-intro { margin: 0 0 var(--sp-md); }
.log-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-md); margin-bottom: var(--sp-md); }
.log-filters .field { margin-bottom: 0; flex: 1 1 140px; min-width: 0; }
.log-filters .field input, .log-filters .field select { width: 100%; }
.log-filters input[type="date"] {
  min-height: 44px; padding: var(--sp-sm) 12px; font: inherit; color: var(--c-text);
  background: var(--c-surface); border: 1px solid #d1d5db; border-radius: 6px;
}
.log-filter-actions { display: flex; gap: var(--sp-sm); flex: 0 0 auto; }
.log-echo { margin: 0 0 var(--sp-md); }
.log-table td { font-variant-numeric: tabular-nums; }
.log-row:target td { background: var(--c-ok-bg); }
.log-when { white-space: nowrap; }
.log-source .badge, .log-undo .badge { white-space: nowrap; }
.log-tyre { overflow-wrap: anywhere; }
.log-change { font-size: var(--fs-body); overflow-wrap: anywhere; }
.log-label { display: block; font-size: var(--fs-label); color: var(--c-muted); }
.log-undo { min-width: 180px; }
.log-undo .btn { min-height: 44px; display: inline-flex; align-items: center; gap: var(--sp-xs); }
.log-undo-form { margin: 0; }
.log-note { display: block; font-size: var(--fs-label); margin-top: var(--sp-xs); }
span.log-note { color: var(--c-text); }
.log-phone-note { display: none; font-size: var(--fs-label); color: var(--c-muted); }
@media (max-width: 959px) {
  .log-filters .field { flex-basis: 100%; }
  .log-filter-actions { flex-basis: 100%; }
}
/* Phones: each entry is a card; the log is readable but Undo is not offered. */
@media (max-width: 719px) {
  .log-table, .log-table tbody, .log-table tr, .log-table td { display: block; width: auto; }
  .log-table thead { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); }
  .log-table tr { border: 1px solid var(--c-border); border-radius: 8px; background: var(--c-surface); padding: var(--sp-sm) var(--sp-md); margin-bottom: var(--sp-sm); }
  .log-table td { border-bottom: 0; padding: var(--sp-xs) 0; }
  .log-table td:empty { display: none; }
  .log-when, .log-who { display: inline-block !important; font-size: var(--fs-label); color: var(--c-muted); margin-right: var(--sp-sm); }
  .log-undo { min-width: 0; }
  .log-undo-form { display: none; }
  .log-phone-note { display: block; }
  .log-filter-actions .btn { flex: 1 1 0; }
}

/* Phase 2: bulk change (S8, admin only) */
.bulk-phone-note { display: none; }
.bulk-form { max-width: 720px; }
.bulk-amount { display: flex; align-items: center; gap: var(--sp-sm); }
.bulk-amount input { max-width: 200px; }
.bulk-suffix { color: var(--c-muted); font-weight: var(--fw-semibold); }
.bulk-rule { background: var(--c-row); border: 1px solid var(--c-border); border-radius: 6px; padding: var(--sp-sm) var(--sp-md); margin: 0 0 var(--sp-md); }
.bulk-rule-label { margin: 0 0 var(--sp-xs); font-size: var(--fs-label); font-weight: var(--fw-semibold); color: var(--c-muted); }
.bulk-rule-text { margin: 0; }
.bulk-page.has-preview { padding-bottom: 120px; }
.bulk-summary { margin: 0 0 var(--sp-md); }
.bulk-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-md); margin-bottom: var(--sp-md); }
.bulk-tiles .tile { background: var(--c-surface); border: 1px solid var(--c-border); border-left: 4px solid var(--c-border); border-radius: 8px; padding: var(--sp-md); }
.bulk-tiles .tile-num { font-size: 28px; font-weight: var(--fw-semibold); line-height: 1.2; margin: 0; font-variant-numeric: tabular-nums; }
.bulk-tiles .tile-label { font-size: var(--fs-label); color: var(--c-muted); margin: 0; }
.bulk-tiles .tile-warn { border-left-color: var(--c-review); }
.bulk-tiles .tile-block { border-left-color: var(--c-danger); }
.bulk-tiles .tile-block .tile-num { color: var(--c-danger); }
.bulk-chips { display: flex; flex-wrap: wrap; gap: var(--sp-sm); margin-bottom: var(--sp-md); }
.bulk-chips[hidden] { display: none; }
.bulk-chips .chip { min-height: 36px; padding: var(--sp-xs) var(--sp-md); border: 1px solid var(--c-border); border-radius: 999px; background: var(--c-surface); color: inherit; font: inherit; cursor: pointer; }
.bulk-chips .chip.is-active { background: var(--c-border); font-weight: var(--fw-semibold); }
.bulk-scroll { overflow: auto; max-height: calc(100vh - 360px); min-height: 240px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px; }
.bulk-table { width: 100%; }
.bulk-table thead th { position: sticky; top: 0; z-index: 2; }
.bulk-table td, .bulk-table th { font-variant-numeric: tabular-nums; }
.bulk-table .num { text-align: right; white-space: nowrap; }
.bulk-table tbody td:first-child { border-left: 4px solid transparent; white-space: nowrap; }
.bulk-table .pv-new { font-weight: var(--fw-semibold); }
.bulk-table .pv-same td { color: var(--c-muted); }
.bulk-table .pv-same td:first-child { border-left-color: var(--c-border); }
.bulk-table .pv-warn td { background: var(--c-review-bg); }
.bulk-table .pv-warn td:first-child { border-left-color: var(--c-review); }
.bulk-table .pv-block td { background: var(--c-danger-bg); }
.bulk-table .pv-block td:first-child { border-left-color: var(--c-danger); }
.pv-note .badge { white-space: nowrap; }
.pv-note-text { font-size: var(--fs-label); }
.bulk-footer .bulk-counters { font-variant-numeric: tabular-nums; }
.bulk-footer .bulk-helper { max-width: 520px; }
@media (max-width: 719px) {
  .bulk-body, .bulk-footer { display: none; }
  .bulk-phone-note { display: block; }
  .bulk-page.has-preview { padding-bottom: 0; }
}

/* Phase 2: change log, bulk runs (S9 run entry, S10 run details; admin only) */
.log-run { margin-top: var(--sp-xs); font-size: var(--fs-label); }
.log-run summary { display: inline-flex; align-items: center; gap: var(--sp-xs); min-height: 32px; cursor: pointer; color: var(--c-accent); list-style: none; }
.log-run summary::-webkit-details-marker { display: none; }
.log-run[open] .icon { transform: rotate(180deg); }
.log-run-scroll { max-height: 480px; overflow: auto; margin-top: var(--sp-xs); border: 1px solid var(--c-border); border-radius: 6px; }
.log-run-table { width: 100%; }
.log-run-table thead th { position: sticky; top: 0; }
.log-run-table .num, .run-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-run-open { display: inline-block; margin-top: var(--sp-xs); font-size: var(--fs-label); }
.run-meta { margin: 0 0 var(--sp-md); }
.run-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 200px)); gap: var(--sp-md); margin-bottom: var(--sp-md); }
.run-tiles .tile { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px; padding: var(--sp-md); }
.run-tiles .tile-num { font-size: 28px; font-weight: var(--fw-semibold); line-height: 1.2; margin: 0; font-variant-numeric: tabular-nums; }
.run-tiles .tile-label { font-size: var(--fs-label); color: var(--c-muted); margin: 0; }
.run-table .run-new { font-weight: var(--fw-semibold); }
.run-links { margin-top: var(--sp-md); display: flex; flex-wrap: wrap; gap: var(--sp-md); }
/* Undo of a whole run: the button with its confirm dialog (S9, S10) and the result page (S10). */
.log-run-state { white-space: nowrap; color: var(--c-muted); }
.log-undo dialog, .run-actions dialog { font-size: var(--fs-body); white-space: normal; text-align: left; }
.run-actions { margin-top: var(--sp-md); }
.run-actions .btn { min-height: 44px; display: inline-flex; align-items: center; gap: var(--sp-xs); }
.run-actions .badge { white-space: nowrap; }
.run-summary { margin: 0 0 var(--sp-md); font-weight: var(--fw-semibold); }
.run-section { margin-bottom: var(--sp-lg); }
.run-section .subheading { margin: 0 0 var(--sp-xs); }
.run-section .meta { margin: 0 0 var(--sp-sm); }
.run-left .run-table tbody td:first-child { border-left: 4px solid var(--c-review); }
@media (max-width: 719px) {
  .log-run-table, .log-run-table tbody { display: table; width: 100%; }
  .log-run-table tr { display: table-row; border: 0; padding: 0; margin: 0; }
  .log-run-table td, .log-run-table th { display: table-cell; padding: var(--sp-xs) var(--sp-sm); border-bottom: 1px solid var(--c-border); }
  .log-run-table thead { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; display: table-header-group; }
}

/* Phase 2: account (S12 change my password; both roles) */
.account-card { width: 100%; max-width: 400px; }
.account-card .field-error { margin-bottom: 0; }
.account-cancel { margin: var(--sp-sm) 0 0; text-align: center; }
.account-cancel .btn { min-height: 44px; display: inline-flex; align-items: center; }
a.nav-user { text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.nav-account { font-size: var(--fs-label); color: #d1d5db; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
a.nav-user:hover, .nav-account:hover { text-decoration: underline; color: #fff; }

/* Phase 2: banners (S13 Import page warning; admin only) */
.banner { display: flex; align-items: flex-start; gap: var(--sp-sm); border: 1px solid; border-radius: 6px; padding: var(--sp-md); margin-bottom: var(--sp-md); }
.banner-warn { color: var(--c-review); background: var(--c-review-bg); border-color: var(--c-review); }
.banner-icon { flex: 0 0 auto; margin-top: 2px; }
.banner-text { min-width: 0; }
.banner-text p { margin: 0 0 var(--sp-xs); }
.banner-text p:last-child { margin-bottom: 0; }
.banner-title { font-weight: var(--fw-semibold); }
.banner-meta { font-size: var(--fs-label); }
.banner a { color: var(--c-accent); }
.import-warn-line { margin-bottom: 0; }

/* API keys (Phase 4): the list is a table on a wide screen and one card per key on a phone,
   so the Revoke button is never off-screen to the right. */
.keys-table .badge { white-space: nowrap; }
.keys-table td { vertical-align: middle; }
.keys-action { text-align: right; }
@media (max-width: 719px) {
  .keys-table, .keys-table tbody, .keys-table tr, .keys-table td { display: block; }
  .keys-table thead {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
  }
  .keys-table tr {
    background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px;
    padding: var(--sp-md); margin-bottom: var(--sp-md);
  }
  .keys-table td { border: 0; padding: var(--sp-xs) 0; }
  .keys-table td[data-label] { display: flex; gap: var(--sp-sm); align-items: baseline; }
  .keys-table td[data-label]::before {
    content: attr(data-label); flex: 0 0 112px; font-size: var(--fs-label); font-weight: var(--fw-semibold);
  }
  .keys-table .keys-app { font-weight: var(--fw-semibold); overflow-wrap: anywhere; }
  .keys-table .keys-action { text-align: left; }
  .keys-table .keys-action:empty, .keys-table .keys-action:not(:has(button)) { display: none; }
  .keys-table .keys-action > .btn { margin-top: var(--sp-xs); }
}

/* Import history on a phone: one card per import, so Status and the links are never off-screen
   (they are all that is left on the page once importing is switched off). Desktop is unchanged. */
@media (max-width: 719px) {
  .imports-table, .imports-table tbody, .imports-table tr, .imports-table td { display: block; }
  .imports-table thead {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
  }
  .imports-table tr {
    background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px;
    padding: var(--sp-md); margin-bottom: var(--sp-md);
  }
  .imports-table td, .table.imports-table td.num { border: 0; padding: var(--sp-xs) 0; text-align: left; }
  .imports-table td[data-label] { display: flex; gap: var(--sp-sm); align-items: baseline; }
  .imports-table td[data-label]::before {
    content: attr(data-label); flex: 0 0 128px; font-size: var(--fs-label); font-weight: var(--fw-semibold);
  }
  .imports-table .imports-file { font-weight: var(--fw-semibold); overflow-wrap: anywhere; }
  .imports-table .imports-file .meta { font-weight: var(--fw-regular, 400); }
  .imports-table .imports-none { display: none; }
  .imports-table .imports-links { display: flex; flex-wrap: wrap; gap: var(--sp-xs) var(--sp-md); padding-top: var(--sp-sm); }
}
