/* Ordeo UI. Every margin, padding and gap comes from the spacing scale below (or is 0); every
   font size from the type scale. A new value means a new token, not a new number. */
:root {
  /* color */
  /* Ordeo brand (brand kit): navy #022b65, blue #007dfd, sky #43b1fe, teal #2dbfd0, slate #565f6f, mist #e0e3eb.
     --accent is the brand blue darkened until white text on it passes 4.5:1 (the pure brand blue gives 3.9:1). */
  --bg: #f4f7fb; --card: #fff; --text: #0b1b3a; --muted: #565f6f; --line: #e0e3eb;
  --accent: #0069e0; --accent-hover: #0059bf; --accent-soft: #e6f2ff; --on-accent: #fff; --ok: #16794c; --warn: #b54708; --err: #b42318;
  --brand: #007dfd; --sky: #43b1fe;
  --header-bg: #022b65; --header-deep: #011a40; --on-header: #fff; --on-header-muted: rgb(255 255 255 / .78); --on-header-hover: rgb(255 255 255 / .1); --on-header-active: rgb(255 255 255 / .16);
  --c1: #0069e0; --c2: #1aa3b4; --c3: #022b65; --c4: #f59e0b; --c5: #8b5cf6; --c6: #9ba4b3; /* chart series: brand blue, teal, navy, amber, violet; red stays for errors */
  /* spacing scale */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px; --space-7: 48px;
  /* type scale */
  --text-2xs: 11px; --text-xs: 12px; --text-sm: 13px; --text-md: 15px; --text-lg: 18px; --text-xl: 22px;
  /* shape and sizes */
  --control-h: 40px; --control-h-sm: 32px; --radius-sm: 8px; --radius: 12px; --radius-pill: 99px;
  --bar: 60px; --head: 64px; --head-sm: 56px; --menu-w: 240px; --auth-w: 420px; --measure: 1000px; --icon: 22px; --icon-sm: 18px; --icon-lg: 36px; --fab: 56px; --check: 18px; --dot: 10px; --thumb: 48px;
  /* elevation and motion */
  --shadow-sm: 0 4px 14px rgb(0 0 0 / .12); --shadow-md: 0 8px 24px rgb(0 0 0 / .18);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
  --dur: .18s; --dur-out: .15s; --ease: cubic-bezier(.16, 1, .3, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1428; --card: #11203d; --text: #e8eef9; --muted: #9fb0cc; --line: #223559;
    --accent: #4da3ff; --accent-hover: #7cb8ff; --accent-soft: #12305c; --on-accent: #04122b; --header-bg: #031a3f; --header-deep: #010d24; --ok: #5fd39a; --warn: #f5a05a; --err: #ff8a80;
    --c1: #4da3ff; --c2: #2dbfd0; --c3: #a9c7ff; --c4: #fbbf24; --c5: #b69bff; --c6: #7c8aa0;
  }
}

