/* Entry stylesheet: only @imports, in cascade order (tokens first). Real rules live in css/. */
/* Design tokens: the ONLY place with raw colours. Dark by default, light via prefers-color-scheme. */
:root {
  color-scheme: dark;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* surfaces */
  --bg: #11141b; --surface: #181c26; --surface-2: #1f2430; --surface-3: #283040;
  --line: #2b3243; --line-strong: #3c465b; --hover: rgba(255, 255, 255, .06);
  --overlay: rgba(0, 0, 0, .55); --shadow: 0 6px 18px rgba(0, 0, 0, .45);
  /* text + accent */
  --text: #e8ecf4; --muted: #9aa5ba; --accent: #6f9cff; --on-accent: #0a0f1c; --on-solid: #fff;
  --danger: #ff7b7b;
  /* semantic status colours */
  --ok: #3fae5a; --warn: #e0a43a; --bad: #e05252; --info: #4f8cff;
  /* document kind colours */
  --k-quote: #4f8cff; --k-proforma: #e0a43a; --k-invoice: #3fae5a;
  --k-warranty: #8a4fe0; --k-receipt: #9aa3b5; --k-note: #35c4c4;
  /* derived tints (follow the colours above, also in the light theme) */
  --tint: 26%;
  --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);
  --ok-soft: color-mix(in srgb, var(--ok) var(--tint), transparent);
  --warn-soft: color-mix(in srgb, var(--warn) var(--tint), transparent);
  --bad-soft: color-mix(in srgb, var(--bad) var(--tint), transparent);
  --info-soft: color-mix(in srgb, var(--info) var(--tint), transparent);
  --input-bg: var(--bg); --focus: var(--accent);
  /* legacy names kept working */
  --glass: var(--surface); --glass-solid: var(--surface-2);
  --table-head: var(--surface-3); --table-row1: transparent;
  --table-row2: color-mix(in srgb, var(--text) 3.5%, transparent);
  --table-highlight: color-mix(in srgb, var(--accent) 22%, transparent);
  /* geometry */
  --r: .35rem; --r-lg: .5rem; --ctl-h: 2rem; --appbar-h: 2.75rem; --side-w: 12.5rem; --blur: none;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f2f4f8; --surface: #fff; --surface-2: #f7f9fc; --surface-3: #e9edf4;
    --line: #dde2ec; --line-strong: #c2cada; --hover: rgba(20, 30, 60, .06);
    --overlay: rgba(20, 28, 45, .4); --shadow: 0 6px 18px rgba(20, 30, 60, .18);
    --text: #1b2230; --muted: #5b6678; --accent: #2b62d9; --on-accent: #fff; --on-solid: #fff;
    --danger: #c62f2f;
    --ok: #1d8a3d; --warn: #b36f00; --bad: #c62f2f; --info: #2563d4;
    --k-quote: #2563d4; --k-proforma: #b36f00; --k-invoice: #1d8a3d;
    --k-warranty: #7a3fd0; --k-receipt: #6b7487; --k-note: #138a8a;
    --tint: 16%;
  }
}

