/* Cantera Utilities — taller de preprensa.
   Las cuatro tintas de proceso (cian, magenta, amarillo, negro) identifican las categorías;
   las marcas de corte enmarcan el único gesto central de la interfaz: soltar un archivo. */

@font-face {
  font-family: "Archivo";
  src: url("/static/fonts/archivo-latin.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  --paper: #f3f4f6;
  --surface: #ffffff;
  --sunk: #e9ecf0;
  --ink: #151922;
  --ink-2: #485163;
  --rule: #d2d7de;
  --rule-strong: #aab2bf;
  --mark: #151922;

  --cyan: #0a8ec4;       --cyan-text: #06698f;
  --magenta: #c8246b;    --magenta-text: #b01e5e;
  --yellow: #e8b800;     --yellow-text: #7d6000;
  --key: #151922;        --key-text: #151922;

  --danger: #b3261e;
  --ok: #17734a;

  --radius: 6px;
  --gutter: clamp(16px, 4vw, 40px);
  --font: "Archivo", "Segoe UI", system-ui, sans-serif;
}

:root[data-theme="dark"] {
  --paper: #12151b;
  --surface: #1a1e26;
  --sunk: #0e1116;
  --ink: #eceef2;
  --ink-2: #a6aebc;
  --rule: #2c323e;
  --rule-strong: #46505f;
  --mark: #eceef2;
  --cyan: #3db8ea;       --cyan-text: #6ccbf2;
  --magenta: #f0679a;    --magenta-text: #f58bb3;
  --yellow: #f2c830;     --yellow-text: #f2c830;
  --key: #eceef2;        --key-text: #eceef2;
  --danger: #ff8a80;
  --ok: #6fd3a0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12151b;
    --surface: #1a1e26;
    --sunk: #0e1116;
    --ink: #eceef2;
    --ink-2: #a6aebc;
    --rule: #2c323e;
    --rule-strong: #46505f;
    --mark: #eceef2;
    --cyan: #3db8ea;       --cyan-text: #6ccbf2;
    --magenta: #f0679a;    --magenta-text: #f58bb3;
    --yellow: #f2c830;     --yellow-text: #f2c830;
    --key: #eceef2;        --key-text: #eceef2;
    --danger: #ff8a80;
    --ok: #6fd3a0;
  }
}

[data-ink="cyan"] { --tint: var(--cyan); --tint-text: var(--cyan-text); }
[data-ink="magenta"] { --tint: var(--magenta); --tint-text: var(--magenta-text); }
[data-ink="yellow"] { --tint: var(--yellow); --tint-text: var(--yellow-text); }
[data-ink="key"] { --tint: var(--key); --tint-text: var(--key-text); }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: light dark; -webkit-text-size-adjust: 100%; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.55 var(--font);
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { font-weight: 750; font-stretch: 72%; letter-spacing: -0.005em; line-height: 1.1; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: var(--radius);
}
.skip:focus { top: 12px; }

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

/* ── Estructura ────────────────────────────────────────────────────────── */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 28px var(--gutter) 72px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px var(--gutter);
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-name { font-size: 1.35rem; font-weight: 800; font-stretch: 68%; letter-spacing: -0.01em; }
.brand svg { width: 30px; height: 30px; }

.search { flex: 1 1 260px; max-width: 420px; position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; translate: 0 -50%; width: 17px; height: 17px; color: var(--ink-2); pointer-events: none; }
.search input {
  width: 100%; height: 40px; padding: 0 12px 0 36px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
}
.search input::placeholder { color: var(--ink-2); opacity: 1; }
.search input:focus-visible { outline-offset: 0; }

.nav { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a, .nav button {
  background: none; border: 0; cursor: pointer; text-decoration: none;
  padding: 8px 12px; border-radius: var(--radius); font-weight: 560; color: var(--ink-2); white-space: nowrap;
}
.nav a:hover, .nav button:hover { background: var(--sunk); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); border-radius: 0; }

.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── Botones y campos ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px; cursor: pointer;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule-strong); border-radius: var(--radius); font-weight: 620;
  text-decoration: none;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 88%, var(--tint, var(--cyan))); }
