/* ════════════════════════════════════════════════════════════════
   TFG · FIDO2 + Zero Trust + PQC — hoja de estilo académica
   Registro: documento técnico-institucional sobre papel.
   Tipografía: STIX Two Text (serif científica) + IBM Plex Mono (datos).
   Firma visual: el retículo (lattice) — la geometría de ML-KEM/ML-DSA.
   ════════════════════════════════════════════════════════════════ */
:root {
  --paper: #FAF9F6;
  --paper-soft: #F3F1EB;
  --ink: #1C1F26;
  --soft: #575D69;
  --rule: #DEDBD3;
  --rule-strong: #1C1F26;
  --accent: #5B2333;        /* granato universitario */
  --accent-ink: #431926;
  --petrol: #2C4A5E;        /* resaltado de datos post-cuánticos */
  --code-bg: #F3F1EB;
  --sidebar-w: 296px;
  --radius: 3px;
  --serif: 'STIX Two Text', Georgia, 'Times New Roman', serif;
  --mono: 'IBM Plex Mono', 'JetBrains Mono', monospace;
}
html[data-theme="dark"] {
  --paper: #15171D;
  --paper-soft: #1B1E26;
  --ink: #E8E6DF;
  --soft: #9BA0AC;
  --rule: #2C303A;
  --rule-strong: #E8E6DF;
  --accent: #C97B8C;
  --accent-ink: #E0A9B4;
  --petrol: #86ACc2;
  --code-bg: #1B1E26;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation: none !important; transition: none !important; }
}
body {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.72;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent); color: var(--paper); }

/* ── Barra de progreso (regla de tinta) ── */
#progress-bar {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--accent); z-index: 1000;
}

/* ══════════ Índice lateral ══════════ */
#sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--paper);
  border-right: 1px solid var(--rule);
  padding: 28px 22px 22px;
  display: flex; flex-direction: column; gap: 18px;
  z-index: 900; overflow-y: auto;
}
.brand { display: flex; gap: 12px; align-items: center; padding-bottom: 18px; border-bottom: 1px solid var(--rule); }
.brand-badge {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  color: var(--paper); background: var(--accent);
}
.brand-title { font-weight: 700; font-size: 14.5px; line-height: 1.3; letter-spacing: .01em; }
.brand-sub { font-family: var(--mono); font-size: 10.5px; color: var(--soft); letter-spacing: .04em; margin-top: 2px; }

.toc-label {
  font-family: var(--mono); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .18em; color: var(--soft); margin: 0;
}
#nav { display: flex; flex-direction: column; }
#nav a {
  color: var(--ink); text-decoration: none;
  font-size: 14.5px; line-height: 1.45;
  padding: 7px 10px 7px 14px;
  border-left: 2px solid transparent;
  display: flex; gap: 10px; align-items: baseline;
  transition: border-color .15s, background .15s;
}
#nav a:hover { background: var(--paper-soft); }
#nav a.active { border-left-color: var(--accent); background: var(--paper-soft); font-weight: 600; }
#nav a.active .num { color: var(--accent); }
#nav a.sub { padding-left: 34px; font-size: 13.5px; color: var(--soft); }
#nav a.sub.active { color: var(--ink); }
#nav .num {
  font-family: var(--mono); font-size: 11px; color: var(--soft);
  min-width: 24px; flex: 0 0 24px; font-weight: 500;
}

.sidebar-footer { margin-top: auto; display: grid; gap: 14px; padding-top: 18px; border-top: 1px solid var(--rule); }
#theme-toggle {
  font-family: var(--mono); font-size: 12px;
  background: none; color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 8px 12px; cursor: pointer; text-align: left;
}
#theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.stamp {
  font-family: var(--mono); font-size: 11px; letter-spacing: .08em;
  color: var(--accent); border: 1.5px solid var(--accent);
  padding: 8px 10px; border-radius: 2px; text-align: center;
  transform: rotate(-2deg); opacity: .85; line-height: 1.5;
}
.stamp span { color: var(--soft); letter-spacing: .02em; font-size: 10px; }

