/* Tareas Vencidas — estilos. Identidad Performance Perú (manual AD-RADAR): navy + teal + rojo solo para alarma */
/* Identidad Performance Perú (manual AD-RADAR): navy oscuro + teal + acento rojo */
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/montserrat-variable.woff2') format('woff2');
}
:root {
  --bg: #061d30;
  --bg-grad: radial-gradient(1200px 600px at 82% -12%, rgba(63, 167, 201, 0.07), transparent 60%),
             radial-gradient(900px 600px at -5% 108%, rgba(52, 119, 140, 0.10), transparent 60%);
  --surface: #0e2536;
  --surface-2: #143042;
  --surface-3: #1c3c4f;
  --border: #3a6474;
  --border-soft: #15303f;
  --text: #eef3f7;
  --text-dim: #9bb3c0;
  --text-mut: #7d99a8;
  --accent: #f44040;
  --accent-soft: rgba(244, 64, 64, 0.14);
  --blue: #3fa7c9;
  --blue-soft: rgba(63, 167, 201, 0.15);
  --green: #34c77b;
  --amber: #f0a830;
  --amber-soft: rgba(240, 168, 48, 0.14);
  --orange: #ef7d3a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
  --ring: 0 0 0 3px rgba(63, 167, 201, 0.4);
  --sel: var(--blue); --sel-hover: #5cbcd9; --sel-text: #061d30;   /* seleccionado / interactivo: teal con texto navy */
  --danger-text: #ff7676;
  --topbar-bg: #0a2233;   /* errores sobre fondo oscuro (el rojo de marca no contrasta) */
  --st-hoy: #7fd3ea;       --st-ayer: var(--amber);
  --st-d2a7: var(--orange); --st-mas7: var(--accent);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Montserrat', -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-repeat: no-repeat;
  color: var(--text);
  font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.kpi-v, td { font-variant-numeric: tabular-nums; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; flex-direction: column;
  border-bottom: 1px solid var(--border-soft);
  background: var(--topbar-bg);
  position: sticky; top: 0; z-index: 20;
}
.topbar-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; padding: 12px 28px 10px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-sep { width: 1px; height: 30px; background: var(--border); }
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.2px; }
.subtitle { margin: 1px 0 0; font-size: 12px; color: var(--text-dim); }
.topbar-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.chip {
  font-size: 11px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim);
  background: var(--surface); white-space: nowrap;
}
.fuentes { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.fuente-btn {
  appearance: none; border: none; background: var(--surface); color: var(--text-dim);
  font: inherit; font-size: 11px; font-weight: 600; padding: 5px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.14s ease, color 0.14s ease;
}
.fuente-btn:hover { color: var(--text); }
.fuente-btn.on { background: var(--sel); color: var(--sel-text); }
.fuente-btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* capa "Ahora" (Perfy): encendida pero sin poder aplicarse a la vista actual */
.fuente-btn.pausa { opacity: 0.55; }
/* filas que siguen en el cierre de anoche mientras "Ahora" está encendido */
tr.anoche td { color: var(--text-dim); }
tr.anoche td.zero { color: var(--text-mut); }
tr.anoche td.tot { color: var(--text-dim); }
.fuente-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 199, 123, 0.18); }
.fuente-btn.on .fuente-dot { background: var(--sel-text); box-shadow: 0 0 0 3px rgba(6, 29, 48, 0.2); }
.topbar-nav {
  display: flex; align-items: stretch; gap: 2px; padding: 0 20px;
  border-top: 1px solid var(--border-soft);
  overflow-x: auto; scrollbar-width: none;
}
.topbar-nav::-webkit-scrollbar { display: none; }
.nav-tab {
  appearance: none; border: none; background: transparent;
  color: var(--text-dim); font: inherit; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 11px 13px; border-bottom: 2px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: color 0.16s ease, border-color 0.16s ease;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--text); border-bottom-color: var(--sel); }
.metricsw { margin-left: auto; align-self: center; flex: none; }
.metricsw button { font-size: 12px; padding: 6px 12px; }

/* ---------- Botones y controles ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; font-weight: 500; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.08s ease, box-shadow 0.16s ease;
}
.btn:hover { background: var(--surface-3); border-color: var(--border); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--sel); border-color: transparent; color: var(--sel-text); font-weight: 600;
  justify-content: center;
}
.btn.primary:hover { background: var(--sel-hover); }
select, input[type=search], input[type=password], input[type=text] {
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 11px; outline: none;
}
select:focus, input:focus { box-shadow: var(--ring); border-color: var(--blue); }
input::placeholder { color: var(--text-mut); }

/* ---------- Layout ---------- */
.wrap { max-width: 1140px; margin: 0 auto; padding: 20px 20px 70px; }
.stale {
  background: var(--amber-soft); border: 1px solid rgba(240, 168, 48, 0.45);
  color: var(--amber); font-weight: 600; font-size: 13px;
  padding: 9px 14px; border-radius: var(--radius-sm); margin-bottom: 14px;
}