/* Reset + typography + tiny utilities */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--appbar-h) + .5rem); }
body { margin: 0; min-height: 100vh; font: 14px/1.4 var(--font); color: var(--text); background: var(--bg);
  scrollbar-color: var(--line-strong) transparent; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: .6rem 0 .4rem; line-height: 1.2; font-weight: 600; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
h4 { font-size: .9rem; }
p { margin: .4rem 0; }
small { font-size: .85em; }
a { color: var(--accent); text-underline-offset: .15em; }
a:hover { text-decoration: underline; }
:where(a, button, summary, [tabindex]):focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
code, kbd, samp { font-family: var(--mono); font-size: .92em; }
code.rid { font-weight: 700; letter-spacing: .05em; }
hr { border: 0; border-top: 1px solid var(--line); margin: .3rem 0; }
dl, ul, ol { margin: .4rem 0; }
img, svg { max-width: 100%; }
.muted { color: var(--muted); }
.neg { color: var(--bad); font-weight: 600; font-variant-numeric: tabular-nums; }
.inline { display: inline; }
.num, .total, .count { font-variant-numeric: tabular-nums; }
.num { text-align: right; white-space: nowrap; }
.error { color: var(--danger); font-size: .9rem; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Page frame: appbar on top, then sidebar rail + main. Small-screen overrides live in css/mobile.css */
.shell { display: flex; align-items: flex-start; min-height: 100vh; padding-top: var(--appbar-h); }
.shell > main { flex: 1 1 auto; min-width: 0; }
main { margin: 0; padding: .75rem 1rem 2rem; min-width: 0; }
.toolbar { display: flex; flex-wrap: nowrap; justify-content: space-between; align-items: center; gap: .4rem 1rem; }
.toolbar h1, .toolbar h2 { min-width: 0; flex: 0 1 auto; margin: .3rem 0; overflow-wrap: anywhere; }
.toolbar .search { display: flex; gap: .4rem; flex: 1 1 auto; justify-content: center; }
.toolbar .search input[type=text] { width: 100%; max-width: 26rem; }
.toolbar .buttons { flex: 0 0 auto; margin-left: auto; }
.toolbar > .button { margin-left: auto; }
.toolbar .buttons .button, .toolbar .buttons button { white-space: nowrap; }
.tabs { display: flex; gap: .25rem; margin: .6rem 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: .35rem .8rem; border: 1px solid transparent; border-bottom: 0; border-radius: var(--r) var(--r) 0 0;
  color: var(--muted); text-decoration: none; white-space: nowrap; }
.tabs a:hover { background: var(--hover); color: var(--text); }
.tabs a.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.folders { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.folders a { padding: .3rem .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  color: var(--text); text-decoration: none; }
.folders a:hover { background: var(--hover); border-color: var(--line-strong); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); gap: 0 1.25rem;
  align-items: start; }
.flow { column-width: 21rem; column-gap: 1.25rem; }
.flow > div { break-inside: avoid; margin-bottom: .5rem; }

/* Fixed top bar: toggle, brand, workspace tabs, global search, user menu */
.appbar { position: fixed; inset: 0 0 auto; z-index: 40; display: flex; align-items: center; gap: .75rem;
  height: var(--appbar-h); padding: 0 .75rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { padding: 0 .25rem; font-size: 1.05rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
  color: var(--text); text-decoration: none; }
.brand:hover { color: var(--accent); text-decoration: none; }
.navtoggle { display: none; flex: 0 0 auto; align-items: center; justify-content: center; width: 2.25rem;
  height: 2.25rem; min-height: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--r);
  background: none; color: var(--text); font-size: 1.15rem; line-height: 1; cursor: pointer; }
.navtoggle:hover, .navtoggle[aria-expanded=true] { background: var(--hover); }
.wsswitch { display: flex; align-self: stretch; gap: .1rem; min-width: 0; }
.wsswitch a { display: flex; align-items: center; padding: 0 .8rem; border-bottom: 2px solid transparent;
  color: var(--muted); font-weight: 500; text-decoration: none; white-space: nowrap; }
.wsswitch a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.wsswitch a.active { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
.gsearch { flex: 1 1 12rem; min-width: 0; max-width: 26rem; margin: 0; }
.gsearch input[type=search] { width: 100%; }
.topright { display: flex; align-items: center; gap: .5rem; margin-left: auto; }

/* Left rail + generic .menu / .item list (also reused by the settings page) */
.sidebar { position: sticky; top: var(--appbar-h); flex: 0 0 var(--side-w); width: var(--side-w);
  align-self: flex-start; height: calc(100vh - var(--appbar-h)); padding: .4rem; overflow-y: auto;
  scrollbar-width: thin; background: var(--surface); border-right: 1px solid var(--line); }
.menu { padding: .3rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.menu form { margin: 0; }
.settings-links { max-width: 22rem; }
.sidebar .menu { padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
.menu-title { margin: .7rem .5rem .2rem; color: var(--muted); font-size: .7rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; }
.menu-title:first-child { margin-top: .3rem; }
.item { display: flex; align-items: center; justify-content: space-between; gap: .5rem; width: 100%; min-height: 1.9rem;
  padding: .2rem .6rem; border: 0; border-radius: var(--r); background: none; color: var(--text); font: inherit;
  text-align: left; text-decoration: none; cursor: pointer; }
.item:hover { background: var(--hover); text-decoration: none; }
.item.active { background: var(--accent-soft); box-shadow: inset 2px 0 var(--accent); font-weight: 600; }
.count { flex: 0 0 auto; min-width: 1.4rem; margin-left: auto; padding: 0 .4rem; border-radius: 999px;
  background: var(--surface-3); color: var(--muted); font-size: .72rem; font-weight: 600; line-height: 1.25rem;
  text-align: center; }
.count.warn { background: var(--warn-soft); color: var(--text); }
.count.bad { background: var(--bad); color: var(--on-solid); }

/* Right side of the appbar: view switch + user/company dropdown (<details class="topbar">) */
.topbar { position: relative; }
.topbar summary { display: flex; align-items: center; gap: .6rem; min-height: var(--ctl-h); padding: .15rem .6rem;
  list-style: none; cursor: pointer; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r); }
.topbar summary::-webkit-details-marker { display: none; }
.topbar summary:hover, .topbar[open] summary { background: var(--surface-3); border-color: var(--line-strong); }
.topbar .who { font-weight: 600; white-space: nowrap; }
.topbar .company { padding: 0 .55rem; border-radius: 999px; background: var(--accent-soft); font-size: .8rem;
  white-space: nowrap; }
.topbar .menu { position: absolute; top: calc(100% + .3rem); right: 0; z-index: 50; min-width: 16rem; max-width: 90vw;
  max-height: calc(100vh - var(--appbar-h) - 1rem); padding: .3rem; overflow-y: auto; background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.viewbar { display: flex; gap: .15rem; padding: .15rem; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r); }
.viewbar a { padding: .1rem .7rem; border-radius: .25rem; color: var(--muted); text-decoration: none;
  white-space: nowrap; }
.viewbar a:hover { background: var(--hover); color: var(--text); }
.viewbar a.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* Breadcrumb line above the page content */
.crumbs { display: flex; align-items: center; gap: .4rem; margin: 0 0 .5rem; padding: 0; overflow-x: auto;
  scrollbar-width: none; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--muted); }
.crumbs .here { color: var(--text); font-weight: 600; }

/* Compact form controls */
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=date],
input[type=tel], input[type=url], input:not([type]), select, textarea {
  min-height: var(--ctl-h); max-width: 100%; padding: .3rem .5rem; border: 1px solid var(--line-strong);
  border-radius: var(--r); background: var(--input-bg); color: var(--text); font: inherit; }
input[type=number] { font-variant-numeric: tabular-nums; }
textarea { min-height: 3.5rem; resize: vertical; }
::placeholder { color: var(--muted); opacity: .75; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: 2px solid var(--focus);
  outline-offset: 0; }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
label { font-size: .9rem; }
fieldset { min-width: 0; margin: 0 0 .6rem; padding: .3rem .7rem .5rem; border: 1px solid var(--line);
  border-radius: var(--r-lg); }
legend { padding: 0 .3rem; font-weight: 600; }
.row { display: flex; flex-direction: column; gap: .15rem; margin-bottom: .6rem; }
.row > label { color: var(--muted); font-size: .85rem; }
.check { display: flex; align-items: center; gap: .4rem; }
.row.check { flex-direction: row; align-self: end; align-items: center; gap: .4rem; min-height: var(--ctl-h); }
.row.check label { margin: 0; color: var(--text); font-size: .9rem; line-height: 1.25; }
input[type=checkbox] { appearance: none; -webkit-appearance: none; display: inline-grid; place-content: center;
  flex: 0 0 1.1rem; width: 1.1rem; height: 1.1rem; margin: 0; padding: 0; border: 1px solid var(--line-strong);
  border-radius: .25rem; background: var(--input-bg); cursor: pointer; }
input[type=checkbox]::after { content: ""; width: .3rem; height: .58rem; margin-top: -.1rem;
  border: solid var(--on-accent); border-width: 0 2px 2px 0; transform: rotate(45deg) scale(0);
  transition: transform .1s; }
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::after { transform: rotate(45deg) scale(1); }
input[type=checkbox]:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.row.check input[type=checkbox] { align-self: center; margin-top: 0; }
.searchrow { display: flex; align-items: flex-start; gap: .5rem; }
.searchrow .picker { flex: 1 1 auto; }
.note-form { align-items: flex-start; margin-top: 1rem; }
.note-form textarea { flex: 1 1 auto; width: 100%; min-width: 20rem; max-width: 60rem; height: 4rem; }

/* Buttons: flat, ~2rem high. :where(button) keeps bare <button> low-specificity so .item/.pick/.chip… can reset it */
:where(button), .button { display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: var(--ctl-h); padding: .3rem .8rem; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--text); font: inherit; line-height: 1.2; text-decoration: none;
  cursor: pointer; }
.button:hover, button.primary:hover, button.danger:hover, button:not([class]):hover {
  background: var(--surface-3); text-decoration: none; }
.button.primary, button.primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent);
  font-weight: 600; }
