/* ═══════════════════════════════════════════════════════════════════════════
   SISTEMA DE DISEÑO POSVALIDACIÓN — EXECUTIVE & OPERATIONS
   Basado estrictamente en: referencia_diseno/posvalidacion_rediseno_v3.html
   Tipografía: IBM Plex Sans & IBM Plex Mono | Modo Oscuro (Default) y Claro
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

/* ── 1. TOKENS DE DISEÑO (TEMA OSCURO DEFAULT) ─────────────────────────── */
:root {
  --bg:         #0a111d;
  --side:       #080d17;
  --line:       #22304a;
  --line-soft:  #182236;
  --card-a:     #152035;
  --card-b:     #0f1829;
  --glass:      rgba(12, 19, 32, 0.74);

  --ink:        #eaeef6;
  --ink-2:      #a6b2c6;
  --ink-3:      #7685a0;

  --brass:      #d2ae7b;
  --brass-2:    #a8814f;
  --red:        #ef6b77;
  --green:      #52c496;
  --blue:       #79a6e6;
  --amber:      #e0ac48;

  --sh-1:       0 1px 0 rgba(255,255,255,.04) inset, 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -8px rgba(0,0,0,.55);
  --sh-2:       0 1px 0 rgba(255,255,255,.06) inset, 0 2px 4px rgba(0,0,0,.4), 0 18px 40px -12px rgba(0,0,0,.7);

  --row-hover:  rgba(255,255,255,.03);
  --track:      rgba(255,255,255,.08);
  --sel:        rgba(210,174,123,.09);
  --sw:         236px;
  --hdr-h:      68px;

  /* Aliases para compatibilidad con código existente */
  --txt:        var(--ink);
  --txt2:       var(--ink-2);
  --txt3:       var(--ink-3);
  --glass2:     var(--card-b);
  --glassBrd:   var(--line);
  --glassBrd2:  var(--line-soft);
  --blue2:      var(--blue);
}

/* ── 2. TEMA CLARO ──────────────────────────────────────────────────────── */
[data-theme="light"], body.light, body[data-theme="light"] {
  --bg:         #eef1f6;
  --side:       #080d17; /* Sidebar ejecutivo navy oscuro en ambos temas para garantizar máximo contraste */
  --line:       #d2d9e5;
  --line-soft:  #e2e8f0;
  --card-a:     #ffffff;
  --card-b:     #f8fafc;
  --glass:      rgba(255,255,255,.88);

  --ink:        #0f172a;
  --ink-2:      #334155;
  --ink-3:      #475569;

  --brass:      #8d6a3a;
  --brass-2:    #6f5128;
  --red:        #c0404d;
  --green:      #23805c;
  --blue:       #2f5f9e;
  --amber:      #8f620c;

  --sh-1:       0 1px 0 #fff inset, 0 1px 2px rgba(20,32,51,.08), 0 8px 22px -8px rgba(20,32,51,.15);
  --sh-2:       0 1px 0 #fff inset, 0 2px 4px rgba(20,32,51,.08), 0 18px 38px -12px rgba(20,32,51,.25);

  --row-hover:  rgba(20,32,51,.04);
  --track:      rgba(20,32,51,.08);
  --sel:        rgba(141,106,58,.09);

  /* Aliases para compatibilidad */
  --txt:        var(--ink);
  --txt2:       var(--ink-2);
  --txt3:       var(--ink-3);
  --glass2:     #ffffff;
  --glassBrd:   #d2d9e5;
  --glassBrd2:  #e2e8f0;
  --blue2:      var(--blue);
}

