/* ==========================================================================
   OCR, "Papeterie" theme.
   A bright scanning room: warm paper for the page, white sheets for the
   surfaces, blue ink for everything that acts. The signature element stays
   the beam, now a stroke of ink sweeping a white sheet, used both as the
   scan sweep and as the progress bar.
   No webfont (offline constraint): the display voice is the platform serif,
   the interface voice the platform sans, numbers are mono.
   ========================================================================== */

:root {
  /* Colours: paper, ink, beam */
  --paper: #f6f4ee;          /* page background, warm cream */
  --paper-deep: #efece3;     /* bottom of the page gradient */
  --card: #fffdf9;           /* surfaces: cards, drop zone, sheets */
  --line: #e6e1d4;           /* hairline borders */
  --line-strong: #d4cdbb;    /* dashed borders, resting outlines */
  --ink: #1d2130;            /* primary text, blue-black ink */
  --ink-2: #6f7482;          /* secondary text, quiet labels */
  --accent: #2c4fd8;         /* blue ink: actions, beam, selection */
  --accent-deep: #1e3cb4;
  --accent-soft: #edf1ff;    /* tinted fills behind selected things */
  --accent-halo: rgba(44, 79, 216, .22);
  --ok: #1e8f52;
  --ok-soft: #e6f6ec;
  --error: #cc4444;
  --error-soft: #fbecec;

  /* Type: three platform voices, no download. */
  --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: ui-serif, "Iowan Old Style", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", monospace;

  --radius: 14px;
  --radius-small: 9px;
  --shadow-1: 0 1px 2px rgba(29, 33, 48, .05), 0 4px 16px rgba(29, 33, 48, .06);
  --shadow-2: 0 2px 4px rgba(29, 33, 48, .07), 0 12px 32px rgba(29, 33, 48, .10);
  --transition: 180ms cubic-bezier(.4, 0, .2, 1);
  --spring: cubic-bezier(.2, .7, .25, 1);

  --text-small: .875rem;
  --text-large: 1.25rem;
}

*, *::before, *::after { box-sizing: border-box; }

/* The layout rules below would win over the browser stylesheet: restate the
   hidden attribute once and for all. */
[hidden] { display: none !important; }

html { color-scheme: light; }

body {
  margin: 0;
  min-height: 100vh;
  /* A faint dot grid over a warm gradient: paper, not a void. */
  background:
    radial-gradient(circle at 1px 1px, rgba(29, 33, 48, .045) 1px, transparent 1.5px)
      0 0 / 26px 26px,
    linear-gradient(180deg, var(--paper), var(--paper-deep));
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--ui);
  font-size: var(--text-small);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, a { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-halo); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow-1);
  z-index: 10;
}
.skip-link:focus { left: 8px; }

/* --- Header ------------------------------------------------------------- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  color: var(--ink-2);
}

.brand { display: inline-flex; align-items: center; gap: 10px; }

.brand__mark {
  width: 22px; height: 22px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
}
/* The mark's beam sweeps once on load: the room switches on. */
.brand__mark line {
  transform-origin: center;
  animation: mark-sweep 900ms var(--spring) 200ms backwards;
}

.header__title {
  color: var(--ink);
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.header__right { display: inline-flex; align-items: center; gap: 18px; }
/* The job's cost estimate, pinned in the header across every state. A quiet
   pill on the paper: white card, hairline border, the amount in ink. Money
   stays out of the accent colour, an estimate is never a call to action. */
.header__cost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-1);
  white-space: nowrap;
  animation: cost-in 300ms var(--spring) backwards;
}
.header__cost strong { color: var(--ink); font-weight: 600; }
.header__cost-icon {
  width: 14px; height: 14px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.6;
  stroke-linejoin: round;
}
@keyframes cost-in {
  from { opacity: 0; transform: translateY(-4px); }
}
.header__health { display: inline-flex; align-items: center; gap: 8px; }

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background var(--transition), box-shadow var(--transition);
}
.header__health[data-state="ok"] .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}
.header__health[data-state="error"] .dot {
  background: var(--error);
  box-shadow: 0 0 0 3px var(--error-soft);
}

