/* paperless-extractor UI. Design tokens + components; templates use var(--token), never colour literals.
 * Approved values: docs/plans/2026-10-05-ui-redesign.md (Phase 0). Dark is the primary theme; the browser decides. */

/* 1. Tokens ----------------------------------------------------------------- */
:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem; --space-5: 1.5rem; --space-6: 2rem;
  --radius: 12px; --radius-sm: 8px;
  --row: 44px;
  --topbar-h: 53px; /* 36px buttons + padding + border: the validation screen's height depends on it */

  --bg: #F5F6F8; --surface: #FFFFFF; --surface-2: #F3F5F8;
  --border: #E2E6EC; --border-strong: #CDD3DC;
  --text: #18202B; --text-muted: #5A6576;
  --accent: #2457C5; --accent-hover: #1C47A6; --accent-soft: #E8EEFB; --accent-contrast: #FFFFFF;
  --ok: #17703F; --ok-bg: #E3F3EA;
  --warn: #8F5300; --warn-bg: #FCEFD9;
  --danger: #B02331; --danger-bg: #FBE7E9;
  --info: #2457C5; --info-bg: #E8EEFB;
  --neutral: #4A5463; --neutral-bg: #EDEFF2;
  --pdf-bg: #8A919C;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-pop: 0 8px 24px rgba(16, 24, 40, .2);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237A8494' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1217; --surface: #161B22; --surface-2: #1B2129;
    --border: #29313C; --border-strong: #3A4452;
    --text: #E5E9EF; --text-muted: #9AA5B4;
    --accent: #7FA5FF; --accent-hover: #A1BEFF; --accent-soft: #1A2747; --accent-contrast: #0E1217;
    --ok: #62CC93; --ok-bg: #132C1F;
    --warn: #F1B65A; --warn-bg: #36280F;
    --danger: #F28B95; --danger-bg: #3A191D;
    --info: #7FA5FF; --info-bg: #1A2747;
    --neutral: #AEB7C4; --neutral-bg: #222932;
    --pdf-bg: #0A0D11;
    --shadow-sm: none;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .02);
    --shadow-pop: 0 8px 24px rgba(0, 0, 0, .45);
  }
}

/* 2. Base -------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 680; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: var(--font-mono); font-size: .9em; }
kbd {
  font: inherit; font-size: .75em; font-weight: 600; padding: 0 .35em; border-radius: 4px;
  border: 1px solid currentColor; opacity: .7; line-height: 1.4; white-space: nowrap;
}
.muted { color: var(--text-muted); font-size: .875em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: .93em; }
.icon { width: 1em; height: 1em; flex: none; vertical-align: -.125em; }
.error { color: var(--danger); }
.warning { color: var(--warn); }

/* 3. Controls ----------------------------------------------------------------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 36px; padding: 0 .9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: .93rem; font-weight: 550; line-height: 1.2; cursor: pointer; white-space: nowrap;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
button:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary, button.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn-danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-ghost-danger { background: transparent; border-color: transparent; color: var(--danger); font-weight: 500; }
.btn-ghost-danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-sm { min-height: 30px; padding: 0 .6rem; font-size: .85rem; }

/* :where() keeps these base rules at zero specificity, so components and pages override them. */
:where(input:not([type=checkbox], [type=radio], [type=file], [type=hidden]), select, textarea) {
  min-height: 36px; padding: .35rem .7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: .95rem;
}
textarea { min-height: 5rem; }
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: .8; }
:where(select) { appearance: none; padding-right: 2rem; background: var(--surface) var(--chevron) no-repeat right .6rem center; }
:where(input, select, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 1rem; height: 1rem; vertical-align: -.15em; }
input[type=file] { font: inherit; color: var(--text-muted); }
input.no-spin { appearance: textfield; -moz-appearance: textfield; }
input.no-spin::-webkit-inner-spin-button, input.no-spin::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=file]::file-selector-button {
  font: inherit; font-weight: 550; margin-right: .6rem; padding: .35rem .8rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer;
}
label { color: var(--text); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem 1rem 1rem; }
legend { padding: 0 .4rem; font-weight: 600; color: var(--text-muted); font-size: .9rem; }
details > summary { cursor: pointer; color: var(--text-muted); }
details > summary:hover { color: var(--text); }
progress { accent-color: var(--accent); }
form.inline { display: inline; }

