/* ============================================================================
   Creditor Invoice Automation — "Engineered Ledger" theme
   Parchment + blueprint grid · ink + burnt-orange signal · Fraunces / Plex
   ========================================================================== */

:root {
  /* surfaces */
  --paper:      #f0eae0;
  --paper-edge: #e6dfd0;
  --panel:      #fcfaf5;
  --panel-2:    #f7f3ea;

  /* ink */
  --ink:        #18140d;
  --ink-soft:   #3a342a;
  --muted:      #756c5c;
  --faint:      #a89e8a;

  /* rules */
  --line:       #ddd4c1;
  --line-2:     #c8bda4;

  /* signal + semantics */
  --signal:     #c2410c;   /* burnt orange — in-progress / active */
  --signal-2:   #e2691f;
  --signal-tint:#f6e3d4;
  --ok:         #2c6a3f;
  --ok-tint:    #dfeadf;
  --warn:       #8a5d00;
  --warn-tint:  #f3e6cc;
  --err:        #a02822;
  --err-tint:   #f3dcd8;

  --radius:     4px;
  --radius-lg:  9px;
  --shadow:     0 1px 0 #fff inset, 0 14px 30px -22px rgba(40,30,15,.5);
  --ease:       cubic-bezier(.2, .7, .2, 1);

  --font-display: "Fraunces", Georgia, serif;
  --font-sans:    "IBM Plex Sans", system-ui, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 80% -10%, #fff7ec 0%, transparent 60%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-edge) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

/* faint blueprint grid laid over the page */
.grid-overlay {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(100, 80, 40, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100, 80, 40, .045) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at 50% 30%, #000 60%, transparent 100%);
}

main, .topbar, .footer { position: relative; z-index: 1; }

/* --- type ---------------------------------------------------------------- */
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; line-height: 1.08; }
h1 { font-size: clamp(2rem, 4.4vw, 3.2rem); font-weight: 900; margin: 0; }
h1 em { font-style: italic; font-weight: 500; color: var(--signal); }
h2 { font-size: 1.4rem; margin: 0 0 .5rem; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; font-weight: 400; font-family: var(--font-sans); }
a { color: var(--signal); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
code {
  font-family: var(--font-mono); font-size: .85em;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: .05em .4em; border-radius: 3px; color: var(--ink-soft);
}

/* --- header -------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px clamp(16px, 5vw, 48px);
  border-bottom: 1px solid var(--line-2);
  box-shadow: 0 1px 0 #fff;
}
.brand { display: flex; align-items: center; gap: 14px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  font-family: var(--font-display); font-weight: 900; font-size: 1.5rem;
  width: 42px; height: 42px; display: grid; place-items: center;
  color: var(--paper); background: var(--ink);
  border-radius: 8px; box-shadow: var(--shadow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.12rem; }
.brand-name em { font-style: italic; font-weight: 500; color: var(--signal); }
.brand-sub { font-family: var(--font-mono); font-size: .62rem; letter-spacing: .22em; color: var(--faint); }

.sess-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .06em;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--panel); white-space: nowrap;
}
.sess-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.sess-pill.is-on  { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.sess-pill.is-on  .sess-dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-tint); }
.sess-pill.is-off { color: var(--warn); }
.sess-pill.is-off .sess-dot { background: var(--warn); }

.topbar-end { display: inline-flex; align-items: center; gap: 12px; }
.logout-form { margin: 0; }
.logout-btn {
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .06em;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2);
  background: transparent; color: var(--faint); cursor: pointer; white-space: nowrap;
}
.logout-btn:hover { color: var(--ink); border-color: var(--ink); background: var(--panel-2); }

/* --- layout -------------------------------------------------------------- */
main { max-width: 1000px; margin: 0 auto; padding: clamp(20px, 4vw, 40px) clamp(16px, 5vw, 48px) 64px; }
main.wide { max-width: none; padding-left: 6px; padding-right: 6px; }

.hero { margin-bottom: 28px; }
.hero.compact { margin-bottom: 22px; }
.hero-head { margin-bottom: 26px; }
.eyebrow {
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .26em;
  text-transform: uppercase; color: var(--signal); margin: 0 0 12px;
}
.back { font-family: var(--font-mono); font-size: .78rem; letter-spacing: .04em; }
.invoice-title { font-size: clamp(1.7rem, 3.6vw, 2.6rem); margin-top: 8px; }
.invoice-title em { font-style: normal; color: var(--signal); }

.columns { display: grid; grid-template-columns: 1fr 1.25fr; gap: 18px; }
@media (max-width: 760px) { .columns { grid-template-columns: 1fr; } }

/* --- lifecycle rail ------------------------------------------------------ */
.rail { overflow-x: auto; padding-bottom: 4px; }
.rail-track {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(5, 1fr); min-width: 520px;
}
.rail-node {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding-top: 4px;
}
/* connector line to the previous node */
.rail-node::before {
  content: ""; position: absolute; top: 21px; right: 50%; left: -50%; height: 2px;
  background: var(--line-2); z-index: 0;
}
.rail-node:first-child::before { display: none; }
.rail-dot {
  position: relative; z-index: 1;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: .82rem; font-weight: 600;
  background: var(--panel); color: var(--faint);
  border: 2px solid var(--line-2);
  transition: transform .3s var(--ease);
}
.rail-label {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--faint);
}
/* states */
.rail-node.is-done  .rail-dot   { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.rail-node.is-done::before      { background: var(--ink); }
.rail-node.is-done  .rail-label { color: var(--ink-soft); }

.rail-node.is-active .rail-dot {
  background: var(--signal); color: #fff; border-color: var(--signal);
  box-shadow: 0 0 0 5px var(--signal-tint), 0 8px 18px -8px var(--signal);
  transform: scale(1.08);
  animation: breathe 2.6s var(--ease) infinite;
}
.rail-node.is-active .rail-label { color: var(--signal); font-weight: 600; }
.rail-node.is-active::before { background: linear-gradient(90deg, var(--ink), var(--signal)); }

.rail-node.is-error .rail-dot {
  background: var(--err); color: #fff; border-color: var(--err);
  box-shadow: 0 0 0 5px var(--err-tint);
  animation: shake .5s var(--ease);
}
.rail-node.is-error .rail-label { color: var(--err); font-weight: 600; }
.rail-node.is-error::before { background: linear-gradient(90deg, var(--ink), var(--err)); }

@keyframes breathe { 50% { box-shadow: 0 0 0 8px transparent, 0 8px 18px -8px var(--signal); } }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* --- panels -------------------------------------------------------------- */
.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px 24px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.panel.alert { border-color: color-mix(in srgb, var(--err) 45%, var(--line)); background: linear-gradient(var(--panel), var(--err-tint) 320%); }
.panel-tab {
  position: absolute; top: -10px; left: 20px;
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--paper);
  background: var(--ink); padding: 3px 10px; border-radius: 999px;
}
.panel-tab.tab-err { background: var(--err); }
.panel-tab.tab-warn { background: var(--warn); }