.btn-quiet { background: none; border-color: transparent; color: var(--ink-2); min-height: 36px; padding: 0 10px; }
.btn-quiet:hover { background: var(--sunk); color: var(--ink); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; min-height: 48px; font-size: 1.02rem; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label, .field > .label { font-weight: 620; font-size: .92rem; }
.field .hint { font-size: .85rem; color: var(--ink-2); }
.field input[type="text"], .field input[type="number"], .field input[type="password"], .field input[type="url"], .field input[type="email"],
.field select, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius);
}
.field textarea { min-height: 140px; resize: vertical; font: 0.9rem/1.5 ui-monospace, "DejaVu Sans Mono", monospace; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline-offset: 0; border-color: var(--cyan); }
.field input[type="color"] { width: 64px; height: 42px; padding: 3px; background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--ink); flex: none; }
.check label { font-weight: 560; }
.pages-row { display: flex; gap: 8px; }
.pages-row input { flex: 1; }

details.advanced { border-top: 1px solid var(--rule); padding-top: 12px; margin-top: 6px; }
details.advanced > summary { cursor: pointer; font-weight: 620; color: var(--ink-2); padding: 4px 0 12px; }
details.advanced[open] > summary { color: var(--ink); }

/* ── La zona de soltar: marcas de corte ────────────────────────────────── */
.trim { position: relative; margin: 18px; }
.trim::before {
  content: ""; position: absolute; inset: -14px; pointer-events: none; transition: inset .18s ease;
  background:
    linear-gradient(var(--mark), var(--mark)) left 0 top 14px / 10px 2px no-repeat,
    linear-gradient(var(--mark), var(--mark)) left 14px top 0 / 2px 10px no-repeat,
    linear-gradient(var(--mark), var(--mark)) right 0 top 14px / 10px 2px no-repeat,
    linear-gradient(var(--mark), var(--mark)) right 14px top 0 / 2px 10px no-repeat,
    linear-gradient(var(--mark), var(--mark)) left 0 bottom 14px / 10px 2px no-repeat,
    linear-gradient(var(--mark), var(--mark)) left 14px bottom 0 / 2px 10px no-repeat,
    linear-gradient(var(--mark), var(--mark)) right 0 bottom 14px / 10px 2px no-repeat,
    linear-gradient(var(--mark), var(--mark)) right 14px bottom 0 / 2px 10px no-repeat;
}
.dropzone {
  position: relative; display: grid; place-items: center; text-align: center; gap: 10px;
  padding: clamp(32px, 7vw, 64px) 24px;
  background: var(--surface); border: 1px solid var(--rule); cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}
.dropzone h2 { font-size: clamp(2rem, 5.2vw, 3.6rem); font-weight: 800; font-stretch: 64%; max-width: 26ch; text-wrap: balance; }
.dropzone p { color: var(--ink-2); max-width: 54ch; }
.dropzone .btn { margin-top: 6px; }
.dropzone.compact { padding: 22px 18px; }
.dropzone.compact h2 { font-size: 1.5rem; }
.dropzone[data-over="true"] { background: color-mix(in srgb, var(--magenta) 9%, var(--surface)); border-color: var(--magenta); }
.trim:has(.dropzone[data-over="true"])::before { inset: -8px; --mark: var(--magenta); }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.dropzone .btn, .dropzone a { position: relative; z-index: 1; }

.filechips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 0; padding: 0; list-style: none; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 6px 6px 6px 12px; background: var(--surface); border: 1px solid var(--rule); border-radius: 999px; font-size: .9rem;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28ch; }
.chip small { color: var(--ink-2); }
.chip button { border: 0; background: none; cursor: pointer; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); }
.chip button:hover { background: var(--sunk); color: var(--ink); }

/* ── Inicio: catálogo ──────────────────────────────────────────────────── */
.intro { display: grid; gap: 6px; margin-bottom: 8px; }
.intro h1 { font-size: clamp(1.5rem, 3vw, 2rem); }
.intro p { color: var(--ink-2); max-width: 70ch; }

.suggest { margin: 22px 0 8px; }
.suggest-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.suggest-head h2 { font-size: 1.4rem; }

.category { margin-top: 40px; }
.category-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.category-head h2 { font-size: 1.7rem; display: flex; align-items: center; gap: 12px; }
.category-head p { color: var(--ink-2); font-size: .95rem; }
.ink-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--tint); flex: none; box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px var(--tint); }

.tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; list-style: none; margin: 0; padding: 0; }
.tool {
  position: relative; display: flex; flex-direction: column; gap: 8px; height: 100%;
  padding: 16px 16px 14px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  transition: border-color .12s ease, background-color .12s ease;
}
.tool::before { /* esquina de corte en la tinta de la categoría */
  content: ""; position: absolute; left: -1px; top: -1px; width: 16px; height: 16px;
  border-left: 3px solid var(--tint); border-top: 3px solid var(--tint); border-top-left-radius: var(--radius);
}
.tool:hover { border-color: var(--tint); }
.tool h3 { font-size: 1.12rem; font-stretch: 82%; font-weight: 720; letter-spacing: 0; }
.tool p { color: var(--ink-2); font-size: .9rem; line-height: 1.45; flex: 1; }
.tool .io { font-size: .82rem; font-weight: 620; color: var(--tint-text); }
.tool[data-fit="false"] { opacity: .45; }

.empty { padding: 40px 0; color: var(--ink-2); }

/* ── Herramienta ───────────────────────────────────────────────────────── */
.crumbs { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; font-size: .92rem; color: var(--ink-2); }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }

.tool-head { display: grid; gap: 6px; margin-bottom: 24px; }
.tool-head h1 { font-size: clamp(1.9rem, 4vw, 2.7rem); font-weight: 800; font-stretch: 66%; display: flex; align-items: center; gap: 14px; }
.tool-head p { color: var(--ink-2); max-width: 70ch; }

.workbench { display: grid; gap: 28px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 960px) { .workbench { grid-template-columns: minmax(0, 1fr) 380px; } .options { position: sticky; top: 84px; } }

.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px; }
.panel h2 { font-size: 1.25rem; margin-bottom: 14px; }
.stack { display: grid; gap: 20px; }

.files { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.file {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 10px 10px 10px 14px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
}
.file[draggable="true"] { cursor: grab; }
.file.drag-over { border-color: var(--tint); box-shadow: 0 -2px 0 var(--tint); }
.file-name { font-weight: 600; overflow-wrap: anywhere; }
.file-meta { font-size: .85rem; color: var(--ink-2); }
.file-actions { display: flex; gap: 2px; }
.file-actions .btn-quiet { min-height: 34px; padding: 0 8px; }
.file .pos { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink-2); min-width: 1.4em; }

.need { color: var(--ink-2); padding: 14px 4px 0; }

