/* PolicyKit — sistema de diseño
   Idea: una mesa de redactor. Hoja blanca, tinta de bolígrafo azul y un resaltador amarillo
   que marca lo que la IA acaba de escribir. */

:root {
  --paper: #ffffff;
  --desk: #f5f6f9;
  --ink: #1f2a44;
  --ink-soft: #56607a;
  --line: #e3e7ef;
  --line-strong: #c9d0de;
  --marker: #ffe45c;
  --marker-soft: #fff4b3;
  --red: #b42323;
  --ok: #17794f;
  --warn: #9a6200;

  --f-ui: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-doc: "Newsreader", Georgia, "Times New Roman", serif;

  --s-1: 0.8125rem;
  --s0: 1rem;
  --s1: 1.125rem;
  --s2: 1.5rem;
  --s3: 2.25rem;

  --topbar: 64px;
  --r-ctl: 10px;
  --r-bubble: 16px;
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-ui);
  font-size: var(--s0);
  line-height: 1.5;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--marker); color: var(--ink); }

h1, h2, h3, p { margin: 0; }
a { color: inherit; }
img, svg { max-width: 100%; }

.sr {
  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: 1rem; top: -4rem; z-index: 50;
  background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: var(--r-ctl);
}
.skip:focus { top: 1rem; }

:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); border-radius: 6px; }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding-inline: clamp(1rem, 4vw, 2.5rem); }
.narrow { max-width: 640px; margin-inline: 0; }
.inline { display: inline; margin: 0; }

/* ---------- Barra superior ---------- */
.top { height: var(--topbar); border-bottom: 1px solid var(--line); background: var(--paper); position: relative; z-index: 10; }
.top-row { height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.top-row-app { padding-inline: clamp(1rem, 3vw, 2rem); }
.top-nav { display: flex; align-items: center; gap: 1.25rem; font-size: .9375rem; }
.who { color: var(--ink-soft); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.credits { font-weight: 600; background: var(--marker-soft); padding: .2rem .65rem; border-radius: 999px; white-space: nowrap; }

.wordmark {
  font-weight: 700; font-size: 1.3rem; letter-spacing: -0.02em; text-decoration: none;
  font-variation-settings: "opsz" 40;
}
.wordmark span {
  background: linear-gradient(var(--marker), var(--marker)) no-repeat 0 78% / 100% .5em;
  padding-inline: .02em;
}

/* ---------- Enlaces y botones ---------- */
.link { text-decoration: none; font-weight: 500; background: linear-gradient(var(--line-strong), var(--line-strong)) no-repeat 0 100% / 100% 1px; padding-bottom: 1px; }
.link:hover { background-image: linear-gradient(var(--marker), var(--marker)); background-size: 100% .5em; }
.link-button { border: 0; background-color: transparent; font: inherit; font-weight: 500; color: inherit; cursor: pointer; padding: 0 0 1px; }
.link-danger { color: var(--red); }
.mk { text-decoration: none; background: linear-gradient(var(--marker), var(--marker)) no-repeat 0 88% / 100% .45em; font-weight: 600; }
.mk:hover { background-size: 100% 100%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: 600 var(--s0)/1 var(--f-ui); text-decoration: none; cursor: pointer;
  background: var(--ink); color: #fff; border: 1.5px solid var(--ink);
  padding: .8rem 1.2rem; border-radius: var(--r-ctl);
  transition: background-color .15s, color .15s;
}
.btn:hover { background: #2d3c63; border-color: #2d3c63; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-big { padding: 1rem 1.5rem; font-size: var(--s1); }
.btn-small { padding: .55rem .85rem; font-size: .875rem; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--desk); border-color: var(--ink-soft); color: var(--ink); }

/* ---------- Formularios ---------- */
.field { margin-bottom: 1.15rem; }
.field label:not(.check) { display: block; font-weight: 600; font-size: .9375rem; margin-bottom: .35rem; }
input[type="text"], input[type="email"], input[type="password"], textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--line-strong); border-radius: var(--r-ctl); padding: .75rem .9rem;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--marker-soft); }
input[aria-invalid="true"] { border-color: var(--red); }
textarea { resize: vertical; line-height: 1.5; }
.hint { display: block; font-size: var(--s-1); color: var(--ink-soft); margin-top: .3rem; }
.field-error, .form-error { display: block; color: var(--red); font-size: .9rem; font-weight: 500; margin-top: .35rem; }
.form-error { background: #fdf0ef; border-left: 3px solid var(--red); padding: .7rem .9rem; margin: 0 0 1.25rem; border-radius: 0 var(--r-ctl) var(--r-ctl) 0; }
.notice { background: var(--marker-soft); padding: .7rem .9rem; border-radius: var(--r-ctl); margin-bottom: 1.25rem; }
.check { display: flex; gap: .7rem; align-items: flex-start; font-size: .9375rem; cursor: pointer; }
.check input { margin-top: .25rem; width: 1.1rem; height: 1.1rem; accent-color: var(--ink); flex: none; }

/* ---------- Titulares ---------- */
.h-hero { font-size: clamp(2.5rem, 5.4vw, 4.5rem); line-height: 1.02; letter-spacing: -0.03em; font-weight: 700; font-variation-settings: "opsz" 96; text-wrap: balance; }
.h-page { font-size: clamp(1.75rem, 3.4vw, 2.6rem); line-height: 1.08; letter-spacing: -0.025em; font-weight: 700; font-variation-settings: "opsz" 72; text-wrap: balance; }
.h-section { font-size: clamp(1.6rem, 3vw, 2.4rem); line-height: 1.1; letter-spacing: -0.02em; font-weight: 650; font-variation-settings: "opsz" 64; text-wrap: balance; }
.h-section-small { font-size: var(--s2); }
.lead { font-size: clamp(1.1rem, 1.6vw, 1.3rem); line-height: 1.5; color: var(--ink-soft); max-width: 36ch; margin-top: 1.4rem; }
.lead-small { color: var(--ink-soft); margin: .6rem 0 1.6rem; }
.fine { font-size: .875rem; color: var(--ink-soft); margin-top: 1rem; }
.aside { margin-top: 1.6rem; color: var(--ink-soft); }
.error-code { font-size: 5rem; font-weight: 700; letter-spacing: -0.04em; line-height: 1; margin-bottom: 1rem; background: linear-gradient(var(--marker), var(--marker)) no-repeat 0 85% / 2.4ch .35em; width: fit-content; }
.plain { padding-block: 4rem; }

/* ---------- Portada ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: clamp(2rem, 6vw, 5rem); align-items: start; padding-block: clamp(2.5rem, 7vw, 5.5rem); }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1.5rem; margin-top: 2rem; }
.hero-sheet { padding-top: .5rem; }
.sheet-demo { transform: rotate(.7deg); }

.process { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: clamp(2rem, 6vw, 5rem); padding-block: clamp(3rem, 8vw, 6rem); border-top: 1px solid var(--line); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 2rem; }
.steps li { display: grid; grid-template-columns: 3.2rem 1fr; gap: 1rem; }
.step-n { font-size: 2.6rem; line-height: .95; font-weight: 700; letter-spacing: -0.04em; font-variation-settings: "opsz" 96; font-variant-numeric: tabular-nums; }
.steps h3 { font-size: 1.2rem; font-weight: 650; letter-spacing: -0.01em; }
.steps p { color: var(--ink-soft); margin-top: .35rem; max-width: 48ch; }

.index-sec { padding-block: clamp(2.5rem, 7vw, 5rem); border-top: 1px solid var(--line); }
.toc { list-style: none; margin: 2rem 0 0; padding: 0; max-width: 46rem; }
.toc li { display: flex; align-items: baseline; gap: .7rem; padding: .6rem 0; }
.toc-code { width: 4.6rem; flex: none; font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: .9375rem; }
.toc-title { font-family: var(--f-doc); font-size: 1.2rem; }
.toc-lead { flex: 1; min-width: 1.5rem; border-bottom: 2px dotted var(--line-strong); transform: translateY(-.25em); }
.toc-type { font-size: .9rem; color: var(--ink-soft); }

.closing { padding-block: clamp(3rem, 8vw, 6rem); border-top: 1px solid var(--line); }
.closing p { margin-top: 1.6rem; }

.foot { border-top: 1px solid var(--line); padding-block: 2rem; color: var(--ink-soft); font-size: .9rem; }
.foot-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem 2rem; }
.foot-note { max-width: 52ch; }

/* ---------- Acceso ---------- */
.auth { padding-block: clamp(2.5rem, 7vw, 5rem); }
.auth-box { max-width: 26rem; }
.auth-box .h-page { margin-bottom: 1.5rem; }
.auth-box .lead-small { margin-top: -.9rem; }

/* ---------- Biblioteca ---------- */
.library { padding-block: clamp(2rem, 5vw, 4rem); display: grid; gap: clamp(2.5rem, 6vw, 4.5rem); }
.start { max-width: 46rem; }
.start .h-page { margin-bottom: 1.4rem; }
.start-form { display: grid; gap: 1rem; justify-items: start; }
.start-form textarea { min-height: 6.5rem; }

.seg { border: 0; margin: 0; padding: 0; display: flex; gap: .5rem; flex-wrap: wrap; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: .5rem 1rem; border: 1.5px solid var(--line-strong); border-radius: 999px; font-weight: 600; font-size: .9375rem; transition: background-color .15s, border-color .15s; }
.seg input:checked + span { background: var(--marker); border-color: var(--marker); }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.seg label:hover span { border-color: var(--ink-soft); }

.shelf .h-section { margin-bottom: 1rem; }
.empty-note { color: var(--ink-soft); padding: 1.5rem 0; max-width: 46ch; }
.docs { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.doc-row { display: grid; grid-template-columns: 5.2rem minmax(0, 1fr) 8rem 6.5rem 5.5rem auto; align-items: center; gap: 1rem; padding: .95rem .4rem; border-bottom: 1px solid var(--line); }
.doc-row:hover { background: #fafbfd; }
.doc-code { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: .9375rem; }
.doc-title { font-family: var(--f-doc); font-size: 1.2rem; font-weight: 500; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-title:hover { text-decoration: underline; text-decoration-color: var(--marker); text-decoration-thickness: .35em; text-underline-offset: -.15em; }
.doc-type, .doc-date { color: var(--ink-soft); font-size: .9rem; }

/* ---------- Sello de estado ---------- */
.stamp {
  display: inline-block; width: fit-content; border: 1.5px solid currentColor; border-radius: 5px;
  padding: .12rem .55rem; font-weight: 650; font-size: .8125rem; line-height: 1.4;
  color: var(--ink-soft); transform: rotate(-3deg); white-space: nowrap;
}
.stamp[data-status="en_revision"] { color: var(--warn); }
.stamp[data-status="aprobado"] { color: var(--ok); }
.stamp-small { transform: none; font-size: .78rem; }

/* ---------- La hoja ---------- */
.sheet {
  background: var(--paper); border: 1px solid var(--line); border-radius: 3px;
  box-shadow: 0 1px 0 rgba(31, 42, 68, .04), 0 22px 44px -26px rgba(31, 42, 68, .35);
  padding: clamp(1.4rem, 3.6vw, 3rem);
}
.sheet-head { display: grid; grid-template-columns: 1fr auto; gap: .4rem 1rem; align-items: start; padding-bottom: 1.3rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.sheet-meta { display: flex; flex-wrap: wrap; gap: .25rem 1.1rem; color: var(--ink-soft); font-size: .875rem; font-variant-numeric: tabular-nums; align-self: center; }
.sheet-meta .code { color: var(--ink); font-weight: 650; }
.sheet-title, .sheet-title-static { grid-column: 1 / -1; margin-top: .6rem; font: 650 clamp(1.5rem, 2.6vw, 2.1rem)/1.12 var(--f-ui); letter-spacing: -0.02em; font-variation-settings: "opsz" 60; }
.sheet-title { border: 1.5px solid transparent; border-radius: 8px; padding: .2rem .4rem; margin-left: -.4rem; width: calc(100% + .4rem); background: transparent; color: var(--ink); }
.sheet-title:hover { border-color: var(--line); }
.sheet-title:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--marker-soft); }

.sheet-body { font-family: var(--f-doc); font-size: 1.125rem; line-height: 1.65; font-optical-sizing: auto; }
.sheet-body > * { max-width: 70ch; }
.sheet-body h2, .sheet-body h3, .sheet-body h4 { font-family: var(--f-ui); font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; margin: 1.9em 0 .5em; }
.sheet-body h2 { font-size: 1.3rem; }
.sheet-body h3 { font-size: 1.1rem; }
.sheet-body h4 { font-size: 1rem; }
.sheet-body > :first-child { margin-top: 0; }
.sheet-body p { margin: 0 0 .9em; }
.sheet-body ul, .sheet-body ol { margin: 0 0 1em; padding-left: 1.35rem; }
.sheet-body li { margin-bottom: .3em; padding-left: .2rem; }
.sheet-body li::marker { color: var(--ink-soft); }
.sheet-body li.sub { margin-left: 1.3rem; list-style: circle; }
.sheet-body strong { font-weight: 650; }
.sheet-body code { font-size: .9em; background: var(--desk); padding: .05em .3em; border-radius: 4px; }
.sheet-body hr { border: 0; border-top: 1px solid var(--line); margin: 1.6rem 0; }
.sheet-body table { width: 100%; max-width: 100%; border-collapse: collapse; margin: .4rem 0 1.4rem; font-family: var(--f-ui); font-size: .9375rem; line-height: 1.4; display: block; overflow-x: auto; }
.sheet-body th, .sheet-body td { border: 1px solid var(--line-strong); padding: .55rem .75rem; text-align: left; vertical-align: top; }
.sheet-body th { background: var(--desk); font-weight: 650; }
.sheet-body .empty { color: var(--ink-soft); font-family: var(--f-ui); font-size: 1rem; max-width: 40ch; }

/* El resaltador: marca lo último que se escribió y se desvanece al terminar. */
.sheet-body > .fresh {
  background-image: linear-gradient(var(--marker), var(--marker));
  background-repeat: no-repeat; background-position: 0 92%; background-size: 100% .55em;
}
.sheet-body > .fresh.settled { background-size: 0 .55em; transition: background-size 1.8s ease .4s; }

.editor { width: 100%; min-height: 60vh; font: 400 .9375rem/1.6 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

/* ---------- Estudio ---------- */
.is-app main { min-height: calc(100dvh - var(--topbar)); }
.studio { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); height: calc(100dvh - var(--topbar)); }
.pane-tabs { display: none; }

.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--paper); }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.chat-kind { color: var(--ink-soft); font-weight: 600; }
.chat-log { flex: 1; overflow-y: auto; padding: 1.2rem 1.1rem; display: flex; flex-direction: column; gap: 1rem; scroll-behavior: smooth; }
.msg { max-width: 92%; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.msg-user { align-self: flex-end; background: #eef1f7; padding: .65rem .9rem; border-radius: var(--r-bubble) var(--r-bubble) 4px var(--r-bubble); }
.msg-ai { align-self: flex-start; border-left: 3px solid var(--marker); padding: .1rem 0 .1rem .8rem; }
.msg-ai.is-thinking { color: var(--ink-soft); }
.msg-error { border-left-color: var(--red); color: var(--red); }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; padding: 0 1.1rem .8rem; }
.chip { font: 500 .875rem/1.25 var(--f-ui); color: var(--ink); background: var(--paper); border: 1.5px solid var(--line-strong); border-radius: 999px; padding: .4rem .8rem; cursor: pointer; text-align: left; }
.chip:hover { background: var(--marker-soft); border-color: var(--marker); }

.composer { display: grid; grid-template-columns: 1fr auto; gap: .6rem; align-items: end; padding: .9rem 1.1rem 1.1rem; border-top: 1px solid var(--line); }
.composer textarea { min-height: 3rem; max-height: 10rem; resize: none; }

.desk { background: var(--desk); overflow-y: auto; padding: 0 clamp(1rem, 3vw, 2.5rem) 3rem; min-width: 0; scroll-behavior: smooth; }
.toolbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .9rem 0; background: var(--desk); }
.toolbar select { width: auto; padding: .5rem .8rem; font-weight: 600; font-size: .875rem; }
.desk .sheet { max-width: 52rem; margin-inline: auto; }

/* ---------- Impresión ---------- */
.is-print { background: var(--desk); }
.print-bar { display: flex; align-items: center; gap: 1.5rem; padding: 1rem clamp(1rem, 4vw, 2.5rem); }
.sheet-print { max-width: 52rem; margin: 0 auto 3rem; }
.sheet-print .company { color: var(--ink); font-weight: 650; }
@media print {
  .is-print { background: #fff; }
  .print-bar { display: none; }
  .sheet-print { border: 0; box-shadow: none; padding: 0; margin: 0; max-width: none; }
  .sheet-body h2, .sheet-body h3 { break-after: avoid; }
  .sheet-body table, .sheet-body li { break-inside: avoid; }
  .stamp { transform: none; }
}

/* ---------- Pantallas angostas ---------- */
@media (max-width: 900px) {
  .hero, .process { grid-template-columns: 1fr; }
  .sheet-demo { transform: none; }
  .doc-row { grid-template-columns: 1fr auto; gap: .25rem 1rem; }
  .doc-code, .doc-type, .doc-date { font-size: .8125rem; }
  .doc-title { grid-column: 1 / -1; order: -1; white-space: normal; }
  .who { display: none; }

  .studio { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .pane-tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--paper); }
  .pane-tabs button { flex: 1; font: 600 .9375rem var(--f-ui); color: var(--ink-soft); background: transparent; border: 0; padding: .8rem; cursor: pointer; border-bottom: 3px solid transparent; }
  .pane-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--marker); }
  .studio[data-pane="chat"] .desk, .studio[data-pane="doc"] .chat { display: none; }
  .chat { border-right: 0; min-height: 0; }
  .desk { min-height: 0; }
  .studio { height: calc(100dvh - var(--topbar)); }
}

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