/* --- status lines -------------------------------------------------------- */
.status { padding: 10px 14px; border-radius: var(--radius); margin: 4px 0 14px; border: 1px solid transparent; }
.status b { font-family: var(--font-display); }
.status-ok   { background: var(--ok-tint);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.status-warn { background: var(--warn-tint); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.status-err  { background: var(--err-tint);  color: var(--err);  border-color: color-mix(in srgb, var(--err) 25%, transparent); }
/* Warning triangle flagging an item dropped by a re-review re-pull (refresh_read). */
.warn-tri { color: var(--warn); flex: none; margin-right: 4px; cursor: help; }
.refresh-dropped .dropped-list { margin: 6px 0 0; padding-left: 4px; list-style: none; }
.refresh-dropped .dropped-list li { display: flex; align-items: baseline; gap: 2px; margin: 3px 0; }
.note { color: var(--muted); font-size: .92rem; margin: 8px 0; }
.note.pulsing { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.codeblock-inline {
  background: var(--ink); color: #ffd9c9; padding: 12px 14px; border-radius: var(--radius);
  font-size: .85rem; word-break: break-word; margin: 8px 0;
}

/* --- forms / inputs ------------------------------------------------------ */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 14px 0; }
@media (max-width: 560px) { .field-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--ink-soft); font-weight: 500; }
input[type=text], select.line-uom, select.line-code {
  width: 100%; padding: 10px 12px; font-family: var(--font-mono); font-size: .92rem;
  color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--line-2); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input[type=text]:focus, select.line-uom:focus, select.line-code:focus {
  outline: none; background: #fff; border-color: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-tint);
}
input[type=text]::placeholder { color: var(--faint); }

/* dropzone */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; padding: 34px 20px; cursor: pointer;
  border: 2px dashed var(--line-2); border-radius: var(--radius-lg);
  background:
    repeating-linear-gradient(45deg, transparent 0 10px, rgba(194,65,12,.025) 10px 20px),
    var(--panel-2);
  transition: border-color .2s, background .2s, transform .2s var(--ease);
}
.dropzone:hover { border-color: var(--signal); }
.dropzone.is-drag { border-color: var(--signal); background: var(--signal-tint); transform: scale(1.01); }
.dropzone.has-file { border-style: solid; border-color: var(--ok); background: var(--ok-tint); }
.dz-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dz-glyph { font-size: 1.7rem; color: var(--signal); line-height: 1; }
.dropzone.has-file .dz-glyph { color: var(--ok); }
.dz-text { font-family: var(--font-mono); font-size: .95rem; word-break: break-all; }
.dz-text em { font-style: normal; color: var(--signal); text-decoration: underline; text-underline-offset: 3px; }
.dz-hint { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); }

.overrides { margin: 16px 0 4px; border-top: 1px dashed var(--line-2); padding-top: 8px; }
.overrides > summary, .manifest > summary {
  cursor: pointer; font-family: var(--font-mono); font-size: .78rem; letter-spacing: .04em;
  color: var(--ink-soft); padding: 8px 0; list-style: none;
}
.overrides > summary::before, .manifest > summary::before {
  content: "▸ "; color: var(--signal); display: inline-block; transition: transform .2s;
}
.overrides[open] > summary::before, .manifest[open] > summary::before { content: "▾ "; }

/* --- buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-sans); font-size: .95rem; font-weight: 600;
  padding: 12px 22px; border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; margin-top: 14px;
  transition: transform .12s var(--ease), box-shadow .2s, background .2s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: var(--paper); box-shadow: 0 10px 18px -12px var(--ink); }
.btn-primary:hover { background: #2a241a; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-2); }
.btn-ghost:hover { border-color: var(--ink); background: var(--panel-2); }
/* compact button — inline table actions (NPO add/delete line) */
.btn-sm { padding: 5px 11px; font-size: .8rem; margin-top: 0; }