/* --- State 0: the login form -------------------------------------------- */

.login {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  width: min(360px, 100%);
  padding: 36px 32px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
}

.login__title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 500;
  letter-spacing: -.01em;
}
.login__hint { margin: -8px 0 4px; color: var(--ink-2); }
.login__field { width: 100%; }
.login__error { margin: 0; color: var(--error); }

/* --- Alert banner -------------------------------------------------------- */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 24px 8px;
  padding: 12px 16px;
  background: var(--error-soft);
  border: 1px solid color-mix(in srgb, var(--error) 25%, transparent);
  border-left: 3px solid var(--error);
  border-radius: var(--radius-small);
  animation: appear 250ms var(--spring);
}

.banner__text { margin: 0; }
.banner code {
  font-family: var(--mono);
  background: var(--card);
  padding: .1em .35em;
  border-radius: 4px;
}

/* --- States -------------------------------------------------------------- */

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px 24px 48px;
}

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  min-height: calc(100vh - 180px);
  justify-content: center;
}

/* Entering a state: its blocks rise in, one after the other. The animation
   restarts each time [hidden] is removed, so every state change is staged. */
.state > * { animation: rise 480ms var(--spring) backwards; }
.state > :nth-child(2) { animation-delay: 60ms; }
.state > :nth-child(3) { animation-delay: 120ms; }
.state > :nth-child(4) { animation-delay: 180ms; }
.state > :nth-child(5) { animation-delay: 240ms; }
.state > :nth-child(6) { animation-delay: 300ms; }
.state > :nth-child(n+7) { animation-delay: 360ms; }

/* --- State 1: the drop zone --------------------------------------------- */

/* One column, so everything must fit a laptop screen: a tighter rhythm than
   the other states. */
.state--upload { gap: 18px; }

/* Compact and horizontal: the icon beside the words, not a tall empty box,
   so the state below stays on screen. */
.dropzone {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 22px;
  row-gap: 2px;
  width: min(560px, 100%);
  padding: 22px 30px;
  background: var(--card);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition),
              transform var(--transition);
}

.dropzone:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-2);
  transform: translateY(-2px);
}

/* A file is being dragged over: the scanner light switches on. */
.dropzone.dragging {
  border-color: var(--accent);
  border-style: solid;
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-2);
  transform: scale(1.015);
}

.dropzone.rejected { border-color: var(--error); }

.dropzone__icon {
  grid-row: 1 / 3;
  width: 34px; height: 42px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--transition), transform var(--transition);
}
.dropzone:hover .dropzone__icon,
.dropzone.dragging .dropzone__icon {
  stroke: var(--accent);
  transform: translateY(-3px);
}

.dropzone__line {
  margin: 0;
  font-family: var(--display);
  font-size: 1.25rem;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}
.dropzone__formats { margin: 0; color: var(--ink-2); }

/* A file is in the zone: the sheet is on the glass, ready to scan. */
.dropzone.has-file {
  border-style: solid;
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--card), var(--accent-soft));
}
.dropzone.has-file .dropzone__icon { stroke: var(--accent); }
.dropzone.has-file .dropzone__line {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
}

/* The way back out of a chosen file, without having to replace it. It only
   exists once a file is in the zone, and stays invisible until the pointer is
   on it: the filename is the subject, the cross is the afterthought. */
.dropzone.has-file { grid-template-columns: auto 1fr auto; }
.dropzone__remove {
  /* Last column, both rows: pinned right, centred on the two lines of text. */
  grid-column: 3;
  grid-row: 1 / 3;
  display: none;
  place-items: center;
  width: 32px; height: 32px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--ink-2);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition),
              color var(--transition);
}
.dropzone.has-file .dropzone__remove { display: grid; }
.dropzone:hover .dropzone__remove,
.dropzone__remove:focus-visible { opacity: 1; }
.dropzone__remove:hover { background: var(--card); color: var(--error); }
.dropzone__remove svg {
  width: 15px; height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}