/* Miniaturas de páginas */
.grid-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; color: var(--ink-2); font-size: .92rem; }
.pagegrid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.pg {
  position: relative; display: grid; gap: 6px; padding: 8px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius); text-align: center;
}
.pg.selected { border-color: var(--tint); box-shadow: 0 0 0 2px var(--tint); }
.pg.removed { opacity: .35; }
.pg-thumb { aspect-ratio: 1; display: grid; place-items: center; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.pg-thumb img { width: 100%; height: 100%; object-fit: contain; transition: rotate .18s ease; }
.pg-select { cursor: pointer; border: 0; padding: 0; background: none; width: 100%; }
.pg-label { font-size: .82rem; font-weight: 640; font-variant-numeric: tabular-nums; }
.pg-actions { display: flex; justify-content: center; gap: 0; }
.pg-actions button { border: 0; background: none; cursor: pointer; width: 30px; height: 32px; border-radius: 4px; display: grid; place-items: center; color: var(--ink-2); }
.pg-actions button:hover { background: var(--sunk); color: var(--ink); }
.pg.dragging { opacity: .4; }
.pg.drop-target { box-shadow: -3px 0 0 var(--tint); }

/* Resultado */
.result { margin-top: 20px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.result-head { padding: 16px 18px; display: grid; gap: 4px; border-bottom: 1px solid var(--rule); }
.result-head h2 { font-size: 1.3rem; display: flex; align-items: center; gap: 10px; }
.result-head h2 .icon { color: var(--ok); width: 22px; height: 22px; stroke-width: 2.4; }
.result-note { color: var(--ink-2); font-size: .95rem; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 18px; }
.result-preview { border-top: 1px solid var(--rule); background: var(--sunk); }
.result-preview iframe { width: 100%; height: min(78vh, 760px); border: 0; display: block; background: #fff; }
.result-preview img { margin: 0 auto; max-height: 560px; width: auto; }
.result-preview pre { margin: 0; padding: 16px 18px; max-height: 420px; overflow: auto; font: .85rem/1.5 ui-monospace, "DejaVu Sans Mono", monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.error {
  margin-top: 16px; padding: 12px 14px; border: 1px solid var(--danger); border-radius: var(--radius);
  color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); font-weight: 560;
}
.progress { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; margin-top: 14px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--tint, var(--cyan)); transition: width .15s linear; }
.progress[data-busy="true"] > i { width: 40% !important; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { margin-left: -40%; } to { margin-left: 100%; } }

/* ── API y administración ──────────────────────────────────────────────── */
.doc { max-width: 880px; }
.doc h1 { font-size: clamp(1.9rem, 4vw, 2.7rem); font-weight: 800; font-stretch: 66%; margin-bottom: 10px; }
.doc > p { color: var(--ink-2); margin-bottom: 16px; }
.doc h2 { font-size: 1.6rem; margin: 40px 0 12px; }
pre.code {
  margin: 0 0 14px; padding: 14px 16px; overflow: auto; background: var(--sunk); border: 1px solid var(--rule); border-radius: var(--radius);
  font: .85rem/1.55 ui-monospace, "DejaVu Sans Mono", monospace;
}
code { font: .88em ui-monospace, "DejaVu Sans Mono", monospace; background: var(--sunk); padding: .1em .35em; border-radius: 3px; }
.ops { display: grid; gap: 10px; }
.op { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.op > summary { cursor: pointer; padding: 14px 16px; display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; list-style: none; }
.op > summary::-webkit-details-marker { display: none; }
.op > summary h3 { font-size: 1.1rem; font-stretch: 82%; }
.op > summary code { background: none; padding: 0; color: var(--tint-text); font-weight: 600; }
.op-body { padding: 0 16px 16px; display: grid; gap: 12px; }
.op-body p { color: var(--ink-2); }
table.params { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.params th, table.params td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--rule); vertical-align: top; }
table.params th { font-weight: 650; color: var(--ink-2); border-top: 0; }
.table-wrap { overflow-x: auto; }

.callout { padding: 16px 18px; border: 1px solid var(--rule-strong); border-left: 4px solid var(--yellow); border-radius: var(--radius); background: var(--surface); margin-bottom: 20px; display: grid; gap: 10px; }
.callout pre { margin: 0; padding: 10px 12px; background: var(--sunk); border-radius: var(--radius); overflow-x: auto; font: .95rem ui-monospace, monospace; user-select: all; }

.keys { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.keys th, .keys td { padding: 11px 14px; text-align: left; border-top: 1px solid var(--rule); font-size: .92rem; vertical-align: middle; }
.keys th { border-top: 0; color: var(--ink-2); font-weight: 650; }
.scopes { display: grid; gap: 8px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 640; background: var(--sunk); color: var(--ink-2); border: 1px solid var(--rule); }
.badge-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--rule)); }
.badge-warn { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--rule)); }
.row-actions { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.keys select { min-height: 36px; padding: 4px 8px; background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius); }
.doc section + section { margin-top: 8px; }
.doc .panel { max-width: 560px; }
.engines { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.engine { padding: 12px 14px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.engine b { display: block; font-weight: 700; }
.engine span { color: var(--ink-2); font-size: .88rem; overflow-wrap: anywhere; }

/* ── Inicio de sesión ──────────────────────────────────────────────────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); }
.login-card .brand { margin-bottom: 18px; }
.login-card .dropzone { cursor: default; text-align: left; place-items: stretch; gap: 14px; }
.login-card h1 { font-size: 2.2rem; font-stretch: 64%; font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .progress[data-busy="true"] > i { margin-left: 0; width: 100% !important; opacity: .5; }
}

@media (max-width: 640px) {
  .topbar-inner { gap: 10px; }
  .nav { margin-left: 0; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .search { max-width: none; }
  .file { grid-template-columns: auto 1fr; }
  .file-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .keys { display: block; overflow-x: auto; }
}