/* Change-PO control (re-point an invoice that fetched the wrong PO). */
.po-change-wrap { margin: 10px 0 4px; }
.po-change-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.po-change { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* `input` qualifier so this beats the global `input[type=text]` rule (equal
   specificity, later in the file) — otherwise the PO box stretches full-width
   and wraps its button onto a second line, knocking the NPO button out of line. */
input.po-input {
  width: 11ch; padding: 6px 10px; border: 1px solid var(--line-2);
  border-radius: 8px; background: var(--panel); font-size: .85rem;
}
.po-change-btn { padding: 6px 12px; font-size: .8rem; white-space: nowrap; }
.po-change-wrap .note.small { margin: 0 0 6px; font-size: .75rem; }
/* "Has a PO?" control on an NPO card — a separate form below the creation form
   that moves the invoice to its own PO batch. Separated from the form above by a
   top rule; label + 11ch PO box + button sit on one baseline-aligned row. */
.npo-to-po {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  margin: 16px 0 2px; padding-top: 14px; border-top: 1px solid var(--line-2);
}
.npo-to-po-field { flex: 0 0 auto; gap: 4px; font-size: .8rem; }
.npo-to-po .status-err { flex: 1 0 100%; margin: 0 0 2px; }
/* Moved-to-PO link panel; a moved batch card reads as parked, not active. */
.moved-to-po .btn { margin-top: 8px; }
.invoice-card.is-moved > summary { opacity: .82; }
.btn-danger {
  background: var(--err); color: #fff;
  box-shadow: 0 10px 22px -10px var(--err);
}
.btn-danger:hover { background: #b8302a; }
.btn[disabled] { opacity: .55; cursor: default; transform: none; }
.spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.approve-bar {
  margin-top: 20px; padding: 16px 18px; border-radius: var(--radius-lg);
  background: var(--err-tint); border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
}
.approve-bar .note { margin: 6px 0 0; }

/* --- upload status (replaces the form during in-flight upload + read) ---- */
.upload-status { margin-top: 8px; }
.us-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.us-head h3 { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; margin: 0; color: var(--ink); }
.us-head .us-spin { width: 16px; height: 16px; color: var(--signal); }
.us-steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.us-step {
  display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); opacity: .55;
  transition: background .2s, border-color .2s, opacity .2s;
}
.us-step.is-active { opacity: 1; border-color: color-mix(in srgb, var(--signal) 30%, transparent); background: var(--signal-tint); }
.us-step.is-done   { opacity: 1; border-color: color-mix(in srgb, var(--ok)     30%, transparent); background: var(--ok-tint); }
.us-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--line-2);
  color: var(--muted); font-family: var(--font-mono); font-size: .7rem; font-weight: 600;
}
.us-step.is-active .us-mark { color: var(--signal); border-color: color-mix(in srgb, var(--signal) 40%, transparent); }
.us-step.is-done   .us-mark { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.us-mark .spin { width: 12px; height: 12px; }
.us-check { font-size: 1rem; line-height: 1; }
.us-body { min-width: 0; }
.us-label { font-size: .92rem; color: var(--ink-soft); }
.us-step.is-active .us-label { color: var(--ink); }
.us-detail { font-family: var(--font-mono); font-size: .82rem; color: var(--ink); word-break: break-all; }
.us-bar {
  margin-top: 8px; height: 6px; border-radius: 999px; overflow: hidden;
  background: color-mix(in srgb, var(--signal) 14%, var(--paper));
}
.us-bar-fill { display: block; height: 100%; width: 0%; background: var(--signal); transition: width .18s ease; }
.us-step.is-done .us-bar-fill { background: var(--ok); }
.us-note { margin: 12px 0 0; font-size: .82rem; }
/* Reuses the .chip pill, but holds a full error message — override the chip's
   single-line nowrap so a long error (e.g. an Azure auth failure with a GUID and
   data-action path) wraps inside the card instead of stretching it wide. */
.us-error {
  margin-top: 12px; display: flex; align-items: flex-start;
  white-space: normal; overflow-wrap: anywhere; word-break: break-word;
  border-radius: 12px; line-height: 1.45; text-align: left;
}
.us-error .chip-dot { margin-top: 6px; flex: 0 0 auto; }
/* display: flex above would otherwise beat the UA [hidden], leaving the empty
   error chip visible before any failure. */
.us-error[hidden] { display: none !important; }

/* --- readout (key/value) ------------------------------------------------- */
.readout { display: grid; gap: 1px; margin: 6px 0 0; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ro { display: grid; grid-template-columns: 200px 1fr; gap: 12px; padding: 11px 14px; background: var(--panel); align-items: baseline; }
@media (max-width: 520px) { .ro { grid-template-columns: 1fr; gap: 2px; } }
.ro dt { color: var(--muted); font-size: .82rem; }
.ro dd { margin: 0; }
.ro .big { font-size: 1.25rem; color: var(--signal); }
.arrow { color: var(--faint); margin: 0 4px; }

.tag { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.tag-ok  { background: var(--ok-tint);  color: var(--ok); }
.tag-err { background: var(--err-tint); color: var(--err); }

/* order totals */
.totals { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.total {
  flex: 1 1 120px; display: flex; flex-direction: column; gap: 2px;
  padding: 12px 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.total b { font-size: 1.15rem; }
.total small { font-family: var(--font-mono); font-size: .64rem; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); }

/* --- tables (ledger) ----------------------------------------------------- */
.ledger { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: .92rem; }
.ledger thead th {
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--line-2); font-weight: 600;
}
.ledger td { padding: 10px; border-bottom: 1px solid var(--line); }
.ledger tbody tr { transition: background .12s; }
.ledger tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.ra, td.ra, th.ra { text-align: right; }

/* keep the wide line-item table inside its panel; scroll instead of overflow.
   Cap the height to the sticky PDF viewer (same calc as .pdf-frame) so the list
   never extends past the bottom of the document — the operator can always see
   both the PDF and the order lines at once. Shared by the invoice review cards
   and the NPO creation cards (both use .lines-wrap). */
.lines-wrap { overflow: auto; margin-top: 12px; max-height: calc(100vh - 150px); }
.lines { margin-top: 0; min-width: 560px; }
.lines td, .lines th { overflow-wrap: anywhere; }

/* pin the column headers (and the invoice totals footer) while the rows scroll
   inside the capped wrapper, so context stays visible at every scroll position */
.lines-wrap thead th { position: sticky; top: 0; z-index: 2; background: var(--panel); }
.lines-wrap .lines-foot { position: sticky; bottom: 0; z-index: 2; }
.lines-wrap .lines-foot td { background: var(--panel); }

/* Description is the widest column; clip it to ~half so the editable
   qty/rate columns have room. The inner div enforces the cap reliably. */
.lines .desc-clip { max-width: 220px; overflow-wrap: anywhere; }

/* editable qty / rate cells */
input.cell-input {
  width: 84px; padding: 5px 8px; font-family: var(--font-mono); font-size: .86rem;
  color: var(--ink); background: var(--panel-2); text-align: right;
  border: 1px solid var(--line-2); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input.cell-input:focus { outline: none; background: #fff; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-tint); }

.lines .line-row { cursor: pointer; }
.lines .line-row:hover td { background: var(--signal-tint); }
.ledger tr.matchrow td { background: var(--signal-tint) !important; }
/* single accent bar down the left of the row — not one per cell */
.ledger tr.matchrow td:first-child { box-shadow: inset 3px 0 0 var(--signal); }
input[type=radio],
input[type=checkbox] { accent-color: var(--signal); width: 16px; height: 16px; cursor: pointer; }

.rowlink { font-family: var(--font-mono); font-size: .82rem; white-space: nowrap; }

/* --- chips (worklist) ---------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .03em;
  padding: 4px 11px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-ok     { background: var(--ok-tint);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.chip-err    { background: var(--err-tint);    color: var(--err);    border-color: color-mix(in srgb, var(--err) 25%, transparent); }
.chip-active { background: var(--signal-tint); color: var(--signal); border-color: color-mix(in srgb, var(--signal) 25%, transparent); }
.chip-active .chip-dot { animation: pulse 1.6s ease-in-out infinite; }
.chip-warn   { background: var(--warn-tint);   color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 25%, transparent); }

.empty { text-align: center; color: var(--muted); padding: 36px; border: 1px dashed var(--line-2); border-radius: var(--radius-lg); }

/* --- worklist batch groups ---------------------------------------------- */
/* An expandable batch: the summary is the batch row; the dropdown holds its
   individual invoices. Each batch is boxed so multiple groups read as distinct. */
.batch-group { border: 1px solid var(--line); border-radius: var(--radius); margin-top: 14px; background: var(--panel-2); }
.batch-group + .batch-group { margin-top: 12px; }
.batch-summary {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  cursor: pointer; padding: 12px 14px; list-style: none;
}
.batch-summary::-webkit-details-marker { display: none; }
.batch-caret {
  width: 0; height: 0; border-left: 5px solid var(--signal);
  border-top: 4px solid transparent; border-bottom: 4px solid transparent;
  transition: transform .2s; flex: none;
}
.batch-group[open] > .batch-summary .batch-caret { transform: rotate(90deg); }
.batch-group[open] > .batch-summary { border-bottom: 1px solid var(--line); }
.batch-id { font-size: .9rem; }
.batch-meta { font-size: .78rem; }
/* push the review link to the far right, after the status chip */
.batch-open { margin-left: auto; }
/* the dropdown's invoice table sits flush inside the box */
.batch-group > .ledger { margin-top: 0; padding: 0 14px 10px; }
/* sub-section header inside a mixed upload group (PO invoices / No-PO invoices) */
.batch-sub-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px 4px; font-size: .82rem;
}
.batch-sub-head .rowlink { margin-left: auto; }
.batch-group > .batch-sub-head + .ledger { padding-top: 0; }

/* --- manifest / documents ------------------------------------------------ */
.manifest { margin-top: 18px; }
#manifestBody { transition: opacity .15s ease; }
#manifestBody.is-stale { opacity: .5; }
.doc { position: relative; margin: 10px 0; }
.doc-tag {
  display: inline-block; font-family: var(--font-mono); font-size: .66rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--signal); margin-bottom: 4px;
}
pre {
  font-family: var(--font-mono); font-size: .82rem; line-height: 1.5;
  background: var(--ink); color: #e9e0cf; padding: 14px 16px;
  border-radius: var(--radius); overflow: auto; margin: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.05);
}
pre.wrap { white-space: pre-wrap; word-break: break-all; }

/* --- result page --------------------------------------------------------- */
.result-head { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.seal {
  flex: none; width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.6rem; color: #fff;
  background: var(--ok); box-shadow: 0 0 0 6px var(--ok-tint);
  animation: pop .4s var(--ease);
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.terminal pre { background: #14110b; }
.ln-ok  { color: #b9e6c4; }
.ln-err { color: #ffb4ab; }

/* --- review split: source PDF beside the data --------------------------- */
.review-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.04fr);
  gap: 22px;
  align-items: start;
}
@media (max-width: 980px) { .review-split { grid-template-columns: 1fr; } }

.pdf-pane {
  position: sticky; top: 18px;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow);
}
@media (max-width: 980px) { .pdf-pane { position: static; } }

.pdf-head { display: flex; align-items: center; justify-content: space-between; }
.pdf-tag {
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--paper);
  background: var(--ink); padding: 3px 10px; border-radius: 999px;
}
.pdf-open { font-family: var(--font-mono); font-size: .74rem; letter-spacing: .04em; }
.pdf-frame {
  width: 100%; height: calc(100vh - 150px); min-height: 460px;
  border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--panel-2);
  /* subtle blueprint backing visible while the PDF paints */
  background-image:
    linear-gradient(rgba(100, 80, 40, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100, 80, 40, .05) 1px, transparent 1px);
  background-size: 22px 22px;
}
.pdf-fallback {
  display: grid; place-items: center; gap: 12px; text-align: center;
  padding: 48px 20px; color: var(--muted);
  height: calc(100vh - 150px); min-height: 460px;
}
.pdf-fallback .btn { margin-top: 0; }
.pdf-hint {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint); margin: 0; text-align: center;
}
.review-col { min-width: 0; }
.review-col .panel:first-child { margin-top: 0; }

/* locked rows: already carry an invoice (cinvid != 0), not selectable */
.lines tr.line-row.is-locked { cursor: not-allowed; }
.lines tr.line-row.is-locked td { color: var(--faint); background: var(--panel-2); }
.lines tr.line-row.is-locked:hover td { background: var(--panel-2); }
.lines tr.line-row.is-locked input[type=checkbox] { cursor: not-allowed; opacity: .5; }
.tag-locked { background: var(--line); color: var(--muted); }

/* --- per-row notes on the line table ------------------------------------- */
.lines tr.note-row td { padding: 0 10px 14px; border-bottom: 1px solid var(--line); background: var(--signal-tint); }
.lines tr.note-row[hidden] { display: none; }
.lines tr.matchrow + tr.note-row td:first-child { box-shadow: inset 3px 0 0 var(--signal); }
.row-edit { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: flex-end; padding-top: 10px; }
.uom-field, .code-field { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.note-lbl { font-family: var(--font-mono); font-size: .7rem; letter-spacing: .04em; color: var(--ink-soft); }
.note-lbl code { font-size: .9em; }
.line-uom { min-width: 130px; }
.line-code { min-width: 280px; }

/* --- NPO line editor: compact, inline columns matching the invoice lines --- */
.npo-lines { min-width: 720px; }
.npo-lines td, .npo-lines th { padding: 7px 8px; }
.npo-lines .line-desc { width: 100%; min-width: 150px; text-align: left; }
.npo-lines .line-qty, .npo-lines .line-rate { width: 76px; }
/* compact inline selects (override the big global input/select sizing) */
.npo-lines select.line-uom, .npo-lines select.line-code {
  width: auto; padding: 5px 8px; font-size: .86rem;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius);
}
.npo-lines select.line-uom { min-width: 68px; }
.npo-lines select.line-code { min-width: 130px; }
.npo-lines .gst-cell { white-space: nowrap; }

/* --- per-row note button + editor dialog --------------------------------- */
.note-cell { white-space: nowrap; }
.note-btn {
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .03em;
  padding: 4px 11px; border-radius: 999px; cursor: pointer;
  color: var(--ink-soft); background: var(--panel-2);
  border: 1px solid var(--line-2); transition: border-color .15s, color .15s, background .15s;
}
.note-btn:hover:not(:disabled) { border-color: var(--signal); color: var(--ink); }
.note-btn.has-note { background: var(--signal-tint); border-color: var(--signal); color: var(--ink); font-weight: 600; }
.note-btn.has-note::before { content: "● "; color: var(--signal); }
.note-btn:disabled { opacity: .5; cursor: not-allowed; }

.note-dialog {
  border: 1px solid var(--line-2); border-radius: var(--radius-lg); padding: 20px;
  max-width: 460px; width: 90vw; background: var(--panel); color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}
.note-dialog::backdrop { background: rgba(0, 0, 0, .4); }
.note-dialog h3 { margin: 0 0 12px; font-size: 1rem; }
.note-dialog textarea {
  width: 100%; padding: 10px 12px; font-family: var(--font-mono); font-size: .92rem;
  color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--line-2); border-radius: var(--radius); resize: vertical;
}
.note-dialog textarea:focus { outline: none; background: #fff; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-tint); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* --- add new order line (button + injected editable rows) ---------------- */
.add-items { margin: 4px 0 16px; }
.add-item-btn { font-size: .82rem; }
/* Added lines render like a normal linked (matchrow) row; the only tell is the
   "New" badge in the tick/edit cell. */
.tag-new { background: var(--signal-tint); color: var(--signal); }
.ai-remove:hover:not(:disabled) { border-color: var(--err); color: var(--err); }
/* New lines carry both a Note and a Delete button in the note cell. */
.note-cell .note-btn + .note-btn { margin-left: 6px; }
/* Description is editable on a new line; left-align it (qty/rate stay right). */
.lines tr.new-row .line-desc { width: 100%; max-width: 240px; text-align: left; }

/* --- selected-line totals footer ---------------------------------------- */
.lines-foot td { border-top: 2px solid var(--line-2); border-bottom: none; }
.totals-row td { padding-top: 12px; font-weight: 600; }
.totals-row .total-count { font-weight: 400; margin-left: 6px; }
.totals-warn-row td { padding: 0; border-top: none; }
.totals-warn-row .total-mismatch { margin: 8px 0 0; }

/* --- per-line GST toggle ------------------------------------------------- */
.gst-cell { white-space: nowrap; }
.gst-toggle { display: inline-block; margin-left: 6px; vertical-align: middle; }
.line-gst-toggle { cursor: pointer; }

/* --- "changed from CATS" markers + per-field revert ---------------------- */
/* A field whose live value differs from what we pulled from CATS wears a warm
   amber cue; the ↺ Reset button beside it restores the pulled value. Amber, not
   the burnt-orange signal, so "operator changed this" reads apart from "active". */
.cell-input.is-changed,
.line-uom.is-changed,
.line-code.is-changed {
  border-color: var(--warn);
  background: var(--warn-tint);
}
.line-gst-toggle.is-changed { outline: 2px solid var(--warn); outline-offset: 2px; border-radius: 2px; }

.field-revert {
  display: flex; width: max-content; margin: 4px 0 0 auto; padding: 1px 7px;
  align-items: center; gap: 4px;
  font-family: var(--font-mono); font-size: .64rem; font-weight: 600;
  letter-spacing: .03em; line-height: 1.5;
  color: var(--warn); background: var(--warn-tint);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line));
  border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: background .14s, border-color .14s, color .14s;
  animation: ai-pop .3s var(--ease);
}
/* `.field-revert` sets display, which would otherwise beat the UA [hidden]
   rule and leave every button showing — restore hide-when-unchanged. */