/* ---------- Barra de filtros ---------- */
.filterbar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 14px;
  display: flex; flex-wrap: wrap; gap: 9px; align-items: center;
}
.flabel { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-mut); font-weight: 700; margin-right: -2px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  appearance: none; border: none; background: var(--surface-2); color: var(--text-dim);
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 8px 13px; cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--sel); color: var(--sel-text); }
.filterbar select { max-width: 250px; }
.filterbar input[type=search] { flex: 1; min-width: 150px; }
.check {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font-size: 12.5px; color: var(--text-dim); user-select: none;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 12px; background: var(--surface-2);
  transition: color 0.14s ease, border-color 0.14s ease;
}
.check:hover { color: var(--text); }
.check input { accent-color: var(--sel); margin: 0; }
/* chips de filtros activos */
.activefilters { display: flex; flex-wrap: wrap; gap: 7px; margin: -6px 0 14px; }
.activefilters:empty { display: none; }
.fchip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11.5px; font-weight: 600; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--blue); color: var(--blue); background: var(--blue-soft);
  cursor: pointer; transition: background 0.14s ease;
}
.fchip:hover { background: rgba(63, 167, 201, 0.28); }
.fchip.clear { border-color: var(--border); color: var(--text-dim); background: transparent; }

/* ---------- KPIs ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 11px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 16px; box-shadow: var(--shadow);
  cursor: pointer; transition: transform 0.12s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.kpi:hover { transform: translateY(-2px); border-color: var(--border); box-shadow: var(--shadow-md); }
.kpi.sorted { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue), var(--shadow-md); }
.kpi-l { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.kpi-v { font-size: 23px; font-weight: 800; letter-spacing: -0.5px; margin-top: 3px; }
.kpi-hot { border-color: rgba(244, 64, 64, 0.45); background: var(--accent-soft); }
.kpi-hot .kpi-v { color: var(--accent); }
.kpi-hint { font-size: 10.5px; color: var(--text-mut); margin-top: 2px; }

/* ---------- Tabla ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: clip;   /* clip (no hidden): así el encabezado fijo sí funciona */
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* en escritorio la tabla cabe: sin contenedor de scroll, el encabezado y la fila TOTAL
   se quedan fijos contra la ventana (bajo la cabecera, cuya altura mide el JS) */
@media (min-width: 900px) {
  .table-scroll { overflow-x: clip; }
  thead th { top: var(--topbar-h, 0px); z-index: 3; }   /* debajo de la cabecera fija; sobre las celdas */
  tfoot td { z-index: 3; }
}
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
th {
  text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-mut); font-weight: 600; padding: 11px 14px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface);
  white-space: nowrap;
}
th:first-child { text-align: left; }
th.sort { cursor: pointer; user-select: none; transition: color 0.14s ease; }
th.sort:hover { color: var(--text); }
th.sort.on { color: var(--text); }
th.sort.on .arrow { color: var(--sel); }
th .arrow { font-size: 9px; margin-left: 3px; }
th .kpi-dot { display: inline-block; margin-right: 6px; vertical-align: baseline; }
td { padding: 9px 14px; border-bottom: 1px solid var(--border-soft); text-align: right; white-space: nowrap; }
td:first-child { text-align: left; white-space: normal; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.click { cursor: pointer; font-weight: 600; }
td.click:hover { color: var(--blue); text-decoration: underline; }
td.zero { color: var(--text-mut); }
td.tot { font-weight: 800; }
tr.rowlink { cursor: pointer; }
td.empty { text-align: center; padding: 26px; color: var(--text-dim); white-space: normal; }
tfoot td {
  background: var(--surface-2); font-weight: 800;
  border-top: 2px solid var(--border); border-bottom: 0;
  position: sticky; bottom: 0;
}
tfoot .btn { font-size: 11.5px; padding: 5px 11px; margin-left: 10px; font-weight: 600; }
.pill {
  display: inline-block; font-size: 10px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--border);
  color: var(--text-dim); background: var(--surface-2); margin-left: 7px; vertical-align: middle;
}
.pill-c { display: none; }
.pill.inactivo { border-color: rgba(240, 168, 48, 0.5); color: var(--amber); background: var(--amber-soft); }
/* mini barra de distribución por fila */
td.distcell { width: 130px; min-width: 110px; padding-right: 8px; }
.dist { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden;
  background: var(--border-soft); }
.dist span { display: block; height: 100%; min-width: 2px; }
.footnote { margin-top: 12px; font-size: 12px; color: var(--text-mut); }

