/* ============================================================
   Tokens — paleta de referencia dataviz (claro/oscuro)
   ============================================================ */
:root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface:        #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --series-1:       #2a78d6;   /* subtarea crítica (énfasis) */
  --deemph:         #c3c2b7;   /* subtareas de contexto */
  --status-critico:  #d03b3b;
  --status-alto:     #ec835a;
  --status-moderado: #fab219;
  --tooltip-bg:     #0b0b0b;
  --tooltip-ink:    #ffffff;
  --accent:         #1f66c0;   /* series-1 oscurecido para texto AA sobre tinte */
  --accent-soft:    rgba(31, 102, 192, 0.10);
  --sidebar-bg:     #fcfcfb;
  --brand-ink:      #0b0b0b;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface:        #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --deemph:         #52514e;
    --tooltip-bg:     #fcfcfb;
    --tooltip-ink:    #0b0b0b;
    --accent:         #64a1ee;   /* series-1 aclarado para texto AA sobre tinte */
    --accent-soft:    rgba(100, 161, 238, 0.16);
    --sidebar-bg:     #1a1a19;
    --brand-ink:      #ffffff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface:        #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --deemph:         #52514e;
  --tooltip-bg:     #fcfcfb;
  --tooltip-ink:    #0b0b0b;
  --accent:         #64a1ee;   /* series-1 aclarado para texto AA sobre tinte */
  --accent-soft:    rgba(100, 161, 238, 0.16);
  --sidebar-bg:     #1a1a19;
  --brand-ink:      #ffffff;
}

/* Theme de marca Morphy (default) — paleta extraída de morphy.fun */
:root[data-theme="morphy"] {
  color-scheme: light;
  --page:           #f7f5fb;   /* lavanda muy claro */
  --surface:        #fdfcfe;
  --text-primary:   #1c1332;
  --text-secondary: #534d6b;
  --text-muted:     #8781a0;
  --gridline:       #e6e2f0;
  --baseline:       #c8c2dd;
  --border:         rgba(91, 30, 198, 0.12);
  --series-1:       #5b1ec6;   /* morado de marca */
  --deemph:         #c8c2dd;
  --tooltip-bg:     #241448;   /* morado profundo */
  --tooltip-ink:    #f5f3fa;
  --accent:         #5b1ec6;
  --accent-soft:    #f1eef9;   /* tinte lavanda del sitio */
  --sidebar-bg:     #f3f1f9;   /* segunda capa neutra */
  --brand-ink:      #5b1ec6;
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1020px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

a { color: inherit; }

a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   Layout con sidebar
   ============================================================ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  flex: none;
  width: 228px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 26px 14px 20px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
}
.sidebar-brand { padding: 0 12px; }
.sidebar-brand .brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--brand-ink);
}
.sidebar-brand .brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.sidebar nav a:hover { color: var(--text-primary); background: var(--page); }
.sidebar nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}
/* subsecciones: solo visibles bajo el ítem activo */
.sidebar nav .subnav {
  list-style: none;
  display: none;
  margin: 2px 0 8px;
  padding: 0 0 0 14px;
}
.sidebar nav a[aria-current="page"] + .subnav { display: block; }
.subnav-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 1px solid var(--gridline);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
  padding: 5px 10px;
}
.subnav-link:hover {
  color: var(--text-primary);
  border-left-color: var(--text-muted);
}

/* destinos de ancla: aire bajo el borde superior al hacer scroll */
section[id], article[id], footer[id] { scroll-margin-top: 16px; }

.sidebar-foot { margin-top: auto; padding: 0 8px; }

.content { flex: 1; min-width: 0; }

@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar {
    position: static;
    width: auto;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 18px;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-brand { padding: 0; }
  .sidebar-brand .brand-sub { display: none; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .sidebar nav .subnav { display: none !important; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; }
}

/* ============================================================
   Header
   ============================================================ */
.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}
.report-header h1 {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.report-header .kicker {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.subtitle {
  color: var(--text-secondary);
  max-width: 72ch;
  margin: 10px 0 28px;
}

.theme-toggle {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* ============================================================
   KPI row — stat tiles
   ============================================================ */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 36px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.tile .label {
  font-size: 13px;
  color: var(--text-secondary);
}
.tile .value {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 2px 0 4px;
}
.tile .value .unit { font-size: 17px; font-weight: 500; color: var(--text-secondary); }
.tile .context { font-size: 12.5px; color: var(--text-muted); }
.tile .delta-bad { color: var(--status-critico); font-weight: 600; }

/* ============================================================
   Secciones y tarjetas de gráfico
   ============================================================ */
section { margin-bottom: 44px; }

h2 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.section-lede {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 76ch;
  margin-bottom: 16px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 18px 10px;
}

/* leyenda (HTML, encima del gráfico) */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  align-items: center;
  font-size: 12.5px;
  color: var(--text-secondary);
  padding: 2px 4px 12px;
}
.legend .item { display: inline-flex; align-items: center; gap: 7px; }
.legend .swatch {
  display: inline-block;
  width: 18px; height: 8px;
  border-radius: 4px;
}
.legend .diamond {
  display: inline-block;
  width: 9px; height: 9px;
  background: var(--text-primary);
  transform: rotate(45deg);
  border: 2px solid var(--surface);
  box-sizing: content-box;
}
.sev-glyph { font-size: 11px; line-height: 1; }
.sev-critico  { color: var(--status-critico); }
.sev-alto     { color: var(--status-alto); }
.sev-moderado { color: var(--status-moderado); }

/* el SVG ancho hace scroll dentro de su propio contenedor, nunca la página */
.chart-scroll { overflow-x: auto; }
.chart-scroll svg { display: block; min-width: 640px; width: 100%; height: auto; }

/* filas interactivas del SVG */
.row-hit { cursor: pointer; }
.row-hit:focus { outline: none; }
.row-hit:focus-visible + .row-focus-ring { opacity: 1; }
.row-focus-ring { opacity: 0; pointer-events: none; }

/* vista de tabla (gemela accesible del gráfico) */
details.table-view {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding: 10px 4px;
  font-size: 13px;
}
details.table-view summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12.5px;
  user-select: none;
}
details.table-view table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}
details.table-view th, details.table-view td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--gridline);
}
details.table-view th {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
details.table-view td.num, details.table-view th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Drill-down — tarjetas por hito
   ============================================================ */
.milestone-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 18px;
  scroll-margin-top: 16px;
}
.milestone-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin-bottom: 2px;
}
.milestone-head h3 {
  font-size: 16.5px;
  font-weight: 650;
}
.milestone-head .meta { font-size: 13px; color: var(--text-muted); }

.sev-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

.deficit-callout {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 6px 0 14px;
}
.deficit-callout strong { color: var(--text-primary); }
.deficit-callout .bad { color: var(--status-critico); font-weight: 650; }

.milestone-note { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }

.subchart-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 4px 0 8px;
}

/* tarjetas de factores de riesgo */
.risk-list { display: grid; gap: 10px; margin-top: 16px; }
.risk-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface);
}
.risk-card .risk-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
  margin-bottom: 4px;
}
.risk-card .risk-title { font-weight: 650; font-size: 14px; }
.risk-card .risk-impact { font-size: 12.5px; color: var(--text-muted); }
.risk-card p { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 6px; }
.risk-card .mitigation { font-size: 13.5px; }
.risk-card .mitigation strong { font-weight: 650; }

/* ============================================================
   Resumen ejecutivo — tarjetas de opción
   ============================================================ */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}