/* No pointer to hover with: the cross is simply always there. */
@media (hover: none) {
  .dropzone.has-file .dropzone__remove { opacity: 1; }
}

/* --- The model picker ----------------------------------------------------
   A real list, not a native select: searchable, scrollable, each row naming
   its price. Over-cap models are hidden by default and never selectable. */

.models {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.models__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 0;
}

.models__title { font-weight: 600; }

.models__cap {
  margin-left: auto;   /* the favourites chip sits next to the title, the cap stays right */
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: .78rem;
}

.models__search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 10px 18px 12px;
}

.models__glass {
  position: absolute;
  left: 12px;
  width: 15px; height: 15px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.8;
  stroke-linecap: round;
  pointer-events: none;
  transition: stroke var(--transition);
}
.models__search:focus-within .models__glass { stroke: var(--accent); }

.models__field {
  width: 100%;
  padding: 9px 76px 9px 36px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: border-color var(--transition), background var(--transition),
              box-shadow var(--transition);
}
.models__field:hover { border-color: var(--line-strong); }
.models__field:focus {
  outline: none;
  background: var(--card);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.models__count {
  position: absolute;
  right: 12px;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: .78rem;
  white-space: nowrap;
  pointer-events: none;
}

.models__list {
  max-height: min(240px, 32vh);
  overflow-y: auto;
  border-top: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  overscroll-behavior: contain;
}
.models__list::-webkit-scrollbar { width: 10px; }
.models__list::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 999px;
  border: 3px solid var(--card);
}

.models__empty {
  margin: 0;
  padding: 22px 18px;
  color: var(--ink-2);
  text-align: center;
  font-style: italic;
}

.model-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 18px 10px 15px;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.model-row + .model-row { border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
.model-row:hover:not(:disabled) { background: var(--paper); }
.model-row:focus-visible { outline-offset: -2px; }

.model-row.is-selected {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}
.model-row.is-selected .model-row__name { color: var(--accent-deep); font-weight: 600; }
.model-row.is-selected .model-row__price { color: var(--accent-deep); }

.model-row__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: .82rem;
}
.model-row__vendor { color: var(--ink-2); }

/* Rank in FAVORITE_MODELS: 1 is the model to reach for first. */
.model-row__rank {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-right: 7px;
  border-radius: 50%;
  background: #f6e7bb;
  color: #7a5c05;
  font-family: var(--mono);
  font-size: .66rem;
  font-weight: 600;
  vertical-align: 1px;
}

.model-row__price {
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: .78rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Over the price cap: visible on demand, priced, never selectable. */
.model-row--capped { cursor: not-allowed; }
.model-row--capped .model-row__name,
.model-row--capped .model-row__price { opacity: .45; }

.model-row__badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: .7rem;
  white-space: nowrap;
}

.models__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px 12px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 55%, var(--card));
}

/* Small pill actions: reveal the over-cap models, load the full catalogue. */
.chip {
  padding: 5px 12px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--ink-2);
  font-size: .78rem;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition),
              background var(--transition);
}
.chip:hover { color: var(--ink); border-color: var(--ink-2); }
.chip.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-deep);
}

.field {
  padding: 9px 12px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field:hover { border-color: var(--line-strong); }
.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* The optimize pill and the start button share one line: one decision, one
   action, and a state short enough for a laptop screen. */
.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

/* Optional pre-pass, on by default: a plain checkbox, styled as a small pill. */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-2);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition),
              box-shadow var(--transition);
}
.toggle:hover { color: var(--ink); border-color: var(--line-strong); box-shadow: var(--shadow-1); }
.toggle:has(:checked) { color: var(--ink); }
.toggle input { accent-color: var(--accent); cursor: pointer; }