.field-revert[hidden] { display: none !important; }
.field-revert::after { content: "Reset"; }
.field-revert .fr-icon { font-size: .9rem; line-height: 1; }
.field-revert:hover { background: var(--warn); color: var(--paper); border-color: transparent; }
/* In the unit/code sub-row each field is a left-aligned column, so the button
   sits below its select on the left rather than pushed under a right-aligned cell. */
.row-edit .field-revert { margin: 2px 0 0; }
/* Beside the GST checkbox there's no cell to drop under — sit inline instead. */
.gst-cell .field-revert { display: inline-flex; margin: 6px 0 0 8px; vertical-align: middle; }

/* --- per-row "edit" (write value changes without linking) ---------------- */
.check-cell { white-space: nowrap; }
.upd-toggle {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 7px;
  font-size: 10px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); cursor: pointer;
}
.upd-toggle input { cursor: pointer; }
.ledger tr.updaterow td { background: var(--ok-tint) !important; }
.ledger tr.updaterow td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.lines tr.updaterow + tr.note-row td { background: var(--ok-tint); }
.lines tr.updaterow + tr.note-row td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.tag-update { background: var(--ok-tint); color: var(--ok); }
.upd-row.is-upd {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--line));
  box-shadow: inset 3px 0 0 var(--ok);
  background: var(--ok-tint);
}

