/* =============================================================================
   Ark — sistema de tokens y componentes (identidad SAYCO VIRTUAL)
   Institucional, sobrio, preciso. El protagonismo se reserva al veredicto.
   ============================================================================= */
:root {
  /* Marca */
  --navy-900: #16224F;   /* primario */
  --navy-700: #2A3C82;   /* acentos / enlaces */
  --red-600:  #C8102E;   /* la lira: reservado a "real" y acciones destructivas */
  --paper:    #F7F8FA;   /* fondo */
  --surface:  #FFFFFF;
  --ink:      #1C2230;   /* texto */
  --slate-400:#8A93A6;   /* texto atenuado */
  --line:     #E4E7EE;   /* bordes */

  /* Triada de seguridad (el rojo comparte la marca: el rojo es escaso y significativo) */
  --success:  #1E8E5A;
  --caution:  #C77A11;
  --danger:   #C8102E;
  --success-bg:#E8F4EE;
  --caution-bg:#FBF1E1;
  --danger-bg: #FBE9EC;
  --info-bg:   #EAEEF8;

  /* Tipografía: institucional, nativa de Windows, soporta acentos perfectamente */
  --font-ui: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-display: "Segoe UI Semibold", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "Courier New", monospace;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(22,34,79,.06), 0 1px 3px rgba(22,34,79,.05);
  --shadow-md: 0 4px 16px rgba(22,34,79,.10);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* La página nunca se estira a lo ancho. OJO: 'clip' y no 'hidden' — hidden crea un
   contenedor de scroll y ROMPE position:sticky (la barra lateral se iba al hacer scroll)
   además de producir desplazamientos fantasma del cursor. */
html, body { overflow-x: clip; }

/* Default inline-icon size (every macro icon). Specific contexts override below. */
.ic { width: 1.1em; height: 1.1em; flex: none; vertical-align: -0.15em; }
body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--navy-700); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--red-600); }
h1, h2, h3 { font-family: var(--font-display); color: var(--navy-900); line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
.mono { font-family: var(--font-mono); overflow-wrap: anywhere; }
.alert { overflow-wrap: anywhere; }
.muted { color: var(--slate-400); }
.small { font-size: .85rem; }

/* ----------------------------------------------------------------- Layout shell */
/* minmax(0,1fr): el contenido nunca puede empujar la cuadrícula más allá de la ventana. */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
/* Barra lateral tipográfica: menú grande numerado (números en rojo lira), fondo claro,
   pegada a la ventana (sticky) — nunca "se acaba" al hacer scroll. */
.sidebar {
  background: var(--surface); color: var(--ink); padding: 26px 22px 18px;
  display: flex; flex-direction: column; gap: 0; position: sticky; top: 0; height: 100vh;
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 26px; }
.brand .brandmark, .rail-cap .brandmark { display: block; flex: none; }
.brand .wordmark { font-family: var(--font-display); color: var(--navy-900); font-size: 1.15rem; letter-spacing: .3px; line-height: 1.05; }
.brand .wordmark small { display: block; color: var(--slate-400); font-size: .62rem; letter-spacing: 2.5px; font-weight: 600; }
.nav-cap { font-size: .66rem; font-weight: 800; letter-spacing: 2.2px; text-transform: uppercase;
  color: var(--red-600); padding: 0 4px 8px; }
.nav-link {
  display: flex; align-items: flex-start; gap: 8px; padding: 13px 4px;
  font-family: var(--font-display); font-size: 1.18rem; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; line-height: 1.05; color: var(--navy-900);
  border-bottom: 1px solid var(--line); transition: color .13s, padding-left .13s;
}
.nav-link .idx { font-size: .64rem; font-weight: 800; color: var(--red-600); margin-top: 1px; letter-spacing: .5px; }
.nav-link:hover { text-decoration: none; color: var(--red-600); padding-left: 12px; }
.nav-link.active { color: var(--red-600); }
.nav-link.active .idx { color: var(--navy-900); }
.nav-spacer { flex: 1; }
.nav-foot { padding: 14px 4px 0; border-top: 1px solid var(--line); color: var(--slate-400); font-size: .78rem; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border-bottom: 2px solid var(--red-600); padding: 12px 28px; position: sticky; top: 0; z-index: 5;
}
.topbar .section { font-family: var(--font-display); color: var(--navy-900); font-size: 1.05rem; }
.who { display: flex; align-items: center; gap: 12px; }
.who .name { font-weight: 600; }
/* Sin tope: la página usa todo el ancho de la ventana. Los pocos elementos que se
   estiran mal (formularios, prosa del manual) conservan su propio tope local. */
.content { padding: 26px 28px 60px; width: 100%; min-width: 0; }
.page-cap { max-width: 1220px; }

/* ------------------------------------------------------------------ Rail lateral
   El escenario: contenido a la izquierda + rail contextual a la derecha. El rail es
   sticky (como la barra lateral) y con scroll propio si su contenido es más alto. */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) var(--rail-w, 330px); align-items: start; }
.rail {
  position: sticky; top: 52px; max-height: calc(100vh - 52px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: 26px 28px 40px 0; scrollbar-width: thin;
}
.rail .card.pad { padding: 16px 18px; }

/* Cabecera de marca: la única pieza permanente "vistosa" del rail */
.rail-cap {
  display: flex; align-items: center; gap: 12px; padding: 16px 18px;
  border-radius: var(--radius); color: #fff; box-shadow: var(--shadow-sm);
  /* tokens (no literales): así el color de marca de la instancia alcanza también al rail */
  background: linear-gradient(135deg, var(--navy-900) 0%, color-mix(in srgb, var(--navy-900) 45%, var(--navy-700) 55%) 62%, var(--navy-700) 100%);
  border-bottom: 3px solid var(--red-600);
}
.rail-cap .rc-title { font-family: var(--font-display); font-size: .92rem; letter-spacing: .07em; }
.rail-cap .rc-date { font-size: .76rem; color: #B9C3E4; margin-top: 2px; }

/* Título pequeño de cada bloque del rail */
.rail-title {
  font-size: .7rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--slate-400); margin-bottom: 10px;
}

/* Trabajo en curso: anillo de progreso (rojo SOLO en envío real) + contadores */
.gauge {
  --p: 0; width: 84px; height: 84px; flex: none; border-radius: 50%; position: relative;
  background: conic-gradient(var(--navy-700) calc(var(--p) * 1%), var(--line) 0);
}
.gauge.live { background: conic-gradient(var(--red-600) calc(var(--p) * 1%), var(--line) 0); }
.gauge.done { background: conic-gradient(var(--success) calc(var(--p) * 1%), var(--line) 0); }
.gauge::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--surface); }
.gauge .pct {
  position: absolute; inset: 0; z-index: 1; display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: .92rem; color: var(--ink);
}
.rj-label { font-family: var(--font-display); color: var(--navy-900); font-size: .95rem; }
.rj-counts { font-family: var(--font-mono); font-size: .8rem; margin-top: 6px; color: var(--ink); }
.rail-idle { display: flex; align-items: center; gap: 9px; color: var(--slate-400); font-size: .88rem; }
.rail-idle .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--slate-400); opacity: .55; }
.joblog.compact { max-height: 92px; font-size: .72rem; margin-top: 10px; padding: 8px 12px; line-height: 1.6; }

/* KPIs compactos del rail (2 columnas) */
.rail-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.rail-kpis .kpi .v { font-size: 1.35rem; }

/* Mini-barras horizontales (motivos de retención, proporciones, mezcla de estados) */
.mini-bars { display: flex; flex-direction: column; gap: 9px; }
.mb-top { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; margin-bottom: 3px; }
.mb-top .n { font-family: var(--font-mono); color: var(--slate-400); }
.mb-track { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.mb-fill { display: block; height: 100%; border-radius: 999px; background: var(--navy-700); min-width: 2px; }
.mb-fill.tone-success { background: var(--success); }
.mb-fill.tone-danger { background: var(--red-600); }
.mb-fill.tone-caution { background: var(--caution); }
.mb-fill.tone-muted { background: var(--slate-400); }

/* Sparkline de barras (envíos por día) — CSS puro, sin librerías */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 66px; margin-top: 4px; }
.spark i { flex: 1; background: var(--navy-700); border-radius: 3px 3px 0 0; min-height: 3px; opacity: .92; }
.spark i.cero { background: var(--line); }
.spark i:hover { opacity: 1; outline: 1px solid var(--navy-900); }
.spark-cap { display: flex; justify-content: space-between; font-size: .7rem; color: var(--slate-400); margin-top: 5px; }

/* Línea de tiempo de actividad reciente */
.timeline { position: relative; display: flex; flex-direction: column; gap: 13px; }
.tl-item { display: flex; gap: 11px; align-items: flex-start; position: relative; }
.tl-item::before { content: ""; position: absolute; left: 4px; top: 16px; bottom: -14px; width: 2px; background: var(--line); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 4px; background: var(--slate-400); position: relative; z-index: 1; }
.tl-dot.tone-success { background: var(--success); }
.tl-dot.tone-danger { background: var(--red-600); }
.tl-dot.tone-progress, .tl-dot.tone-caution { background: var(--caution); }
.tl-dot.tone-info, .tl-dot.tone-ready { background: var(--navy-700); }
.tl-body { min-width: 0; font-size: .84rem; line-height: 1.45; }
.tl-body .tl-when { color: var(--slate-400); font-size: .74rem; font-family: var(--font-mono); }