/* ── 3. BASE & RESET ────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background: radial-gradient(1000px 480px at 90% -10%, rgba(121,166,230,.08), transparent 60%), var(--bg);
  background-attachment: fixed;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.num {
  font-variant-numeric: tabular-nums;
  font-family: inherit;
}

.mono, .order {
  font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  font-size: 13px;
  color: var(--ink-2);
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ── 4. ESTRUCTURA PRINCIPAL (APP & BARRA LATERAL) ───────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sw) 1fr;
  min-height: 100vh;
  transition: grid-template-columns .28s cubic-bezier(.4, 0, .2, 1);
}

.app.collapsed {
  --sw: 56px;
}

.side {
  background: linear-gradient(180deg, #0c1424 0%, #080d17 100%) !important;
  border-right: 1px solid #1a253a !important;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: #c4cddc;
  overflow: hidden;
  z-index: 20;
}

.brand {
  height: var(--hdr-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  border-bottom: 1px solid #16213a;
  white-space: nowrap;
}

.logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 8px;
  flex: none;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.45));
}

.logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--brass), var(--brass-2));
  display: grid;
  place-items: center;
  color: #1a1308;
  font-weight: 700;
  flex: none;
}

.brand span {
  font-weight: 600;
  font-size: 17px;
  color: #f3f5f9;
}

.nav {
  padding: 8px 14px 20px;
  overflow: hidden auto;
  flex: 1;
}

.nav h6, .nav-grp {
  font-size: 11px;
  font-weight: 600;
  color: #8da0be !important;
  padding: 18px 12px 6px;
  white-space: nowrap;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.nav a, .nbtn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 9px;
  color: #c2cee2 !important;
  text-decoration: none;
  position: relative;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav a:hover, .nbtn:hover {
  background: #142138 !important;
  color: #ffffff !important;
}

.nav a.on, .nbtn.on {
  color: #ffffff !important;
  background: linear-gradient(90deg, rgba(210,174,123,.22), rgba(210,174,123,.05)) !important;
  box-shadow: inset 0 0 0 1px rgba(210,174,123,.3) !important;
}

.nav a.on svg, .nbtn.on svg {
  color: var(--brass) !important;
}

.nav .lb {
  overflow: hidden;
  transition: opacity .2s;
}

/* Badge contador de alertas en sidebar */
.badge, .nbadge {
  margin-left: auto;
  background: var(--brass);
  color: #1a1308;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 10px;
}

.app.collapsed .brand {
  padding: 0;
  justify-content: center;
}

.app.collapsed .brand span,
.app.collapsed .nav .lb {
  opacity: 0;
  width: 0;
  display: none;
}

.app.collapsed .nav {
  padding: 8px 4px 20px;
}

.app.collapsed .nav h6, .app.collapsed .nav-grp {
  height: 1px;
  padding: 0;
  margin: 12px 4px;
  background: #16213a;
  font-size: 0;
  overflow: hidden;
}

.app.collapsed .nav a, .app.collapsed .nbtn {
  justify-content: center;
  padding: 10px 0;
  gap: 0;
}

/* Contador en barra lateral colapsada: esquina superior derecha del ícono sin taparlo */
.app.collapsed .badge, .app.collapsed .nbadge {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 9px;
  padding: 1px 4px;
  margin: 0;
  box-shadow: 0 0 0 2px #080d17;
}

.app.collapsed .nav a[data-tip]:hover::after {
  content: attr(data-tip);
  position: fixed;
  left: 64px;
  background: #1a2740;
  color: #fff;
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 13px;
  box-shadow: var(--sh-2);
  border: 1px solid var(--line);
  z-index: 50;
  pointer-events: none;
}

/* Pie de barra lateral (PostgreSQL al pie) */
.side-foot {
  padding: 14px 18px;
  border-top: 1px solid #16213a;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  font-size: 12.5px;
  color: #8da0be !important;
  background: #080d17 !important;
}

.app.collapsed .side-foot {
  padding: 12px 0;
  justify-content: center;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(82, 196, 150, 0.18);
  flex: none;
  margin: 0 2px;
}

.app.collapsed .side-foot span.t {
  display: none;
}

.scrim {
  display: none;
}

/* ── 5. CONTENEDOR PRINCIPAL & HEADER SUPERIOR ─────────────────────────── */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.top, #hdr {
  height: var(--hdr-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.crumb {
  color: var(--ink-3);
  font-size: 13px;
}

.crumb b {
  color: var(--ink);
  font-weight: 500;
}

.sp {
  flex: 1;
}

.icon-btn, .theme-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--card-a), var(--card-b));
  box-shadow: var(--sh-1);
  color: var(--ink-2);
  transition: color .15s, border-color .15s;
}

.icon-btn:hover, .theme-btn:hover {
  color: var(--ink);
  border-color: var(--brass);
}

.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--card-a), var(--card-b));
  box-shadow: var(--sh-1);
  color: var(--ink-2);
  font-size: 13px;
}

.pill.btn:hover {
  border-color: var(--red);
  color: var(--red);
}

.upd {
  font-size: 12.5px;
  color: var(--ink-3);
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 0 14px;
  border-left: 1px solid var(--line);
}

.av {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--brass), var(--brass-2));
  color: #1a1308;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