button.is-busy::after {
  content: ""; display: inline-block; width: .8em; height: .8em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: busy-spin .7s linear infinite;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }

/* 4. Layout -------------------------------------------------------------------- */
main { padding: .75rem 1.5rem 1.5rem; max-width: 1600px; margin: 0 auto; }
main:has(> .split) { max-width: none; } /* validation screen: the PDF gets the whole width */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 1.25rem; }
.page-header h1 { margin: 0; font-size: 1.6rem; }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.spacer { flex: 1; }

/* 5. App shell ------------------------------------------------------------------ */
nav.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  min-height: var(--topbar-h); padding: .5rem 1.5rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 650; color: var(--text); }
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: var(--radius-sm); display: grid; place-items: center;
  background: var(--accent); color: var(--accent-contrast);
}
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.tabs a { padding: .3rem .8rem; border-radius: 999px; color: var(--text-muted); font-weight: 500; }
.tabs a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.user-menu { display: flex; align-items: center; gap: .5rem; color: var(--text-muted); }
.app-version { font-size: .8rem; font-variant-numeric: tabular-nums; margin-right: .5rem; opacity: .75; }
/* Ollama host status: a quiet dot while it answers, a red pill when it doesn't. */
.llm-badge { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; cursor: help; }
.llm-dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--text-muted); }
.llm-ok .llm-dot { background: var(--ok); }
.llm-unknown { opacity: .75; }
.llm-down { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.llm-down .llm-dot { background: var(--danger); animation: llm-pulse 1.6s ease-in-out infinite; }
.llm-missing { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.llm-missing .llm-dot { background: var(--warn); }
@keyframes llm-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .llm-down .llm-dot { animation: none; } }

/* 6. Surfaces --------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.card-header h2, .card-header h3 { margin: 0; }
.banner { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem .9rem; border-radius: 10px; border: 1px solid transparent; margin: .6rem 0; }
.banner > .icon { margin-top: .2em; }
.banner p { margin: .15rem 0; }
.banner-info { background: var(--info-bg); } .banner-info > .icon { color: var(--info); }
.banner-ok { background: var(--ok-bg); } .banner-ok > .icon { color: var(--ok); }
.banner-warn { background: var(--warn-bg); } .banner-warn > .icon { color: var(--warn); }
.banner-error { background: var(--danger-bg); } .banner-error > .icon { color: var(--danger); }

.toast-region { position: fixed; top: calc(var(--topbar-h) + .75rem); right: 1.5rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem .55rem .9rem; border-radius: 10px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-pop); font-weight: 550;
  transition: opacity .3s, transform .3s;
}
.toast-ok > .icon { color: var(--ok); }
.toast-warn > .icon { color: var(--warn); }
.toast-error > .icon { color: var(--danger); }
.toast-info > .icon { color: var(--accent); }
.toast button { min-height: 0; padding: .2rem; border: 0; background: transparent; color: inherit; opacity: .6; }
.toast button:hover { opacity: 1; background: transparent; color: inherit; }
.toast.is-leaving { opacity: 0; transform: translateY(-.4rem); }

/* 7. Tables ------------------------------------------------------------------------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .93rem; }
th, td { text-align: left; padding: .5rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th {
  position: sticky; top: var(--topbar-h); z-index: 2; background: var(--surface);
  font-size: .78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
tbody td { height: var(--row); }
tbody tr:nth-child(even of :not(.group-row)) > td { background: var(--surface-2); }
tbody tr:hover > td { background: var(--accent-soft); }
tfoot td, tfoot th { font-weight: 650; border-top: 1px solid var(--border-strong); border-bottom: 0; }
table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
thead tr:first-child th:first-child { border-top-left-radius: var(--radius); }
thead tr:first-child th:last-child { border-top-right-radius: var(--radius); }
tbody tr:last-child > td { border-bottom: 0; }
tbody tr:last-child > td:first-child { border-bottom-left-radius: var(--radius); }
tbody tr:last-child > td:last-child { border-bottom-right-radius: var(--radius); }
.table-wrap { overflow-x: auto; }
.table-wrap thead th { top: 0; } /* the wrapper is the scroll box: offset from it, not from the page */
tr.group-row > th, tr.group-row > td { background: var(--bg); height: auto; padding: .4rem .9rem; font-size: .82rem; font-weight: 650; color: var(--text-muted); }
tbody tr:has(.row-link) { position: relative; }
.row-link { color: var(--text); font-weight: 550; }
.row-link::after { content: ""; position: absolute; inset: 0; }
.row-link:hover { color: var(--text); text-decoration: none; }
.sub { display: block; font-size: .82rem; color: var(--text-muted); font-weight: 400; }

.table-tools { display: flex; gap: .6rem; align-items: center; margin: .75rem 0; }
.table-tools input[type=search] {
  min-width: 18rem; padding-left: 2rem;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237A8494' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat .6rem center;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: " ↕"; opacity: .4; font-size: .9em; }
th[aria-sort="ascending"]::after { content: " ▲"; opacity: .9; }
th[aria-sort="descending"]::after { content: " ▼"; opacity: .9; }

/* 8. Badges & chips ---------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .05rem .6rem .05rem .45rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.badge .icon { width: .85rem; height: .85rem; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }
.chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .83rem; font-weight: 500; }
.chip-warn { color: var(--warn); }
.empty { padding: 3rem 1rem; text-align: center; color: var(--text-muted); }
.empty > .icon { width: 2rem; height: 2rem; color: var(--border-strong); }
.empty p { margin: .3rem 0; }

/* 9. Filters ------------------------------------------------------------------------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat-card {
  display: flex; flex-direction: column; gap: .2rem; padding: .8rem 1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); color: var(--text);
}
.stat-card:hover { border-color: var(--border-strong); color: var(--text); text-decoration: none; }
.stat-card[aria-current] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.stat-label { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--text-muted); font-weight: 500; }
.dot { width: .5rem; height: .5rem; border-radius: 50%; flex: none; background: var(--border-strong); }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); } .dot-info { background: var(--info); }
.dot-danger { background: var(--danger); } .dot-neutral { background: var(--neutral); }
.filters { margin-bottom: .75rem; }
.filters .table-tools { margin: 0; }
.stat-value { font-size: 1.6rem; font-weight: 680; font-variant-numeric: tabular-nums; line-height: 1.1; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.seg a, .seg button {
  min-height: 30px; padding: .2rem .75rem; border: 0; border-radius: 7px; background: transparent;
  color: var(--text-muted); font-weight: 550; font-size: .9rem; display: inline-flex; align-items: center; gap: .35rem;
}
.seg a:hover, .seg button:hover { color: var(--text); text-decoration: none; background: transparent; }
.seg [aria-current], .seg .on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.action-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.action-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; margin-bottom: var(--space-6); }
.action-card h3 { margin: 0 0 .15rem; display: flex; align-items: center; gap: .45rem; }
.action-card p { margin: 0; display: flex; align-items: center; gap: .4rem; }
.action-card p .icon { color: var(--warn); }
.action-card label { color: var(--text-muted); font-size: .9rem; font-weight: 550; }
section > h2 { margin: 0; }

/* 10. Progressive enhancement (app.js) ---------------------------------------------- */
#busy-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 1000;
  background: var(--accent); opacity: 0; pointer-events: none;
}
body.busy #busy-bar { opacity: 1; animation: busy-bar 8s cubic-bezier(.1, .7, .3, 1) forwards; }
@keyframes busy-bar { from { width: 0; } 30% { width: 55%; } to { width: 92%; } }
body.busy main, body.busy .values { opacity: .6; transition: opacity .2s .15s; }
body.busy { cursor: progress; }

.live-checks { margin: .4rem 0; padding: .45rem .7rem; border-radius: var(--radius-sm); background: var(--warn-bg); }
.live-checks p { margin: .15rem 0; }
.live-checks p.ok { color: var(--ok); }
.live-checks button { margin: .2rem .4rem .2rem 0; }
.live-checks:has(p.ok:only-child) { background: var(--ok-bg); }
input.live-invalid { outline: 2px solid var(--danger); }

#bulk-status progress { width: 14rem; vertical-align: middle; margin-left: .5rem; }
html:not(.js) #bulk-status progress { display: none; }

/* Validation screen ------------------------------------------------------------------
 * Fits dad's 1920×950 viewport without scrolling: the page is one screen high, the PDF on
 * the left (invoice header above, totals below, PDF.js), every field + the actions on the right.
 * The right pane only scrolls as a fallback on smaller screens. */
main:has(> .split) { padding-bottom: .75rem; }
.split {
  display: grid; grid-template-columns: minmax(0, 3fr) minmax(440px, 2fr); gap: 1.25rem;
  height: calc(100vh - var(--topbar-h) - 1.5rem); height: calc(100dvh - var(--topbar-h) - 1.5rem);
}
.pdf-view { display: flex; flex-direction: column; gap: .4rem; min-height: 0; min-width: 0; }
.pdf-view iframe { flex: 1; width: 100%; min-height: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--pdf-bg); }
.pdf-tools { flex: none; display: flex; gap: .6rem; align-items: center; font-size: .85rem; color: var(--text-muted); }
.pdf-tools .seg button { min-height: 26px; font-size: .83rem; padding: .1rem .65rem; }
.pdf-tools a { display: inline-flex; align-items: center; gap: .3rem; }
.pdf-split { flex: 1; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--pdf-bg); }
.pdf-split[hidden] { display: none; }
.pdf-pane { overflow: auto; min-height: 3rem; background: #fff; }
.pdf-page { position: relative; width: fit-content; }
.pdf-pane canvas { display: block; }
/* PDF.js text layer (from its pdf_viewer.css): invisible spans placed over the glyphs */
.textLayer { position: absolute; inset: 0; overflow: clip; line-height: 1; text-align: initial; text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; z-index: 0; }
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) { z-index: 1; }
.textLayer span.markedContent { top: 0; height: 0; }
.textLayer ::selection { background: rgb(0 0 255 / .25); }
.textLayer br::selection { background: transparent; }
.pdf-divider { flex: 0 0 10px; cursor: row-resize; background: var(--surface-2); border-block: 1px solid var(--border); touch-action: none; position: relative; }
.pdf-divider::after { content: ""; position: absolute; left: 50%; top: 50%; width: 40px; height: 3px; margin: -1.5px 0 0 -20px; border-radius: 2px; background: var(--border-strong); }
.pdf-divider:hover { background: var(--accent-soft); }

.values { display: flex; flex-direction: column; gap: .6rem; min-height: 0; min-width: 0; overflow-y: auto; padding: 0 .25rem 0 0; }
.values > * { flex: none; margin: 0; }
.values-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.values-head h1 { margin: 0; font-size: 1.35rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.queue-pos { margin-left: auto; display: inline-flex; align-items: center; gap: .5rem; font-size: .83rem; color: var(--text-muted); white-space: nowrap; }
.queue-pos progress {
  appearance: none; width: 90px; height: 6px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); overflow: hidden;
}
.queue-pos progress::-webkit-progress-bar { background: var(--surface-2); }
.queue-pos progress::-webkit-progress-value { background: var(--accent); }
.queue-pos progress::-moz-progress-bar { background: var(--accent); }
.run-detail { margin-top: -.35rem !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.values .banner { margin: 0; align-items: center; font-size: .9rem; }
.values .banner > .icon { margin-top: 0; }
.banner-line .banner-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.banner-line .btn-sm { flex: none; }
.values p.warning { font-size: .9rem; }

.validate-form { display: flex; flex-direction: column; gap: .6rem; }
.validate-form .card { display: flex; flex-direction: column; gap: .65rem; padding: .8rem .9rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.field { display: flex; flex-direction: column; gap: .25rem; font-size: .83rem; font-weight: 550; color: var(--text-muted); }
.values .input { width: 100%; height: 40px; padding: 0 .75rem; font-size: 1.05rem; color: var(--text); font-weight: 400; }
.values .input.amount { text-align: right; font-family: var(--font-mono); font-size: 1rem; font-variant-numeric: tabular-nums; }
.values .input.total { font-weight: 700; }
.values .input.doubt, .vat-table tbody.doubt .input { border-color: var(--warn); background: var(--warn-bg); }
.field :where(input, select, textarea) { font-weight: 400; color: var(--text); }
.field .chip, .vat-notes .chip { font-weight: 500; align-items: flex-start; }
.field .chip .icon, .vat-notes .chip .icon { margin-top: .2em; }
.field button { align-self: flex-start; }
.supplier { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.supplier .supplier-open { margin-left: auto; flex: none; border-color: var(--border); }
.avatar {
  width: 28px; height: 28px; border-radius: 7px; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .75rem;
}
.new-supplier {
  display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.2fr) minmax(5.5rem, .6fr); gap: .65rem;
  margin: 0; padding: .2rem .8rem .8rem;
}
.new-supplier .muted { font-weight: 400; }

.vat-table, .vat-table th, .vat-table td { background: none; border: 0; box-shadow: none; border-radius: 0; height: auto; }
.vat-table th, .vat-table td { padding: .15rem 0; }
.vat-table td + td { padding-left: .5rem; }
.vat-table thead th {
  position: static; text-align: right; padding-bottom: .3rem; text-transform: none; letter-spacing: 0;
  font-size: .8rem; font-weight: 600; color: var(--text-muted);
}
.vat-table thead th:first-child { text-align: left; }
.vat-table tbody th, .vat-table tfoot th { width: 4rem; text-align: left; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.vat-table tbody tr:hover > td, .vat-table tbody tr:nth-child(even of :not(.group-row)) > td { background: none; }
.vat-table tfoot th, .vat-table tfoot td { padding-top: .5rem; color: var(--text); }
.vat-notes { display: flex; flex-direction: column; gap: .3rem; }
.vat-notes:empty { display: none; }
.vat-notes p { margin: 0; font-size: .9rem; }
.validate-form .live-checks { margin: 0; }
/* Validated / exported: the saved values, read-only (fieldset disabled). */
fieldset.validate-form.readonly { border: 0; padding: 0; margin: .6rem 0 0; min-width: 0; }
.readonly .input { background: transparent; border-style: dashed; color: var(--text); opacity: 1; cursor: default; -webkit-text-fill-color: var(--text); }
.field-reviews { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
.field-reviews li { display: flex; flex-wrap: wrap; align-items: baseline; gap: .3rem .6rem; font-size: .88rem; }
.field-reviews .change { font-variant-numeric: tabular-nums; }
.accept { font-size: .9rem; }

.values > .action-row { margin-top: auto; position: sticky; bottom: 0; z-index: 1; padding: .4rem 0 .1rem; background: var(--bg); }
.values .action-row button, .values .action-row .btn { min-height: 42px; padding: 0 1rem; font-size: .95rem; }
.values .card .action-row button, .values .card .action-row .btn { min-height: 38px; }
@media (max-width: 1600px) { /* one row in a narrower pane: the shortcuts still work, only Alt+V stays spelled out */
  .values > .action-row kbd:not([data-accesskey="V"]) { display: none; }
  .values > .action-row .btn-ghost, .values > .action-row .btn-ghost-danger { padding: 0 .6rem; }
}
.discard { position: relative; }
.discard > summary { list-style: none; }
.discard > summary::-webkit-details-marker { display: none; }
.discard-pop {
  position: absolute; right: 0; bottom: calc(100% + .4rem); z-index: 5; width: min(28rem, 80vw);
  display: flex; flex-direction: column; gap: .5rem; padding: .8rem .9rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-pop);
}
.discard-pop p { margin: 0; }
.discard-pop .action-row { align-items: flex-end; }
.discard-pop .field { flex: 1; }

/* Shared page pieces ------------------------------------------------------------------ */
html:not(.js) .js-only { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; white-space: nowrap; }
.section-gap { margin-top: var(--space-6); }
main > .banner + section, main > .stat-cards + .legend { margin-top: 1.1rem; }

/* Exportació */
.period-picker { display: flex; align-items: end; gap: .75rem; }
.period-picker .year-input { width: 6.5rem; }
.period-picker .seg { align-self: end; }
.period-picker .seg button { min-height: 32px; }
.export-table .badge { margin-left: .35rem; }
.export-card { display: flex; flex-direction: column; gap: .75rem; }
.export-card p { margin: 0; max-width: 60rem; }
.export-number { display: flex; align-items: end; gap: 1rem; flex-wrap: wrap; }
.export-number .field { font-size: .9rem; color: var(--text); }
.export-number input { width: 12rem; min-height: 40px; font-size: 1.1rem; font-family: var(--font-mono); }
.revert-row { margin-top: .5rem; justify-content: flex-end; color: var(--text-muted); font-size: .9rem; }
.stack-sm { display: flex; flex-direction: column; gap: .6rem; }
.stack-sm > * { margin: 0; }
.back-link { display: inline-flex; align-items: center; gap: .3rem; font-weight: 500; margin-bottom: .2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .75rem; align-items: end; }
.form-grid input:not([type=hidden]) { width: 100%; }
.form-actions { display: flex; align-items: end; }
.edit-card { max-width: 46rem; }
.edit-card input:not([type=hidden], [type=checkbox]) { width: 100%; min-height: 40px; }
.check-row { display: flex; align-items: flex-start; gap: .55rem; font-size: .9rem; }
.check-row input { margin-top: .2em; flex: none; }
.check-row .muted { display: block; font-size: .83rem; }
.card > h2, .card > p { margin: 0; }
.card + .card, .card + .banner, .banner + .card, details.panel + .table-tools { margin-top: .9rem; }
.note-card { margin: 1rem 0 0; }
.note-card p { max-width: 60rem; }

/* <details class="card panel">: a collapsible form card. The header buttons open it (app.js);
 * with JS a closed panel is hidden altogether, without JS its summary stays to click. */
details.panel { margin-bottom: .9rem; }
details.panel > summary { list-style: none; display: flex; align-items: center; gap: .5rem; color: var(--text); }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: "▸"; color: var(--text-muted); transition: transform .15s; }
details.panel[open] > summary::before { transform: rotate(90deg); }
details.panel > summary h2 { margin: 0; font-size: 1.05rem; }
details.panel[open] > summary { margin-bottom: .75rem; }
details.panel > p { margin: 0 0 .75rem; }
html.js details.panel:not([open]) { display: none; }

/* Login */
body.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(100%, 360px); max-width: none; margin: 0; padding: 1.75rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.login-card h1 { margin: 0; font-size: 1.35rem; }
.login-card .banner { margin: 0; }
.login-card .stack { gap: .9rem; }
.login-card input { width: 100%; min-height: 40px; }
.login-card button { width: 100%; min-height: 42px; }
.error-card { width: min(100%, 480px); margin: 2rem auto; }
.error-card .empty { padding-bottom: 1rem; }
.error-actions { display: flex; justify-content: center; margin: 0 0 1.5rem; }

/* Revisions */
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin: 0 0 .5rem; }
.stat-value.error { color: var(--danger); }
.revisions-table td { vertical-align: top; padding-block: .6rem; }
.reasons { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: .2rem; font-size: .88rem; }
.reasons li { display: flex; gap: .45rem; align-items: baseline; }
.reasons .dot { transform: translateY(-.1em); }
.change { white-space: nowrap; font-size: .88rem; }
.change code { padding: 0 .3rem; border-radius: 4px; background: var(--surface-2); }
.change code.new { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Proveïdors */
.link-table { box-shadow: none; }
.link-table select { width: 100%; max-width: 32rem; }
.link-table td:nth-child(3) { width: 55%; }
.suppliers-table tbody td { height: var(--row); padding-block: .3rem; }
.suppliers-table .sub { display: inline; margin-left: .5rem; font-size: .8rem; } /* one line: rows stay 44px */
.row-actions-form { position: relative; z-index: 1; display: inline-flex; align-items: center; gap: .4rem; }
.row-action { opacity: 0; transition: opacity .12s; }
tr:hover .row-action, tr:focus-within .row-action, .row-action:focus-visible { opacity: 1; }
@media (hover: none) { .row-action { opacity: 1; } }

/* 11. Responsive + motion ------------------------------------------------------------ */
@media (max-width: 900px) {
  nav.topbar { gap: .4rem .75rem; padding: .5rem 1rem .4rem; }
  /* brand + user on the first row, the tabs as one row below that scrolls sideways */
  nav.topbar .user-menu { margin-left: auto; }
  nav.topbar .tabs { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -.25rem; }
  nav.topbar .tabs a { white-space: nowrap; }
  .page-header { align-items: flex-start; }
  .period-picker { flex-wrap: wrap; }
  main { padding: .75rem 1rem 1.5rem; }
  .hide-sm { display: none; }
  thead th { top: 0; }
  .table-tools { flex-wrap: wrap; }
  .table-tools input[type=search] { min-width: 0; flex: 1 1 12rem; }
  .table-tools .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .table-tools .seg button { white-space: nowrap; }
  .link-table select { min-width: 12rem; }
  .split { grid-template-columns: minmax(0, 1fr); height: auto; }
  .pdf-view { height: 70vh; }
  .values { overflow: visible; padding: 0; }
  .values > .action-row { position: static; }
  .pdf-tools { flex-wrap: wrap; }
  .pdf-tools > .muted { display: none; }
  .new-supplier { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  body.busy #busy-bar { animation: none; width: 60%; }
  button.is-busy::after { animation: none; }
  .toast { transition: none; }
}