.button.primary:hover, button.primary:hover { background: var(--accent); filter: brightness(1.12); }
button.danger, .button.danger { border-color: var(--bad); background: var(--bad-soft); color: var(--danger); }
button.danger:hover, .button.danger:hover { background: var(--bad); color: var(--on-solid); }
button:disabled, .button[aria-disabled=true] { opacity: .55; cursor: not-allowed; filter: none; }
.buttons { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }

/* Dense tables: hairline borders, header row, zebra + hover; numeric columns via .num */
table { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg); font-variant-numeric: tabular-nums; }
th, td { padding: .3rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
tr:last-child > td { border-bottom: 0; }
th { color: var(--muted); font-size: .8rem; font-weight: 600; }
table:not(.kv) th { background: var(--table-head); border-bottom-color: var(--line-strong); }
table:not(.kv) tr:nth-child(odd) td { background: var(--table-row1); }
table:not(.kv) tr:nth-child(even) td { background: var(--table-row2); }
table:not(.kv) tr:hover td { background: var(--table-highlight); }
th.num, td.num { text-align: right; white-space: nowrap; }
table.tree, table.stock { margin-top: 1rem; }
table.items { margin-top: .75rem; }
table.docs td.num { text-align: right; white-space: nowrap; }
.tree .folder td { font-weight: 600; }
.tree td.edit { width: 2rem; text-align: center; }
.tree .edit a { color: var(--text); text-decoration: none; }
tr.rowlink { cursor: pointer; }
td.clickable { cursor: pointer; text-decoration: underline dotted; }
td.clickable:hover { background: var(--table-highlight) !important; }
th.pick, td.pick { display: none; width: 2.5rem; }
.categorizing th.pick, .categorizing td.pick { display: table-cell; }
table.kv { width: auto; min-width: 20rem; border: 0; border-radius: 0; background: none; line-height: 1.3; }
table.kv th { padding: .1rem .6rem; border: 0; background: var(--hover); color: var(--muted); font-size: .85rem;
  font-weight: 400; }
table.kv td { padding: .1rem .6rem; border: 0; font-weight: 700; }
.kv input[type=text] { width: 8rem; }
#gross-preview { padding: .25rem .4rem; border: 1px solid transparent; font-weight: 700; }

/* Status pills, status bar, chips, sub-tabs */
.status { display: inline-block; padding: .05rem .55rem; border-radius: 999px; background: var(--surface-3);
  color: var(--text); font-size: .8rem; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.status.big { padding: .2rem .8rem; font-size: 1.05rem; }
.status.ok { background: var(--ok-soft); }
.status.warn { background: var(--warn-soft); }
.status.bad { background: var(--bad-soft); }
.status.info { background: var(--info-soft); }
.statusbar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1.25rem; margin: .5rem 0;
  padding: .4rem .75rem; border: 1px solid var(--line); border-left: 4px solid var(--line-strong);
  border-radius: var(--r-lg); background: var(--surface); }
.statusbar.ok { border-left-color: var(--ok); }
.statusbar.warn { border-left-color: var(--warn); }
.statusbar.bad { border-left-color: var(--bad); }
.statusbar.info { border-left-color: var(--info); }
.statusbar .total { margin-left: auto; }
.total { font-size: 1.05rem; font-weight: 700; text-align: right; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .65rem;
  border: 1px dashed var(--line-strong); border-radius: 999px; background: var(--hover); color: var(--text);
  font-size: .85rem; text-decoration: none; }
a.chip:hover { background: var(--accent-soft); text-decoration: none; }
.chip.on { border-style: solid; border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.chip button { display: inline; min-height: 0; padding: 0 .1rem; border: 0; background: none; color: var(--muted);
  font-size: 1rem; line-height: 1; cursor: pointer; }
.chip button:hover { background: none; color: var(--danger); }
.subtabs { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin: -.2rem 0 .6rem 1rem;
  padding-left: .6rem; border-left: 3px solid var(--line-strong); }

/* Pager under long lists: row range, previous / numbers / next. */
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; margin: .6rem 0; }
.pager .muted { margin-right: .5rem; font-variant-numeric: tabular-nums; }
.pager .button { min-width: 2rem; justify-content: center; }
.pager .gap { color: var(--muted); padding: 0 .2rem; }
p.pager { display: block; }

/* Flat surfaces: card, panel, flash/notice, form groups */
.card, .panel { padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); }
.card { padding: 1rem 1.25rem; }
.card:has(.group) { padding: .7rem 1rem; }
.card:has(.group) h1 { margin: 0 0 .5rem; font-size: 1.2rem; }
.panel { min-width: 0; padding: .5rem .9rem; }
.panel h2, .panel h3 { margin: .6rem 0 .25rem; font-size: 1rem; font-weight: 500; }
.panel .toolbar h2 { margin: 0; }
.flash { margin-bottom: .75rem; padding: .45rem .8rem; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); }
.flash.ok { border-color: var(--ok); background: var(--ok-soft); }
.flash.warn { border-color: var(--warn); background: var(--warn-soft); }
.flash.info { border-color: var(--info); background: var(--info-soft); }
.flash.error { border-color: var(--bad); background: var(--bad-soft); color: var(--text); font-size: inherit; }
.notice { padding: .6rem .9rem; border: 1px solid var(--warn); border-radius: var(--r); background: var(--warn-soft); }
.group { margin: 0 0 .5rem; padding: .3rem .7rem .4rem; }
.group legend { padding: 0 .3rem; font-size: .9rem; }
.group .row { margin-bottom: .35rem; font-size: .9rem; }
.group input, .group select, .group textarea { min-height: 1.8rem; padding: .2rem .4rem; }
.group .grid { display: flex; flex-wrap: wrap; gap: 0 .6rem; }
.group .grid > .row { flex: 1 1 11rem; min-width: min-content; max-width: 24rem; }
.group .grid.aligned { display: grid; grid-template-columns: repeat(auto-fill, minmax(13.5rem, 1fr)); }
.group .grid.aligned > .row { min-width: 0; max-width: none; }
.group .grid > .row:has(textarea) { max-width: none; }
.group .grid > .row label { white-space: nowrap; }
fieldset.group summary { padding: .2rem 0; font-weight: 600; cursor: pointer; }