.user b {
  display: block;
  font-weight: 600;
  line-height: 1.2;
}

.user small {
  font-size: 11.5px;
  color: var(--ink-3);
}

/* ── 6. ÁREA DE CONTENIDO & ENCABEZADOS DE PÁGINA ───────────────────────── */
.content, .pane, #main {
  padding: 18px 20px 48px;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}

.head, .page-header {
  margin-bottom: 24px;
}

.head h1, .page-header h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -.015em;
  color: var(--ink);
  margin: 0 0 6px;
}

.head p, .page-header p {
  color: var(--ink-2);
  font-size: 13.5px;
  margin: 0 0 24px;
  max-width: 75ch;
  line-height: 1.5;
}

/* ── 7. TARJETAS DE INDICADORES (KPIs) CON DEGRADADOS PREMIUM ────────────── */
.kpis, .kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 34px;
  width: 100%;
}

.kpi {
  --c: var(--ink-3);
  position: relative;
  padding: 22px 24px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, var(--card-a), var(--card-b));
  box-shadow: 0 4px 20px -4px rgba(0,0,0,0.45), 0 1px 0 rgba(255,255,255,0.05) inset;
  transition: transform .22s cubic-bezier(.16,1,.3,1), box-shadow .22s, border-color .22s;
  overflow: hidden;
}

.kpi:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 30px -6px rgba(0,0,0,0.65), 0 1px 0 rgba(255,255,255,0.08) inset;
}

/* ── Degradados Premium: Tema Oscuro (Default) ── */
.kpi.alert, .kpi.kpi-red {
  --c: var(--red);
  border-color: rgba(239, 107, 119, 0.35);
  background: radial-gradient(340px 190px at 100% 0%, rgba(239, 107, 119, 0.16) 0%, transparent 70%),
              linear-gradient(165deg, rgba(26, 32, 48, 0.96) 0%, rgba(15, 23, 38, 0.98) 100%);
  box-shadow: 0 8px 24px -4px rgba(239, 107, 119, 0.12), 0 1px 0 rgba(255,255,255,0.05) inset;
}
.kpi.alert:hover {
  border-color: rgba(239, 107, 119, 0.6);
  box-shadow: 0 14px 34px -4px rgba(239, 107, 119, 0.22), 0 0 24px rgba(239, 107, 119, 0.15);
}

.kpi.wa, .kpi.kpi-amber {
  --c: var(--amber);
  border-color: rgba(224, 172, 72, 0.28);
  background: radial-gradient(340px 190px at 100% 0%, rgba(224, 172, 72, 0.14) 0%, transparent 70%),
              linear-gradient(165deg, rgba(28, 33, 46, 0.96) 0%, rgba(15, 23, 38, 0.98) 100%);
  box-shadow: 0 8px 24px -4px rgba(224, 172, 72, 0.08), 0 1px 0 rgba(255,255,255,0.05) inset;
}
.kpi.wa:hover {
  border-color: rgba(224, 172, 72, 0.48);
  box-shadow: 0 14px 34px -4px rgba(224, 172, 72, 0.16);
}

.kpi.ok, .kpi.kpi-green {
  --c: var(--green);
  border-color: rgba(82, 196, 150, 0.28);
  background: radial-gradient(340px 190px at 100% 0%, rgba(82, 196, 150, 0.14) 0%, transparent 70%),
              linear-gradient(165deg, rgba(24, 35, 46, 0.96) 0%, rgba(15, 23, 38, 0.98) 100%);
  box-shadow: 0 8px 24px -4px rgba(82, 196, 150, 0.08), 0 1px 0 rgba(255,255,255,0.05) inset;
}
.kpi.ok:hover {
  border-color: rgba(82, 196, 150, 0.48);
  box-shadow: 0 14px 34px -4px rgba(82, 196, 150, 0.16);
}

.kpi.info, .kpi.kpi-cyan {
  --c: var(--blue);
  border-color: rgba(121, 166, 230, 0.28);
  background: radial-gradient(340px 190px at 100% 0%, rgba(121, 166, 230, 0.14) 0%, transparent 70%),
              linear-gradient(165deg, rgba(22, 33, 49, 0.96) 0%, rgba(15, 23, 38, 0.98) 100%);
  box-shadow: 0 8px 24px -4px rgba(121, 166, 230, 0.08), 0 1px 0 rgba(255,255,255,0.05) inset;
}
.kpi.info:hover {
  border-color: rgba(121, 166, 230, 0.48);
  box-shadow: 0 14px 34px -4px rgba(121, 166, 230, 0.16);
}