/* ── Menú móvil ── */
#menu-toggle {
  display: none; position: fixed; top: 12px; right: 12px; z-index: 950;
  width: 44px; height: 40px; border-radius: var(--radius);
  background: var(--paper); border: 1px solid var(--rule); cursor: pointer;
  flex-direction: column; gap: 4px; align-items: center; justify-content: center;
}
#menu-toggle span { width: 18px; height: 1.5px; background: var(--ink); }

/* ══════════ Contenido ══════════ */
#content {
  margin-left: var(--sidebar-w);
  padding: 0 56px 32px;
  max-width: 1200px;
}
section {
  padding: 56px 0 6px;
  scroll-margin-top: 8px;
  max-width: 900px;
}
#bibliografia { max-width: none; }

/* ── Portada / masthead ── */
.masthead { position: relative; padding-top: 64px; overflow: hidden; }
.lattice {
  position: absolute; top: -40px; right: -60px;
  width: 460px; height: 300px; pointer-events: none;
  opacity: .5;
  mask-image: radial-gradient(closest-side at 70% 40%, #000 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(closest-side at 70% 40%, #000 30%, transparent 100%);
}
.lat-dot { fill: var(--accent); opacity: .35; }
.lat-line { stroke: var(--accent); stroke-width: .6; opacity: .22; }

.report-head { position: relative; }
.report-eyebrow {
  font-family: var(--mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: .22em; color: var(--accent);
  margin: 0 0 20px; padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
  display: inline-block; min-width: 420px;
}
h1 {
  font-size: clamp(30px, 4.2vw, 46px);
  line-height: 1.12; font-weight: 700;
  margin: 0 0 14px; letter-spacing: -.01em;
  max-width: 20ch;
}
.report-sub { font-size: 19px; color: var(--soft); font-style: italic; max-width: 56ch; margin: 0; }

.abstract {
  margin: 34px 0 0; padding: 20px 26px;
  border-top: 2px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule);
  background: var(--paper-soft);
}
.abs-label {
  font-family: var(--mono); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .2em; color: var(--accent); margin: 0 0 8px;
}
.abstract p { margin: 0; font-size: 15.5px; line-height: 1.75; text-align: justify; hyphens: auto; }

.report-meta {
  display: grid; grid-template-columns: repeat(4, auto);
  gap: 0; margin: 22px 0 0; padding: 0;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.report-meta > div { padding: 12px 22px 12px 0; }
.report-meta > div + div { padding-left: 22px; border-left: 1px solid var(--rule); }
.report-meta dt {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .16em; color: var(--soft); margin-bottom: 2px;
}
.report-meta dd { margin: 0; font-size: 14.5px; font-weight: 600; }

.keyfigures {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--rule); border-radius: var(--radius);
  margin-top: 26px;
}
.kf {
  padding: 16px 20px; display: flex; flex-direction: column; gap: 3px;
}
.kf + .kf { border-left: 1px solid var(--rule); }
.kf b {
  font-family: var(--mono); font-weight: 600; font-size: 24px;
  color: var(--accent); letter-spacing: -.02em;
}
.kf span { font-size: 13px; color: var(--soft); line-height: 1.4; }
.kf sup a { text-decoration: none; }

.divider { max-width: 900px; display: flex; justify-content: center; padding: 8px 0 0; }
.divider-dots circle { fill: var(--rule); }

/* ── Encabezados numerados ── */
h2 {
  font-size: clamp(23px, 2.6vw, 29px);
  font-weight: 700; line-height: 1.22;
  margin: 0 0 8px; letter-spacing: -.005em;
  padding-top: 18px; border-top: 2px solid var(--rule-strong);
}
.secnum {
  display: block;
  font-family: var(--mono); font-size: 12px; font-weight: 500;
  color: var(--accent); letter-spacing: .14em;
  margin-bottom: 8px;
}
.section-lead { color: var(--soft); font-size: 16.5px; max-width: 66ch; margin: 0 0 26px; }

h3 {
  font-size: 18px; font-weight: 700; margin: 26px 0 10px; line-height: 1.35;
}
h3.minor {
  font-size: 16px; font-weight: 600; margin-top: 4px;
}
h3.minor::before { content: ""; }
p { margin: 10px 0; text-align: justify; hyphens: auto; }
ul, ol { margin: 10px 0; padding-left: 26px; }
li { margin: 6px 0; text-align: justify; }
li::marker { color: var(--accent); }
dfn { font-weight: 600; font-style: normal; }
strong { font-weight: 700; }
.note {
  font-size: 13.8px; color: var(--soft); line-height: 1.65;
  padding-left: 14px; border-left: 2px solid var(--rule);
}

/* ── Bloques de algoritmo (§1) ── */
.algo-block {
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 18px 22px; margin: 14px 0;
  background: var(--paper);
}
.algo-block.primary { border-left: 3px solid var(--accent); background: var(--paper-soft); }
.algo-block h3 {
  margin: 0 0 8px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
}
.tag {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: .1em; color: var(--paper);
  background: var(--ink); padding: 3px 9px; border-radius: 2px;
}
.algo-block.primary .tag { background: var(--accent); }
.tag-role {
  font-family: var(--mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--soft);
}

/* ── Figuras, tablas, listados ── */
figure.block {
  margin: 30px 0; padding: 0;
  border-top: 1px solid var(--rule);
}
figure.block.tight { margin: 8px 0 0; }
.block-caption {
  font-family: var(--mono); font-size: 11.5px; color: var(--soft);
  letter-spacing: .04em; padding: 10px 0 6px;
}
.block-caption a { color: inherit; }

table {
  width: 100%; border-collapse: collapse;
  font-size: 14.5px; margin: 6px 0 14px;
  border-top: 2px solid var(--rule-strong);
  border-bottom: 2px solid var(--rule-strong);
}
th, td { padding: 8px 12px; text-align: left; vertical-align: top; }
thead th {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em; color: var(--soft);
  border-bottom: 1px solid var(--rule-strong);
  padding-top: 10px;
}
tbody tr + tr td { border-top: 1px solid var(--rule); }
tbody tr:hover { background: var(--paper-soft); }
td.r, th.r { text-align: right; }
.mono, code { font-family: var(--mono); font-size: .84em; }
td.mono { font-size: 13px; color: var(--soft); white-space: nowrap; }
.hl-row td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.pq-row td { background: color-mix(in srgb, var(--petrol) 9%, transparent); }

code {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  padding: 1px 5px; border-radius: 2px;
  font-size: .82em;
}
.listing { position: relative; margin: 12px 0 4px; }
.listing-label {
  position: absolute; top: 0; right: 0;
  font-family: var(--mono); font-size: 10px; letter-spacing: .12em;
  color: var(--soft); text-transform: uppercase;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 2px;
  padding: 3px 8px; z-index: 1;
}
pre {
  background: var(--code-bg);
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 20px 18px 14px;
  overflow-x: auto;
  font-size: 12.8px; line-height: 1.6;
}
pre code { background: none; border: none; padding: 0; }

/* ── Citas ── */
.cite {
  font-family: var(--mono); font-size: .72em;
  color: var(--accent); text-decoration: none;
  vertical-align: super; letter-spacing: 0;
  padding: 0 1px;
}
.cite:hover { text-decoration: underline; }
sup a.cite { vertical-align: baseline; }

/* ── Dos columnas ── */
.two-col {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 0 40px; margin: 18px 0;
}
.two-col > div { min-width: 0; }

/* ── Diagrama ── */
.diagram { overflow-x: auto; margin: 10px 0 14px; border: 1px solid var(--rule); border-radius: var(--radius); padding: 8px; background: var(--paper); }
.diagram svg { width: 100%; min-width: 760px; height: auto; }
.zone { fill: var(--paper-soft); stroke: var(--rule); stroke-width: 1.2; }
.zone.pub { stroke: var(--soft); }
.zone.edge { stroke: var(--accent); }
.zone.dom { stroke: var(--accent); stroke-dasharray: 4 3; }
.zone.data { stroke: var(--petrol); }
.svc rect { fill: var(--paper); stroke: var(--ink); stroke-width: 1.1; }
.svg-zone { fill: var(--soft); font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .16em; }
.svg-node { fill: var(--ink); font-family: var(--mono); font-size: 13px; font-weight: 600; text-anchor: middle; }
.svg-sub { fill: var(--soft); font-family: var(--mono); font-size: 10.5px; text-anchor: middle; }
.svg-label { fill: var(--accent); font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .1em; text-anchor: middle; }
.edge { stroke: var(--soft); stroke-width: 1.2; fill: none; }
.edge.dash { stroke-dasharray: 4 4; }
.arrow { fill: var(--soft); }

/* ── Plan de trabajo ── */
.phase { margin: 22px 0; }
.phase-head {
  display: flex; gap: 16px; align-items: baseline;
  padding-bottom: 8px; border-bottom: 1px solid var(--rule);
}
.phase-head h3 { margin: 0; font-size: 17px; }
.phase-head small { color: var(--soft); font-weight: 400; font-style: italic; }
.phase-status {
  margin-left: auto; font-family: var(--mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: .14em; color: var(--accent);
  border: 1px solid var(--accent); padding: 2px 8px; border-radius: 2px;
}
.phase-num {
  font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--soft);
  min-width: 30px; flex: 0 0 30px;
}
.phase-num.current { color: var(--accent); }
.checklist { list-style: none; margin: 8px 0 0; padding: 0 0 0 46px; }
.checklist li {
  padding: 4px 0 4px 24px; position: relative;
  font-size: 15px; color: var(--soft);
}
.checklist li::before { content: "·"; position: absolute; left: 6px; color: var(--soft); }
.checklist li.done { color: var(--ink); }
.checklist li.done::before { content: "✓"; color: var(--accent); left: 2px; }

/* ── Estructura de memoria ── */
.toc-chapters { border-top: 2px solid var(--rule-strong); margin-top: 10px; }
.toc-row {
  display: grid; grid-template-columns: 240px 1fr; gap: 18px;
  padding: 13px 0; border-bottom: 1px solid var(--rule);
}
.toc-row b { font-weight: 700; font-size: 15px; }
.toc-row span { font-size: 14.5px; color: var(--soft); line-height: 1.6; }

/* ── Bibliografía ── */
.refs {
  list-style: none; margin: 10px 0 0; padding: 0;
  max-width: 860px;
  counter-reset: none;
  border-top: 2px solid var(--rule-strong);
}
.refs li {
  display: grid; grid-template-columns: 40px 1fr; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--rule);
  font-size: 14.5px; line-height: 1.6; text-align: left;
  scroll-margin-top: 24px;
}
.refs li:target { background: color-mix(in srgb, var(--accent) 8%, transparent); outline: 1px solid var(--accent); }
.refnum { font-family: var(--mono); font-size: 12px; color: var(--accent); padding-top: 2px; }
.refs em { font-style: italic; }
.refs a { color: var(--petrol); text-decoration: none; }
.refs a:hover { text-decoration: underline; }