/* --- human-readable in_order_detail?update viewer ------------------------ */
.upd {
  display: grid; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
}
.upd-scalars { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-bottom: 4px; }
.upd-scalars .kv,
.upd-fields dd { font-family: var(--font-mono); }
.kv { font-family: var(--font-mono); font-size: .8rem; color: var(--ink-soft); }
.kv b { color: var(--muted); font-weight: 500; margin-right: 6px; }

.upd-row {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 10px 12px;
}
.upd-row.is-incl {
  border-color: color-mix(in srgb, var(--signal) 45%, var(--line));
  box-shadow: inset 3px 0 0 var(--signal);
  background: var(--signal-tint);
}
.upd-row-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.upd-idx { font-family: var(--font-mono); font-size: .74rem; font-weight: 600; letter-spacing: .06em; color: var(--ink-soft); }
.upd-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 2px 14px; margin: 0; }
.upd-fields > div { display: flex; gap: 8px; align-items: baseline; min-width: 0; padding: 2px 0; }
.upd-fields dt { font-size: .72rem; color: var(--muted); flex: none; min-width: 96px; }
.upd-fields dd { margin: 0; font-size: .8rem; color: var(--ink); word-break: break-word; }

/* --- footer -------------------------------------------------------------- */
.footer { max-width: 1000px; margin: 0 auto; padding: 0 clamp(16px, 5vw, 48px) 56px; color: var(--muted); }
.footer-rule { display: block; height: 1px; background: var(--line-2); box-shadow: 0 2px 0 var(--line); margin-bottom: 14px; }
.footer p { font-size: .82rem; margin: 0; }

/* --- entrance animation -------------------------------------------------- */
.reveal { animation: rise .6s var(--ease) both; animation-delay: calc(var(--d, 0) * 80ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}

/* ============================================================================
   LOGIN — "Sheet 01 · Access": the title sheet of an engineering ledger.
   Registration-mark framed blueprint, oversized typographic statement, and a
   precision instrument login card with focus brackets.
   ========================================================================== */
.login-body {
  min-height: 100vh;
  /* warmer, deeper atmosphere than the app: a burnt-orange glow + corner light */
  background:
    radial-gradient(1100px 680px at 86% -8%, #fff6e8 0%, transparent 55%),
    radial-gradient(760px 520px at 12% 112%, var(--signal-tint) 0%, transparent 60%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-edge) 100%);
}
.login-body .grid-overlay {
  mask-image: radial-gradient(140% 100% at 70% 30%, #000 55%, transparent 100%);
}
.login-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(28px, 6vw, 72px);
  overflow: hidden;
}

/* corner registration marks framing the whole sheet */
.reg-mark { position: fixed; width: 30px; height: 30px; z-index: 2; pointer-events: none;
  border: 2px solid var(--line-2); opacity: .9; }
.rm-tl { top: 22px; left: 22px; border-right: 0; border-bottom: 0; }
.rm-tr { top: 22px; right: 22px; border-left: 0; border-bottom: 0; }
.rm-bl { bottom: 22px; left: 22px; border-right: 0; border-top: 0; }
.rm-br { bottom: 22px; right: 22px; border-left: 0; border-top: 0; }

/* enormous ghosted sheet number behind everything */
.sheet-ghost {
  position: fixed; right: 2vw; bottom: -4vh; z-index: 0; pointer-events: none;
  font-family: var(--font-display); font-weight: 900; font-style: italic;
  font-size: 46vh; line-height: .8; color: var(--ink);
  opacity: .035; letter-spacing: -.04em; user-select: none;
}

.login-sheet {
  position: relative; z-index: 1;
  width: 100%; max-width: 1060px;
  display: grid; grid-template-columns: 1.04fr .96fr;
  gap: clamp(36px, 5vw, 68px); align-items: center;
}
@media (max-width: 900px) {
  .login-sheet { grid-template-columns: 1fr; gap: 30px; max-width: 460px; }
}

/* ---- left: title block ---- */
.login-eyebrow {
  font-family: var(--font-mono); font-size: .74rem; letter-spacing: .26em;
  text-transform: uppercase; color: var(--signal); margin: 0 0 18px;
  display: flex; align-items: center; gap: 12px;
}
.login-eyebrow::after { content: ""; flex: 1; height: 1px; background: var(--line-2); max-width: 120px; }
.login-title {
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(2.6rem, 6vw, 4.6rem); line-height: .98; letter-spacing: -.025em;
  margin: 0 0 22px; color: var(--ink);
}
.login-title em { font-style: italic; font-weight: 500; color: var(--signal); }
.login-lede { max-width: 42ch; color: var(--ink-soft); font-size: 1.02rem; margin: 0 0 26px; }
.login-lede .mono { font-family: var(--font-mono); font-size: .92em; color: var(--ink); }

.login-specs { display: grid; gap: 0; margin: 0; border-top: 1px solid var(--line); max-width: 420px; }
.login-specs > div {
  display: grid; grid-template-columns: 96px 1fr; gap: 14px;
  padding: 10px 2px; border-bottom: 1px solid var(--line); align-items: baseline;
}
.login-specs dt {
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .16em;
  text-transform: uppercase; color: var(--faint); margin: 0;
}
.login-specs dd { margin: 0; font-size: .9rem; color: var(--ink-soft); }

/* ---- right: instrument login card ---- */
.login-card {
  position: relative; overflow: hidden;
  background:
    linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line-2); border-radius: var(--radius-lg);
  padding: 30px 30px 24px 36px;
  box-shadow: 0 1px 0 #fff inset, 0 30px 60px -34px rgba(40,30,15,.55), 0 2px 8px -4px rgba(40,30,15,.25);
}
.login-card-rail { position: absolute; left: 0; top: 0; bottom: 0; width: 6px;
  background: linear-gradient(180deg, var(--signal) 0%, var(--signal-2) 100%); }

.login-card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px dashed var(--line-2);
}
.login-seal {
  display: grid; place-items: center; width: 42px; height: 42px;
  font-family: var(--font-display); font-weight: 900; font-size: 1.4rem; color: var(--paper);
  background: var(--ink); border-radius: 50%;
  box-shadow: 0 0 0 4px var(--panel), 0 0 0 5px var(--line-2), 0 6px 14px -8px var(--ink);
}
.login-strip {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--muted);
}
.login-strip .strip-arrow { color: var(--signal); margin: 0 3px; }