/* ── Degradados Premium: Tema Claro ── */
[data-theme="light"] .kpi,
body.light .kpi {
  border-radius: 18px;
  box-shadow: 0 10px 28px -6px rgba(20, 32, 51, 0.06), 0 2px 6px -1px rgba(20, 32, 51, 0.03);
}

[data-theme="light"] .kpi.alert,
body.light .kpi.alert {
  border-color: rgba(224, 86, 94, 0.32);
  background: radial-gradient(340px 190px at 100% 0%, rgba(224, 86, 94, 0.10) 0%, transparent 72%),
              linear-gradient(165deg, #ffffff 0%, #fafbfc 100%);
  box-shadow: 0 12px 32px -6px rgba(224, 86, 94, 0.12), 0 2px 6px -1px rgba(20, 32, 51, 0.04);
}
[data-theme="light"] .kpi.alert:hover,
body.light .kpi.alert:hover {
  border-color: rgba(224, 86, 94, 0.55);
  box-shadow: 0 16px 38px -6px rgba(224, 86, 94, 0.18);
}

[data-theme="light"] .kpi.wa,
body.light .kpi.wa {
  border-color: rgba(210, 174, 123, 0.35);
  background: radial-gradient(340px 190px at 100% 0%, rgba(210, 174, 123, 0.11) 0%, transparent 72%),
              linear-gradient(165deg, #ffffff 0%, #fafbfc 100%);
  box-shadow: 0 12px 32px -6px rgba(210, 174, 123, 0.1), 0 2px 6px -1px rgba(20, 32, 51, 0.04);
}
[data-theme="light"] .kpi.wa:hover,
body.light .kpi.wa:hover {
  border-color: rgba(210, 174, 123, 0.55);
  box-shadow: 0 16px 38px -6px rgba(210, 174, 123, 0.16);
}

[data-theme="light"] .kpi.ok,
body.light .kpi.ok {
  border-color: rgba(35, 128, 92, 0.3);
  background: radial-gradient(340px 190px at 100% 0%, rgba(35, 128, 92, 0.10) 0%, transparent 72%),
              linear-gradient(165deg, #ffffff 0%, #fafbfc 100%);
  box-shadow: 0 12px 32px -6px rgba(35, 128, 92, 0.1), 0 2px 6px -1px rgba(20, 32, 51, 0.04);
}
[data-theme="light"] .kpi.ok:hover,
body.light .kpi.ok:hover {
  border-color: rgba(35, 128, 92, 0.5);
  box-shadow: 0 16px 38px -6px rgba(35, 128, 92, 0.16);
}

[data-theme="light"] .kpi.info,
body.light .kpi.info {
  border-color: rgba(47, 95, 158, 0.3);
  background: radial-gradient(340px 190px at 100% 0%, rgba(47, 95, 158, 0.10) 0%, transparent 72%),
              linear-gradient(165deg, #ffffff 0%, #fafbfc 100%);
  box-shadow: 0 12px 32px -6px rgba(47, 95, 158, 0.1), 0 2px 6px -1px rgba(20, 32, 51, 0.04);
}
[data-theme="light"] .kpi.info:hover,
body.light .kpi.info:hover {
  border-color: rgba(47, 95, 158, 0.5);
  box-shadow: 0 16px 38px -6px rgba(47, 95, 158, 0.16);
}

.kpi-top {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-2);
  font-weight: 500;
  font-size: 13.5px;
  text-transform: none; /* En minúsculas / normal, no mayúsculas */
}

.ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 28%, transparent);
  flex: none;
}

.ico svg {
  width: 17px;
  height: 17px;
}

.kpi .val, .kpi-num {
  font-size: 42px;
  font-weight: 600;
  letter-spacing: -.025em;
  line-height: 1.1;
  margin: 14px 0 2px;
  color: var(--ink); /* Números en blanco en oscuro, charcoal en claro */
  font-variant-numeric: tabular-nums;
}

.kpi.alert .val, .kpi.kpi-red .val {
  color: var(--red); /* Solo alertas en rojo */
}

.kpi .sub, .kpi-sub {
  color: var(--ink-3);
  font-size: 12.5px;
  text-transform: none;
}

.kpi-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 10px;
  gap: 10px;
}

.delta {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 7px;
  white-space: nowrap;
}