/* Modal <dialog> + its variants */
dialog { max-width: 96vw; padding: .9rem 1.1rem; border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  background: var(--surface-2); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: var(--overlay); }
dialog .buttons { justify-content: space-between; gap: 1rem; }
dialog input[type=text] { display: block; width: 100%; margin: .4rem 0 .8rem; }
dialog .row { gap: .15rem; margin-bottom: .35rem; }
dialog .row input[type=text] { margin: 0; }
dialog h3 { margin: 0 0 .5rem; }
dialog .row + .buttons { margin-top: .6rem; }
dialog .pickrids input[type=text] { display: inline-block; width: 8rem; margin: .15rem .25rem .15rem 0; }
.treedialog { width: min(36rem, 92vw); }
.pickdialog { width: fit-content; min-width: min(40rem, 94vw); max-width: 96vw; max-height: 94vh; }
.pickdialog table { width: 100%; margin-top: .5rem; }
.itemdrawer { max-height: 20rem; margin: .5rem 0; padding: .5rem; overflow-y: auto; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--surface); }

/* Login: the only narrow, centred page */
.login { max-width: 24rem; margin: 4rem auto; }
.login .row { margin-bottom: .6rem; }
.login button.primary { width: 100%; }

/* Collapsible category tree (warehouse list, drawers, dialogs) */
.cattree, .cattree ul { margin: 0; padding: 0; list-style: none; }
.cattree ul { margin-left: .6rem; padding-left: 1rem; border-left: 1px solid var(--line); }
.cattree summary { display: flex; align-items: center; gap: .35rem; padding: .1rem 0; list-style: none; outline: none;
  font-weight: 400; cursor: pointer; }