/* ---- base: browser defaults off, so spacing only ever comes from the scale ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--text-md)/1.5 system-ui, sans-serif; }
h1, h2, h3, p, dl, dd, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; }
button { font: inherit; padding: 0; }
input[type=checkbox], input[type=radio] { margin: 0; }
a { color: var(--accent); }
h1 { font-size: var(--text-xl); line-height: 1.25; }
h2 { font-size: var(--text-md); font-weight: 700; }
h3 { font-size: var(--text-sm); font-weight: 600; }
.muted { color: var(--muted); font-size: var(--text-sm); }
svg.icon, nav svg, .add-btn svg, button svg, .dropzone svg { width: var(--icon); height: var(--icon); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- shell ---- */
header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: var(--space-4); min-height: var(--head); padding: 0 var(--space-5); background: var(--header-bg); color: var(--on-header); }
header :focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--sky); }
.brand { display: flex; flex: none; border-radius: var(--radius-sm); }
.brand img { display: block; height: var(--control-h-sm); width: auto; }
nav { display: flex; gap: var(--space-1); flex: 1; }
nav button { position: relative; display: flex; align-items: center; gap: var(--space-2); border: 0; background: none; color: var(--on-header-muted); padding: 0 var(--space-3); border-radius: var(--radius-sm); cursor: pointer; min-height: var(--control-h); }
nav button svg { width: var(--icon-sm); height: var(--icon-sm); }
.nav-count { margin: 0; }
nav button:hover:not(.active) { background: var(--on-header-hover); color: var(--on-header); }
nav button.active { background: var(--on-header-active); color: var(--on-header); font-weight: 600; }
.add-btn { display: flex; align-items: center; gap: var(--space-2); text-decoration: none; background: var(--accent); color: var(--on-accent); padding: 0 var(--space-4); border-radius: var(--radius-pill); font-weight: 600; min-height: var(--control-h); border: 1px solid var(--on-header-active); }
.add-btn svg { width: var(--icon-sm); height: var(--icon-sm); stroke-width: 2.4; }
.add-btn:hover { background: var(--accent-hover); }
/* sections of the current group: tabs under the bar */
#subnav { position: sticky; top: var(--head); z-index: 9; display: flex; gap: var(--space-1); padding: 0 var(--space-5); background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
#subnav button { position: relative; display: flex; align-items: center; gap: var(--space-2); flex: none; border: 0; background: none; color: var(--muted); padding: 0 var(--space-3); min-height: var(--control-h); cursor: pointer; border-bottom: 2px solid transparent; }
#subnav button:hover:not(.active) { color: var(--text); }
#subnav button.active { color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); }
#subnav button:focus-visible { outline: 0; box-shadow: var(--ring); }
#account { position: relative; flex: none; }
#account summary { display: grid; place-items: center; list-style: none; width: var(--control-h); height: var(--control-h); border-radius: 50%; cursor: pointer; background: var(--on-header-active); color: var(--on-header); font-weight: 600; }
#account summary::-webkit-details-marker { display: none; }
#account summary:hover { background: var(--on-header-hover); }
#account .menu { position: absolute; right: 0; top: calc(100% + var(--space-2)); z-index: 40; display: flex; flex-direction: column; gap: var(--space-1); min-width: var(--menu-w); padding: var(--space-2); background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-md); animation: pop var(--dur) var(--ease); }
#account .menu .muted { padding: var(--space-2) var(--space-3); overflow-wrap: anywhere; border-bottom: 1px solid var(--line); }
#account .menu a, #account .menu button { display: flex; align-items: center; min-height: var(--control-h); padding: 0 var(--space-3); border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); text-decoration: none; cursor: pointer; text-align: left; }
#account .menu a:hover, #account .menu button:hover { background: var(--accent-soft); }
#account .menu button { color: var(--err); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius-sm) var(--radius-sm); } /* leaving is kept apart from the places to go */
body.auth #account, body.auth #subnav { display: none; }
body.auth { min-height: 100vh; background: linear-gradient(var(--accent-soft), var(--bg) 60%) fixed; }
#splash { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--space-4); text-align: center; background: linear-gradient(160deg, var(--header-bg), var(--header-deep)); color: var(--on-header); transition: opacity .3s ease; }
#splash strong { font-size: var(--text-xl); }
#splash span { color: var(--on-header-muted); font-size: var(--text-sm); }
#splash.done { opacity: 0; pointer-events: none; }

main { max-width: var(--measure); margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-7); }
/* Views that opt in (`page: true` in register) get one vertical rhythm: blocks are separated by
   a gap, never by margins on the blocks themselves. */