.delta.good, .delta.pos {
  color: var(--green);
  background: color-mix(in srgb, var(--green) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--green) 25%, transparent);
}

.delta.bad, .delta.neg {
  color: var(--red);
  background: color-mix(in srgb, var(--red) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--red) 25%, transparent);
}

.delta.flat, .delta.neutral {
  color: var(--ink-3);
  background: rgba(127, 140, 165, .14);
  border: 1px solid rgba(127, 140, 165, .2);
}

.spark {
  width: 104px;
  height: 34px;
  overflow: visible;
}

/* ── 8. PANELES, TABLAS Y BARRA DE HERRAMIENTAS ────────────────────────── */
.panel, .tcard {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, var(--card-a), var(--card-b));
  box-shadow: var(--sh-1);
  overflow: hidden;
  margin-bottom: 24px;
}

.sect, .sec-hdr {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.sect h2, .sec-ttl {
  font-size: 19px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -.01em;
}

.sect p, .sec-sub {
  color: var(--ink-2);
  font-size: 13px;
  margin-top: 2px;
}

.tools, .tbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.search {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 440px;
}

.search svg {
  position: absolute;
  left: 12px;
  top: 10px;
  width: 16px;
  height: 16px;
  color: var(--ink-3);
  pointer-events: none;
}

/* Controles de herramientas (alto 38px, radio 10px, borde fino) */
.field, select, input[type=search], input[type=text], textarea {
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(127, 140, 165, .07);
  padding: 0 12px;
  color: var(--ink);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, background .15s;
}

.search .field, .search input[type=search], #busP, #busL {
  width: 100%;
  padding-left: 36px;
}

select {
  padding-right: 28px;
  cursor: pointer;
}

.field:hover, select:hover, input[type=search]:hover, input[type=text]:hover {
  border-color: var(--ink-3);
}

.field:focus, select:focus, input[type=search]:focus, input[type=text]:focus {
  border-color: var(--brass);
  background: rgba(127, 140, 165, .12);
}

/* Casilla de verificación con acento dorado */
input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: #b8935f;
  cursor: pointer;
  vertical-align: middle;
}

.selinfo {
  margin-left: auto;
  font-size: 13px;
  color: var(--ink-3);
}

.scroll {
  max-height: calc(100vh - 270px);
  min-height: 480px;
  overflow: auto;
}

/* Tabla de datos con encabezado fijo */
table {
  width: 100%;
  border-collapse: collapse;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-3);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card-b) 92%, #7f8ca5);
  white-space: nowrap;
}

th.r, td.r, td.num {
  text-align: right;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  font-size: 13px;
  color: var(--ink);
}

tbody tr {
  cursor: pointer;
  transition: background .15s;
}

tbody tr:hover {
  background: var(--row-hover);
}

tbody tr.sel {
  background: var(--sel);
}

tbody tr.open {
  box-shadow: inset 3px 0 0 var(--brass);
}

/* Prioridad con punto de color */
.prio {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 13px;
  color: var(--c);
}

.prio::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
}

.p-alta, .prio-alta    { --c: var(--red); }
.p-media, .prio-media  { --c: var(--amber); }
.p-baja, .prio-baja    { --c: var(--blue); }

.client b {
  display: block;
  font-weight: 600;
}

.client span {
  font-size: 12px;
  color: var(--ink-3);
}

/* Barra de puntuación de riesgo fina */
.score, .pbar, .progress-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 120px;
  color: var(--c);
  font-size: 13px;
}

.bar, .pbar-track, .progress-track {
  flex: 1;
  height: 6px;
  background: var(--track);
  border-radius: 4px;
  overflow: hidden;
}

.bar i, .pbar-fill, .progress-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--c);
}

.score b, .pbar-num, .progress-label {
  font-weight: 600;
  width: 24px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  font-size: 12px;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--ink-2);
  background: rgba(127,140,165,.07);
  white-space: nowrap;
}

.amt {
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.age {
  color: var(--ink-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.age.old {
  color: var(--amber);
  font-weight: 500;
}

/* Estados de posvalidación como etiquetas redondeadas */
.state, .status-chip {
  display: inline-block;
  font-size: 12px;
  padding: 3px 11px;
  border-radius: 20px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 28%, transparent);
}

.st-alerta, .error    { --c: var(--red); }
.st-pend, .warning    { --c: var(--amber); }
.st-wa, .pending      { --c: var(--blue); }
.st-ok, .success      { --c: var(--green); }
.st-can, .neutral     { --c: var(--ink-3); }

/* Pie de tabla & paginador */
.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 13px;
  gap: 12px;
  flex-wrap: wrap;
}

.pager {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ── 9. BOTONES ─────────────────────────────────────────────────────────── */
.btn, .b {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--card-a), var(--card-b));
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s, color .15s, transform .15s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--sh-1);
}