/* flashes */
.login-flash {
  font-size: .9rem; margin: 0 0 18px; padding: 11px 13px; border-radius: var(--radius);
  border: 1px solid transparent;
}
.login-flash.is-ok  { background: var(--ok-tint);  border-color: color-mix(in srgb, var(--ok) 30%, transparent); color: #1f4d2e; }
.login-flash.is-err { background: var(--err-tint); border-color: color-mix(in srgb, var(--err) 35%, transparent); color: #7a1d18;
  display: flex; align-items: center; gap: 10px; }
.flash-stamp {
  font-family: var(--font-mono); font-size: .62rem; font-weight: 600; letter-spacing: .14em;
  color: var(--err); border: 1.5px solid var(--err); border-radius: 3px; padding: 2px 6px;
  transform: rotate(-4deg); white-space: nowrap;
}

/* fields with focus brackets */
.login-form { display: grid; gap: 16px; }
.login-field {
  position: relative; display: grid; gap: 7px;
  animation: rise .6s var(--ease) both; animation-delay: calc(var(--fd, 0) * 90ms + 120ms);
}
.login-lbl {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-soft); display: flex; gap: 8px; align-items: baseline;
}
.login-lbl .muted { text-transform: none; letter-spacing: 0; font-size: .92em; }
.login-field input {
  width: 100%; font: inherit; font-size: 1rem; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 12px 13px; transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
.login-field input::placeholder { color: var(--faint); }
.login-field input:focus {
  outline: none; background: #fff; border-color: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-tint);
}
/* mechanical corner brackets that snap in on focus */
.login-field::before, .login-field::after {
  content: ""; position: absolute; bottom: 0; width: 11px; height: 11px;
  border: 2px solid var(--signal); opacity: 0; transition: opacity .15s var(--ease), transform .15s var(--ease);
  pointer-events: none;
}
.login-field::before { left: -5px; border-right: 0; border-top: 0; transform: translate(4px, -4px); }
.login-field::after  { right: -5px; border-left: 0; border-top: 0; transform: translate(-4px, -4px); }
.login-field:focus-within::before,
.login-field:focus-within::after { opacity: 1; transform: translate(0, 0); }

/* primary submit */
.login-submit {
  margin-top: 6px; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--font-sans); font-weight: 600; font-size: 1rem; letter-spacing: .01em;
  color: var(--paper); background: var(--ink); cursor: pointer;
  border: 1px solid var(--ink); border-radius: var(--radius); padding: 13px 18px;
  box-shadow: 0 10px 22px -14px var(--ink); transition: transform .12s var(--ease), background .2s var(--ease), box-shadow .2s var(--ease);
  animation: rise .6s var(--ease) both; animation-delay: 480ms;
}
.login-submit:hover { background: var(--signal); border-color: var(--signal); box-shadow: 0 14px 26px -12px var(--signal); }
.login-submit:active { transform: translateY(1px); }
.login-submit .ls-arrow { transition: transform .18s var(--ease); }
.login-submit:hover .ls-arrow { transform: translateX(4px); }
.login-submit .spin { display: none; }
.login-submit.is-busy { background: var(--ink-soft); border-color: var(--ink-soft); cursor: default; opacity: .8; }
.login-submit.is-busy .spin { display: inline-block; }
.login-submit.is-busy .ls-arrow { display: none; }

/* browser-login fallback */
.login-fallback { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; }
.login-fallback > summary {
  cursor: pointer; list-style: none; font-size: .86rem; color: var(--muted);
}
.login-fallback > summary::-webkit-details-marker { display: none; }
.login-fallback > summary::before { content: "▸ "; color: var(--signal); }
.login-fallback[open] > summary::before { content: "▾ "; }
.login-fallback .note { margin: 10px 0; }
.login-fallback .btn { margin-top: 4px; }

.login-foot {
  position: fixed; left: 0; right: 0; bottom: 26px; text-align: center; z-index: 1;
  font-family: var(--font-mono); font-size: .64rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--faint); margin: 0;
}
@media (max-width: 900px) { .login-foot { display: none; } }

/* --- bulk review (round cards) ------------------------------------------- */
/* The spinner glyph only shows while a submit is in flight. (#npoSubmitAll is
   the NPO batch's "Submit approved" button — same busy behaviour.) */
#submitAll .spin,
#npoSubmitAll .spin { display: none; margin-right: 8px; }
#submitAll.is-busy .spin,
#npoSubmitAll.is-busy .spin { display: inline-block; }
#submitAll.is-busy,
#npoSubmitAll.is-busy { opacity: .7; cursor: default; }

/* --- AI order-item match assist ------------------------------------------ */
.ai-match { margin: 0 0 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
/* .btn carries a 14px top margin; drop it here so the button's box lines up
   with the status box in the centered flex row (else the button sits low). */
.ai-match-btn { margin-top: 0; }
.ai-match-btn .spin { display: none; margin-right: 8px; }
.ai-match-btn.is-busy .spin { display: inline-block; }
.ai-match-btn.is-busy { opacity: .7; cursor: default; }
.ai-match-status { margin: 0; }

/* AI-match provenance badge: a typeset margin-mark stamped above an order
   line the model suggested. Stack the badge above the description only on
   AI-matched rows, and reveal it only while the row is still ticked
   (.matchrow) — untick the suggestion and the mark quietly retires. */
.line-row.ai-matched .desc-cell {
  display: flex; flex-direction: column; align-items: flex-start; gap: 5px;
}
.ai-flag { display: none; }
.line-row.ai-matched.matchrow .ai-flag {
  display: inline-flex; align-items: center; gap: 5px; position: relative;
  font-family: var(--font-mono); font-size: .6rem; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--signal); background: var(--panel);
  border: 1px solid color-mix(in srgb, var(--signal) 35%, var(--line));
  padding: 2px 8px 2px 5px; border-radius: 999px;
  cursor: help; outline: none;
  box-shadow: 0 1px 0 #fff inset, 0 4px 10px -7px var(--signal);
  animation: ai-pop .3s var(--ease);
}
.line-row.ai-matched.matchrow .ai-flag:hover,
.line-row.ai-matched.matchrow .ai-flag:focus-visible {
  background: var(--signal-tint);
  border-color: color-mix(in srgb, var(--signal) 55%, transparent);
}
.ai-flag__bot { width: 14px; height: 14px; flex: none; }
.ai-flag__lbl { line-height: 1; }
@keyframes ai-pop {
  from { opacity: 0; transform: translateY(2px) scale(.9); }
  to   { opacity: 1; transform: none; }
}