.cattree summary::-webkit-details-marker { display: none; }
.cattree summary::before { content: "▶"; flex: 0 0 1rem; width: 1rem; color: var(--muted); font-size: .65rem;
  text-align: center; }
.cattree details[open] > summary::before { content: "▼"; }
.cattree summary:focus-visible { border-radius: var(--r); outline: 1px solid var(--line-strong); }
.cattree label { display: inline-flex; align-items: center; gap: .4rem; margin: 0; cursor: pointer; }
.cattree .leaf { padding: .1rem 0 .1rem 1.35rem; }
.cattree .pick { display: inline; min-height: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit;
  text-align: left; cursor: pointer; }
.cattree .pick:hover { background: none; text-decoration: underline; }

/* Floating "categorize" panel at the bottom of the warehouse list */
.catpanel { position: fixed; bottom: .75rem; left: 50%; z-index: 12; width: min(34rem, calc(100vw - 1.5rem));
  transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); box-shadow: var(--shadow); }
.catpanel[hidden], .catbody[hidden] { display: none; }
.catbar { display: block; width: 100%; min-height: 0; padding: .45rem .8rem; border: 0; border-radius: var(--r-lg);
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.catbar:hover { background: var(--hover); }
.catbody { max-height: 60vh; padding: 0 .8rem .8rem; overflow-y: auto; }
.catbody summary { padding: .3rem 0; font-weight: 600; cursor: pointer; }
.catlist { display: flex; flex-direction: column; gap: .2rem; margin: .3rem 0 .5rem; }
.catlist label { display: flex; align-items: center; gap: .4rem; }

/* "Type to search, pick from dropdown" widget (alt_picker macro, case partner) */
.picker { position: relative; }
.picker input[type=search] { width: 100%; max-width: 26rem; }
.picker .results { position: absolute; z-index: 5; width: 100%; max-width: 26rem; max-height: 16rem; margin: .15rem 0 0;
  padding: .2rem; overflow-y: auto; list-style: none; background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.picker .results li { padding: .3rem .5rem; border-radius: var(--r); cursor: pointer; }
.picker .results li:hover { background: var(--accent-soft); }
.picker .chosen { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }

/* Product page: header strip + section list + content panel */
.phead { margin-bottom: .6rem; padding: .5rem .9rem; background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--accent); border-radius: var(--r-lg); }
.phead h1 { margin: 0; font-size: 1.3rem; }
.phead .sub { color: var(--muted); font-size: .85rem; }
.product { display: grid; grid-template-columns: 11.5rem 1fr; gap: 1rem; align-items: start; }
.sections { display: flex; flex-direction: column; gap: .25rem; }
.sections a, .sections .soon { display: block; padding: .35rem .7rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r); color: var(--text); text-decoration: none; }
.sections a:hover { background: var(--hover); }
.sections a.active { border-color: var(--accent); background: var(--accent); color: var(--on-accent);
  font-weight: 600; }
.sections .soon { color: var(--muted); opacity: .6; cursor: not-allowed; }

/* Stock list helpers */
form.stocksearch { margin-top: 1rem; }
.vehfilter { max-height: 18rem; margin: .5rem 0; overflow-y: auto; }

/* Document detail page: side column (info + action buttons) + sheet */
.docpage { display: grid; grid-template-columns: 13rem 1fr; gap: .75rem; align-items: start; }
.doctabs { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.docside { display: flex; flex-direction: column; gap: .6rem; }
.docside section { padding: .5rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); }
.docside h3 { margin: 0 0 .35rem; font-size: 1rem; }
.docside dl { margin: 0 0 .4rem; font-size: .85rem; }
.docside dt { color: var(--muted); font-size: .72rem; }
.docside dd { margin: 0 0 .25rem; overflow-wrap: anywhere; }
.docbtn { display: block; width: 100%; margin-top: .3rem; padding: .3rem .6rem; border: 1px solid var(--line-strong);
  border-radius: var(--r); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; }
.docbtn.green { border-color: var(--ok); background: var(--ok-soft); }
.docbtn.grey { background: var(--surface-3); }
.docbtn:disabled { cursor: not-allowed; opacity: .75; }
.docsheet { min-width: 0; }

/* Case document chain: tree of boxes (.cbox) joined by connector lines */
.chainbar { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 .4rem; }
.chainwrap { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1rem 3rem; margin: .5rem 0 1rem;
  overflow-x: auto; }
.chain, .chain ul { margin: 0; padding: 0; list-style: none; }
.chain ul { margin-left: 1.5rem; padding-left: 1.5rem; }
.chain li { position: relative; margin: .5rem 0; }
.chain ul > li::before { content: ""; position: absolute; left: -1.5rem; top: -.5rem; bottom: -.5rem;
  border-left: 2px solid var(--line-strong); }
.chain ul > li:last-child::before { bottom: auto; height: 1.65rem; }
.chain ul > li::after { content: ""; position: absolute; left: -1.5rem; top: 1.15rem; width: 1.5rem;
  border-top: 2px solid var(--line-strong); }
.cbox { position: relative; display: inline-block; min-width: 18rem; max-width: 60rem; padding: .4rem .7rem;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line-strong);
  border-radius: var(--r-lg); }
.cbox.k-quote { border-left-color: var(--k-quote); }
.cbox.k-proforma { border-left-color: var(--k-proforma); }
.cbox.k-invoice { border-left-color: var(--k-invoice); }
.cbox.k-warranty { border-left-color: var(--k-warranty); }
.cbox.k-receipt { border-left-color: var(--k-receipt); }
.cbox.k-note { border-left-color: var(--k-note); }
.cbox.dead { border-style: dashed; opacity: .65; }
.cbox:hover { background: var(--table-highlight); }
.cbox .chead { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .6rem; }
.cbox a.stretch { color: var(--text); text-decoration: none; }
.cbox a.stretch::after { content: ""; position: absolute; inset: 0; border-radius: var(--r-lg); }
.cbox .cmeta { margin-top: .15rem; color: var(--muted); font-size: .85rem; }
.cbox .cacts { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.cbox .cacts .button, .cbox .cacts button { min-height: 1.7rem; padding: .1rem .6rem; font-size: .85rem; }
.cbox .chead .status { position: relative; z-index: 1; }
.crow { display: flex; flex-wrap: nowrap; align-items: flex-start; }
.crow > .cbox, .crow > .clink { flex: 0 0 auto; }
.clink { align-self: flex-start; width: 2.5rem; margin-top: 1.15rem; border-top: 2px dashed var(--line-strong); }
.chainside h3 { margin: 0; color: var(--muted); font-weight: 500; }
.chainlog { margin-top: 1rem; }

/* Relations strip above a document: small linked boxes, coloured by document kind */
.relbar { display: flex; flex-wrap: wrap; align-items: stretch; gap: .35rem; margin: 0 0 .6rem; }
.rel-title { align-self: center; margin-right: .2rem; color: var(--muted); font-size: .72rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; }
.rel { position: relative; display: inline-flex; flex-direction: column; gap: .05rem; min-width: 8rem;
  padding: .25rem 1.4rem .25rem .6rem; background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong); border-radius: var(--r); color: var(--text); font-size: .85rem;
  line-height: 1.25; text-decoration: none; }