.btn:hover:not(:disabled), .b:hover:not(:disabled) {
  border-color: var(--brass);
  color: var(--brass);
}

.btn:disabled, .b:disabled {
  opacity: .4;
  cursor: default;
}

/* Botón principal dorado */
.btn.primary, .b.pri {
  background: linear-gradient(145deg, var(--brass), var(--brass-2));
  border-color: transparent;
  color: #1a1308;
  font-weight: 600;
  box-shadow: 0 8px 18px -6px rgba(210,174,123,.5);
}

.btn.primary:hover:not(:disabled), .b.pri:hover:not(:disabled) {
  color: #1a1308;
  filter: brightness(1.08);
}

.btn.danger, .b.danger {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 40%, var(--line));
}

.btn.danger:hover:not(:disabled), .b.danger:hover:not(:disabled) {
  border-color: var(--red);
  color: var(--red);
  background: color-mix(in srgb, var(--red) 10%, transparent);
}

.btn.sm, .b.sm {
  padding: 5px 11px;
  font-size: 12px;
  border-radius: 8px;
}

.empty, .vacio {
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-2);
}

.empty b, .vacio strong {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
  font-size: 15px;
}

/* ── 10. PANEL DE DETALLE (DRAWER) & DIÁLOGOS ───────────────────────────── */
.shade {
  position: fixed;
  inset: 0;
  background: rgba(3,7,13,.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 30;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(480px, 100%);
  background: linear-gradient(170deg, var(--card-a), var(--card-b));
  border-left: 1px solid var(--line);
  box-shadow: var(--sh-2);
  transform: translateX(102%);
  transition: transform .3s cubic-bezier(.4, 0, .2, 1);
  z-index: 31;
  display: flex;
  flex-direction: column;
}

body.dopen .shade {
  opacity: 1;
  pointer-events: auto;
}

body.dopen .drawer {
  transform: none;
}

.d-head, .dlg-hdr {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.d-head h3, .dlg-hdr h2 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}

.d-body, .dlg-body {
  padding: 20px 24px;
  overflow: auto;
  flex: 1;
}

.d-body h4 {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  margin: 22px 0 10px;
}

.d-body h4:first-child {
  margin-top: 0;
}

.big {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.big b {
  font-size: 44px;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--c);
  line-height: 1;
}

.big span {
  color: var(--ink-3);
}

.kv {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  font-size: 13.5px;
}

.kv dt {
  color: var(--ink-2);
}

.kv dd {
  font-weight: 500;
  text-align: right;
  margin: 0;
  color: var(--ink);
}

.brk {
  display: grid;
  gap: 10px;
}

.brk div {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 4px 12px;
  font-size: 13.5px;
}

.brk .bar {
  grid-column: 1/-1;
  height: 5px;
}

.brk .bar i {
  background: var(--brass);
}

.d-foot, .dlg-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: rgba(127,140,165,.04);
}

dialog {
  border: 1px solid var(--line);
  background: linear-gradient(170deg, var(--card-a), var(--card-b));
  color: var(--ink);
  border-radius: 16px;
  box-shadow: var(--sh-2);
  padding: 0;
  max-width: 1100px;
  width: 95%;
  margin: auto;
}

dialog#dlg {
  max-width: 1120px;
  width: 95%;
}

dialog::backdrop {
  background: rgba(3, 7, 13, 0.65);
  backdrop-filter: blur(8px);
}

/* Modales con Overlay Flotante Centrado */
.modal-overlay {
  position: fixed !important;
  inset: 0 !important;
  z-index: 99999 !important;
  background: rgba(3, 7, 13, 0.78) !important;
  backdrop-filter: blur(10px) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 20px !important;
  overflow-y: auto !important;
  box-sizing: border-box !important;
}