main.page { display: flex; flex-direction: column; gap: var(--space-5); }
main.page > :empty { display: none; }
.flow { display: flex; flex-direction: column; gap: var(--space-4); }
.flow:empty { display: none; }
#entries.flow { gap: var(--space-5); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); flex-wrap: wrap; }
.page-head > div { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.page-head > .actions { flex-direction: row; }

/* ---- controls: one height, one inner padding, whatever the element ---- */
input:not([type=checkbox], [type=radio], [type=file], [type=range]) { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 var(--space-3); min-height: var(--control-h); max-width: 100%; }
input:not([type=checkbox], [type=radio], [type=file], [type=range]):hover:not(:disabled) { border-color: var(--muted); }
input:not([type=checkbox], [type=radio], [type=file], [type=range]):focus { outline: 0; border-color: var(--accent); box-shadow: var(--ring); }
input:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); min-height: calc(var(--control-h) * 2); max-width: 100%; resize: vertical; }
textarea:focus { outline: 0; border-color: var(--accent); box-shadow: var(--ring); }
input::placeholder { color: var(--muted); opacity: .8; }
input[type=checkbox], input[type=radio], progress { accent-color: var(--accent); }
input, button, .dd-btn { transition: border-color var(--dur-out), box-shadow var(--dur-out), background var(--dur-out), color var(--dur-out); }
button:focus-visible, a.button:focus-visible { outline: 0; box-shadow: var(--ring); }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }
button.secondary:hover:not(:disabled), a.button:hover { background: var(--accent-soft); }
button.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--err) 10%, transparent); }
button.primary.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--err) 88%, #000); }
button:active:not(:disabled) { transform: translateY(1px); }
button.primary, button.secondary, a.button { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); text-decoration: none; padding: 0 var(--space-4); min-height: var(--control-h); border-radius: var(--radius-sm); border: 1px solid var(--accent); cursor: pointer; background: var(--accent); color: var(--on-accent); }
a.button, button.secondary { background: none; color: var(--accent); }
a.button.primary { background: var(--accent); color: var(--on-accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field > label, .field > legend { font-size: var(--text-sm); color: var(--muted); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-3); }
.hint { font-size: var(--text-sm); color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.toolbar .dd { flex: 0 1 220px; }
.switch { display: flex; align-items: center; gap: var(--space-2); min-height: var(--control-h); cursor: pointer; }
.custom-range { display: flex; align-items: center; gap: var(--space-2); }

/* ---- surfaces ---- */
.card { display: flex; flex-direction: column; gap: var(--space-3); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4); }
.card > * { min-width: 0; }
.card > :empty:not(.chart-box, img) { display: none; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; }
.row { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.badge { display: inline-block; padding: 0 var(--space-2); line-height: 20px; border-radius: var(--radius-pill); font-size: var(--text-xs); background: var(--bg); border: 1px solid var(--line); margin-inline-end: var(--space-1); }
.badge.ok { color: var(--ok); } .badge.warn { color: var(--warn); } .badge.err { color: var(--err); }
.warnings { color: var(--warn); padding-left: var(--space-4); }
p.warnings { padding-left: 0; }
.callout-error { color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); }
.empty { text-align: center; padding: var(--space-6); }
details.card summary { cursor: pointer; display: flex; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; align-items: center; min-height: var(--control-h-sm); }
table { width: 100%; border-collapse: collapse; }
.scroll { overflow-x: auto; } /* a table wider than its card scrolls inside the card instead of widening the page */
th, td { text-align: left; padding: var(--space-2); border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: var(--text-xs); color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap, .nowrap { white-space: nowrap; }
tr.clickable { cursor: pointer; } tr.clickable:hover { background: var(--bg); }
dt { font-size: var(--text-xs); color: var(--muted); }
dd { font-variant-numeric: tabular-nums; }
#toasts { position: fixed; bottom: calc(var(--bar) + var(--space-4)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: var(--space-2); max-width: 90vw; z-index: 30; pointer-events: none; }
.toast { pointer-events: auto; cursor: pointer; background: var(--text); color: var(--bg); padding: var(--space-3) var(--space-4); border-radius: var(--radius); box-shadow: var(--shadow-md); font-size: var(--text-sm); animation: pop var(--dur) var(--ease); }
.toast.error { background: var(--err); color: #fff; }
.toast.leaving, .dd-menu.closing { animation: fade var(--dur-out) ease forwards; }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(var(--space-2)); } }
@keyframes fade { to { opacity: 0; } }
.login { max-width: var(--auth-w); margin: var(--space-7) auto 0; padding: var(--space-5); text-align: center; gap: var(--space-4); align-items: center; box-shadow: var(--shadow-sm); }
.login form, .login .field { align-self: stretch; }
@media (prefers-color-scheme: dark) { .login > img { content: url("/brand/logo-dark.svg"); } }
.login .field { text-align: left; }
.login form { display: flex; flex-direction: column; gap: var(--space-4); }
.login button.primary, .login a.button { width: 100%; }

/* ---- entries ---- */
.entry p { margin: 0; }
.amounts { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); }
.amounts div { min-width: 110px; }
.amounts .total dd { font-size: var(--text-lg); font-weight: 700; }