.option-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--opt-accent, var(--border));
  border-radius: 10px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
}
.option-card .opt-kicker {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.option-card .opt-title {
  font-size: 15px;
  font-weight: 650;
  margin: 2px 0 8px;
}
.option-card .opt-hero {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.option-card .opt-hero-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin: 2px 0 10px;
}
.option-card ul {
  list-style: none;
  margin: 0 0 12px;
  display: grid;
  gap: 6px;
}
.option-card li {
  font-size: 13px;
  color: var(--text-secondary);
  padding-left: 14px;
  position: relative;
}
.option-card li::before {
  content: "·";
  position: absolute;
  left: 2px;
  font-weight: 700;
  color: var(--opt-accent, var(--text-muted));
}
.option-card .opt-foot {
  margin-top: auto;
  font-size: 12.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--gridline);
  padding-top: 10px;
}
.option-card .opt-foot a { color: inherit; }

/* ============================================================
   Tabla de mitigaciones (visible, no colapsada)
   ============================================================ */
.data-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th, .data-table td {
  text-align: left;
  vertical-align: top;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gridline);
}
.data-table thead th {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td.nowrap { white-space: nowrap; }
.data-table td.muted-cell { color: var(--text-secondary); }
.data-table th.num, .data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.link-quiet {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}
.link-quiet:hover { text-decoration: underline; }

/* ============================================================
   Vista: preguntas para Morphy
   ============================================================ */
.group-intro {
  font-size: 13.5px;
  color: var(--text-muted);
  max-width: 78ch;
  margin-bottom: 14px;
}
.question {
  border-top: 1px solid var(--gridline);
  padding: 12px 2px;
}
.question:last-child { padding-bottom: 2px; }
.question .q-text {
  font-size: 14.5px;
  font-weight: 600;
  max-width: 82ch;
  margin-bottom: 4px;
}
.question .why {
  font-size: 13.5px;
  color: var(--text-secondary);
  max-width: 82ch;
  border-left: 2px solid var(--baseline);
  padding-left: 10px;
}
.question .why strong { color: var(--text-primary); font-weight: 600; }

/* ============================================================
   Vista: redacción del alcance
   ============================================================ */
.stage-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 18px;
}
.stage-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin-bottom: 10px;
}
.stage-chip {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  border: 1px solid var(--border);
  background: var(--page);
  border-radius: 6px;
  padding: 2px 8px;
}
.stage-head h3 { font-size: 16.5px; font-weight: 650; }
.stage-head .meta { font-size: 13px; color: var(--text-muted); }
.stage-card ul { margin: 0 0 12px 20px; }
.stage-card li {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  max-width: 82ch;
}
.stage-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--series-1);
  cursor: pointer;
}
.stage-link:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.92em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ============================================================
   Vista: glosario
   ============================================================ */
.glossary {
  display: grid;
  grid-template-columns: 250px 1fr;
}
.glossary dt, .glossary dd {
  padding: 12px 0;
  border-top: 1px solid var(--gridline);
  margin: 0;
}
.glossary dt:first-of-type,
.glossary dt:first-of-type + dd {
  border-top: none;
  padding-top: 2px;
}
.glossary dt {
  font-weight: 650;
  font-size: 14px;
  padding-right: 20px;
}
.glossary dt .expansion {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.glossary dd {
  font-size: 13.5px;
  color: var(--text-secondary);
  max-width: 78ch;
}
@media (max-width: 640px) {
  .glossary { grid-template-columns: 1fr; }
  .glossary dd {
    border-top: none;
    padding-top: 0;
  }
  .glossary dt:first-of-type + dd { padding-top: 0; }
}

/* ============================================================
   Tooltip
   ============================================================ */
#tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 280px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 80ms linear;
}
#tooltip.visible { opacity: 1; }
#tooltip .tt-value { font-size: 15px; font-weight: 650; }
#tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; }
#tooltip .tt-row .k { opacity: 0.75; }

/* ============================================================
   Pie
   ============================================================ */
footer.methodology {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}
footer.methodology h2 { font-size: 14px; margin-bottom: 8px; }
footer.methodology ul { margin: 6px 0 14px 18px; }
footer.methodology li { margin-bottom: 3px; }

@media (max-width: 560px) {
  .report-header h1 { font-size: 21px; }
  .tile .value { font-size: 24px; }
}