/* Money is an estimate, never a quote: kept quiet, never in the accent colour. */
.estimate {
  margin: 0;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: var(--text-small);
}

/* --- State 2: the page previews ----------------------------------------- */

.state--preview {
  justify-content: flex-start;
  align-items: stretch;
  gap: 20px;
  padding-top: 24px;
}

.pagebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.pagebar--footer { justify-content: flex-end; gap: 24px; }
.pagebar__title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: -.01em;
}
.pagebar__detail {
  margin: 4px 0 0;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: var(--text-small);
}
.pagebar__actions { display: flex; align-items: center; gap: 12px; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.thumb {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 8px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--card);
  box-shadow: var(--shadow-1);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: .78rem;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition),
              transform var(--transition), color var(--transition);
  animation: rise 400ms var(--spring) backwards;
}
.thumb:hover {
  border-color: var(--accent);
  color: var(--ink);
  transform: translateY(-3px);
  box-shadow: var(--shadow-2);
}
.thumb img {
  width: 100%;
  border-radius: 5px;
  background: white;
  border: 1px solid var(--line);
  /* Pages have different shapes once cropped: a fixed box keeps the grid even
     and makes an odd render stand out at a glance. */
  aspect-ratio: 3 / 4;
  object-fit: contain;
}
.thumb span { align-self: center; }

.lightbox {
  max-width: min(92vw, 900px);
  max-height: 92vh;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-2);
}
.lightbox[open] { animation: pop 220ms var(--spring); }
.lightbox::backdrop { background: rgba(29, 33, 48, .45); backdrop-filter: blur(2px); }
.lightbox__image {
  display: block;
  max-width: 100%;
  max-height: calc(92vh - 110px);
  border-radius: var(--radius-small);
  border: 1px solid var(--line);
  background: white;
}
.lightbox__caption {
  margin: 12px 0;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: var(--text-small);
}

/* --- Buttons ------------------------------------------------------------- */

.button {
  padding: 12px 24px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), opacity var(--transition),
              transform var(--transition), box-shadow var(--transition);
}
.button:active:not(:disabled) { transform: translateY(1px) scale(.99); }

.button--primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 6px var(--accent-halo), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.button--primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px var(--accent-halo), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.button--primary:disabled {
  background: var(--line);
  color: var(--ink-2);
  box-shadow: none;
  cursor: not-allowed;
}

.button--quiet {
  color: var(--ink-2);
  border-color: var(--line-strong);
  background: var(--card);
}
.button--quiet:hover { color: var(--ink); border-color: var(--ink-2); }

.link {
  padding: 4px;
  background: none;
  border: none;
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  transition: color var(--transition);
}
.link:hover { color: var(--accent); }

/* --- State 3: tracker on the left, sheet on the right -------------------- */

.processing {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 40px;
  width: 100%;
  align-items: start;
}

.tracker { display: flex; flex-direction: column; gap: 20px; }

.tracker__step {
  margin: 0;
  color: var(--ink-2);
  letter-spacing: .1em;
  text-transform: uppercase;
  font-size: .78rem;
  font-weight: 600;
}

