/* Parts Ledger stylesheet.
   A quiet, minimal system: one neutral scale, hairline borders instead of shadows, a single accent
   reserved for links and focus, and status colours that meet WCAG AA on their backgrounds.
   Order: tokens, base elements, app shell, shared components, page layouts, responsive rules. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f3f3f5;
  --surface-3: #e9e9ec;
  --border: #e3e3e7;
  --border-strong: #cfcfd5;
  --input-border: #8e8e93;
  --text: #1c1c1e;
  --text-2: #68686e;
  --placeholder: #8e8e93;
  --accent: #2857d8;
  --accent-soft: #e8eefc;
  --focus: #2857d8;
  --primary: #1c1c1e;
  --primary-hover: #333336;
  --on-primary: #ffffff;
  --danger: #b4231b;
  --danger-bg: #fdecea;
  --success: #1a7a3e;
  --success-bg: #e6f6ec;
  --warn: #8a5300;
  --warn-bg: #fff3df;
  --code-bg: #efeff2;
  --overlay: rgb(28 28 30 / .4);
  --shadow-pop: 0 8px 24px rgb(28 28 30 / .1), 0 0 0 1px var(--border);
  --shadow-modal: 0 24px 64px rgb(28 28 30 / .22);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 224px;
  --content-max: 1080px;
  --form-max: 680px;
  --tabbar-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0e10;
  --surface: #171719;
  --surface-2: #1f1f22;
  --surface-3: #28282c;
  --border: #2a2a2f;
  --border-strong: #3c3c43;
  --input-border: #6e6e76;
  --text: #f2f2f4;
  --text-2: #a4a4ab;
  --placeholder: #7c7c84;
  --accent: #86a9ff;
  --accent-soft: #1d2740;
  --focus: #86a9ff;
  --primary: #f2f2f4;
  --primary-hover: #dcdce0;
  --on-primary: #1c1c1e;
  --danger: #ff8a80;
  --danger-bg: #3a1a18;
  --success: #6fd394;
  --success-bg: #14301f;
  --warn: #f2b45a;
  --warn-bg: #3a2a10;
  --code-bg: #26262b;
  --overlay: rgb(0 0 0 / .55);
  --shadow-pop: 0 8px 24px rgb(0 0 0 / .5), 0 0 0 1px var(--border-strong);
  --shadow-modal: 0 24px 64px rgb(0 0 0 / .6);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e0e10;
    --surface: #171719;
    --surface-2: #1f1f22;
    --surface-3: #28282c;
    --border: #2a2a2f;
    --border-strong: #3c3c43;
  --input-border: #6e6e76;
    --text: #f2f2f4;
    --text-2: #a4a4ab;
    --placeholder: #7c7c84;
    --accent: #86a9ff;
    --accent-soft: #1d2740;
    --focus: #86a9ff;
    --primary: #f2f2f4;
    --primary-hover: #dcdce0;
    --on-primary: #1c1c1e;
    --danger: #ff8a80;
    --danger-bg: #3a1a18;
    --success: #6fd394;
    --success-bg: #14301f;
    --warn: #f2b45a;
    --warn-bg: #3a2a10;
    --code-bg: #26262b;
    --overlay: rgb(0 0 0 / .55);
    --shadow-pop: 0 8px 24px rgb(0 0 0 / .5), 0 0 0 1px var(--border-strong);
    --shadow-modal: 0 24px 64px rgb(0 0 0 / .6);
  }
}

/* ---------- Base elements ---------- */
html { font-family: var(--font); font-size: 15px; color: var(--text); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body { margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
h1, h2, h3, p, dl, dd, figure { margin: 0; }
h1 { font-size: 1.75rem; line-height: 1.2; font-weight: 600; letter-spacing: -.02em; overflow-wrap: anywhere; }
h2 { font-size: 1rem; line-height: 1.4; font-weight: 600; }
h3 { font-size: .9375rem; font-weight: 600; }
strong { font-weight: 600; }
small { display: block; font-size: .8125rem; line-height: 1.45; color: var(--text-2); }
code { display: inline-block; padding: 0 6px; border-radius: 5px; background: var(--code-bg); color: var(--text); font: 500 .8125rem/1.6 var(--mono); white-space: nowrap; }
hr { margin: 20px 0; border: 0; border-top: 1px solid var(--border); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }
.icon { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon.small { width: 15px; height: 15px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- App shell ---------- */
.app-shell { min-height: 100dvh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 2px; padding: 18px 12px 14px; border-right: 1px solid var(--border); background: var(--bg); overflow-y: auto; }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); font-size: .9375rem; font-weight: 600; letter-spacing: -.01em; text-decoration: none; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 7px; background: var(--primary); color: var(--on-primary); font: 600 .625rem var(--mono); letter-spacing: .02em; }
.sidebar .brand { margin: 2px 8px 22px; }
.nav-group { display: grid; gap: 1px; margin-bottom: 18px; }
.nav-group-label { display: none; }
.nav-link { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-size: .9rem; font-weight: 500; text-decoration: none; transition: background-color .12s, color .12s; }
.nav-link .icon { color: var(--text-2); }
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--surface-3); color: var(--text); font-weight: 600; }
.nav-link[aria-current="page"] .icon { color: var(--text); }
.sidebar-bottom { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
.theme-toggle { width: 100%; justify-content: flex-start; gap: 10px; min-height: 36px; padding: 6px 10px; background: transparent; border-color: transparent; color: var(--text-2); font-weight: 500; }
.theme-toggle:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }
:root[data-theme="dark"] .theme-toggle .icon-sun, :root:not([data-theme="dark"]) .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; } :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; } }
.topbar, .tabbar, .sheet { display: none; }
main { min-width: 0; padding: 44px clamp(24px, 5vw, 56px) 88px; }
main > * { width: min(100%, var(--content-max)); }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-head > div:first-child { min-width: 0; }
.page-head .lede { margin-top: 6px; max-width: 560px; color: var(--text-2); }
.page-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; flex: 0 0 auto; }
.page-actions.start { justify-content: flex-start; }
.detail-actions { margin-bottom: 28px; }
.eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text-2); font-size: .875rem; }
.back { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; margin-bottom: 6px; color: var(--text-2); font-size: .875rem; font-weight: 500; }
.back:hover { color: var(--text); text-decoration: none; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.section-head a, .card-head a { font-size: .875rem; }

/* ---------- Buttons ---------- */
.button, button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 7px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: .875rem; line-height: 1.3; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; transition: background-color .12s, border-color .12s, color .12s; }
.button:hover, button:hover { background: var(--surface-2); text-decoration: none; }
.button.primary, button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.button.primary:hover, button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.button.quiet, button.quiet { background: transparent; border-color: transparent; color: var(--text-2); }
.button.quiet:hover, button.quiet:hover { background: var(--surface-3); color: var(--text); }
.button.danger, button.danger { color: var(--danger); }
.button.danger:hover, button.danger:hover { background: var(--danger-bg); border-color: transparent; }
.button.small, button.small { min-height: 30px; padding: 4px 10px; font-size: .8125rem; }
.button.block { width: 100%; }
button:disabled { opacity: .5; cursor: not-allowed; }
.segmented { display: inline-flex; padding: 2px; border-radius: var(--radius-sm); background: var(--surface-3); }
.segmented a { display: inline-flex; align-items: center; min-height: 30px; padding: 3px 12px; border-radius: 5px; color: var(--text-2); font-size: .8125rem; font-weight: 500; }
.segmented a:hover { color: var(--text); text-decoration: none; }
.segmented a[aria-current="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }

/* ---------- Surfaces ---------- */
.card { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.card > h2:first-child { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card-intro { margin: -6px 0 14px; }
.stack { display: grid; gap: 16px; align-content: start; }
.empty { padding: 28px 20px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); font-size: .9rem; text-align: center; }
.card .empty { padding: 20px; border: 0; background: var(--surface-2); }
.copy { color: var(--text-2); font-size: .875rem; }
.copy + form, .copy + .button, .copy + a, .copy + .theme-options { margin-top: 14px; }
.flash { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 20px; padding: 11px 14px; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 500; }
.flash .icon { margin-top: 1px; }
.flash.success { color: var(--success); background: var(--success-bg); }
.flash.error { color: var(--danger); background: var(--danger-bg); }

/* ---------- Status and numbers ---------- */
.qty { display: inline-flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.qty span { font-size: .8125rem; font-weight: 400; color: var(--text-2); }
.qty.low { color: var(--warn); }
.qty.out { color: var(--danger); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 500; line-height: 1.6; white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.neutral { background: var(--surface-3); color: var(--text-2); }
.positive { color: var(--success); font-weight: 600; }
.danger-text { color: var(--danger); font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { padding: 10px 16px; color: var(--text-2); font-size: .75rem; font-weight: 500; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
td { padding: 11px 16px; border-top: 1px solid var(--border); vertical-align: middle; overflow-wrap: anywhere; }
tbody tr:first-child td { border-top: 0; }
td a { font-weight: 500; color: var(--text); }
td a:hover { color: var(--accent); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td .empty { padding: 8px 0; border: 0; background: transparent; }

/* ---------- Forms ---------- */
label { display: block; font-size: .875rem; font-weight: 500; color: var(--text); }
.form label, .adjust label, dialog label { margin-bottom: 16px; }
.form { width: min(100%, var(--form-max)); }
:where(input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea) { width: 100%; min-width: 0; min-height: 40px; margin-top: 6px; padding: 8px 12px; border: 1px solid var(--input-border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 16px; transition: border-color .12s, box-shadow .12s; }
@media (min-width: 961px) { :where(input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea) { font-size: .9375rem; } }
input[type="file"] { display: block; width: 100%; margin-top: 6px; padding: 8px 0; font-size: .875rem; color: var(--text-2); }
input[type="file"]::file-selector-button { margin-right: 10px; min-height: 30px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; font-size: .8125rem; font-weight: 500; cursor: pointer; }
input:not([type="hidden"]):focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>"); background-position: calc(100% - 12px) 50%; background-repeat: no-repeat; }
textarea { resize: vertical; }
input[type="checkbox"] { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; min-height: 28px; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-section { margin-bottom: 6px; padding-top: 20px; border-top: 1px solid var(--border); }
.form-section:first-of-type { padding-top: 0; border-top: 0; }
.form-section > h2 { margin-bottom: 2px; }
.form-section > .copy { margin-bottom: 16px; }
.guided-fields { margin: 0 0 16px; padding: 12px 14px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.guided-fields legend { padding: 0 6px; color: var(--text-2); font-size: .8125rem; font-weight: 500; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.form .hint { margin: -8px 0 16px; }
.optional { color: var(--text-2); font-weight: 400; }
form details { margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
form details summary { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; cursor: pointer; font-size: .875rem; font-weight: 500; list-style: none; }
form details summary::-webkit-details-marker { display: none; }
form details summary::after { content: '+'; color: var(--text-2); font-size: 1.125rem; line-height: 1; }
form details[open] summary::after { content: '−'; }
form details > :not(summary) { margin-left: 14px; margin-right: 14px; }
form details[open] summary { margin-bottom: 14px; border-bottom: 1px solid var(--border); }

/* ---------- Search ---------- */
.search { display: flex; align-items: stretch; gap: 8px; width: min(100%, var(--form-max)); margin: 0 0 20px; }
.search-field { position: relative; flex: 1; min-width: 0; }
.search-field > .icon { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--placeholder); pointer-events: none; }
.search-field input { margin: 0; height: 100%; padding-left: 38px; }
.search button { flex: 0 0 auto; }
.search.large input { min-height: 46px; font-size: 1rem; }
.suggestions { position: absolute; z-index: 20; top: calc(100% + 6px); width: 100%; overflow: auto; max-height: 55vh; border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow-pop); }
.suggestions a { display: block; padding: 10px 14px; color: var(--text); font-weight: 500; text-decoration: none; border-bottom: 1px solid var(--border); }
.suggestions a:last-child { border-bottom: 0; }
.suggestions a:hover, .suggestions a:focus-visible { background: var(--surface-2); outline: none; }
.suggestions span { display: block; margin-top: 1px; font-size: .8125rem; font-weight: 400; color: var(--text-2); }
.search-panel { width: min(100%, var(--form-max)); margin-bottom: 20px; }
.search-panel label { margin-bottom: 0; }
.search-panel .search { margin: 0; width: 100%; }

/* ---------- Lists of records ---------- */
.record-list { display: grid; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.record { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; }
.record:first-child { border-top: 0; }
a.record:hover { background: var(--surface-2); text-decoration: none; }
.record > div:first-child { min-width: 0; }
.record strong { display: block; overflow-wrap: anywhere; font-weight: 500; }
.record small { margin-top: 2px; }
.record .qty { flex: 0 0 auto; }
.record.is-selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.record-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.record-list .empty { border: 0; border-radius: 0; }
.card .record-list { border: 0; border-radius: 0; background: transparent; overflow: visible; }
.card .record { padding: 11px 0; }
.card a.record:hover { background: transparent; }
.card a.record:hover strong { color: var(--accent); }

/* ---------- Dashboard ---------- */
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.metric { display: flex; flex-direction: column; gap: 4px; padding: 16px 20px; border-left: 1px solid var(--border); color: var(--text); text-decoration: none; }
.metric:first-child { border-left: 0; }
.metric span { color: var(--text-2); font-size: .8125rem; font-weight: 500; }
.metric strong { font-size: 1.75rem; line-height: 1.15; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
a.metric:hover { background: var(--surface-2); text-decoration: none; }
.metric.warning strong { color: var(--warn); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 16px; align-items: start; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.split.wide { grid-template-columns: minmax(0, 1.4fr) minmax(300px, .8fr); }

/* ---------- Components ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.toolbar .search { margin: 0; flex: 1 1 340px; }
.component-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.component-card { display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); transition: border-color .12s; }
.component-card:hover { border-color: var(--border-strong); }
.component-image { display: grid; width: 100%; height: 120px; place-items: center; place-content: center; gap: 2px; padding: 0; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: var(--surface-2); color: var(--placeholder); }
.component-image:hover { background: var(--surface-2); }
.component-image:not(:disabled) { cursor: zoom-in; }
.component-image:disabled { opacity: 1; cursor: default; }
.component-image img { width: 100%; height: 100%; object-fit: contain; }
.component-image .icon { width: 22px; height: 22px; }
.component-image small { font-size: .75rem; color: var(--placeholder); }
.component-card-body { display: flex; flex: 1; flex-direction: column; gap: 4px; padding: 14px 16px; }
.component-title { color: var(--text); font-weight: 500; line-height: 1.35; text-decoration: none; overflow-wrap: anywhere; }
.component-title:hover { color: var(--accent); text-decoration: none; }
.component-card-body p { color: var(--text-2); font-size: .8125rem; overflow-wrap: anywhere; }
.component-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 10px; }
.image-dialog { width: min(760px, calc(100% - 32px)); padding: 24px; }
.image-dialog img { display: block; width: 100%; max-height: 65dvh; object-fit: contain; }
.image-dialog p { margin: 12px 0 0; font-weight: 500; }
.image-dialog-close { position: absolute; right: 10px; top: 10px; min-height: 32px; min-width: 32px; padding: 0; }

/* ---------- Component detail ---------- */
.detail-head { align-items: stretch; }
.quantity-panel { display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 170px; padding: 14px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-align: right; }
.quantity-panel strong { font-size: 2rem; line-height: 1.1; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.quantity-panel span { color: var(--text-2); font-size: .8125rem; }
.quantity-panel.low strong, .quantity-panel.low span { color: var(--warn); }
.quantity-panel.out strong, .quantity-panel.out span { color: var(--danger); }
.attribute-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; }
.attribute-list div { min-width: 110px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.attribute-list dt { color: var(--text-2); font-size: .75rem; }
.attribute-list dd { margin-top: 1px; font-weight: 500; }
.notes { margin-bottom: 20px; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text-2); font-size: .9rem; white-space: pre-wrap; }

/* ---------- Stock ---------- */
.stock-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, .5fr); gap: 16px; align-items: start; }
.checkout-card { position: sticky; top: 20px; }
.checkout-card label { margin-top: 14px; }
.checkout-lines { max-height: 340px; overflow: auto; }
.checkout-line { display: grid; grid-template-columns: 1fr 80px auto; gap: 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.checkout-line:first-child { border-top: 0; }
.checkout-line > span { min-width: 0; }
.checkout-line strong { display: block; overflow-wrap: anywhere; font-size: .875rem; font-weight: 500; }
.checkout-line input { min-height: 34px; margin: 0; padding: 5px 9px; }
.checkout-line button { min-height: 34px; min-width: 34px; padding: 5px; }
.checkout-submit { width: 100%; margin-top: 14px; }
.checkout-fab { display: none; }
.transactions { margin-top: 28px; }

/* ---------- Storage ---------- */
.storage-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.storage-group { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; align-items: center; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; transition: border-color .12s; }
.storage-group:hover { border-color: var(--border-strong); text-decoration: none; }
.storage-group code { grid-row: span 2; align-self: center; padding: 6px 9px; font-size: .9375rem; }
.storage-group h2 { font-size: .9375rem; }
.storage-group span { color: var(--text-2); font-size: .8125rem; }
.storage-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; margin: 2px 0 12px; }
.storage-heading h2 { font-size: 1.125rem; }
.storage-heading small { display: inline; }
.drawer-list { display: grid; gap: 0; max-width: 820px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.drawer { border-top: 1px solid var(--border); }
.drawer:first-child { border-top: 0; }
.drawer summary { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 14px; padding: 11px 16px; cursor: pointer; list-style: none; }
.drawer summary:hover { background: var(--surface-2); }
.drawer summary::-webkit-details-marker { display: none; }
.drawer summary::after { content: ''; width: 8px; height: 8px; border-right: 1.5px solid var(--text-2); border-bottom: 1.5px solid var(--text-2); rotate: 45deg; translate: 0 -2px; transition: rotate .12s; }
.drawer[open] summary::after { rotate: -135deg; translate: 0 3px; }
.drawer summary span { font-weight: 500; overflow-wrap: anywhere; }
.drawer summary .badge { justify-self: end; }
.drawer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 2px 16px 14px; }
.drawer-list .empty { border: 0; border-radius: 0; }

/* ---------- Quick add ---------- */
.quick-hero { width: min(100%, var(--form-max)); margin-bottom: 16px; }
.quick-status { min-height: 1.4em; margin: -6px 0 16px; color: var(--text-2); font-size: .875rem; }
.quick-section { width: min(100%, var(--form-max)); margin-bottom: 26px; }
.quick-section > h2 { margin-bottom: 8px; }
.quick-section > p { margin-bottom: 8px; color: var(--text-2); font-size: .875rem; }
.quick-matches { display: grid; gap: 0; margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.quick-match { display: grid; grid-template-columns: 1fr auto; gap: 1px 14px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; }
.quick-match:first-child { border-top: 0; }
.quick-match:hover { background: var(--surface-2); text-decoration: none; }
.quick-match strong { font-weight: 500; overflow-wrap: anywhere; }
.quick-match span { color: var(--text-2); font-size: .8125rem; overflow-wrap: anywhere; }
.quick-match .cta { grid-column: 2; grid-row: 1 / span 3; color: var(--accent); font-size: .875rem; font-weight: 500; white-space: nowrap; }
.receive-form { width: min(100%, var(--form-max)); }
.receive-form .quantity-input { font-size: 1.375rem; font-weight: 600; min-height: 52px; }

/* ---------- Projects ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.project-card { display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; transition: border-color .12s; }
.project-card:hover { border-color: var(--border-strong); text-decoration: none; }
.project-card:hover h2 { color: var(--accent); }
.project-card img { width: 100%; height: 120px; object-fit: cover; border-bottom: 1px solid var(--border); }
.project-card > div { display: flex; flex: 1; flex-direction: column; gap: 4px; padding: 16px; }
.project-card p { color: var(--text-2); font-size: .8125rem; }
.project-card .badge { align-self: flex-start; margin-top: 10px; }
.project-search { display: flex; gap: 8px; }
.project-search input { margin: 0; }
.project-search-results { display: grid; gap: 8px; margin-top: 14px; }
.project-search-results form { display: grid; grid-template-columns: 1fr auto; gap: 1px 10px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.project-search-results strong, .project-search-results small { grid-column: 1 / -1; overflow-wrap: anywhere; }
.project-search-results strong { font-weight: 500; }
.inline-qty { display: flex; align-items: center; gap: 8px; grid-column: 1; margin: 8px 0 0; }
.inline-qty input { width: 76px; min-height: 34px; margin: 0; padding: 5px 9px; }
.project-search-results .button { grid-column: 2; margin-top: 8px; }

/* ---------- Reports and settings ---------- */
.report-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; width: min(100%, 720px); }
.report-card > div:first-child { display: flex; gap: 14px; align-items: flex-start; }
.report-card .icon { width: 20px; height: 20px; margin-top: 2px; color: var(--text-2); }
.report-card h2 { margin: 0 0 2px; }
.report-card p { color: var(--text-2); font-size: .875rem; }
.report-card .button-group { flex: 0 0 auto; }
.button-group { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.settings-grid h2 { margin-bottom: 2px; }
.settings-grid h2 + .copy { margin-bottom: 14px; }
.webhook-form, .feature-form, .password-form { display: grid; gap: 2px; }
.feature-form { gap: 8px; }
.feature-form .button, .password-form .button, .webhook-form .button { justify-self: start; margin-top: 6px; }
.webhook-form label, .password-form label { margin-bottom: 10px; }
.webhook-list { display: grid; gap: 0; margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.webhook-list > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--border); }
.webhook-list > div:first-child { border-top: 0; }
.webhook-list > div > span { min-width: 0; }
.webhook-list strong { font-weight: 500; }
.webhook-list small { overflow-wrap: anywhere; }
.webhook-list .empty { border: 0; border-radius: 0; }
.theme-options { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-options button[aria-pressed="true"] { background: var(--surface-3); border-color: var(--text); }

/* ---------- Dialogs ---------- */
dialog { width: min(520px, calc(100% - 32px)); max-height: 90dvh; overflow: auto; margin: auto; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-modal); }
dialog::backdrop { background: var(--overlay); }
dialog .form { width: 100%; padding: 24px; }
dialog .form > h2 { margin-bottom: 16px; font-size: 1.125rem; }

/* ---------- Access page ---------- */
body.access-page .sidebar, body.access-page .topbar, body.access-page .tabbar, body.access-page .sheet { display: none; }
body.access-page .app-shell { display: block; }
.access-panel { width: min(100%, 400px); margin: 10vh auto; }
.access-panel .brand { margin-bottom: 20px; }
.access-panel .copy { margin: 6px 0 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
  .topbar-actions { display: flex; gap: 2px; }
  .topbar-actions button { min-height: 36px; min-width: 36px; padding: 6px; background: transparent; border-color: transparent; color: var(--text-2); }
  .topbar-actions button:hover { background: var(--surface-3); color: var(--text); }
  .topbar-actions .icon-sun, .topbar-actions .icon-moon { display: block; }
  :root[data-theme="dark"] .topbar-actions .icon-sun, :root:not([data-theme="dark"]) .topbar-actions .icon-moon { display: none; }
  .sheet { position: fixed; inset: 0; z-index: 40; display: block; padding: 0; border: 0; background: var(--overlay); }
  .sheet[hidden] { display: none; }
  .sheet nav { position: absolute; left: 0; right: 0; top: 0; display: grid; gap: 1px; padding: 10px 12px 14px; background: var(--bg); border-bottom: 1px solid var(--border); border-radius: 0 0 14px 14px; box-shadow: var(--shadow-modal); }
  .sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 8px 10px; color: var(--text-2); font-size: .8125rem; font-weight: 500; }
  .sheet .sheet-head button { min-height: 34px; min-width: 34px; padding: 4px; background: transparent; border-color: transparent; color: var(--text-2); }
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 0 4px env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--border); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text-2); font-size: .6875rem; font-weight: 500; text-decoration: none; }
  .tabbar a .icon { width: 21px; height: 21px; }
  .tabbar a[aria-current="page"] { color: var(--text); font-weight: 600; }
  main { padding: 20px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px); }
  .page-head { flex-direction: column; gap: 14px; margin-bottom: 20px; }
  .page-actions { width: 100%; justify-content: flex-start; }
  .page-actions .button { flex: 1 1 auto; min-height: 42px; }
  .button, button { min-height: 40px; }
  .button.small, button.small { min-height: 34px; }
  .dashboard-grid, .split, .split.wide, .stock-layout, .settings-grid, .form-grid { grid-template-columns: 1fr; }
  .checkout-card { position: static; }
  .checkout-fab { position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 25; display: inline-flex; box-shadow: var(--shadow-pop); }
  .checkout-fab[hidden] { display: none; }
  .detail-head { flex-direction: column; }
  .quantity-panel { text-align: left; }
}
@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .card { padding: 16px; }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric { padding: 12px 10px; gap: 2px; }
  .metric strong { font-size: 1.375rem; }
  .metric span { font-size: .75rem; }
  .component-grid, .project-grid, .storage-groups { grid-template-columns: 1fr; }
  .component-card { flex-direction: row; }
  .component-image { width: 88px; height: auto; min-height: 88px; border-bottom: 0; border-right: 1px solid var(--border); }
  .component-image small { display: none; }
  .toolbar .search { flex-basis: 100%; }
  .search:not(.keep-button) button { display: none; }
  .report-card { flex-direction: column; align-items: stretch; }
  .drawer summary { grid-template-columns: auto 1fr auto; }
  .drawer summary .badge { grid-column: 2; justify-self: start; }
  .drawer summary span { grid-column: 2; }
  .drawer summary code { grid-row: span 2; }
  .drawer summary::after { grid-column: 3; grid-row: span 2; }
  .checkout-line { grid-template-columns: 1fr 70px auto; }
  .quick-match .cta { grid-row: auto; grid-column: 1; margin-top: 4px; }
  dialog .form { padding: 20px 16px; }
  /* Tables collapse into labelled cards. */
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  table, tbody, tr { display: block; width: 100%; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  tr { margin-bottom: 8px; padding: 4px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
  td { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border: 0; border-top: 1px solid var(--border); text-align: right; }
  td::before { content: attr(data-label); flex: 0 0 auto; color: var(--text-2); font-size: .75rem; font-weight: 500; text-align: left; }
  td:first-child { display: block; padding-bottom: 6px; border-top: 0; font-weight: 500; text-align: left; }
  td:first-child::before { display: none; }
  td[colspan] { display: block; text-align: center; }
  td[colspan]::before { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