/* ---- panel ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
.kpi { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3) var(--space-4); }
.kpi strong { font-size: var(--text-xl); font-variant-numeric: tabular-nums; }
.chart-box { min-width: 0; }
.pick { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-2) 0; cursor: pointer; }
.pick input { width: var(--check); height: var(--check); flex: none; }
.pick span { display: grid; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); width: min(560px, calc(100vw - 2 * var(--space-3))); max-height: 85vh; padding: var(--space-4); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog fieldset { border-top: 1px solid var(--line); margin-top: var(--space-3); padding-top: var(--space-2); }
dialog legend { font-weight: 600; padding-right: var(--space-2); }

/* ---- custom select and modal ---- */
.dd { position: relative; min-width: 0; }
.dd-btn { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); width: 100%; text-align: left; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 var(--space-3); min-height: var(--control-h); cursor: pointer; transition: border-color var(--dur-out); }
.dd-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-btn::after { content: ""; flex: none; width: 8px; height: 8px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); transition: transform var(--dur) var(--ease); }
.dd-btn[aria-expanded=true]::after { transform: translateY(2px) rotate(-135deg); }
.dd-btn:hover:not(:disabled), .dd-btn[aria-expanded=true] { border-color: var(--accent); }
.dd-btn:focus-visible, .dd-menu:focus-visible { outline: 0; border-color: var(--accent); box-shadow: var(--ring); }
.dd-btn:disabled { opacity: .5; cursor: not-allowed; }
.dd-menu { position: fixed; z-index: 70; margin: 0; padding: var(--space-1); list-style: none; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-md); max-height: 280px; overflow: auto; outline: 0; animation: pop var(--dur) var(--ease); }
.dd-menu li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; }
.cb { position: relative; min-width: 0; }
.cb input { width: 100%; }
.dd-menu li.active { background: var(--accent-soft); }
.dd-menu li[aria-selected=true] { color: var(--accent); font-weight: 600; }
.dd-menu li[aria-selected=true]::after { content: "✓"; }
dialog.modal { display: flex; flex-direction: column; gap: var(--space-3); width: min(420px, calc(100vw - 2 * var(--space-3))); padding: var(--space-5); box-shadow: var(--shadow-md); }
dialog.modal[open] { animation: pop var(--dur) var(--ease); }
dialog.modal.closing[open] { animation: fade var(--dur-out) ease forwards; }
dialog.modal[open]::backdrop { animation: fade-in var(--dur) ease; }
dialog.modal.closing::backdrop { animation: fade var(--dur-out) ease forwards; }
dialog.modal.viewer { width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; padding: var(--space-5); align-items: center; justify-content: center; background: transparent; border: 0; box-shadow: none; }
dialog.modal.viewer[open]:not(.closing) { animation: fade-in var(--dur) ease; }
dialog.modal.viewer[open]::backdrop { background: rgb(0 0 0 / .55); backdrop-filter: blur(8px); }
dialog.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); }
dialog.viewer iframe { width: min(960px, 100%); height: 100%; border: 0; border-radius: var(--radius-sm); background: var(--card); box-shadow: var(--shadow-md); }
.viewer-close { position: fixed; top: var(--space-4); right: var(--space-4); display: grid; place-items: center; width: var(--control-h); height: var(--control-h); padding: 0; border: 1px solid var(--on-header-active); border-radius: 50%; background: var(--header-bg); color: var(--on-header); cursor: pointer; box-shadow: var(--shadow-md); }
.viewer-close:hover { background: var(--accent); }
.viewer-close:focus-visible { outline: 0; box-shadow: 0 0 0 2px var(--sky); }
dialog.modal .actions.end { justify-content: flex-end; }
dialog.modal .modal-form { display: flex; flex-direction: column; gap: var(--space-3); }
/* row buttons inside a table cell: the small control height, grouped, never touching the text */
.actions.compact button { min-height: var(--control-h-sm); padding: 0 var(--space-3); white-space: nowrap; }
td.row-actions .actions { justify-content: flex-end; }
/* Several actions that must wrap: two equal columns, so the rows share their edges instead of a ragged line. */
.actions.grid { display: grid; grid-template-columns: repeat(2, max-content); }
.actions.grid button { width: 100%; }
@keyframes fade-in { from { opacity: 0; } }
button.primary.danger { background: var(--err); border-color: var(--err); color: #fff; }
@media (prefers-reduced-motion: reduce) { *, ::before, ::after, ::backdrop { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---- charts ---- */
.chart { display: block; max-width: 100%; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.chart text { font-size: var(--text-2xs); fill: var(--muted); }
.chart .val { fill: var(--text); font-weight: 600; }
.chart .axis-group { font-weight: 600; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .bar, .chart .marker { transition: opacity .12s, transform .12s; transform-box: fill-box; transform-origin: center; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; }
.chart .cross.on { opacity: .8; }
.hovering .chart .bar:not(.on) { opacity: .4; }
.chart .marker.on { transform: scale(1.7); }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); font-size: var(--text-sm); }
.legend.vertical { flex-direction: column; gap: var(--space-2); }
.legend li { cursor: default; padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm); }
.legend li.on, .bars li.on { background: var(--accent-soft); }
.dot { display: inline-block; width: var(--dot); height: var(--dot); border-radius: 50%; margin-right: var(--space-2); flex: none; background: var(--c, var(--c6)); }
.bars { list-style: none; display: grid; gap: var(--space-2); }
.bars li { display: grid; grid-template-columns: minmax(90px, 30%) 1fr minmax(110px, auto); align-items: center; gap: var(--space-3); padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm); }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--bg); border-radius: var(--radius-pill); height: 12px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: var(--radius-pill); width: var(--w, 0); background: var(--c, var(--c1)); }
.bar-value { font-variant-numeric: tabular-nums; text-align: right; font-size: var(--text-sm); line-height: 1.25; }
.donut { display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap; }
.donut svg { width: 160px; height: 160px; flex: none; }
.seg { transition: stroke-width .12s; cursor: default; }
.seg.on { stroke-width: 32; }
.donut .center-title { font-size: var(--text-2xs); fill: var(--muted); }
.donut .center-value { font-size: var(--text-md); font-weight: 700; fill: var(--text); }
.tip { position: fixed; top: 0; left: 0; z-index: 60; pointer-events: none; background: var(--text); color: var(--bg); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); font-size: var(--text-xs); line-height: 1.4; max-width: 280px; box-shadow: var(--shadow-md); }
.tip-title { font-weight: 700; margin-bottom: var(--space-1); }
.tip-row { display: flex; align-items: center; gap: var(--space-2); }
.tip-row strong { margin-left: auto; padding-left: var(--space-3); font-variant-numeric: tabular-nums; }
.tip-foot { margin-top: var(--space-1); opacity: .75; }