/* Mechanical counter: the current page rolls, the total stays put. */
.counter {
  display: flex;
  align-items: baseline;
  gap: .14em;
  margin: 0;
  font-family: var(--display);
  font-size: clamp(3rem, 7vw, 4.4rem);
  line-height: 1.15;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.counter__frame { overflow: hidden; height: 1.15em; display: inline-block; }
.counter__value { display: block; }
.counter__value.rolling { animation: roll 300ms var(--spring); }
.counter__slash,
.counter__total { color: var(--ink-2); }

.progress {
  height: 5px;
  background: var(--line);
  border-radius: 999px;
  overflow: visible;
}

.progress__beam {
  height: 100%;
  width: calc(var(--progress, 0) * 1%);
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  border-radius: inherit;
  position: relative;
  transition: width 500ms cubic-bezier(.4, 0, .2, 1);
}

.progress__beam::after {                 /* glowing head */
  content: "";
  position: absolute;
  right: -3px; top: 50%;
  width: 11px; height: 11px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px 3px var(--accent-halo);
  animation: pulse 1.6s ease-in-out infinite;
}

/* End of job: the head goes out. */
.progress.off .progress__beam::after {
  animation: none;
  opacity: 0;
  transition: opacity 300ms linear;
}

.times {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 0;
}
.times__item { display: flex; flex-direction: column; gap: 2px; }
.times dt { color: var(--ink-2); font-size: .78rem; }
.times dd {
  margin: 0;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.failures { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }

.failure {
  padding: 4px 10px;
  background: var(--error-soft);
  border: 1px solid color-mix(in srgb, var(--error) 30%, transparent);
  border-radius: 999px;
  color: var(--error);
  font-family: var(--mono);
  font-size: .78rem;
  animation: shake 300ms ease-in-out;
}

.tracker .button--quiet { align-self: flex-start; }

/* The sheet: a real page on the desk, the beam sweeps it while it is read. */
.sheet {
  position: relative;
  overflow: hidden;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  height: min(72vh, 780px);
}

.sheet__content {
  height: 100%;
  overflow-y: auto;
  padding: 32px 36px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: var(--text-small);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.sheet__content.revealed { animation: reveal 450ms ease-out; }

.sheet__placeholder { color: var(--ink-2); margin: 0; font-family: var(--ui); }

.sheet.scanning::after {
  content: "";
  position: absolute;
  inset: 0;
  /* A 72px band moved through background-position: the sweep covers the whole
     height of the sheet without triggering any reflow. */
  background-image: linear-gradient(to bottom,
    transparent,
    var(--accent-halo) 45%,
    rgba(44, 79, 216, .55) 50%,
    var(--accent-halo) 55%,
    transparent);
  background-size: 100% 72px;
  background-repeat: no-repeat;
  animation: scan 2.6s linear infinite;
  pointer-events: none;
}

/* Preview typography: this is a document, not interface chrome. */
.sheet__content h1,
.sheet__content h2,
.sheet__content h3 { font-size: 1.15em; margin: 1.2em 0 .5em; line-height: 1.35; }
.sheet__content h1 { font-size: 1.35em; }
.sheet__content p, .sheet__content li { margin: .5em 0; }
.sheet__content ul, .sheet__content ol { padding-left: 1.4em; }
.sheet__content table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.sheet__content th, .sheet__content td {
  border: 1px solid var(--line-strong);
  padding: 6px 9px;
  text-align: left;
}
.sheet__content blockquote {
  margin: 1em 0;
  padding-left: 1em;
  border-left: 2px solid var(--line-strong);
  color: var(--ink-2);
}
.sheet__content code {
  background: var(--paper);
  padding: .1em .3em;
  border-radius: 3px;
}
.sheet__content pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 1em 0;
}
.sheet__content pre code { background: none; padding: 0; }
.sheet__content img { max-width: 100%; }

/* --- State 4: done ------------------------------------------------------- */

.state--done { gap: 20px; }

.check-ring {
  display: grid;
  place-items: center;
  width: 88px; height: 88px;
  border-radius: 50%;
  background: var(--ok-soft);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ok) 25%, transparent) inset;
  animation: pop 350ms var(--spring);
}

.check {
  width: 48px; height: 48px;
  fill: none;
  stroke: var(--ok);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.check path { stroke-dasharray: 48; stroke-dashoffset: 48; }
.check.drawn path { animation: draw 400ms ease-out 150ms forwards; }

.counter--done { justify-content: center; }

.button--rise { opacity: 0; }
.button--rise.risen { animation: rise 300ms var(--spring) 250ms forwards; }

.summary {
  margin: 0;
  font-family: var(--mono);
  color: var(--ink-2);
  text-align: center;
}

/* --- Toasts -------------------------------------------------------------- */

.toasts {
  position: fixed;
  right: 20px; bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(420px, calc(100vw - 40px));
  z-index: 20;
}

.toast {
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--error);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow-2);
  animation: slide-in 250ms var(--spring);
}
.toast--info { border-left-color: var(--accent); }