.rel:hover { background: var(--table-highlight); text-decoration: none; }
.rel.k-quote { border-left-color: var(--k-quote); }
.rel.k-proforma { border-left-color: var(--k-proforma); }
.rel.k-invoice { border-left-color: var(--k-invoice); }
.rel.k-warranty { border-left-color: var(--k-warranty); }
.rel.k-receipt { border-left-color: var(--k-receipt); }
.rel.k-note { border-left-color: var(--k-note); }
.rel.dead { border-style: dashed; opacity: .6; }
.rel::before { position: absolute; top: .2rem; right: .45rem; color: var(--muted); font-size: .85rem; }
.rel.dir-up::before { content: "\2191"; }
.rel.dir-down::before { content: "\2193"; }
.rel.dir-side::before { content: "\2194"; }
.rel .nature { color: var(--muted); font-size: .68rem; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; }
.rel .what { font-weight: 600; }
.rel .status { align-self: flex-start; margin-top: .1rem; padding: 0 .45rem; font-size: .72rem; }

/* "Next step" call-to-action box */
.nextsteps { margin: .6rem 0; padding: .5rem .8rem; background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--accent); border-radius: var(--r-lg); }
.nextsteps h3 { margin: 0 0 .4rem; color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; }
.steps { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.step { font-weight: 600; }
.hint { margin: .4rem 0 0; color: var(--muted); font-size: .85rem; }

/* Case change log: 2-column grid (note | time) with zebra rows */
.changelog { display: grid; grid-template-columns: minmax(0, 1fr) max-content; margin-top: .6rem; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.changelog > div { padding: .3rem .6rem; border-bottom: 1px solid var(--line); }
.changelog > div:nth-last-child(-n+2) { border-bottom: 0; }
.changelog > div:nth-child(4n+1), .changelog > div:nth-child(4n+2) { background: var(--table-row1); }
.changelog > div:nth-child(4n+3), .changelog > div:nth-child(4n) { background: var(--table-row2); }
.cl-note { white-space: pre-wrap; overflow-wrap: anywhere; }
.cl-time { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Dashboard: header, card grid, compact tables and lists inside cards */
.dash { display: flex; flex-direction: column; gap: .75rem; }
.dhead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem 1rem; }
.dhead h1 { margin: 0; }
.quick { display: flex; flex-wrap: wrap; gap: .4rem; }
.dgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(22rem, 100%), 1fr)); gap: .75rem;
  align-items: start; }
.dcard { min-width: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); }
.dcard.wide { grid-column: 1 / -1; }
.dcard > header { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem;
  padding: .35rem .75rem; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.dcard h2 { margin: 0; font-size: .95rem; }
.dcard .more { font-size: .85rem; text-decoration: none; white-space: nowrap; }
.dcard .more:hover { text-decoration: underline; }
.dtable { border: 0; border-radius: 0; background: none; font-size: .9rem; }
.dtable th, .dtable td { padding: .2rem .6rem; }
.dlist { margin: 0; padding: 0; list-style: none; }
.dlist li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .1rem .6rem;
  padding: .3rem .75rem; border-bottom: 1px solid var(--line); }
.dlist li:last-child { border-bottom: 0; }
.dlist li:hover { background: var(--hover); }
.empty { margin: 0; padding: .9rem .75rem; color: var(--muted); text-align: center; }

/* KPI tiles on the dashboards */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(9.5rem, 100%), 1fr)); gap: .5rem; }
.kpi { display: flex; flex-direction: column; gap: .05rem; padding: .45rem .7rem; background: var(--surface);
  border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: var(--r-lg);
  color: var(--text); text-decoration: none; }