/* ---- add document ---- */
.dropzone { display: grid; place-items: center; gap: var(--space-2); text-align: center; padding: var(--space-6) var(--space-4); border: 2px dashed var(--line); border-radius: var(--radius); background: var(--bg); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone svg { width: var(--icon-lg); height: var(--icon-lg); color: var(--accent); }
.dropzone strong { font-size: var(--text-md); }
.actions.center { justify-content: center; }
.file-chip { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.file-chip img { width: var(--thumb); height: var(--thumb); object-fit: cover; border-radius: var(--radius-sm); }
.file-chip .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
/* payments calendar: a month as seven columns, each day a button that opens its invoices */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-1); }
.cal-head { text-align: center; }
.cal-day { display: flex; flex-direction: column; align-items: center; min-height: var(--thumb); padding: var(--space-1); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); color: var(--text); cursor: pointer; font-size: var(--text-2xs); font-variant-numeric: tabular-nums; min-width: 0; }
.cal-day[data-empty] { color: var(--muted); }
.cal-day.out { opacity: .5; }
.cal-day.today { border-color: var(--accent); }
.cal-day.picked { background: var(--accent-soft); border-color: var(--accent); }
.cal-num { font-size: var(--text-sm); font-weight: 600; }
.chips legend { flex-basis: 100%; font-size: var(--text-sm); color: var(--muted); }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: inline-flex; align-items: center; padding: 0 var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-pill); cursor: pointer; min-height: var(--control-h); }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