/* ── Colofón ── */
.colophon {
  margin-top: 70px; padding-top: 18px;
  border-top: 2px solid var(--rule-strong);
  color: var(--soft); font-size: 13px; line-height: 1.7;
}
.colophon p { margin: 4px 0; text-align: left; }
.colophon a { color: var(--petrol); }
.colophon-meta { font-family: var(--mono); font-size: 11px; letter-spacing: .04em; }

/* ── Enlaces generales ── */
a { color: var(--accent); }
p a, li a { text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; }

/* ── Responsive ── */
@media (max-width: 1080px) {
  .report-meta { grid-template-columns: repeat(2, 1fr); }
  .report-meta > div:nth-child(3) { border-left: none; padding-left: 0; }
  .report-meta > div { border-top: 1px solid var(--rule); }
  .report-meta { border-top: 1px solid var(--rule); }
  .keyfigures { grid-template-columns: repeat(2, 1fr); }
  .kf:nth-child(3) { border-left: none; }
  .kf:nth-child(n+3) { border-top: 1px solid var(--rule); }
  .two-col { grid-template-columns: 1fr; gap: 22px; }
}
@media (max-width: 860px) {
  #sidebar {
    transform: translateX(-100%); transition: transform .22s ease;
    width: min(320px, 84vw);
    border-right: 1px solid var(--rule);
  }
  #sidebar.open { transform: none; }
  #menu-toggle { display: flex; }
  #content { margin-left: 0; padding: 0 20px 32px; }
  section { padding-top: 44px; }
  .report-eyebrow { min-width: 0; }
  .toc-row { grid-template-columns: 1fr; gap: 2px; }
}