.kpi:hover { background: var(--table-highlight); text-decoration: none; }
.kpi .n { font-size: 1.5rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .85rem; font-weight: 600; }
.kpi .s { color: var(--muted); font-size: .75rem; }
.kpi.ok { border-left-color: var(--ok); }
.kpi.warn { border-left-color: var(--warn); }
.kpi.bad { border-left-color: var(--bad); }
.kpi.info { border-left-color: var(--info); }
.kpi.ok .n { color: var(--ok); }
.kpi.warn .n { color: var(--warn); }
.kpi.bad .n { color: var(--bad); }
.kpi.info .n { color: var(--info); }

/* Global search results: groups of linked rows */
.rgroup { margin: 0 0 1rem; }
.rgroup h2 { margin: 0 0 .3rem; padding-bottom: .2rem; border-bottom: 1px solid var(--line-strong); color: var(--muted);
  font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; }
.rlist { margin: 0; padding: 0; list-style: none; }
.rlist li { border-bottom: 1px solid var(--line); }
.rlist a { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .1rem 1rem;
  padding: .35rem .5rem; border-radius: var(--r); color: var(--text); text-decoration: none; }
.rlist a:hover { background: var(--hover); }
.r-main { font-weight: 600; }
.r-sub { color: var(--muted); font-size: .85rem; }

/* Unit tracking timeline: vertical line with dots (done = ok, now = accent, todo = hollow) */
.timeline { position: relative; margin: .5rem 0; padding: 0 0 0 1.4rem; list-style: none; }
.timeline::before { content: ""; position: absolute; left: .45rem; top: .6rem; bottom: .6rem;
  border-left: 2px solid var(--line-strong); }
.timeline li { position: relative; display: flex; flex-wrap: wrap; gap: .1rem .75rem; padding: .25rem 0; }
.timeline li::before { content: ""; position: absolute; left: -1.3rem; top: .5rem; width: .7rem; height: .7rem;
  border: 2px solid var(--muted); border-radius: 50%; background: var(--bg); }
.timeline time { flex: 0 0 6.5rem; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.timeline li.done::before { border-color: var(--ok); background: var(--ok); }
.timeline li.now::before { border-color: var(--accent); background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
.timeline li.now { font-weight: 600; }
.timeline li.todo { color: var(--muted); }

/* Compact definition grid: label/value pairs flow into as many column pairs as fit */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(6rem, 9rem) minmax(9rem, 1fr));
  gap: 0 1.25rem; margin: .5rem 0; }
.facts dt, .facts dd { padding: .2rem 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: .8rem; }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* Small screens (< 60rem). Loaded last so it wins the cascade. */
@media (max-width: 59.99rem) {
  .navtoggle { display: inline-flex; }
  .appbar { gap: .4rem; padding: 0 .5rem; }
  .wsswitch { flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
  .wsswitch::-webkit-scrollbar { display: none; }
  .gsearch { flex: 0 1 9rem; }
  .topbar .who { display: none; }
  .sidebar { position: fixed; top: var(--appbar-h); bottom: 0; left: 0; z-index: 30; display: none;
    width: min(17rem, 86vw); height: auto; box-shadow: var(--shadow); }
  .sidebar.open { display: block; }
  main { padding: .6rem .6rem 2rem; }
  .product, .docpage { grid-template-columns: 1fr; }
  .sections { flex-direction: row; flex-wrap: wrap; }
  .toolbar, .toolbar .buttons { flex-wrap: wrap; }
  .toolbar .search { flex: 1 1 14rem; }
  table { display: block; max-width: 100%; overflow-x: auto; }
  .catpanel { bottom: 0; width: 100vw; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .cbox { min-width: 0; }
  .chainwrap { gap: 1rem; }
  .crow { flex-wrap: wrap; }
  .picker input[type=search], .picker .results { max-width: none; }
  /* touch targets: at least 2.25rem high */
  :where(button), .button, .item, .docbtn, .tabs a, .chip, .viewbar a, .folders a, .sections a, .crumbs a,
  .wsswitch a, .rlist a, .topbar summary, input:not([type=checkbox]):not([type=hidden]), select {
    min-height: 2.25rem; }
  .tabs a, .viewbar a, .wsswitch a, .crumbs a { display: inline-flex; align-items: center; }
  .kpi, .dlist li, .cattree summary, .cattree .leaf, .catbar { min-height: 2.25rem; }
  .cattree .pick { display: inline-flex; align-items: center; min-height: 2.25rem; }
  .chip button { min-width: 2rem; min-height: 2rem; }
  input[type=checkbox] { flex-basis: 1.4rem; width: 1.4rem; height: 1.4rem; }
}