/* ---- stock ---- */
.summary-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
.summary-meta .badge { margin: 0; }
/* a row of pills/links/name: wraps, one gap between all of them (no per-badge margins) */
.tags { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
.tags .badge { margin: 0; }
.line-side { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); min-width: 0; }
/* a table cell holding several pieces (name + note, figure + pill): stacked with a gap */
td > div:not(.actions) { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-1); }
/* A cell holding pills, text and buttons: the information stacks on top, the actions below it, and
   everything shares the cell's left edge (right edge on a phone, where the cells are right-aligned). */
td > div.cell-stack { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.cell-info { display: flex; flex-direction: column; align-items: inherit; gap: var(--space-1); }
td.num > div { align-items: flex-end; } /* a number column keeps its right edge even when a pill sits under it */
/* Values (quantities, prices, amounts) are text, tinted when they are the problem; pills are for states. */
.tone-ok { color: var(--ok); font-weight: 600; } .tone-warn { color: var(--warn); font-weight: 600; } .tone-err { color: var(--err); font-weight: 600; }
.inbox-list { list-style: none; display: flex; flex-direction: column; }
.inbox-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-3); align-items: start; padding: var(--space-3) 0; border-top: 1px solid var(--line); }
.inbox-name { padding: var(--space-2) 0; overflow-wrap: anywhere; }
.inbox-pick { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.inbox-pick input { width: 100%; }

/* ---- review (confirmation) screen ---- */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3) var(--space-5); }
.callout-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); }
.link-list { list-style: none; display: flex; flex-direction: column; gap: var(--space-2); }
.link-list label { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; cursor: pointer; min-height: var(--control-h); }
.links-note { font-weight: 600; }
.line { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.line-info { display: flex; flex-direction: column; gap: var(--space-1); }
.line-fields { display: flex; flex-direction: column; gap: var(--space-3); }
.line-category { display: flex; flex-direction: column; gap: var(--space-3); }
.confirm-bar { position: sticky; bottom: var(--space-4); display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3) var(--space-4); box-shadow: var(--shadow-sm); z-index: 5; }

/* ---- phones ---- */
@media (min-width: 721px) { nav button { white-space: nowrap; } }
@media (max-width: 720px) {
  :root { --head: var(--head-sm); }
  header { padding: env(safe-area-inset-top) var(--space-4) 0; min-height: calc(var(--head) + env(safe-area-inset-top)); }
  #subnav { top: calc(var(--head) + env(safe-area-inset-top)); padding: 0 var(--space-2); }
  nav { position: fixed; inset: auto 0 0 0; height: calc(var(--bar) + env(safe-area-inset-bottom)); padding: 0 var(--space-2) env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); justify-content: space-around; z-index: 20; gap: 0; }
  nav button { flex-direction: column; justify-content: center; gap: var(--space-1); font-size: var(--text-2xs); padding: var(--space-1) var(--space-2); flex: 1; border-radius: 0; background: none !important; }
  nav button svg { display: block; }
  #nav .nav-count { position: absolute; top: var(--space-1); right: var(--space-1); line-height: 1.4; padding: 0 var(--space-1); }
  nav button { color: var(--muted); }
  nav button svg { width: var(--icon); height: var(--icon); }
  nav button.active { color: var(--accent); }
  .add-btn { position: fixed; right: var(--space-4); bottom: calc(var(--bar) + var(--space-4) + env(safe-area-inset-bottom)); height: var(--fab); padding: 0 var(--space-5); border: 0; box-shadow: var(--shadow-md); z-index: 25; }
  .add-btn .long { display: none; }
  .brand { flex: 1; }
  .brand img { height: var(--icon-lg); }
  main { padding: var(--space-4) var(--space-3) calc(var(--bar) + var(--fab) + var(--space-5) + var(--space-4)); }
  .dropzone { padding: var(--space-5) var(--space-3); }
  body:has(.confirm-bar) .add-btn { display: none; }
  .toolbar .dd { flex: 1 1 100%; }
  .line, .inbox-list li { grid-template-columns: 1fr; }
  .inbox-name { padding: 0; }
  .confirm-bar { bottom: calc(var(--bar) + var(--space-3) + env(safe-area-inset-bottom)); }
  .bars li { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; order: 3; }
  /* tables become cards: each cell shows its data-label */
  .stack tr.head { display: none; }
  .stack, .stack tbody, .stack tr, .stack td { display: block; }
  .stack tr { padding: var(--space-3) 0; border-bottom: 1px solid var(--line); }
  .stack td { border: 0; padding: var(--space-1) 0; display: flex; justify-content: space-between; gap: var(--space-3); text-align: right; }
  .stack td > div:not(.actions) { align-items: flex-end; }
  .stack td:empty { display: none; } /* a figure not there yet (a count's live difference) leaves no empty label */
  .stack td::before { content: attr(data-label); color: var(--muted); font-size: var(--text-xs); text-align: left; }
  .stack td.wide { display: block; text-align: left; } .stack td.wide::before { display: block; }
}