/* Accesos del rail: botones fantasma a lo ancho */
.rail-links { display: flex; flex-direction: column; gap: 8px; }
.rail-links .btn { justify-content: flex-start; width: 100%; }

/* Próximo paso: tarjeta CTA con acento */
.next-step { border-left: 4px solid var(--navy-700); }
.next-step.step-live { border-left-color: var(--red-600); }
.next-step .ns-big { font-family: var(--font-display); color: var(--navy-900); font-size: 1rem; margin: 2px 0 6px; }

/* ----------------------------------------------------------------- Components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card.pad { padding: 20px 22px; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid > * { min-width: 0; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.spacer { flex: 1; }

/* Botones — modernos: elevación sutil al pasar y presión al hacer clic */
.btn {
  display: inline-flex; align-items: center; gap: 8px; font: inherit; font-weight: 600;
  padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
  cursor: pointer; background: #EEF1F7; color: var(--navy-900);
  transition: transform .1s, box-shadow .14s, filter .12s, background .12s;
}
.btn:hover { filter: brightness(.98); text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-sm); color: inherit; }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; filter: none; transform: none; box-shadow: none; }
.btn-primary { background: linear-gradient(180deg, #22337A 0%, var(--navy-900) 100%); color: #fff; box-shadow: 0 2px 8px rgba(22,34,79,.28); }
.btn-primary:hover { color: #fff; }
.btn-accent { background: var(--navy-700); color: #fff; box-shadow: 0 2px 8px rgba(42,60,130,.25); }
.btn-accent:hover { color: #fff; }
.btn-danger { background: linear-gradient(180deg, #D71F3D 0%, var(--red-600) 100%); color: #fff; box-shadow: 0 2px 8px rgba(200,16,46,.28); }
.btn-danger:hover { color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-lg { padding: 12px 22px; font-size: 1rem; }

/* Campos de archivo: el "Choose File" nativo se reemplaza por un botón de la casa */
input[type=file] { width: 100%; padding: 8px; border: 1px dashed #C6CDDC; border-radius: 9px;
  background: var(--paper); font: inherit; color: var(--slate-400); }
input[type=file]::file-selector-button {
  font: inherit; font-weight: 600; color: #fff; background: var(--navy-700);
  border: 0; border-radius: 7px; padding: 8px 14px; margin-right: 12px; cursor: pointer;
  transition: filter .12s;
}
input[type=file]::file-selector-button:hover { filter: brightness(1.12); }

/* Pills de estado — un solo lenguaje, reutilizado en todas partes */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tone-muted   { color: #5C657A; background: #EEF0F4; }
.tone-info    { color: var(--navy-700); background: var(--info-bg); }
.tone-ready   { color: #0F6B57; background: #E4F3EE; }
.tone-progress{ color: var(--caution); background: var(--caution-bg); }
.tone-success { color: var(--success); background: var(--success-bg); }
.tone-danger  { color: var(--danger); background: var(--danger-bg); }
.role-badge { font-size: .72rem; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  color: var(--navy-700); background: var(--info-bg); padding: 3px 9px; border-radius: 6px; }

/* Tablas */
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th { text-align: left; color: var(--slate-400); font-weight: 600; font-size: .76rem;
  text-transform: uppercase; letter-spacing: .4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #FAFBFD; }
.num { font-family: var(--font-mono); }

/* Alertas */
.alert { border-radius: var(--radius-sm); padding: 12px 16px; font-size: .92rem; border: 1px solid; }
.alert-danger { background: var(--danger-bg); border-color: #F1C3CB; color: #8E1022; }
.alert-info { background: var(--info-bg); border-color: #CDD7EF; color: var(--navy-700); }

/* Iconos de módulo */
.module { display: inline-flex; align-items: center; gap: 9px; }
.module .ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--info-bg); color: var(--navy-700); flex: none; }
.module .ico svg { width: 17px; height: 17px; }

/* KPIs */
.kpis { display: flex; gap: 26px; flex-wrap: wrap; }
.kpi .v { font-family: var(--font-mono); font-size: 1.5rem; color: var(--navy-900); font-weight: 700; }
.kpi .l { font-size: .76rem; color: var(--slate-400); text-transform: uppercase; letter-spacing: .4px; }

/* ----------------------------------------------------------------- Stepper / gate */
.stepper { display: flex; align-items: center; gap: 0; margin: 8px 0 22px; }
.step { display: flex; align-items: center; gap: 10px; color: var(--slate-400); }
.step .dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; font-weight: 700; background: #fff; font-size: .85rem; }
.step.done .dot { background: var(--success); border-color: var(--success); color: #fff; }
.step.current .dot { border-color: var(--navy-900); color: var(--navy-900); }
.step.current .lbl { color: var(--navy-900); font-weight: 700; }
.step .lbl { font-weight: 600; }
.step-line { flex: 1; height: 2px; background: var(--line); margin: 0 14px; min-width: 24px; }
.step-line.done { background: var(--success); }
.locked-note { color: var(--slate-400); font-size: .9rem; display: inline-flex; gap: 7px; align-items: center; }

/* ----------------------------------------------------------------- El momento del veredicto */
.verdict { border-radius: 14px; padding: 34px 32px; text-align: center; margin: 6px 0 4px;
  border: 1px solid; animation: rise .35s ease-out; }
@media (prefers-reduced-motion: reduce) { .verdict { animation: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.verdict .icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  margin: 0 auto 14px; }
.verdict .icon svg { width: 28px; height: 28px; }
.verdict .big { font-family: var(--font-display); font-size: 2rem; letter-spacing: .5px; margin: 0; }
.verdict .sub { margin: 6px 0 0; }
.verdict.go { background: var(--success-bg); border-color: #BFE3CF; }
.verdict.go .icon { background: var(--success); color: #fff; }
.verdict.go .big { color: #14764D; }
.verdict.stop { background: var(--danger-bg); border-color: #F1C3CB; }
.verdict.stop .icon { background: var(--red-600); color: #fff; }
.verdict.stop .big { color: #9E0E26; }
.problem-list { text-align: left; max-width: 720px; margin: 18px auto 0; }
.problem-list li { background: #fff; border: 1px solid #F1C3CB; border-radius: 8px; padding: 9px 13px;
  margin-bottom: 7px; font-size: .9rem; list-style: none; }
.problem-list { padding: 0; }

/* ----------------------------------------------------------------- Selector de modos */
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mode {
  border: 2px solid var(--line); border-radius: var(--radius); padding: 15px 16px; cursor: pointer;
  display: block; background: #fff; transition: border-color .12s, box-shadow .12s;
}
.mode:hover { box-shadow: var(--shadow-sm); }
.mode input { position: absolute; opacity: 0; }
.mode .mt { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.mode .mn { color: var(--slate-400); font-size: .85rem; margin-top: 5px; }
.mode .tag { font-size: .68rem; font-weight: 800; letter-spacing: .6px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 5px; }
.mode.neutral .tag { background: #EEF0F4; color: #5C657A; }
.mode.caution .tag { background: var(--caution-bg); color: var(--caution); }
.mode.danger  .tag { background: var(--danger-bg); color: var(--danger); }
.mode.neutral:has(input:checked) { border-color: #5C657A; }
.mode.caution:has(input:checked) { border-color: var(--caution); box-shadow: 0 0 0 3px var(--caution-bg); }
.mode.danger:has(input:checked)  { border-color: var(--red-600); box-shadow: 0 0 0 3px var(--danger-bg); }

/* Confirmación de envío real */
.confirm-live { border: 2px solid var(--red-600); background: var(--danger-bg); border-radius: var(--radius);
  padding: 16px 18px; margin-top: 14px; }
.confirm-live input[type=text] { font-family: var(--font-mono); font-size: 1rem; padding: 9px 12px;
  border: 1px solid #E0A9B2; border-radius: 7px; width: 160px; letter-spacing: 2px; text-transform: uppercase; }

/* Progreso */
.progress { height: 14px; background: #EEF0F4; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--navy-700); transition: width .4s ease; }
.progress.live > span { background: var(--red-600); }
.progress.done > span { background: var(--success); }
.counter { font-family: var(--font-mono); font-size: 1.05rem; color: var(--navy-900); }

/* Tablero de actividad del trabajo en curso: consola oscura bajo la barra de progreso */
.joblog {
  margin-top: 10px; padding: 12px 16px; max-height: 240px; overflow-y: auto;
  background: #0e1733; color: #d9e1f5; border: 1px solid #26335f; border-radius: 10px;
  font-family: var(--font-mono); font-size: .8rem; line-height: 1.7;
  scrollbar-width: thin; scrollbar-color: #3a4a80 #0e1733;
}
.joblog div { white-space: pre-wrap; word-break: break-word; }
.joblog div:last-child { color: #fff; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(1200px 500px at 50% -10%, #20316E 0%, var(--navy-900) 60%); padding: 24px; }
.login-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow-md); width: 100%; max-width: 380px; padding: 34px 32px; }
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.login-card .brand .wordmark { color: var(--navy-900); }
.login-card .brand .wordmark small { color: var(--slate-400); }
.field { margin-top: 14px; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 5px; }
.field input { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.field input:focus { outline: 2px solid var(--navy-700); outline-offset: 1px; border-color: var(--navy-700); }
.sso-slot { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.btn-sso { width: 100%; justify-content: center; background: #fff; border: 1px solid var(--line); color: #5C657A; }

/* Foco visible en todo */
a:focus-visible, button:focus-visible, input:focus-visible, label:focus-visible, .mode:focus-within {
  outline: 2px solid var(--navy-700); outline-offset: 2px;
}

.empty { text-align: center; color: var(--slate-400); padding: 48px 20px; }
.empty svg { width: 40px; height: 40px; opacity: .4; margin-bottom: 8px; }

/* ----------------------------------------------------------------- Campaign cards */
.card-campaign { position: relative; transition: box-shadow .12s; }
.card-campaign:hover { box-shadow: var(--shadow-md); }
.card-cover { position: absolute; inset: 0; z-index: 1; border-radius: var(--radius); }   /* whole-card link */
.cc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.cc-name { font-weight: 700; color: var(--navy-900); }
.cc-top-right { display: flex; align-items: center; gap: 10px; }
.cc-context { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.cc-bottom { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 18px; }
.cc-counts strong { color: var(--navy-900); }
.cc-progress { width: 100%; }
/* Controls that must be clickable above the card-cover link */
.cc-act { position: relative; z-index: 2; }

.chip { font-size: .74rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.chip.tone-danger { color: var(--danger); background: var(--danger-bg); }
.chip.tone-ready { color: #0F6B57; background: #E4F3EE; }
.chip.tone-progress { color: var(--caution); background: var(--caution-bg); }

/* ⋯ menu */
.menu { position: relative; z-index: 2; }
.menu-btn { border: none; background: transparent; font-size: 1.25rem; line-height: 1; padding: 2px 10px;
  border-radius: 6px; cursor: pointer; color: var(--slate-400); }
.menu-btn:hover { background: #EEF0F4; color: var(--navy-900); }
.menu-pop { display: none; position: absolute; right: 0; top: 100%; margin-top: 6px; min-width: 232px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-md);
  padding: 6px; z-index: 50; }
.menu-btn[aria-expanded="true"] + .menu-pop { display: block; }
.menu-pop a, .menu-pop button { display: block; width: 100%; text-align: left; background: none; border: none;
  font: inherit; color: var(--ink); padding: 9px 12px; border-radius: 7px; cursor: pointer; text-decoration: none; }
.menu-pop a:hover, .menu-pop button:hover { background: #F2F4F8; text-decoration: none; }
.menu-pop a.primary { font-weight: 700; color: var(--navy-900); }
.menu-pop form { margin: 0; }
.menu-pop button.danger { color: var(--danger); }
.menu-pop button.danger:hover { background: var(--danger-bg); }

/* Manual page */
.manual { display: grid; grid-template-columns: 240px 1fr; gap: 32px; align-items: start; }
.manual-toc { position: sticky; top: 84px; font-size: .9rem; }
.manual-toc a { display: block; padding: 5px 10px; border-radius: 6px; color: var(--slate-400); }
.manual-toc a:hover { background: #fff; color: var(--navy-700); text-decoration: none; }
.manual-body { max-width: 760px; }
.manual-body section { scroll-margin-top: 84px; margin-bottom: 34px; }
.manual-body h2 { border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-top: 0; }
.manual-body h3 { margin-top: 18px; }
.manual-body p, .manual-body li { line-height: 1.65; }
.manual-body code { background: #EEF0F4; padding: 1px 5px; border-radius: 4px; font-family: var(--font-mono); font-size: .88em; }
@media (max-width: 760px) { .manual { grid-template-columns: 1fr; } .manual-toc { position: static; } }

/* Responsive: en media pantalla las columnas se apilan (la barra lateral se queda);
   solo en ventanas muy angostas la barra pasa a franja superior. */
@media (max-width: 1080px) {
  .grid.cols-3, .grid.cols-2, .modes { grid-template-columns: 1fr; }
  .content { padding: 22px 20px 60px; }
  /* El rail se apila DEBAJO del contenido a ancho completo (ya va después en el DOM). */
  .stage { grid-template-columns: 1fr; }
  .rail { position: static; max-height: none; overflow: visible; padding: 0 20px 40px; }
}
/* ---------------------------------------------------- Responsive: menú lateral (cajón)
   Patrón portado de srd-sayco: bajo 900px la barra lateral se vuelve un CAJÓN lateral
   (off-canvas) que abre la hamburguesa del topbar — una franja aplanada de enlaces se
   volvía ilegible con varias entradas. En escritorio nada de esto aplica. */
.menu-toggle { display: none; padding: 8px 10px; }
.menu-backdrop { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail-deco { display: none; }  /* en móvil solo queda lo esencial del rail */

  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 300px); height: 100dvh;
    transform: translateX(-100%); transition: transform .24s ease;
    z-index: 60; box-shadow: var(--shadow-md); overflow-y: auto; will-change: transform;
  }
  .sidebar.open { transform: translateX(0); }

  .menu-toggle { display: inline-flex; }

  .menu-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(16, 19, 25, .5);
    opacity: 0; pointer-events: none; transition: opacity .24s ease; z-index: 55;
  }
  .menu-backdrop.open { opacity: 1; pointer-events: auto; }

  /* Congela la página detrás del cajón abierto (guardado por esta media query:
     una clase rezagada tras agrandar la ventana no bloquea el escritorio). */
  html.menu-open, html.menu-open body { overflow: hidden; }
}

/* Las tablas densas se apilan como tarjetas en el teléfono — una tabla con scroll
   lateral es inusable en un móvil. Cada fila pasa a ser una tarjeta dividida; el
   encabezado desaparece y un data-label opcional por celda pone el título del campo. */
@media (max-width: 900px) {
  table.data, table.data tbody, table.data td { display: block; }
  table.data thead { display: none; }
  table.data tr {
    display: flex; flex-direction: column; gap: 7px;
    padding: 16px 14px; border-bottom: 1px solid var(--line);
  }
  table.data tr:last-child { border-bottom: none; }
  table.data tr:hover td { background: transparent; }  /* el tinte de hover es ruido en tarjetas */
  table.data td { padding: 0; border: none; }
  table.data td:empty { display: none; }  /* celda vacía = sin hueco en la tarjeta */
  table.data td[data-label]::before {
    content: attr(data-label);
    display: block; margin-bottom: 2px;
    font-size: .66rem; font-weight: 700; letter-spacing: .5px;
    text-transform: uppercase; color: var(--slate-400);
  }
}

/* Teléfonos: el topbar no aguanta hamburguesa + título + tema + nombre + rol + Salir.
   Se ocultan nombre y rol (el Manual, el tema y Salir siguen a mano). */
@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 8px; }
  .who { gap: 8px; }
  .who .name, .who .role-badge { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .menu-backdrop { transition: none; }
}

/* --------------------------------------------------------- Ventana modal (Manual) */
.modal-back { position: fixed; inset: 0; background: rgba(12,17,32,.55); z-index: 100;
  display: grid; place-items: center; padding: 22px; }
.modal-back[hidden] { display: none; }
.modal { width: min(1080px, 96vw); height: min(780px, 92vh); background: var(--paper);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; overflow: hidden; animation: rise .2s ease-out; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.modal-title { font-family: var(--font-display); font-weight: 700; color: var(--navy-900);
  display: inline-flex; align-items: center; gap: 9px; }
.modal-x { border: none; background: transparent; font-size: 1.05rem; line-height: 1;
  padding: 6px 11px; border-radius: 7px; cursor: pointer; color: var(--slate-400); }
.modal-x:hover { background: #EEF0F4; color: var(--navy-900); }
.modal-frame { border: 0; width: 100%; flex: 1; background: var(--paper); }

/* Página incrustada dentro de la ventana (sin topbar): ajustar los anclajes fijos */
.embed-page .manual-toc { top: 14px; }
.embed-page .manual-body section { scroll-margin-top: 14px; }

/* --------------------------------------------------------- Interruptor (tema) */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 44px; height: 24px; border-radius: 999px; background: #C6CDDC;
  position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s; }
.switch input:checked + .track { background: var(--navy-700); }
.switch input:checked + .track::after { left: 23px; }

/* =============================================================================
   Tema OSCURO (negro). Se activa con data-theme="dark" en <html>; la preferencia
   vive en localStorage ('ark-theme') y se alterna desde Configuración → Apariencia.
   ============================================================================= */
[data-theme="dark"] {
  --paper:   #101319;
  --surface: #1A1F2A;
  --ink:     #E7EAF2;
  --slate-400:#9AA4B8;
  --line:    #2B3242;
  --info-bg:   #232C42;
  --success-bg:#17291F;
  --caution-bg:#2E2515;
  --danger-bg: #33191F;
  --success: #4CC38A;
  --caution: #E2A54E;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.35);
  --shadow-md: 0 4px 18px rgba(0,0,0,.55);
}
[data-theme="dark"] h1, [data-theme="dark"] h2, [data-theme="dark"] h3 { color: #EDF0F8; }
[data-theme="dark"] a { color: #9DB4E8; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: #141924; color: var(--ink); border-color: var(--line); }
[data-theme="dark"] .topbar .section, [data-theme="dark"] .who .name,
[data-theme="dark"] .kpi .v, [data-theme="dark"] .counter, [data-theme="dark"] .cc-name { color: #EDF0F8; }
/* Rail en modo oscuro: los títulos navy pasan a claro; el anillo y las barras ya se
   re-tematizan solos porque usan tokens (--surface/--line/tonos). */
[data-theme="dark"] .rj-label, [data-theme="dark"] .next-step .ns-big { color: #EDF0F8; }
[data-theme="dark"] .rail-cap { background: linear-gradient(135deg, #101a3c 0%, #1a2757 62%, #22316E 100%); }
[data-theme="dark"] .btn { background: #252C3A; color: #E7EAF2; }
[data-theme="dark"] .btn-primary { background: #3B4E9E; color: #fff; }
[data-theme="dark"] .btn-accent { background: var(--navy-700); color: #fff; }
[data-theme="dark"] .btn-danger { background: var(--red-600); color: #fff; }
[data-theme="dark"] .btn-ghost { background: transparent; border-color: var(--line); }
[data-theme="dark"] .mode { background: var(--surface); }
[data-theme="dark"] .step .dot { background: var(--surface); }
[data-theme="dark"] .step.current .dot { border-color: #9DB4E8; color: #EDF0F8; }
[data-theme="dark"] .step.current .lbl { color: #EDF0F8; }
[data-theme="dark"] table.data tr:hover td { background: #202634; }
[data-theme="dark"] .tone-muted { color: #AAB3C5; background: #252C3A; }
[data-theme="dark"] .tone-info { color: #9DB4E8; }
[data-theme="dark"] .tone-ready { color: #5AC8A2; background: #17291F; }
[data-theme="dark"] .chip.tone-ready { color: #5AC8A2; background: #17291F; }
[data-theme="dark"] .role-badge { color: #9DB4E8; }
[data-theme="dark"] .alert-danger { color: #F2A9B6; border-color: #6B2533; }
[data-theme="dark"] .alert-info { color: #AFC3EF; border-color: #33406B; }
[data-theme="dark"] .progress { background: #252C3A; }
[data-theme="dark"] .menu-btn:hover { background: #252C3A; color: #E7EAF2; }
[data-theme="dark"] .menu-pop { background: var(--surface); }
[data-theme="dark"] .menu-pop a.primary { color: #EDF0F8; }
[data-theme="dark"] .menu-pop a:hover, [data-theme="dark"] .menu-pop button:hover { background: #252C3A; }
[data-theme="dark"] .verdict.go { background: #142720; border-color: #245B41; }
[data-theme="dark"] .verdict.go .big { color: #57C795; }
[data-theme="dark"] .verdict.stop { background: #2C171D; border-color: #6B2533; }
[data-theme="dark"] .verdict.stop .big { color: #F08CA0; }
[data-theme="dark"] .problem-list li { background: var(--surface); border-color: #6B2533; }
[data-theme="dark"] .login-card { background: var(--surface); }
[data-theme="dark"] .login-card .brand .wordmark { color: #EDF0F8; }
[data-theme="dark"] .manual-body code { background: #252C3A; }
[data-theme="dark"] .manual-toc a:hover { background: var(--surface); color: #9DB4E8; }
[data-theme="dark"] .modal-title { color: #EDF0F8; }
[data-theme="dark"] .modal-x:hover { background: #252C3A; color: #E7EAF2; }
[data-theme="dark"] .btn-sso { background: var(--surface); color: #AAB3C5; }
[data-theme="dark"] .confirm-live input[type=text] { background: #141924; color: var(--ink); border-color: #6B2533; }
[data-theme="dark"] .brand .wordmark { color: #EDF0F8; }
[data-theme="dark"] .nav-link { color: #EDF0F8; border-color: var(--line); }
[data-theme="dark"] .nav-link:hover, [data-theme="dark"] .nav-link.active { color: #F0647B; }
[data-theme="dark"] .nav-link .idx { color: #F0647B; }
[data-theme="dark"] .nav-link.active .idx { color: #EDF0F8; }
[data-theme="dark"] input[type=file] { background: #141924; border-color: var(--line); }
[data-theme="dark"] .btn { background: #252C3A; color: #E7EAF2; }
[data-theme="dark"] .btn-primary { background: #3B4E9E; color: #fff; }
[data-theme="dark"] .btn-danger { background: var(--red-600); color: #fff; }

/* ------------------------------------------------ Opción de seguridad: tarjeta con interruptor
   Se lee de un vistazo si está activada: interruptor verde + borde/fondo verde + texto de estado. */
.optcard {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 15px 16px; border: 1.5px solid var(--line); border-radius: 10px;
  cursor: pointer; transition: border-color .15s, background .15s; user-select: none;
}
.optcard:hover { border-color: var(--navy-700); }
.optcard:has(input:checked) { border-color: var(--success); background: var(--success-bg); }
.optcard .oc-body { min-width: 0; }
.optcard .oc-title { font-family: var(--font-display); color: var(--navy-900); font-size: 1rem;
  display: flex; align-items: center; gap: 7px; }
.optcard .oc-title .ic { width: 1.15em; height: 1.15em; color: var(--slate-400); }
.optcard:has(input:checked) .oc-title .ic { color: var(--success); }
.optcard .oc-desc { color: var(--slate-400); font-size: .86rem; margin-top: 4px; line-height: 1.5; }
.optcard .oc-status { font-size: .8rem; font-weight: 700; margin-top: 8px; display: inline-block; }
.optcard .oc-status .on { display: none; color: var(--success); }
.optcard .oc-status .off { display: inline; color: var(--slate-400); font-weight: 600; }
.optcard:has(input:checked) .oc-status .on { display: inline; }
.optcard:has(input:checked) .oc-status .off { display: none; }

/* interruptor deslizante (on/off) */
.switch { position: relative; flex: none; width: 46px; height: 26px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch .track { display: block; width: 46px; height: 26px; border-radius: 13px; background: var(--slate-400); transition: background .15s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(22,34,79,.4); transition: left .15s; }
.switch input:checked ~ .track { background: var(--success); }
.switch input:checked ~ .knob { left: 23px; }
.switch input:focus-visible ~ .track { outline: 2px solid var(--navy-700); outline-offset: 2px; }

[data-theme="dark"] .optcard:has(input:checked) { background: rgba(30,142,90,.16); }

/* ============================= Tooltip (tarjeta al pasar el cursor) =============================
   Explica qué contiene cada descarga/acción SIN ocupar espacio. Solo CSS: se abre al pasar el
   cursor o al enfocar con teclado (accesible). Uso:
     <span class="tip"> <a ...>Descargar X</a>
       <span class="tip-card" role="tooltip">Texto que explica qué contiene.</span> </span>       */
.tip { position: relative; display: inline-flex; }
.tip .tip-card {
  position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 320px; padding: 10px 12px; z-index: 40;
  background: var(--navy-900); color: #fff; font-size: .8rem; line-height: 1.55;
  border-radius: 8px; box-shadow: 0 6px 22px rgba(22,34,79,.35);
  opacity: 0; visibility: hidden; transition: opacity .12s ease .05s; pointer-events: none;
}
.tip .tip-card::after { /* flecha */
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: var(--navy-900);
}
.tip:hover .tip-card, .tip:focus-within .tip-card { opacity: 1; visibility: visible; }
.tip .tip-card strong { color: #fff; }
[data-theme="dark"] .tip .tip-card { background: #0E1524; box-shadow: 0 6px 22px rgba(0,0,0,.55); }
[data-theme="dark"] .tip .tip-card::after { border-top-color: #0E1524; }

/* --- Ventana de formulario (acciones de Usuarios): la ventana del manual, en tamaño tarjeta --- */
.modal-form { width: min(460px, 94vw); height: auto; max-height: 92vh; overflow: auto; }
.modal-body { padding: 18px 20px 20px; }
.menu-pop button:disabled { color: #98A2B5; cursor: not-allowed; }
.menu-pop button:disabled:hover { background: none; }
[data-theme="dark"] .menu-pop button:disabled { color: #5B6478; }
.menu-pop { z-index: 90; }  /* por encima de tarjetas y pills; debajo del modal (100) */
/* --- Grupos de problemas del veredicto (tabla paginada de a 10, no un muro de 20.000) --- */
.prob-group { background: var(--danger-bg, #FDF0F1); border: 1px solid #F2D5D8; border-radius: 12px;
  padding: 12px 16px; margin-top: 10px; }
.prob-group summary { cursor: pointer; color: var(--navy-900); padding: 4px 0; }
.prob-group summary:hover { opacity: .85; }
.prob-group .prob-tabla { margin-top: 10px; background: #fff; border-radius: 8px; }
.pill.tone-warn { background: #C8102E; color: #fff; }
[data-theme="dark"] .prob-group { background: #2A1A1E; border-color: #4A2A30; }
[data-theme="dark"] .prob-group .prob-tabla { background: var(--surface); }
/* --- Chip de "último archivo guardado" en el formulario de campaña --- */
.chip-guardado { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px;
  background: #EEF6EF; border: 1px solid #CFE7D2; color: #1F5B2A;
  border-radius: 8px; padding: 6px 12px; font-size: .88rem; }
.chip-guardado .mono { font-weight: 600; }
[data-theme="dark"] .chip-guardado { background: #16281B; border-color: #2A4A33; color: #8FCB9B; }
