/* ══ Design tokens ═════════════════════════════════════════════════════════════
   Every colour the app uses has a name here; components never hard-code a hex. The
   Plantilla (plantilla.html) reads the same names for its frame, dialogs and panels;
   only its white sheet keeps the workbook's own colours. A light theme with green as the
   brand colour (the palette chosen 2026-11-08). */
:root {
  /* Surfaces. */
  --bg: #f4f5f7;          /* the canvas */
  --field: #ffffff;       /* inputs */
  --inset: #f8f9fb;       /* boxes inside a card, table heads */
  --card: #ffffff;        /* cards, the top bar, dialogs */
  --raised: #f1f3f6;      /* hover on a row or a quiet button */
  --line: #e7e9ee;        /* dividers and card edges */
  --line-strong: #d5d9e0; /* control borders: a field must read as one */
  --line-hover: #b9c0cb;

  /* Text. */
  --fg: #111827;
  --fg-2: #374151;        /* labels, secondary copy */
  --muted: #6b7280;       /* hints, metadata; 4.8:1 on white */

  /* The brand: green. --accent for focus, icons and marks, --link for text links (darker,
     for contrast on white), the soft fill for active states and the primary button. */
  --accent: #16a34a;
  --accent-hover: #15803d;
  --link: #15803d;
  --accent-soft: #e3f8e6;
  --accent-grad: linear-gradient(135deg, #22c55e 0%, #4ade80 55%, #a3e635 100%);
  --primary: #bbf7d0; --primary-hover: #a7f0bf; --primary-line: #86efac; --on-primary: #14532d;

  /* Meaning. Each has a text colour, a fill and an edge, used together. */
  --ok: #16a34a;  --ok-fg: #15803d;  --ok-bg: #dcfce7;  --ok-line: #bbf7d0;
  --warn: #b45309; --warn-bg: #fef6e0; --warn-line: #fcd78a;
  --err: #dc2626; --err-fg: #991b1b; --err-bg: #fef2f2; --err-line: #fecaca;
  --info: #1d4ed8; --info-bg: #eff6ff; --info-line: #bfdbfe; --info-mark: #3b82f6;

  /* Shape and depth. */
  --r-sm: 6px; --r: 8px; --r-lg: 14px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, .14);
  --ring: 0 0 0 3px rgba(22, 163, 74, .25);

  /* Type. */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* The Plantilla sizes itself to the window minus this bar. */
  --topbar-h: 52px;
  --hs-w: 120px;
}

/* ══ Base ═════════════════════════════════════════════════════════════════════ */
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  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 { margin: 0; font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 650; }
a { color: var(--link); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
ul { padding-left: 1.2rem; }
code, .mono { font-family: var(--font-mono); }
::selection { background: rgba(22, 163, 74, .2); }
/* One focus ring for everything a keyboard can reach. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.error { color: var(--err); margin: 0; }
.inline { display: inline; margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.row-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

/* ══ Frame: top bar, page, cards ══════════════════════════════════════════════ */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; height: var(--topbar-h);
  padding: 0 1.25rem; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: .55rem; flex: none;
  color: var(--fg); font-weight: 700; letter-spacing: .01em; text-decoration: none;
}
.brand:hover { color: var(--fg); }
.brand-logo { display: block; height: 32px; width: auto; }
.nav { display: flex; align-items: center; gap: .25rem; margin-left: auto; min-width: 0; }
.nav-link {
  padding: .35rem .7rem; border-radius: var(--r-sm); color: var(--fg-2);
  font-size: .9rem; font-weight: 500; text-decoration: none;
}
.nav-link:hover { color: var(--fg); background: var(--raised); }
.nav-link[aria-current="page"] { color: var(--on-primary); background: var(--accent-soft); }
.nav-user {
  margin-left: .6rem; padding-left: 1rem; border-left: 1px solid var(--line);
  max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: .85rem;
}
.nav .linkbtn { padding: .35rem .6rem; border-radius: var(--r-sm); font-size: .9rem; }
.nav .linkbtn:hover { background: var(--raised); }