.edit { display: grid; gap: var(--space-3); }

/* ---- review: split screen ---- */
main.wide { max-width: 1500px; }
.rv { display: contents; }
.review { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: var(--space-5); align-items: start; }
.preview { position: sticky; top: calc(var(--bar) + var(--space-4)); height: calc(100dvh - var(--bar) - var(--space-7) - var(--space-5) - var(--space-5)); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.preview:has(iframe) { overflow: hidden; }
.preview iframe { display: block; width: 100%; height: 100%; border: 0; }
.preview img { height: 100%; width: 100%; display: block; object-fit: contain; }
.work { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.header-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
.ctl { display: flex; gap: var(--space-2); }
.ctl input, .ctl .dd { flex: 1; min-width: 0; }
.revert { display: grid; place-items: center; flex: none; width: var(--control-h); min-height: var(--control-h); border: 1px solid var(--line); background: var(--card); color: var(--accent); border-radius: var(--radius-sm); cursor: pointer; }
.revert:hover { background: var(--accent-soft); border-color: var(--accent); }
.revert svg { width: var(--icon-sm); height: var(--icon-sm); }
.field.changed input, .field.changed .dd-btn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, var(--card)); }
.line-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
.line-actions { display: flex; gap: var(--space-2); }
.line-actions button, .card-head > button.secondary { min-height: var(--control-h-sm); padding: 0 var(--space-3); white-space: nowrap; }
.callout-warn button.secondary { min-height: var(--control-h-sm); padding: 0 var(--space-3); margin-inline-start: var(--space-2); }
.line-body { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.line-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: var(--space-3); }
.line-grid [data-name="description"] { grid-column: 1 / -1; }
.line.deleted { opacity: .5; }
.line.deleted .line-body { pointer-events: none; }
.supplier-stats { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.supplier-stats .badge { margin: 0; }
td .badge { margin: 0; } /* inside a cell the column's gap spaces pills, not their own margin */
.camera-view { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm); background: var(--bg); }
.reception, .photo-picker, .photo-chips { display: flex; flex-direction: column; gap: var(--space-3); }
.reception { padding-top: var(--space-3); border-top: 1px dashed var(--line); }
.assign { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); align-items: start; padding-top: var(--space-3); border-top: 1px dashed var(--line); }
.assign .check { grid-column: 1 / -1; display: flex; gap: var(--space-2); align-items: center; min-height: var(--control-h-sm); cursor: pointer; }
.pill { display: inline-block; padding: 0 var(--space-2); border-radius: var(--radius-pill); font-size: var(--text-xs); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#lines { display: flex; flex-direction: column; gap: var(--space-4); }
.line.static { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
@media (max-width: 900px) {
  .review { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; height: 45vh; }
  .assign { grid-template-columns: 1fr; }
}

/* ---- compare two documents ---- */
.compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5); align-items: start; }
.cmp-col { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.cmp-col .preview { position: static; height: 60vh; }
.cmp-lines { padding-left: var(--space-4); display: flex; flex-direction: column; gap: var(--space-1); }
.facts .diff { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: var(--radius-sm); padding: 0 var(--space-2); }
.link-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.duplicate { display: flex; flex-direction: column; gap: var(--space-2); }
button.danger { color: var(--err); border-color: var(--err); }
@media (max-width: 900px) { .compare { grid-template-columns: minmax(0, 1fr); } }
.linked-notes { list-style: none; display: flex; flex-direction: column; gap: var(--space-1); }
.linked-notes li { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* ---- price changes: under a line while reviewing, and on the product panel ---- */
.price-change { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }
.price-change.up { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.price-change.down { color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.price-change.format { color: var(--accent); background: var(--accent-soft); }
.price-change a { margin-inline-start: auto; }
td .muted { display: block; }