.modal-caja {
  background: linear-gradient(170deg, var(--card-a, #182234), var(--card-b, #0f172a)) !important;
  border: 1px solid var(--line, rgba(255, 255, 255, 0.14)) !important;
  border-radius: 16px !important;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.85), 0 0 35px rgba(56, 189, 248, 0.2) !important;
  width: 100% !important;
  max-width: 860px !important;
  max-height: 90vh !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  animation: zoomInModal 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

@keyframes zoomInModal {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-hdr {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 16px 22px !important;
  border-bottom: 1px solid var(--line, rgba(255, 255, 255, 0.1)) !important;
  background: rgba(255, 255, 255, 0.03) !important;
}

.modal-hdr h3 {
  margin: 0 !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  color: var(--ink, #fff) !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}

.btn-cerrar {
  background: transparent !important;
  border: none !important;
  color: var(--ink-2, #94a3b8) !important;
  font-size: 18px !important;
  cursor: pointer !important;
  padding: 4px 8px !important;
  border-radius: 6px !important;
  transition: all 0.15s ease !important;
}

.btn-cerrar:hover {
  background: rgba(255, 255, 255, 0.1) !important;
  color: #fff !important;
}

.modal-body {
  padding: 20px !important;
  overflow-y: auto !important;
  flex: 1 !important;
}

.modal-footer {
  padding: 14px 22px !important;
  border-top: 1px solid var(--line, rgba(255, 255, 255, 0.1)) !important;
  display: flex !important;
  gap: 10px !important;
  justify-content: flex-end !important;
  background: rgba(255, 255, 255, 0.02) !important;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--card-a);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-weight: 500;
  box-shadow: var(--sh-2);
  opacity: 0;
  pointer-events: none;
  transition: .25s;
  z-index: 60;
}

.toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ── 11. COMPONENTES DE VISTAS (PAGINACIÓN, MODALES, REGLAS, DASHBOARD) ── */

/* Paginación */
.pag-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(160deg, var(--card-a), var(--card-b));
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 16px 16px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--ink-2);
}

.pag-info strong {
  color: var(--ink);
  font-weight: 600;
}

.pag-controles {
  display: flex;
  align-items: center;
  gap: 5px;
}

.pag-btn {
  background: linear-gradient(180deg, var(--card-a), var(--card-b));
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
  min-width: 32px;
  text-align: center;
}

.pag-btn:hover:not(:disabled) {
  border-color: var(--brass);
  color: var(--brass);
}

.pag-btn.activo {
  background: linear-gradient(145deg, var(--brass), var(--brass-2));
  border-color: transparent;
  color: #1a1308;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(210,174,123,0.4);
}

.pag-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.pag-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pag-selector-wrap select {
  font-size: 12.5px;
  height: 32px;
  padding: 2px 8px;
  border-radius: 8px;
}

/* Modales & Ficha */
.dgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.dcard {
  background: linear-gradient(160deg, var(--card-a), var(--card-b));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

.dcard-lbl {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 5px;
}

.dcard-lbl.s::after {
  content: " 🔒";
  font-size: 10px;
}

.dcard-val {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  word-break: break-word;
}

.dlg-sec {
  font-size: 11px;
  font-weight: 600;
  color: var(--brass);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 20px 0 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.dlg-sec:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.campo {
  margin: 14px 0;
}

.campo label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

textarea {
  font: inherit;
  color: var(--ink);
  background: rgba(127,140,165,.07);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  width: 100%;
  min-height: 80px;
  resize: vertical;
  outline: none;
}

textarea:focus {
  border-color: var(--brass);
}

.ia-box {
  background: linear-gradient(160deg, color-mix(in srgb, var(--card-a) 85%, #2a1f4a), var(--card-b));
  border: 1px solid color-mix(in srgb, var(--line) 70%, #8b5cf6);
  border-radius: 12px;
  padding: 18px 20px;
  margin: 16px 0;
}

.ia-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}

.ia-head strong {
  font-size: 13.5px;
  color: #c4b5fd;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ia-desc {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
  margin-bottom: 12px;
}

.ia-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.wa-history-box {
  background: color-mix(in srgb, var(--card-a) 90%, #0d3826);
  border: 1px solid color-mix(in srgb, var(--line) 70%, #25D366);
  border-radius: 12px;
  padding: 14px 18px;
  margin: 14px 0;
}

/* Reglas de Validación */
.rcard {
  background: linear-gradient(160deg, var(--card-a), var(--card-b));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 14px;
  transition: border-color .2s, box-shadow .2s, opacity .2s;
}

.rcard:hover {
  border-color: var(--brass);
  box-shadow: var(--sh-1);
}

.rcard.inactiva {
  opacity: 0.6;
  border-style: dashed;
}

.rcard-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.rcard-param-box {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  background: rgba(127,140,165,.05);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 18px;
  margin-top: 12px;
}

.switch-toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--line);
  transition: .25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 26px;
  border: 1px solid var(--line);
}

.slider-toggle:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: .25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,0.45);
}

.switch-toggle input:checked + .slider-toggle {
  background-color: var(--green);
  border-color: var(--green);
}

.switch-toggle input:checked + .slider-toggle:before {
  transform: translateX(22px);
}

/* Dashboard Ejecutivo */
.dash-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.dash-card {
  background: linear-gradient(160deg, var(--card-a), var(--card-b));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: var(--sh-1);
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
  position: relative;
  overflow: hidden;
}

.dash-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-2);
}

/* Variantes con Degradado Premium para Dashboard KPI Cards */
.dash-card.dash-kpi-blue {
  border-color: rgba(79, 140, 255, 0.28);
  background: radial-gradient(280px 160px at 100% 0%, rgba(79, 140, 255, 0.12) 0%, transparent 70%),
              linear-gradient(160deg, var(--card-a), var(--card-b));
}
.dash-card.dash-kpi-purple {
  border-color: rgba(168, 85, 247, 0.28);
  background: radial-gradient(280px 160px at 100% 0%, rgba(168, 85, 247, 0.12) 0%, transparent 70%),
              linear-gradient(160deg, var(--card-a), var(--card-b));
}
.dash-card.dash-kpi-green {
  border-color: rgba(16, 185, 129, 0.32);
  background: radial-gradient(280px 160px at 100% 0%, rgba(16, 185, 129, 0.12) 0%, transparent 70%),
              linear-gradient(160deg, var(--card-a), var(--card-b));
}
.dash-card.dash-kpi-red {
  border-color: rgba(244, 63, 94, 0.32);
  background: radial-gradient(280px 160px at 100% 0%, rgba(244, 63, 94, 0.12) 0%, transparent 70%),
              linear-gradient(160deg, var(--card-a), var(--card-b));
}
.dash-card.dash-kpi-cyan {
  border-color: rgba(6, 182, 212, 0.28);
  background: radial-gradient(280px 160px at 100% 0%, rgba(6, 182, 212, 0.12) 0%, transparent 70%),
              linear-gradient(160deg, var(--card-a), var(--card-b));
}

.dash-card-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.dash-card-ttl {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dash-card-sub {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
}

.dash-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.dash-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.dash-chart-box {
  position: relative;
  width: 100%;
  height: 270px;
}

.dash-pill-group {
  display: inline-flex;
  gap: 4px;
  background: rgba(127,140,165,.08);
  border: 1px solid var(--line);
  padding: 3px;
  border-radius: 20px;
}

.dash-pill-btn {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 16px;
  cursor: pointer;
  transition: all .15s ease;
}

.dash-pill-btn.on {
  background: linear-gradient(145deg, var(--brass), var(--brass-2));
  color: #1a1308;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(210,174,123,0.4);
}

.dash-pill-btn:hover:not(.on) {
  color: var(--ink);
  background: var(--track);
}

.dash-prog-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}

.dash-prog-item:last-child {
  border-bottom: none;
}

.dash-prog-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.dash-prog-track {
  width: 100%;
  height: 6px;
  background: var(--track);
  border-radius: 4px;
  overflow: hidden;
}

.dash-prog-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .6s cubic-bezier(0.16, 1, 0.3, 1);
}

.pulse-live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(82,196,150,0.12);
  border: 1px solid rgba(82,196,150,0.3);
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
}

.pulse-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulseLiveDot 1.5s infinite;
}

@keyframes pulseLiveDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* ── 12. RESPONSIVE MOBILE ──────────────────────────────────────────────── */
@media (max-width: 960px) {
  .app, .app.collapsed {
    grid-template-columns: 1fr;
  }
  .side {
    position: fixed;
    left: 0;
    top: 0;
    width: 264px;
    transform: translateX(-100%);
    transition: transform .28s;
  }
  .app.open .side {
    transform: none;
  }
  .app.open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 15;
  }
  .kpis, .kpi-row {
    grid-template-columns: 1fr 1fr;
  }
  .content, .pane, #main {
    padding: 22px 16px;
  }
  .top, #hdr {
    padding: 0 16px;
  }
  .upd, .crumb {
    display: none;
  }
}

@media (max-width: 560px) {
  .kpis, .kpi-row {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