/* "Set <n>" — the one-click qty/rate the AI suggested, stamped above its input
   so the operator applies the figure instead of retyping it. Block-level so it
   sits on its own line above the 84px cell input. */
.ai-suggest {
  display: flex; width: max-content; margin: 0 0 4px; padding: 2px 8px;
  font-family: var(--font-mono); font-size: .64rem; font-weight: 600;
  letter-spacing: .03em; line-height: 1.4;
  color: var(--signal); background: var(--signal-tint);
  border: 1px solid color-mix(in srgb, var(--signal) 35%, var(--line));
  border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: background .14s, border-color .14s, color .14s;
  animation: ai-pop .3s var(--ease);
}
.ai-suggest:hover {
  background: var(--signal); color: var(--paper);
  border-color: transparent;
}
.ai-suggest.is-applied {
  color: var(--ok); background: var(--ok-tint); cursor: default;
  border-color: color-mix(in srgb, var(--ok) 35%, transparent);
}

/* The reason bubble — IBM Plex Sans on the dark ink ground, mirroring the
   note dialog's voice. Pops above the badge on hover/focus, left-anchored so
   it rarely runs past the scroll container's right edge. */
.ai-flag__tip {
  position: absolute; bottom: calc(100% + 9px); left: -2px; z-index: 30;
  width: max-content; max-width: 250px;
  font-family: var(--font-sans); font-size: .79rem; font-weight: 400;
  letter-spacing: 0; text-transform: none; line-height: 1.4; text-align: left;
  color: var(--paper); background: var(--ink);
  padding: 8px 11px; border-radius: var(--radius);
  box-shadow: 0 14px 30px -14px rgba(20,15,5,.85);
  opacity: 0; transform: translateY(4px) scale(.97); transform-origin: bottom left;
  pointer-events: none; transition: opacity .16s var(--ease), transform .16s var(--ease);
}
.ai-flag__tip::before {
  content: "Why AI matched this"; display: block;
  font-family: var(--font-mono); font-size: .58rem; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  color: color-mix(in srgb, var(--signal) 70%, var(--paper));
  margin-bottom: 3px;
}
.ai-flag__tip::after {     /* arrow pointing down at the badge */
  content: ""; position: absolute; top: 100%; left: 16px;
  border: 5px solid transparent; border-top-color: var(--ink);
}
.line-row.ai-matched.matchrow .ai-flag:hover .ai-flag__tip,
.line-row.ai-matched.matchrow .ai-flag:focus-visible .ai-flag__tip,
.line-row.ai-matched.matchrow .ai-flag:focus .ai-flag__tip {
  opacity: 1; transform: translateY(0) scale(1);
}

/* `overflow: clip` (not `hidden`) so the card still clips its children to the
   rounded corners WITHOUT becoming a scroll container — `hidden` would trap the
   sticky .pdf-pane inside, killing the follow-on-scroll. `clip` lets the pane
   stick to the viewport while still stopping at the bottom of the card body. */
.invoice-card { padding: 0; overflow: clip; }
.invoice-card > .invoice-card-head {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 16px 20px;
}
.invoice-card > .invoice-card-head::-webkit-details-marker { display: none; }
.invoice-card > .invoice-card-head::before {
  content: "▸"; color: var(--faint); font-size: .9rem; transition: transform .15s var(--ease);
}
.invoice-card[open] > .invoice-card-head::before { transform: rotate(90deg); }
.invoice-card[open] > .invoice-card-head { border-bottom: 1px solid var(--line); }
.invoice-card-head .ic-inv { font-size: 1.02rem; }
.invoice-card-head .ic-po { color: var(--ink-soft); }
.invoice-card-head .chip { margin-left: auto; }
.invoice-card-head .pdf-open { font-size: .82rem; }
.invoice-card-body { padding: 12px 20px 20px; }
.readout.compact { margin-bottom: 12px; }
.readout.compact .ro { grid-template-columns: 160px 1fr; padding: 8px 12px; }

/* Per-card PDF viewer: shorter than the single-invoice screen's full-height
   pane, so several open cards don't make the page enormous. Sticks within its
   own card while the line table scrolls beside it. */
.pdf-pane.in-card { top: 14px; box-shadow: none; }
.pdf-pane.in-card .pdf-frame,
.pdf-pane.in-card .pdf-fallback { height: 68vh; min-height: 380px; }

/* per-card approve toggle — idle vs approved swap which label shows */
.card-approve-bar { background: var(--panel-2); border-color: var(--line-2); }
.card-approve { background: var(--ink); color: var(--paper); }
.card-approve:hover { background: #2a241a; }
.card-approve .ca-on { display: none; }
.card-approve.is-approved { background: var(--ok, #2f7d4f); }
.card-approve.is-approved .ca-idle { display: none; }
.card-approve.is-approved .ca-on { display: inline; }
/* an approved card gets a green edge so it stands out in the round */
.invoice-card.is-approved { border-color: color-mix(in srgb, var(--ok, #2f7d4f) 55%, var(--line)); }
.invoice-card.is-approved > .invoice-card-head { background: color-mix(in srgb, var(--ok, #2f7d4f) 8%, transparent); }
/* a totals mismatch outlines the whole card in red — declared after .is-approved
   so it wins the equal-specificity tie when a card is both approved and off. */
.invoice-card.has-mismatch { border-color: var(--err); box-shadow: 0 0 0 2px var(--err-tint); }
.invoice-card.has-mismatch > .invoice-card-head { background: color-mix(in srgb, var(--err) 7%, transparent); }

/* --- submit-time mismatch warning dialog -------------------------------- */
.mismatch-dialog { max-width: 480px; }
.mismatch-list { margin: 4px 0 0; padding-left: 22px; }
.mismatch-list li { padding: 2px 0; font-weight: 600; color: var(--err); }
