:root {
  color-scheme: light;
  --page: #f7fbf8;
  --surface: #ffffff;
  --surface-2: #eef5f1;
  --ink: #0a2620;
  --ink-2: #4f625b;
  --muted: #7d8f88;
  --grid: #e3ece7;
  --axis: #c5d3cc;
  --line: rgba(10, 38, 32, 0.10);
  --band: #0a2620;
  --brand: #004c3d;
  --accent: #18d270;
  --cream: #f3ead9;
  /* categorías de ticket (orden fijo validado) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  /* fases tardías (rampa ordinal validada) */
  --f1: #6bbf97; --f2: #0f7a59; --f3: #004c3d;
  /* semáforo */
  --good: #0ca30c; --warn: #fab219; --crit: #d03b3b; --unk: #9aa5a0;
  --shadow: 0 1px 2px rgba(10, 38, 32, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #071c17; --surface: #12332c; --surface-2: #183d35;
    --ink: #eef5f1; --ink-2: #b5c7bf; --muted: #7e938b;
    --grid: #1e443b; --axis: #2d5a4f; --line: rgba(255, 255, 255, 0.10);
    --band: #051411; --brand: #18d270;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --f1: #a6e3c4; --f2: #5cc495; --f3: #239e74;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #071c17; --surface: #12332c; --surface-2: #183d35;
  --ink: #eef5f1; --ink-2: #b5c7bf; --muted: #7e938b;
  --grid: #1e443b; --axis: #2d5a4f; --line: rgba(255, 255, 255, 0.10);
  --band: #051411; --brand: #18d270;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --f1: #a6e3c4; --f2: #5cc495; --f3: #239e74;
  --shadow: none;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.5 "Libre Franklin", system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3 { font-family: "Archivo", system-ui, sans-serif; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* banda superior */
.band { background: var(--band); color: #fff; border-bottom: 3px solid var(--accent); }
.band-in { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand img { height: 22px; }
.brand span { font-family: "Archivo", sans-serif; font-weight: 600; font-size: 14px; opacity: 0.85; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { text-decoration: none; padding: 6px 12px; border-radius: 6px; font-weight: 500; opacity: 0.8; }
nav a:hover { background: rgba(255, 255, 255, 0.08); opacity: 1; }
nav a.on { background: rgba(24, 210, 112, 0.16); color: var(--accent); opacity: 1; }
.band-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.corte { font-size: 12px; opacity: 0.8; }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 6px; padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* tarjetas */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card > h2, .card > h3 { margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.g-21 { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .g-21 { grid-template-columns: 1fr; } }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .lab { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi .val { font-family: "Archivo", sans-serif; font-size: 30px; font-weight: 600; line-height: 1.15; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.hero .val { font-size: 48px; }

/* semáforo: color + icono + texto */
.sem { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sem i { width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center; font-style: normal; font-size: 10px; color: #fff; }
.sem.Verde i { background: var(--good); }
.sem.Ámbar i { background: var(--warn); color: #0b0b0b; }
.sem.Rojo i { background: var(--crit); }
.sem.unk i { background: var(--unk); }
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.p0 { background: rgba(208, 59, 59, 0.12); color: var(--crit); }

/* listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--grid); display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.list li:first-child { border-top: 0; padding-top: 0; }
.list .t { font-weight: 600; }
.list a { text-decoration: none; }
.list a:hover .t { text-decoration: underline; }
.date { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* filtros */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters select, .filters input { font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--axis); background: var(--surface); color: var(--ink); }
.filters input { min-width: 200px; }
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 6px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 6px 12px; border: 0; background: var(--surface); color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .seg button.on { color: #0a2620; }

/* kanban */
.kanban { display: grid; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: 10px; padding: 8px; min-height: 120px; min-width: 0; }
.col h3 { display: flex; justify-content: space-between; gap: 6px; margin: 2px 4px 10px; font-size: 12px; }
.ini { display: block; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--unk); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; box-shadow: var(--shadow); }
.ini:hover { border-color: var(--axis); }
.ini.Verde { border-left-color: var(--good); } .ini.Ámbar { border-left-color: var(--warn); } .ini.Rojo { border-left-color: var(--crit); }
.ini .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 4px; }
.ini .top { align-items: flex-start; }
.marcas { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.marca { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--ink-2); }
.marca .dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; background: var(--unk); }
.marca .dot.Verde { background: var(--good); } .marca .dot.Ámbar { background: var(--warn); } .marca .dot.Rojo { background: var(--crit); }
.reqs { display: inline-block; min-width: 26px; text-align: center; padding: 1px 5px; border-radius: 3px; font-size: 11px; color: #fff; background: var(--unk); }
.reqs.ok { background: var(--good); }
.reqs.pend { background: var(--warn); color: #0b0b0b; }
.ini .nm { font-weight: 600; line-height: 1.3; margin-bottom: 6px; }
.ini .meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

/* tablero por prioridad */
.prio-grid { display: grid; gap: 8px; overflow-x: auto; padding-bottom: 8px; align-items: stretch; }
.prio-head { display: flex; justify-content: space-between; gap: 6px; margin: 0; padding: 8px 10px; font-size: 12px; background: var(--surface-2); border-radius: 8px; }
.prio-label { display: flex; flex-direction: column; justify-content: flex-start; gap: 6px; padding: 10px 4px; position: sticky; left: 0; background: var(--page); z-index: 1; }
.prio-label .pill { font-size: 13px; padding: 2px 10px; align-self: flex-start; }
.prio-cell { min-height: 60px; padding: 8px; }
.prio-cell .ini:last-child { margin-bottom: 0; }

/* actas */
details.acta { border-top: 1px solid var(--grid); padding: 10px 0; }
details.acta:first-of-type { border-top: 0; }
details.acta summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
details.acta[open] summary { margin-bottom: 4px; }

/* tablas */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }

/* ficha */
.ficha-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 20px; margin: 16px 0; }
.fact .k { font-size: 12px; color: var(--muted); }
.fact .v { font-weight: 500; }
.callout { background: var(--cream); color: #0a2620; border-radius: 8px; padding: 12px 14px; }
:root[data-theme="dark"] .callout { background: #24382f; color: var(--ink); }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .callout { background: #24382f; color: var(--ink); } }
.prose { white-space: pre-line; color: var(--ink-2); }
.resumen { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; }
.resumen p { margin: 4px 0 0; font-weight: 500; }
ul.bullets { margin: 0; padding-left: 18px; color: var(--ink-2); }
ul.bullets li { margin: 0 0 6px; }
.back { font-size: 13px; color: var(--ink-2); text-decoration: none; }
.back:hover { text-decoration: underline; }

/* gráficos */
svg { display: block; overflow: visible; }
svg text { fill: var(--muted); font-size: 11px; font-family: "Libre Franklin", system-ui, sans-serif; }
svg text.ink { fill: var(--ink); }
svg text.ink2 { fill: var(--ink-2); }
svg .gridl { stroke: var(--grid); stroke-width: 1; }
svg .axisl { stroke: var(--axis); stroke-width: 1; }
svg .mark { cursor: default; transition: opacity 0.12s; }
svg .mark:hover, svg .mark:focus { opacity: 0.75; outline: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin: 4px 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend b.dot { border-radius: 50%; }
.legend b.dia { transform: rotate(45deg); border-radius: 1px; width: 9px; height: 9px; }

/* heatmap */
.heat td.cell { text-align: center; padding: 4px; }
.heat .sq { display: inline-grid; place-items: center; width: 34px; height: 26px; border-radius: 4px; font-size: 11px; font-weight: 700; color: #fff; }
.heat .sq.Verde { background: var(--good); } .heat .sq.Ámbar { background: var(--warn); color: #0b0b0b; }
.heat .sq.Rojo { background: var(--crit); } .heat .sq.unk { background: var(--unk); }

/* tooltip */
.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); max-width: 320px; }
.tip .v { font-weight: 700; font-size: 13px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .k { width: 12px; height: 2px; display: inline-block; }

.toast { position: fixed; bottom: 16px; right: 16px; background: var(--band); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
@media (max-width: 640px) { .band-tools { margin-left: 0; } .kpi.hero .val { font-size: 40px; } }

/* ---------- Visión general (vision.js) ---------- */
.vg-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.vg-head p { margin: 4px 0 0; color: var(--ink-2); }
.btn-out { background: transparent; color: var(--brand); border: 1px solid var(--brand); border-radius: 8px; padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-out:hover { background: var(--surface-2); }
.vg-msg { border-top: 4px solid var(--accent); margin-bottom: 16px; }
.vg-lab { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); font-weight: 600; }
.vg-msg p { font-family: "Archivo", sans-serif; font-size: 20px; line-height: 1.45; font-weight: 500; margin: 8px 0 0; max-width: 75ch; }
.vg-msg .kpi { box-shadow: none; background: var(--page); }
.vg-msg .kpi .val small { font-size: 16px; font-weight: 600; }
.vg-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; margin-bottom: 16px; }
.vg-h2 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.vg-ent li { grid-template-columns: 64px 1fr; }
.vg-dia { font-family: "Archivo", sans-serif; font-weight: 700; font-size: 17px; line-height: 1.2; }
.vg-items { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.vg-it { display: flex; align-items: flex-start; gap: 8px; color: var(--ink); }
.vg-it > * { flex: none; }
.vg-it > .t { flex: 0 1 auto; min-width: 0; }
.vg-it > .vg-dot, .vg-it > .vg-hito { margin-top: 5px; }
.vg-it > .small, .vg-it > .conf { margin-top: 2px; }
.vg-it .t { font-weight: 600; }
.vg-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; background: var(--unk); }
.vg-dot.Verde { background: var(--good); } .vg-dot.Ámbar { background: var(--warn); } .vg-dot.Rojo { background: var(--crit); }
.vg-hito { width: 10px; height: 10px; flex: none; transform: rotate(45deg); background: var(--accent); border: 2px solid var(--ink); box-sizing: border-box; }
.conf { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; border: 1px solid var(--line); color: var(--ink-2); }
.conf.Alta { background: var(--f3); border-color: var(--f3); color: #fff; }
.conf.Media { background: var(--surface-2); color: var(--ink); }
.vg-foot { margin: 12px 0 0; padding-top: 10px; border-top: 1px dashed var(--axis); font-size: 13px; color: var(--ink-2); }
.vg-foot.warn { border-top: 0; padding-top: 0; color: var(--crit); }
.vg-dir li { grid-template-columns: 26px 1fr; }
.vg-num { width: 26px; height: 26px; border-radius: 50%; background: var(--band); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.vg-names { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 2px; }
.vg-names a { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.vg-names a:hover { text-decoration: underline; }
.vg-leg { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); align-items: center; }
.vg-leg > span { display: inline-flex; align-items: center; gap: 5px; }
.vg-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; gap: 2px; margin: 0 0 14px; }
.vg-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 24px; }
.vg-col h3 { font-size: 14px; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.vg-sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Hoja de ruta (vision.js) ---------- */
.hr-wrap { overflow-x: auto; }
.hr { min-width: 980px; position: relative; padding: 0 16px; }
.hr-row { display: grid; grid-template-columns: 280px 1fr; align-items: center; min-height: 34px; position: relative; z-index: 1; }
.hr-row.data { border-top: 1px solid var(--grid); cursor: pointer; }
.hr-row.data:hover .hr-name b { text-decoration: underline; }
.hr-name { display: flex; align-items: center; gap: 8px; min-width: 0; padding-right: 12px; font-size: 13px; }
.hr-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.hr-name .id { color: var(--muted); font-size: 12px; font-weight: 600; flex: none; }
.hr-track { position: relative; height: 34px; }
.hr-b { position: absolute; top: 8px; height: 18px; border-radius: 4px; box-sizing: border-box; }
.hr-b.done { background: var(--f3); }
.hr-b.alta { background: var(--f2); }
.hr-b.media { background: var(--f1); }
.hr-b.baja, .hr-b.na { background: repeating-linear-gradient(135deg, var(--f1) 0 5px, transparent 5px 10px); border: 1px solid var(--f2); }
.hr-b.open { background: repeating-linear-gradient(135deg, var(--grid) 0 5px, transparent 5px 10px); border: 1px dashed var(--muted); border-left: 0; border-radius: 0 4px 4px 0; }
.hr-b.open.first { border-left: 1px dashed var(--muted); border-radius: 4px; }
.hr-b.plan { background: transparent; border: 1.5px dashed var(--muted); }
.hr-b.blocked { border: 1.5px solid var(--crit); }
.hr-l { position: absolute; top: 9px; font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--ink); }
.hr-l.in { color: #fff; }
.hr-dia { position: absolute; top: 11px; width: 12px; height: 12px; margin-left: -6px; transform: rotate(45deg); background: var(--accent); border: 2px solid var(--ink); box-sizing: border-box; z-index: 2; }
.hr-pt { position: absolute; top: 13px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); z-index: 2; }
.hr-grp { font-family: "Archivo", sans-serif; font-weight: 700; font-size: 12px; color: var(--brand); text-transform: uppercase; letter-spacing: .05em; padding-top: 12px; }
.hr-axis { position: relative; height: 20px; }
.hr-axis span { position: absolute; padding-left: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.hr-axis.q span { font-family: "Archivo", sans-serif; font-weight: 700; color: var(--ink); font-size: 13px; }
.hr-grid { position: absolute; left: 296px; right: 16px; top: 0; bottom: 0; z-index: 0; pointer-events: none; }
.hr-grid i { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--grid); }
.hr-grid i.q { border-left-color: var(--axis); }
.hr-hoy { position: absolute; top: 0; bottom: 0; border-left: 2px solid var(--ink); z-index: 3; }
.hr-hoy span { position: absolute; top: 0; left: 4px; background: var(--ink); color: var(--page); font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; white-space: nowrap; }
.hr-leg { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--ink-2); margin-bottom: 12px; align-items: center; }
.hr-leg > span { display: inline-flex; align-items: center; gap: 6px; }
.hr-leg .hr-sw { position: static; display: inline-block; width: 26px; height: 12px; }
.hr-sw-dia { display: inline-block; width: 10px; height: 10px; transform: rotate(45deg); background: var(--accent); border: 2px solid var(--ink); box-sizing: border-box; }
.hr-sw-pt { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }

@media print {
  .band, .no-print, #tip { display: none !important; }
  main { max-width: none; padding: 0; }
  body { background: #fff; }
  .hr { min-width: 0; }
  .card { break-inside: avoid; }
}

/* fecha prevista: marcador en la hoja de ruta y dato de cabecera de la ficha */
.hr-prev { position: absolute; top: 9px; width: 16px; height: 16px; margin-left: -8px; transform: rotate(45deg); background: var(--ink); border: 3px solid var(--accent); box-sizing: border-box; z-index: 2; }
.hr-sw-prev { display: inline-block; flex: none; width: 12px; height: 12px; transform: rotate(45deg); background: var(--ink); border: 2px solid var(--accent); box-sizing: border-box; }
.prev-head { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; padding: 6px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.prev-head b { font-family: "Archivo", sans-serif; font-size: 16px; }
.prev-head.sin { color: var(--muted); }

/* fecha prevista inicial (la «Fecha compromiso» del Excel) */
.hr-ini { position: absolute; top: 10px; width: 14px; height: 14px; margin-left: -7px; transform: rotate(45deg); background: var(--surface); border: 2px dashed var(--ink-2); box-sizing: border-box; z-index: 2; }
.hr-sw-ini { display: inline-block; flex: none; width: 11px; height: 11px; transform: rotate(45deg); background: transparent; border: 2px dashed var(--ink-2); box-sizing: border-box; }
.prev-ini { display: inline-flex; align-items: center; gap: 6px; padding-left: 10px; margin-left: 2px; border-left: 1px solid var(--line); color: var(--ink-2); font-size: 13px; }
.prev-ini b { font-family: "Archivo", sans-serif; font-size: 14px; color: var(--ink); }