/* --- Animations ---------------------------------------------------------- */

@keyframes scan {
  from { background-position-y: -72px; }
  to   { background-position-y: calc(100% + 72px); }
}

@keyframes pulse {
  50% { box-shadow: 0 0 18px 6px var(--accent-halo); }
}

@keyframes roll {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes reveal {
  from { clip-path: inset(0 0 100% 0); }
  to   { clip-path: inset(0 0 0 0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

@keyframes rise {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes appear {
  from { transform: translateY(6px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

@keyframes pop {
  from { transform: scale(.92); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

@keyframes slide-in {
  from { transform: translateX(16px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes mark-sweep {
  from { transform: translateY(-5px); opacity: 0; }
  60%  { transform: translateY(3px); }
  to   { transform: translateY(0); opacity: 1; }
}

/* --- History dialog ------------------------------------------------------ */

.history {
  width: min(92vw, 760px);
  max-height: 86vh;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-2);
}
.history[open] { animation: pop 220ms var(--spring); }
.history::backdrop { background: rgba(29, 33, 48, .45); backdrop-filter: blur(2px); }

.history__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.history__title {
  font-family: var(--display);
  font-size: var(--text-large);
  font-weight: 600;
}
.history__empty { color: var(--ink-2); text-align: center; padding: 24px 0; }

.history-entry { border-top: 1px solid var(--line); }
.history-entry:last-of-type { border-bottom: 1px solid var(--line); }

.history-entry__summary {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: baseline;
  padding: 10px 6px;
  cursor: pointer;
  list-style: none;   /* the whole row is the affordance, no marker needed */
  border-radius: var(--radius-small);
}
.history-entry__summary::-webkit-details-marker { display: none; }
.history-entry__summary:hover { background: var(--accent-soft); }
.history-entry__date { color: var(--ink-2); white-space: nowrap; }
.history-entry__name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-entry__meta { color: var(--ink-2); white-space: nowrap; }
.history-entry__status {
  font-size: .75rem;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--accent-soft);
  color: var(--accent-deep);
}
.history-entry__status--done { background: var(--ok-soft); color: var(--ok); }
.history-entry__status--failed,
.history-entry__status--cancelled { background: var(--error-soft); color: var(--error); }

.history-entry__body { padding: 4px 6px 18px; display: grid; gap: 14px; }
.history-entry__info { margin: 0; display: grid; gap: 4px; }
.history-entry__info div { display: flex; gap: 8px; }
.history-entry__info dt { color: var(--ink-2); min-width: 140px; flex-shrink: 0; }
.history-entry__info dd { margin: 0; overflow-wrap: anywhere; }
.history-entry__actions { display: flex; flex-wrap: wrap; gap: 10px; }
.history-entry__delete { color: var(--error); }

.history-entry__thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.history-entry__thumbs img {
  height: 84px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.history-entry__output {
  max-height: 260px;
  overflow: auto;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--paper);
  font-size: .8rem;
}

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 900px) {
  .processing { grid-template-columns: 1fr; gap: 28px; }
  .sheet { height: min(60vh, 560px); }
  main { padding: 8px 16px 40px; }
  .header, .banner { margin-inline: 0; padding-inline: 16px; }
  .history-entry__summary { grid-template-columns: 1fr auto; }
}

/* --- Safeguards ---------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .sheet.scanning::after,
  .progress__beam::after { animation: none; }
  * { transition-duration: 1ms !important; animation-duration: 1ms !important; }
  .check path { stroke-dashoffset: 0; }
  .button--rise { opacity: 1; }
}