.container { max-width: 1040px; margin: 2rem auto 3rem; padding: 0 1.25rem; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1.25rem;
}
.page-sub { margin: .3rem 0 0; color: var(--muted); font-size: .92rem; }
.back {
  display: inline-flex; align-items: center; gap: .35rem; margin-bottom: .75rem;
  color: var(--muted); font-size: .88rem; text-decoration: none;
}
.back:hover { color: var(--fg); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 1.5rem 1.75rem; box-shadow: var(--shadow-card);
}
.card + .card { margin-top: 1.25rem; }
.card > h2:first-child { margin-top: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-narrow { max-width: 380px; margin: 3rem auto; }

/* ══ Buttons ══════════════════════════════════════════════════════════════════
   .btn is the page's one primary action, filled with the accent. .btn-sec is every
   other action: neutral, so the primary is never in doubt. Both size from the same
   base, so a row of them lines up. */
.btn, .btn-sec {
  display: inline-flex; align-items: center; justify-content: center; gap: .1rem;
  padding: .55rem 1rem; border-radius: var(--r); font: inherit; font-size: .92rem;
  font-weight: 600; line-height: 1.2; text-decoration: none; cursor: pointer;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn { border: 1px solid var(--primary-line); background: var(--primary); color: var(--on-primary); }
.btn:hover { background: var(--primary-hover); color: var(--on-primary); }
.btn:disabled { opacity: .85; cursor: wait; }
.btn-sec {
  align-self: flex-start; padding: .48rem .9rem; border: 1px solid var(--line-strong);
  background: var(--card); color: var(--fg-2); font-weight: 500;
}
.btn-sec:hover { background: var(--raised); border-color: var(--line-hover); color: var(--fg); }
.btn:focus-visible, .btn-sec:focus-visible { outline: none; box-shadow: var(--ring); }
.btn .icon, .btn-sec .icon { width: 15px; height: 15px; }
.btn-block { width: 100%; }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.linkbtn:hover { color: var(--fg); }
@media (prefers-reduced-motion: reduce) { .btn, .btn-sec { transition: none; } }

/* Inline SVG icons (Lucide sprite). Size follows font-size; color follows currentColor. */
.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.14em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-l { margin-right: .4rem; }
.icon-r { margin-left: .4rem; }

/* A page-level message: a failed login, a refused upload. */
.alert {
  display: flex; align-items: flex-start; gap: .55rem; margin: 0 0 1.25rem;
  padding: .7rem .9rem; border: 1px solid var(--err-line); border-radius: var(--r);
  background: var(--err-bg); color: var(--err-fg); font-size: .9rem;
}
.alert .icon { flex: none; margin-top: .2rem; }

/* ══ Navigation feedback ══════════════════════════════════════════════════════
   Server-rendered navigation has no built-in "working…" state. The bar is driven
   from base.html; .is-busy lands on the clicked control the instant it is clicked. */
#nav-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100;
  background: var(--accent-grad); box-shadow: 0 0 10px rgba(22, 163, 74, .45);
  transform: scaleX(0); transform-origin: 0 50%; will-change: transform;
}
#nav-progress[hidden] { display: none; }
body.nav-busy { cursor: progress; }
/* pointer-events:none also swallows the impatient second click on a slow link. */
.is-busy { opacity: .65; pointer-events: none; }
.btn.is-busy::after, .btn-sec.is-busy::after {
  content: ""; display: inline-block; width: 13px; height: 13px;
  margin-left: .5rem; vertical-align: -2px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .btn.is-busy::after, .btn-sec.is-busy::after { animation: none; }
}
.spinner {
  display: inline-block; flex: none; width: 15px; height: 15px;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ══ Forms ════════════════════════════════════════════════════════════════════ */
.form { display: flex; flex-direction: column; gap: 1.25rem; }
.form label { display: flex; flex-direction: column; gap: .4rem; font-size: .88rem; font-weight: 500; color: var(--fg-2); }
.form input, .form select {
  padding: .58rem .7rem; border-radius: var(--r); border: 1px solid var(--line-strong);
  background: var(--field); color: var(--fg); font: inherit; font-size: .95rem;
  transition: border-color .12s, box-shadow .12s;
}
.form input:hover, .form select:hover { border-color: var(--line-hover); }
.form input:focus, .form select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.form input:disabled { opacity: .5; cursor: not-allowed; }
.form input[type="file"] { width: 100%; min-width: 0; padding: .4rem; color: var(--muted); font-size: .88rem; cursor: pointer; }
.form input[type="file"]::file-selector-button {
  margin-right: .8rem; padding: .4rem .8rem;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--raised); color: var(--fg);
  font: inherit; font-weight: 500; font-size: .85rem; cursor: pointer;
}
.form input[type="file"]::file-selector-button:hover { border-color: var(--accent); }
.field-hint { margin: -.15rem 0 0; color: var(--muted); font-size: .8rem; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; }

/* A form in titled steps: «1 Declaración», «2 Facturas»… */
.form-section { display: flex; flex-direction: column; gap: 1rem; padding: 1.25rem 0 0; border-top: 1px solid var(--line); }
.form-section:first-of-type { padding-top: 0; border-top: 0; }
.form-section > h2 { display: flex; align-items: center; gap: .6rem; margin: 0; font-size: 1rem; }
.step {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-hover); font-size: .78rem; font-weight: 700;
}
.form-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 1rem; flex-wrap: wrap;
  padding-top: 1.25rem; border-top: 1px solid var(--line);
}

/* One invoice and its packing list. */
fieldset { min-width: 0; }
fieldset.pair {
  margin: 0; padding: .9rem 1.1rem 1.1rem; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--inset);
}
fieldset.pair legend {
  display: flex; align-items: center; gap: .75rem; padding: 0 .4rem;
  color: var(--fg-2); font-size: .84rem; font-weight: 600;
}
.pair-files { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; align-items: start; }
.pair-files > div { display: flex; flex-direction: column; gap: .5rem; }
.pair-remove { display: inline-flex; align-items: center; font-size: .8rem; font-weight: 500; color: var(--muted); }
.pair-remove:hover { color: var(--err); }
#pairs { display: flex; flex-direction: column; gap: .8rem; }

/* "Sin lista de empaque". .is-off greys the packing file label when the pair is
   marked as having none, so the disabled input reads as deliberate, not broken. */
.form .check { flex-direction: row; align-items: center; gap: .5rem; margin: 0; font-weight: 400; font-size: .85rem; color: var(--fg-2); cursor: pointer; }
.form .check input[type="checkbox"] { width: 1rem; height: 1rem; margin: 0; padding: 0; accent-color: var(--accent); cursor: pointer; }
.form .pl-label.is-off { opacity: .45; }

/* The transport mode: three cards to choose from, the chosen one lit. */
.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; margin: 0; padding: 0; border: 0; }
.form .choice {
  position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .15rem .75rem;
  padding: .8rem .9rem; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--field); cursor: pointer; transition: border-color .12s, background-color .12s;
}
.form .choice:hover { border-color: var(--line-hover); }
.choice input {
  position: absolute; top: .7rem; right: .75rem; width: 1rem; height: 1rem; margin: 0; padding: 0;
  accent-color: var(--accent);
}
/* The radio itself is hidden only where the card can show the choice (:has). A browser
   without it (Firefox < 121, Safari < 15.4) keeps the radio, at the card's top right. */
@supports selector(:has(*)) { .choice input { opacity: 0; pointer-events: none; } }
.choice > .icon { grid-row: span 2; width: 22px; height: 22px; color: var(--muted); }
.choice-title { color: var(--fg); font-weight: 600; font-size: .92rem; }
.choice-sub { color: var(--muted); font-size: .78rem; font-weight: 400; }
.form .choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice:has(input:checked) > .icon { color: var(--accent-hover); }
.choice:has(input:focus-visible) { box-shadow: var(--ring); }

/* NIT suggestions. A <datalist> popup is painted by the browser — unreachable from
   here, so it lands as an OS-grey box on a dark form, and it only opens on its own
   arrow. Driven by upload.html's combobox JS. */
.combo { position: relative; display: flex; flex-direction: column; }
.combo input { padding-right: 2rem; }
.combo-caret {
  position: absolute; right: .75rem; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: .8rem; pointer-events: none;
}
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  margin: 0; padding: .3rem; list-style: none; max-height: 220px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--r);
  box-shadow: var(--shadow-pop);
}
.combo-list li { padding: .45rem .6rem; border-radius: var(--r-sm); font-size: .9rem; color: var(--fg); cursor: pointer; }
.combo-list[hidden], .combo-list li[hidden] { display: none; }
.combo-list li:hover, .combo-list li.is-active { background: var(--raised); }

/* Radios laid out as a row (catalogue import: sheet + header row). */
.radio-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem 1.4rem; }

/* ══ Tables ═══════════════════════════════════════════════════════════════════ */
table.jobs, table.cat { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.jobs th, table.jobs td, table.cat th, table.cat td {
  padding: .7rem 1rem; border-bottom: 1px solid var(--line); text-align: left; font-size: .9rem;
}
table.jobs th, table.cat th {
  padding-top: .6rem; padding-bottom: .6rem; background: var(--inset);
  color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
}
table.jobs tbody tr:last-child td, table.cat tbody tr:last-child td { border-bottom: 0; }
table.cat { margin-top: .8rem; }
table.cat td { vertical-align: top; }
table.cat code { font-size: .84rem; }
.card > table.cat { border: 1px solid var(--line); border-radius: var(--r); border-collapse: separate; border-spacing: 0; overflow: hidden; }

/* The dashboard: a whole row is the link to its DAM (the reference's ::after covers it). */
table.jobs tbody tr { position: relative; transition: background-color .1s; }
table.jobs tbody tr:hover { background: var(--raised); }
.job-ref { color: var(--fg); font-weight: 600; text-decoration: none; }
.job-ref::after { content: ""; position: absolute; inset: 0; }
.job-ref:hover { color: var(--fg); }
.job-ref:focus-visible { outline: none; }
table.jobs tbody tr:has(.job-ref:focus-visible) { box-shadow: inset 0 0 0 2px var(--accent); }
.job-transport { display: inline-flex; align-items: center; gap: .45rem; color: var(--fg-2); }
.job-transport .icon { color: var(--muted); }
.job-go { width: 2.5rem; color: var(--muted); text-align: right; }
table.jobs tbody tr:hover .job-go { color: var(--fg); }
.job-meta { display: none; }

/* Wide previews scroll inside their own box so the page never scrolls sideways. */
.table-scroll { overflow-x: auto; max-width: 100%; }

/* Nothing to list yet. */
.empty { display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 3.5rem 1.5rem; text-align: center; }
.empty-icon {
  display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: .3rem;
  border-radius: 14px; background: var(--accent-soft); color: var(--accent-hover);
}
.empty-icon .icon { width: 24px; height: 24px; }
.empty h2 { margin: 0; font-size: 1.05rem; }
.empty p { max-width: 26rem; margin: 0 0 .6rem; color: var(--muted); font-size: .9rem; }

/* ══ Status ═══════════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .6rem .2rem .5rem;
  border-radius: 999px; font-size: .68rem; font-weight: 650; letter-spacing: .04em;
  text-transform: uppercase; white-space: nowrap;
}
.badge::before { content: ""; width: .42rem; height: .42rem; border-radius: 50%; background: currentColor; }
.badge--queued { background: #eef0f4; color: #4b5563; }
.badge--parsing, .badge--running, .badge--demi_running { background: #dbeafe; color: #1d4ed8; }
.badge--parsing::before, .badge--running::before, .badge--demi_running::before { animation: badge-pulse 1.4s ease-in-out infinite; }
.badge--awaiting_review { background: #fef3c7; color: #92400e; }
.badge--done { background: var(--ok-bg); color: #166534; }
.badge--error { background: #fee2e2; color: #991b1b; }
@keyframes badge-pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .badge::before { animation: none !important; } }

/* A DAM's facts (job page). */
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin: 0 0 1.25rem; }
.facts > div { min-width: 0; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--inset); }
.facts dt { color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.facts dd { margin: .2rem 0 0; color: var(--fg); font-weight: 500; overflow-wrap: anywhere; }

/* The job's live state, polled by htmx (job_status.html). Its left edge carries the state. */
.status-panel {
  display: flex; flex-direction: column; gap: .75rem; padding: 1.1rem 1.25rem;
  border: 1px solid var(--line); border-left: 3px solid var(--line-strong);
  border-radius: var(--r); background: var(--inset);
}
.status-panel > * { margin: 0; }
.status-panel[data-state="parsing"], .status-panel[data-state="running"],
.status-panel[data-state="demi_running"] { border-left-color: var(--accent); }
.status-panel[data-state="awaiting_review"] { border-left-color: var(--warn); }
.status-panel[data-state="done"] { border-left-color: var(--ok); }
.status-panel[data-state="error"] { border-left-color: var(--err); }
.status-line { display: flex; align-items: center; gap: .6rem; color: var(--fg-2); font-size: .9rem; }
.status-title { color: var(--fg); font-size: 1rem; font-weight: 600; }
.status-title .icon { width: 18px; height: 18px; vertical-align: -.2em; }
/* A failure can be a sentence or a whole traceback: either reads, neither takes the page. */
.status-error {
  max-height: 16rem; overflow: auto; padding: .7rem .85rem; border: 1px solid var(--err-line);
  border-radius: var(--r-sm); background: var(--err-bg); color: var(--err-fg);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: .82rem;
}
progress {
  width: 100%; height: 6px; border: 0; border-radius: 999px; overflow: hidden;
  background: var(--line); appearance: none; -webkit-appearance: none;
}
progress::-webkit-progress-bar { background: var(--line); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; transition: width .3s; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

/* A box inside a card: a report, a summary. */
.notice { margin: 1rem 0; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--inset); }
.notice h2, .notice h3 { margin: 0 0 .5rem; font-size: .95rem; }
.notice p { margin: .35rem 0; font-size: .9rem; }
ul.tight { margin: .4rem 0 0; padding-left: 1.1rem; }
ul.tight li { font-size: .86rem; color: var(--muted); margin: .15rem 0; }
/* Catalogue import: two columns on a wide screen, one on a narrow one. */
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: .6rem .9rem; }
.map-row { display: flex; flex-direction: column; gap: .25rem; }
.map-label { font-size: .78rem; color: var(--muted); }
.map-row select { width: 100%; }

/* Login. */
.auth { max-width: 380px; margin: 4.5rem auto; }
.auth-head { display: flex; flex-direction: column; align-items: center; gap: .7rem; margin-bottom: 1.5rem; text-align: center; }
.auth-head .brand-logo { height: 52px; }
.auth-head p { margin: 0; color: var(--muted); font-size: .9rem; }

/* ══ Narrow screens ═══════════════════════════════════════════════════════════ */
@media (max-width: 720px) {
  .container { margin-top: 1.25rem; padding: 0 1rem; }
  .card { padding: 1.25rem 1.1rem; }
  .card-flush { padding: 0; }
  h1 { font-size: 1.35rem; }
  .form-grid, .pair-files, .choices, .facts { grid-template-columns: 1fr; }
  .nav-user { display: none; }
  .topbar { gap: .75rem; padding: 0 1rem; }
  /* The dashboard's rows become cards: reference and status, then importer, then
     transport and date. */
  table.jobs thead { display: none; }
  table.jobs, table.jobs tbody, table.jobs tr { display: block; }
  table.jobs tbody tr {
    display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; padding: .85rem 1rem;
    border-bottom: 1px solid var(--line);
  }
  table.jobs tbody tr:last-child { border-bottom: 0; }
  table.jobs td { display: block; padding: 0; border: 0; }
  table.jobs td.job-c-ref { grid-column: 1; }
  table.jobs td.job-c-status { grid-column: 2; grid-row: 1; justify-self: end; }
  table.jobs td.job-c-imp { grid-column: 1 / -1; color: var(--fg-2); }
  table.jobs td.job-c-tr, table.jobs td.job-c-date, table.jobs td.job-go { display: none; }
  table.jobs td.job-meta { display: flex; grid-column: 1 / -1; gap: .9rem; color: var(--muted); font-size: .82rem; }
}

/* ══ Plantilla components ═════════════════════════════════════════════════════
   Everything below is drawn inside the Plantilla (documents pane, FOB card, catalogue
   panel). Their layout is tuned to the sheet; change it with the page's harness at hand. */

/* Documents pane (plantilla_docs.js, pdf.js). */
.pdf-viewer { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--field); }
.pdf-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: 2.45rem; padding: .3rem .4rem; border-bottom: 1px solid var(--line); background: var(--card); }
/* Document tabs (Factura | Lista de empaque). The selected tab takes the viewer's own
   background so it reads as the front of the page stack below it. */
.pdf-tabs { display: flex; align-items: center; gap: .25rem; min-width: 0; }
.pdf-tab {
  padding: .28rem .65rem; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--muted); font: inherit; font-size: .8rem;
  white-space: nowrap; cursor: pointer;
}
.pdf-tab:hover { color: var(--fg); }
.pdf-tab[aria-selected="true"] { color: var(--fg); background: var(--field); border-color: var(--line); }
.pdf-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pdf-tab-none { padding: 0 .45rem; font-size: .76rem; color: var(--muted); white-space: nowrap; }
.pdf-zoom-ctrl { display: flex; align-items: center; gap: .5rem; }
/* An author `display` outranks the UA `[hidden]` rule, so restore it explicitly. */
.pdf-zoom-ctrl[hidden] { display: none; }
.zoom-btn { width: 1.7rem; height: 1.7rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--field); color: var(--fg); font-size: .95rem; font-weight: 700; cursor: pointer; line-height: 1; }
.zoom-btn:hover:not(:disabled) { border-color: var(--accent); }
.zoom-btn:disabled { opacity: .4; cursor: not-allowed; }
.zoom-level { min-width: 3.2rem; text-align: center; font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pdf-pages { height: 560px; overflow: auto; padding: .6rem; }
.pdf-status { text-align: center; padding: 2.5rem 1rem; }
.pdf-zoom { width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: .6rem; }
.pdf-zoom img { display: block; width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 2px; }

/* Another tab or session changed this review: saving stops until the page is reloaded. */
.review-conflict {
  position: sticky; top: 0; z-index: 45; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin: 0 0 1rem; padding: .7rem .9rem; border: 1px solid var(--err-line); border-radius: var(--r);
  background: var(--err-bg); color: var(--err-fg); font-size: .9rem;
}
.review-conflict[hidden] { display: none; }
.review-conflict .btn { margin-left: auto; padding: .4rem .85rem; font-size: .88rem; }

/* Inputs inside the FOB card and the catalogue panel. */
.cell-input {
  width: 100%; padding: .32rem .45rem; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--field); color: var(--fg); font-size: .85rem;
}
.cell-input.num { width: 100%; min-width: 3.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.hs-input {
  width: var(--hs-w); font-family: var(--font-mono); letter-spacing: .04em;
  font-size: .85rem; padding: .32rem .45rem; border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  background: var(--field); color: var(--fg);
}
.hs-input:invalid { border-color: var(--err); }

/* A FOB cell the agent typed: declared as-is, outside the invoice's ratio. */
.cell-input.fob-input--fixed { box-shadow: inset 3px 0 0 var(--info-mark); }
/* FOB card — one per invoice. Its header row is always visible: the invoice's two declared
   totals, E15 and E9, beside the running Σ of the FOB column. Opened, it shows how both
   were built, as a ledger with one column per total. */
.fob-receipt { margin: 0 0 .7rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--inset); }
/* The whole header row is the control: it tints on hover, and its right edge says what a
   click does («Cómo se calculó» / «Ocultar») with a chevron that turns when it opens. The
   figures sit left, that label top right, and any flag on a line of its own below them. */
.fob-receipt > summary {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .4rem .8rem;
  padding: .5rem .75rem; list-style: none; font-size: .82rem; cursor: pointer;
  border-radius: 7px; transition: background-color .15s;
}
.fob-receipt > summary::-webkit-details-marker { display: none; }
.fob-receipt > summary:hover { background: var(--raised); }
.fob-receipt > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fob-receipt[open] > summary { margin-bottom: .35rem; border-bottom: 1px solid var(--line); border-radius: 7px 7px 0 0; }
.fob-receipt-toggle {
  grid-column: 2; grid-row: 1; display: inline-flex; align-items: center; gap: .3rem;
  font-size: .76rem; color: var(--muted); white-space: nowrap; transition: color .15s;
}
.fob-receipt > summary:hover .fob-receipt-toggle { color: var(--accent); }
.fob-receipt-toggle .icon { transition: transform .2s; }
.fob-receipt[open] .fob-receipt-toggle .icon { transform: rotate(180deg); }
.fob-receipt:not([open]) .fob-toggle-open, .fob-receipt[open] .fob-toggle-closed { display: none; }
@media (prefers-reduced-motion: reduce) {
  .fob-receipt > summary, .fob-receipt-toggle, .fob-receipt-toggle .icon { transition: none; }
}
/* The header's figures: label above, value below. */
.fob-stats { grid-column: 1; display: flex; flex-wrap: wrap; align-items: flex-end; gap: .35rem 1.6rem; }
.fob-flags { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .3rem; }
.fob-stat { display: flex; flex-direction: column; gap: .08rem; }
.fob-stat-k { font-size: .64rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.fob-stat-v { font-size: .96rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.fob-sum--off { color: var(--warn); }
.fob-tag { padding: .02rem .42rem; border: 1px solid var(--info-line); border-radius: 999px; font-size: .66rem; font-weight: 400; color: var(--info); background: var(--info-bg); white-space: nowrap; }
.fob-tag--warn { border-color: var(--warn-line); color: var(--warn); background: var(--warn-bg); }
.fob-receipt-body { padding: 0 .75rem .75rem; }
.fob-receipt.is-saving .fob-receipt-body { opacity: .6; pointer-events: none; }
/* The ledger: a concept column, then what each row adds to E15 and to E9 («—»: nothing). */
table.fob-lines { width: 100%; border-collapse: collapse; font-size: .8rem; }
table.fob-lines col.fob-col { width: 8.2rem; }
table.fob-lines th, table.fob-lines td { padding: .38rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.fob-lines tbody th, table.fob-lines tfoot th { text-align: left; font-weight: 400; }
table.fob-lines thead th {
  padding-top: .1rem; vertical-align: bottom; border-bottom-color: var(--line);
  font-size: .64rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
}
table.fob-lines thead td { border-bottom-color: var(--line); }
table.fob-lines .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.fob-lines thead th.num { white-space: normal; }
table.fob-lines .fob-none { color: var(--muted); opacity: .55; }
table.fob-lines tr.is-off .fob-what { color: var(--muted); }
table.fob-lines tr.is-added th { box-shadow: inset 2px 0 0 var(--info-mark); }
table.fob-lines tr.is-warn th, table.fob-lines tr.is-warn td { color: var(--warn); }
table.fob-lines tfoot th, table.fob-lines tfoot td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: 0; }
/* «Subtotal de los ítems», typed when lines were misread. */
table.fob-lines .lines-sum-input { width: 100%; min-width: 0; padding: .2rem .4rem; font-size: .8rem; }
table.fob-lines .lines-sum-input:disabled { opacity: .55; cursor: not-allowed; }
table.fob-lines tr.fob-lines-sum th, table.fob-lines tr.fob-lines-sum td { vertical-align: middle; }
/* A row's concept, then its control; the control drops below when the column is narrow. */
.fob-row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .7rem; }
.fob-what { flex: 1 1 11rem; min-width: 0; overflow-wrap: anywhere; }
.fob-amt { margin-left: .2rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fob-note { display: block; margin-top: .12rem; font-size: .72rem; font-weight: 400; color: var(--muted); }
/* Where a charge counts, as one segmented control: the current choice is filled. A charge
   the extraction could not classify counts as origin (as Phase 1 counts it), and shows so.
   «Quitar», when chosen, is grey rather than accent: nothing is declared. */
.fob-choices { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.fob-choice {
  padding: .16rem .6rem; border: 0; border-left: 1px solid var(--line); background: transparent;
  color: var(--muted); font: inherit; font-size: .72rem; line-height: 1.35; cursor: pointer; white-space: nowrap;
}
.fob-choice:first-child { border-left: 0; }
.fob-choice:hover:not(:disabled):not([aria-pressed="true"]) { color: var(--fg); background: var(--raised); }
.fob-choice:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fob-choice.is-on { background: var(--accent-soft); color: var(--accent-hover); cursor: default; }
.fob-choice.is-on.fob-choice--off { background: var(--raised); color: var(--fg); }
.fob-choice:disabled { opacity: .4; cursor: not-allowed; }
.fob-check { margin: .6rem 0 0; font-size: .78rem; line-height: 1.45; color: var(--muted); }
.fob-check.is-warn { margin-bottom: .7rem; color: var(--warn); }
/* The missing line: its kind and amount, then its description and the two buttons. */
.fob-add { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .4rem; margin-top: .65rem; }
.fob-add[hidden] { display: none; }
.fob-add select, .fob-add input { min-width: 0; padding: .32rem .45rem; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--field); color: var(--fg); font: inherit; font-size: .8rem; }
.fob-add input[data-add="amount"] { width: 9rem; text-align: right; font-variant-numeric: tabular-nums; }
.fob-add-btns { display: inline-flex; align-items: center; gap: .6rem; }
.fob-add .btn-sec { align-self: auto; padding: .3rem .7rem; font-size: .8rem; }
/* «Cancelar» is a link-style button, which inherits the page's size: sized to «Añadir». */
.fob-add .fob-add-cancel { font-size: .8rem; }
.fob-add-open { margin-top: .6rem; font-size: .78rem; color: var(--accent); }
.fob-receipt-error { margin: .45rem 0 0; font-size: .78rem; color: var(--err); }
.fob-receipt-error:empty { display: none; }
@media (max-width: 700px) {
  .fob-add { grid-template-columns: 1fr; }
  .fob-add input[data-add="amount"] { width: 100%; }
}

/* The side panel that hosts the catalogue reconciliation. */
.demi-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 55;
  width: min(31rem, 100vw); display: flex; flex-direction: column;
  background: var(--card); border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px rgba(16, 24, 40, .12);
}
.demi-panel[hidden] { display: none; }
.demi-loading { display: flex; flex-direction: column; align-items: flex-start; gap: .7rem; padding: 1.2rem 1rem; }
.demi-loading .btn-sec { align-self: flex-start; }
.demi-field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; }
.demi-field label { font-size: .78rem; color: var(--fg-2); }
.demi-req { color: var(--warn); }
.demi-field input, .demi-field select {
  width: 100%; padding: .38rem .5rem; border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  background: var(--field); color: var(--fg); font: inherit; font-size: .85rem;
}
.demi-field input[readonly] { color: var(--muted); border-style: dashed; }
.demi-field input[hidden] { display: none; }
.demi-hint { font-size: .72rem; line-height: 1.4; color: var(--muted); }
.demi-hint.is-ok { color: var(--ok-fg); }
.demi-hint.is-warn { color: var(--warn); }

/* ── Conciliación con el catálogo ──────────────────────────────────────────────
   Los ítems que el catálogo no resolvió, de uno en uno, en un panel lateral: la factura
   sigue legible mientras se decide. La cola vive en la hoja (cada fila lleva data-cat). */
.cc-panel { width: min(34rem, 100vw); }
.cc-inner { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.cc-inner:focus { outline: none; }
.cc-head { display: flex; align-items: flex-start; gap: .6rem; padding: .9rem 1rem .6rem; }
.cc-title { flex: 1; min-width: 0; }
.cc-head h2 { margin: 0; font-size: 1rem; }
.cc-count { margin: .1rem 0 0; font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cc-nav { display: flex; gap: .3rem; }
.cc-nav .btn-sec { align-self: auto; padding: .25rem .5rem; }
.cc-nav .icon { width: 14px; height: 14px; }
.cc-close { flex: none; padding: .15rem; display: inline-flex; }
.cc-close .icon { width: 18px; height: 18px; }
.cc-progress { flex: none; height: 3px; background: var(--line); }
.cc-progress span { display: block; height: 100%; background: var(--ok); transition: width .25s; }
@media (prefers-reduced-motion: reduce) { .cc-progress span { transition: none; } }
.cc-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .8rem 1rem 1rem; display: flex; flex-direction: column; gap: .65rem; }
.cc-item { padding: .6rem .7rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--inset); }
.cc-item-meta { margin: 0; font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cc-item-code { margin: .15rem 0 0; font-size: .92rem; letter-spacing: .03em; }
.cc-item-desc { margin: .1rem 0 0; font-size: .85rem; color: var(--fg-2); overflow-wrap: anywhere; }
.cc-state { margin: .45rem 0 0; font-size: .78rem; color: var(--ok-fg); }
.cc-note { display: flex; align-items: flex-start; gap: .4rem; margin: 0; padding: .5rem .65rem; border: 1px solid var(--warn-line); border-radius: var(--r-sm); background: var(--warn-bg); color: var(--warn); font-size: .8rem; }
.cc-note .icon { flex: none; margin-top: .15rem; }
/* La búsqueda, con lo que hay que escribir para encontrar el producto. */
.cc-find { display: flex; flex-direction: column; gap: .3rem; }
.cc-find-title { font-size: .84rem; font-weight: 600; color: var(--fg); }
.cc-find-help { margin: 0 0 .15rem; font-size: .76rem; line-height: 1.45; color: var(--muted); }
.cc-find-help strong { color: var(--fg-2); font-weight: 600; }
.cc-search { display: flex; align-items: center; gap: .45rem; }
.cc-search > .icon { color: var(--muted); flex: none; }
.cc-search input { flex: 1; min-width: 0; padding: .42rem .55rem; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--field); color: var(--fg); font: inherit; font-size: .88rem; }
.cc-search input:focus { border-color: var(--accent); outline: none; }
.cc-list { display: flex; flex-direction: column; gap: .5rem; }
.cc-sec { margin: 0; font-size: .63rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.cc-empty { margin: .2rem 0; font-size: .82rem; color: var(--muted); line-height: 1.5; }
.cc-empty .icon { margin-right: .3rem; }
/* Una ficha de producto: la misma en las sugerencias y en los resultados. */
.cc-cand { position: relative; padding: .6rem .7rem .7rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--inset); }
.cc-cand.is-sel { border-color: var(--accent); background: var(--accent-soft); }
#cc-list > .cc-cand { cursor: pointer; }
.cc-cand-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .25rem; }
.cc-cand-top .btn { padding: .28rem .7rem; font-size: .8rem; margin-left: auto; }
.cc-cand-head { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .55rem; }
.cc-code { font-weight: 600; font-size: .88rem; letter-spacing: .03em; }
.cc-hs { font-size: .8rem; color: var(--fg); }
.cc-cand-desc { margin: .25rem 0 .4rem; font-size: .84rem; }
dl.cc-demi { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem .9rem; margin: 0; }
dl.cc-demi div { min-width: 0; }
dl.cc-demi dt { font-size: .6rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
dl.cc-demi dd { margin: 0; font-size: .8rem; line-height: 1.35; overflow-wrap: anywhere; }
.cc-hsonly { margin: .3rem 0 0; padding: .45rem .55rem; border: 1px dashed var(--line); border-radius: var(--r-sm); font-size: .76rem; color: var(--muted); }
.cc-why { margin: .5rem 0 0; font-size: .74rem; color: var(--info); }
.cc-why span { color: var(--muted); }
/* Un resultado de búsqueda: una línea, y la ficha completa del que está elegido. */
.cc-res { border: 1px solid transparent; border-radius: 7px; }
.cc-res.is-sel { border-color: var(--accent); background: var(--accent-soft); }
.cc-res-main { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: .5rem; align-items: baseline; width: 100%; padding: .4rem .5rem; border: 0; background: transparent; color: var(--fg); font: inherit; text-align: left; cursor: pointer; }
.cc-res:not(.is-sel) .cc-res-main:hover { background: var(--raised); border-radius: 7px; }
.cc-res-desc { font-size: .8rem; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-res-card { padding: 0 .5rem .5rem; }
.cc-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .6rem; padding: .7rem 1rem; border-top: 1px solid var(--line); background: var(--inset); }
.cc-foot .btn-sec { align-self: auto; padding: .36rem .7rem; font-size: .84rem; }
.cc-foot .btn { padding: .42rem .9rem; font-size: .88rem; margin-left: auto; }
.cc-keys { font-size: .74rem; color: var(--muted); margin-right: auto; }
.cc-msg { flex-basis: 100%; margin: 0; font-size: .78rem; color: var(--muted); }
.cc-msg:empty { display: none; }
.cc-msg[data-state="error"] { color: var(--err); }
.cc-msg[data-state="busy"]::before {
  content: ""; display: inline-block; width: 11px; height: 11px; margin-right: .45rem;
  vertical-align: -1px; border-radius: 50%; border: 2px solid var(--line);
  border-top-color: var(--accent); animation: spin .7s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .cc-msg[data-state="busy"]::before { animation: none; } }
/* «Vincular» en camino (conciliar.js, working()): el producto elegido conserva su borde y el
   resto del panel se atenúa y no responde hasta que llega el siguiente. Cerrar sigue activo. */
.cc-inner.is-working .cc-body, .cc-inner.is-working .cc-nav, .cc-inner.is-working .cc-foot > button { pointer-events: none; }
.cc-inner.is-working .cc-nav, .cc-inner.is-working .cc-foot > button, .cc-inner.is-working .cc-find,
.cc-inner.is-working .cc-sec, .cc-inner.is-working .cc-cand:not(.is-linking),
.cc-inner.is-working .cc-res:not(.is-linking) { opacity: .45; }
.cc-cand.is-linking, .cc-res.is-linking { border-color: var(--accent); }
.cc-link-btn.is-linked { background: var(--ok); }
/* Lo que se acaba de hacer, arriba del panel que sigue. */
.cc-flash { display: flex; align-items: flex-start; gap: .4rem; margin: 0; padding: .45rem .65rem; border: 1px solid var(--ok-line); border-radius: var(--r-sm); background: var(--ok-bg); color: var(--ok-fg); font-size: .8rem; line-height: 1.4; }
.cc-flash .icon { flex: none; margin-top: .12rem; }
.cc-undo { align-self: flex-start; font-size: .84rem; }
.cc-done h3 { margin: .2rem 0 .5rem; font-size: 1.05rem; }
.cc-tally { list-style: none; margin: 0 0 .6rem; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; font-size: .88rem; }
.cc-tally strong { font-variant-numeric: tabular-nums; }
/* Uso de un producto del catálogo, y teclas. */
.chip { display: inline-flex; align-items: center; gap: .25rem; padding: .02rem .45rem; border: 1px solid var(--line); border-radius: 999px; font-size: .66rem; line-height: 1.6; color: var(--fg-2); background: var(--raised); white-space: nowrap; }
kbd { display: inline-block; min-width: 1.15rem; padding: 0 .28rem; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--field); color: var(--muted); font-family: var(--font-mono); font-size: .68rem; line-height: 1.45; text-align: center; }
/* La entrada desde la barra de abajo. */
.cc-bar { display: flex; align-items: center; gap: .6rem; padding: .25rem .3rem .25rem .7rem; border: 1px solid var(--info-line); border-radius: 9px; background: var(--info-bg); }
.cc-bar[hidden] { display: none; }
.cc-bar .btn { padding: .32rem .75rem; font-size: .85rem; }
/* «Es nuevo»: el código HS primero, porque de él depende el formulario que sigue. */
.cc-new { display: flex; flex-direction: column; gap: .7rem; }
.cc-info { margin: 0; font-size: .82rem; line-height: 1.5; color: var(--muted); }
.cc-new .hs-input { width: 11rem; }