/* ---------- Modal ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  max-width: 740px; width: calc(100vw - 40px); padding: 0;
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(2, 12, 20, 0.65); }
.mhead {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 15px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.mhead h2 { margin: 0; font-size: 15px; font-weight: 700; }
.msub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.mbody { padding: 8px 20px 18px; max-height: 65vh; overflow-y: auto; }
.tarea { border-bottom: 1px solid var(--border-soft); padding: 11px 0; }
.tarea:last-child { border-bottom: 0; }
.tarea .l1 { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.tarea .nom { font-weight: 700; font-size: 13.5px; }
.tarea .fec { color: var(--text-dim); font-size: 12px; }
.tarea .desc { color: var(--text-dim); font-size: 12.5px; margin-top: 3px; }
.tarea .links { margin-top: 4px; font-size: 12.5px; }
.tarea a { color: var(--blue); text-decoration: none; font-weight: 600; }
.tarea a:hover { text-decoration: underline; }

/* ---------- Login ---------- */
.login {
  max-width: 360px; margin: 13vh auto 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 30px 28px; box-shadow: var(--shadow-lg);
  text-align: center;
}
.login .brand-logo { height: 34px; margin: 0 auto 14px; }
.login h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.2px; }
.login .subtitle { margin-bottom: 4px; }
.login form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.err { color: var(--danger-text); font-size: 14px; font-weight: 600; }
.hidden { display: none !important; }
button:focus-visible, [role="button"]:focus-visible, [tabindex="0"]:focus-visible, a:focus-visible,
select:focus-visible, input:focus-visible, summary:focus-visible { outline: none; box-shadow: var(--ring); }
tr[tabindex="0"]:focus-visible td { background: var(--surface-2); }
.linkbtn { appearance: none; border: 0; background: none; color: var(--blue); font: inherit; font-size: inherit;
  cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
#ayuda .mbody { font-size: 13.5px; line-height: 1.55; }
#ayuda .mbody h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-mut); margin: 16px 0 6px; }
#ayuda .mbody h3:first-child { margin-top: 4px; }
#ayuda .mbody p { margin: 0 0 8px; }
.aviso { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: min(92vw, 560px);
  background: var(--surface-2); color: var(--text); border: 1px solid var(--amber); border-left-width: 4px;
  border-radius: 8px; padding: 10px 14px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,0.35); z-index: 50; }
.aviso.error { border-color: var(--accent); }
.cargando .err { color: var(--text); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
/* ---------- Celular (hasta 640 px) ---------- */
@media (max-width: 640px) {
  .topbar { position: static; }
  .topbar-row { padding: 10px 12px 8px; gap: 8px; }
  .brand { gap: 10px; }
  .brand-logo { height: 24px; }
  .brand-sep { height: 24px; }
  .brand h1 { font-size: 16px; }
  .subtitle { display: none; }
  .topbar-actions { gap: 6px; }
  .chip { max-width: 44vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-nav { flex-wrap: wrap; overflow: visible; padding: 0 6px; }
  .nav-tab { flex: 1; justify-content: center; padding: 10px 6px; font-size: 12.5px; }
  .metricsw { margin: 0 0 8px; width: 100%; display: flex; }
  .metricsw button { flex: 1; min-height: 40px; }
  .wrap { padding: 12px 10px 24px; }
  .filterbar { padding: 10px; gap: 8px; }
  .filterbar .seg, .filterbar select, .filterbar input[type=search], .filterbar .check, .filterbar .btn { width: 100%; max-width: none; }
  .filterbar .seg { display: flex; }
  .filterbar .seg button { flex: 1; }
  .filterbar .flabel { width: 100%; margin-bottom: -4px; }   /* rótulo encima de cada control */
  select, input { font-size: 16px; }            /* evita el zoom automático en iPhone */
  .fuente-btn, .seg button, .fchip, tfoot .btn, .btn, .check { min-height: 40px; }
  .fchip { padding: 8px 12px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
  .kpi { padding: 10px 12px; }
  .kpi-v { font-size: 20px; }
  table { min-width: 520px; }
  .distcell, .dist-h { display: none; }        /* la barra de distribución no cabe; los números sí */
  td:first-child, th:first-child { position: sticky; left: 0; z-index: 2; background: var(--surface);
    max-width: 52vw; box-shadow: 2px 0 0 var(--border-soft); }
  tbody tr:hover td:first-child, tr.anoche td:first-child { background: var(--surface); }
  tfoot td:first-child { background: var(--surface-2); }
  th:first-child { z-index: 3; }
  td { padding: 9px 10px; }
  .pill { font-size: 10.5px; white-space: nowrap; }
  .pill-l { display: none; }
  .pill-c { display: inline-block; }
  .mhead { flex-wrap: wrap; padding: 12px 14px; }
  .mhead > div:last-child { width: 100%; display: flex; gap: 8px; }
  .mhead .btn { flex: 1; justify-content: center; min-height: 40px; }
  .mbody { padding: 6px 14px 14px; max-height: 70vh; }
  .login { margin: 6vh 12px 0; max-width: none; padding: 24px 18px; }
  .footnote { font-size: 12.5px; }
  .aviso { bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .cargando .barra i { animation: none; }
  .kpi, .btn, .nav-tab, .seg button { transition: none; }
}
.cargando { display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; min-height: 60vh; color: var(--text-dim); font-size: 14px; }
.cargando img { width: 132px; opacity: 0.85; }
.cargando .barra { width: 190px; height: 3px; border-radius: 2px; background: rgba(255,255,255,0.10); overflow: hidden; }
.cargando .barra i { display: block; width: 40%; height: 100%; background: var(--blue);
  animation: desliza 1.1s ease-in-out infinite; }
@keyframes desliza { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }
