/* ==========================================================================
   DARSR · Sistema de Gestión de Riesgos para Migración a AWS (TecnoNorte)
   Diseño SaaS de Ciberseguridad de Alta Fidelidad
   WCAG 2.1 AA / AAA · Responsive (>=360px) · Impresión PDF Técnica
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Variables de Diseño (Tokens) y Soporte de Temas
   -------------------------------------------------------------------------- */
:root {
  /* Paleta Base - Modo Claro Ejecutivo */
  --bg: #f8fafc;
  --bg-subtle: #f1f5f9;
  --panel: #ffffff;
  --panel-elevated: #ffffff;
  --panel-hover: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --text-dim: #526077;

  /* Identidad de Marca: Azul Tecnológico / AWS Azure */
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-ink: #ffffff;
  --brand-subtle: #eff6ff;
  --brand-border: #bfdbfe;
  --focus: #2563eb;
  --focus-ring: rgba(37, 99, 235, 0.25);

  /* Niveles de Riesgo ISO 27005 (WCAG AA Contraste >= 4.5:1) */
  --bajo: #059669;
  --bajo-bg: #ecfdf5;
  --bajo-border: #a7f3d0;
  --bajo-ink: #065f46;

  --medio: #d97706;
  --medio-bg: #fffbeb;
  --medio-border: #fde68a;
  --medio-ink: #78350f;

  --alto: #ea580c;
  --alto-bg: #fff7ed;
  --alto-border: #fed7aa;
  --alto-ink: #7c2d12;

  --critico: #dc2626;
  --critico-bg: #fef2f2;
  --critico-border: #fecaca;
  --critico-ink: #7f1d1d;

  /* Estados Funcionales */
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --ok-ink: #065f46;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-ink: #78350f;
  --info: #0284c7;
  --info-bg: #f0f9ff;
  --info-ink: #0369a1;

  /* Topología y Nodos */
  --node-bg: #ffffff;
  --node-line: #94a3b8;
  --node-text: #0f172a;
  --zone-bg: rgba(241, 245, 249, 0.85);
  --zone-line: #94a3b8;

  /* Sombras y Elevaciones */
  --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
  --shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
}

:root[data-theme="dark"] {
  /* Paleta Base - Modo Oscuro Cyber-SaaS (Deep Slate & Obsidian) */
  --bg: #0b101b;
  --bg-subtle: #101827;
  --panel: #151e32;
  --panel-elevated: #1a253e;
  --panel-hover: #1c2944;
  --line: #22314d;
  --line-strong: #2f4469;
  --text: #f8fafc;
  --muted: #94a3b8;
  --text-dim: #94a3b8;

  --brand: #3b82f6;
  --brand-hover: #60a5fa;
  --brand-ink: #071226;
  --brand-subtle: rgba(59, 130, 246, 0.15);
  --brand-border: rgba(96, 165, 250, 0.35);
  --focus: #60a5fa;
  --focus-ring: rgba(96, 165, 250, 0.3);

  /* Niveles de Riesgo Oscuro */
  --bajo: #10b981;
  --bajo-bg: rgba(16, 185, 129, 0.14);
  --bajo-border: rgba(16, 185, 129, 0.35);
  --bajo-ink: #34d399;

  --medio: #f59e0b;
  --medio-bg: rgba(245, 158, 11, 0.14);
  --medio-border: rgba(245, 158, 11, 0.35);
  --medio-ink: #fbbf24;

  --alto: #f97316;
  --alto-bg: rgba(249, 115, 22, 0.16);
  --alto-border: rgba(249, 115, 22, 0.4);
  --alto-ink: #fb923c;

  --critico: #ef4444;
  --critico-bg: rgba(239, 68, 68, 0.16);
  --critico-border: rgba(239, 68, 68, 0.42);
  --critico-ink: #f87171;

  --ok: #10b981;
  --ok-bg: rgba(16, 185, 129, 0.15);
  --ok-ink: #34d399;
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.15);
  --warn-ink: #fbbf24;
  --info: #38bdf8;
  --info-bg: rgba(56, 189, 248, 0.15);
  --info-ink: #7dd3fc;

  /* Topología y Nodos */
  --node-bg: #162238;
  --node-line: #3b4e70;
  --node-text: #f8fafc;
  --zone-bg: rgba(16, 24, 39, 0.65);
  --zone-line: #3b4e70;

  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  --shadow: 0 4px 8px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 20px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b101b;
    --bg-subtle: #101827;
    --panel: #151e32;
    --panel-elevated: #1a253e;
    --panel-hover: #1c2944;
    --line: #22314d;
    --line-strong: #2f4469;
    --text: #f8fafc;
    --muted: #94a3b8;
    --text-dim: #94a3b8;

    --brand: #3b82f6;
    --brand-hover: #60a5fa;
    --brand-ink: #071226;
    --brand-subtle: rgba(59, 130, 246, 0.15);
    --brand-border: rgba(96, 165, 250, 0.35);
    --focus: #60a5fa;
    --focus-ring: rgba(96, 165, 250, 0.3);

    --bajo: #10b981;
    --bajo-bg: rgba(16, 185, 129, 0.14);
    --bajo-border: rgba(16, 185, 129, 0.35);
    --bajo-ink: #34d399;

    --medio: #f59e0b;
    --medio-bg: rgba(245, 158, 11, 0.14);
    --medio-border: rgba(245, 158, 11, 0.35);
    --medio-ink: #fbbf24;

    --alto: #f97316;
    --alto-bg: rgba(249, 115, 22, 0.16);
    --alto-border: rgba(249, 115, 22, 0.4);
    --alto-ink: #fb923c;

    --critico: #ef4444;
    --critico-bg: rgba(239, 68, 68, 0.16);
    --critico-border: rgba(239, 68, 68, 0.42);
    --critico-ink: #f87171;

    --ok: #10b981;
    --ok-bg: rgba(16, 185, 129, 0.15);
    --ok-ink: #34d399;
    --warn: #f59e0b;
    --warn-bg: rgba(245, 158, 11, 0.15);
    --warn-ink: #fbbf24;
    --info: #38bdf8;
    --info-bg: rgba(56, 189, 248, 0.15);
    --info-ink: #7dd3fc;

    --node-bg: #162238;
    --node-line: #3b4e70;
    --node-text: #f8fafc;
    --zone-bg: rgba(16, 24, 39, 0.65);
    --zone-line: #3b4e70;

    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5);
    --shadow: 0 4px 8px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 20px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
  }
}

/* --------------------------------------------------------------------------
   2. Reseteo y Base Tipográfica
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Enlaces */
a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Código y Monospace */
code, pre, .mono {
  font-family: ui-monospace, "SF Mono", Monaco, "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.88em;
}

code {
  background: var(--bg-subtle);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
}

/* Foco Accesible */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   3. Cabecera Ejecutiva y Barra de Navegación (.top)
   -------------------------------------------------------------------------- */
header.top {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

@media (min-width: 1024px) {
  header.top {
    padding: 14px 28px;
  }
}

/* Fila Superior: Marca y Acciones */
.top-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 0;
}

.brand svg {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 9px;
  filter: drop-shadow(0 2px 4px rgba(37, 99, 235, 0.2));
  transition: transform 0.2s ease;
}

.brand:hover svg {
  transform: scale(1.04);
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin: 0;
  line-height: 1.2;
  color: var(--text);
  white-space: nowrap;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 9999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--brand-subtle);
  color: var(--brand);
  border: 1px solid var(--brand-border);
  white-space: nowrap;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Acciones Globales (Restablecer, JSON, Tema) */
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Barra de Navegación por Secciones */
.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 0 4px;
  width: 100%;
  max-width: 100%;
}

.nav::-webkit-scrollbar {
  display: none;
}

.nav a {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.nav a:hover {
  color: var(--text);
  background: var(--bg-subtle);
  text-decoration: none;
}

.nav a[aria-current="page"] {
  color: var(--brand-ink);
  background: var(--brand);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}

:root[data-theme="dark"] .nav a[aria-current="page"] {
  color: #ffffff;
  background: #2563eb;
}

/* --------------------------------------------------------------------------
   4. Botones del Sistema
   -------------------------------------------------------------------------- */
button,
.btn {
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.35;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-xs);
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.btn:hover {
  background: var(--panel-hover);
  border-color: var(--muted);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

button:active,
.btn:active {
  transform: translateY(0);
}

button.primary,
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}

button.primary:hover,
.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: #ffffff;
  box-shadow: 0 3px 6px rgba(37, 99, 235, 0.4);
}

button.danger {
  background: transparent;
  color: var(--critico-ink);
  border-color: var(--critico-border);
}

button.danger:hover {
  background: var(--critico-bg);
  border-color: var(--critico);
  color: var(--critico);
}

/* --------------------------------------------------------------------------
   5. Contenedor Principal y Tarjetas de Sección (.card)
   -------------------------------------------------------------------------- */
main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

@media (min-width: 1024px) {
  main {
    padding: 30px 28px 60px;
    gap: 26px;
  }
}

/* Encabezado del Módulo / Página */
.page-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 2px;
}

.page-meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  padding: 3px 10px;
  border-radius: 9999px;
  width: fit-content;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-dot.pulse {
  box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(37, 99, 235, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}

.page-title {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.25;
  margin: 0;
  color: var(--text);
}

.page-desc {
  font-size: 0.94rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
  max-width: 820px;
}

/* Tarjeta de Sección */
section.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  position: relative;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card-header {
  margin-bottom: 16px;
}

section.card > h2,
.card-header > h2 {
  margin: 0 0 8px 0;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 8px;
}

section.card > h3,
.cols2 h3,
.grid2 h3 {
  margin: 18px 0 10px 0;
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

p.note {
  margin: 0 0 14px 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.info-callout {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--info-bg);
  border: 1px solid rgba(2, 132, 199, 0.2);
  border-left: 3.5px solid var(--info);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 14px;
}

.info-callout p.note {
  margin: 0;
  color: var(--text);
  font-size: 0.83rem;
}

.callout-icon {
  font-size: 1rem;
  color: var(--info);
  line-height: 1.2;
}

/* Columnas y Grillas */
.cols2,
.grid2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  margin-top: 14px;
  min-width: 0;
  width: 100%;
}

@media (min-width: 900px) {
  .cols2,
  .grid2 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
  }
}

.cols2 > div,
.grid2 > div {
  min-width: 0;
  width: 100%;
}

/* --------------------------------------------------------------------------
   6. Tablero de Indicadores Clave (KPIs)
   -------------------------------------------------------------------------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 14px 0;
  min-width: 0;
  width: 100%;
}

.kpi {
  background: var(--panel-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 84px;
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
  min-width: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.kpi:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.kpi b {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.kpi span {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.3;
  margin-top: 6px;
}

/* Acentos Visuales de KPIs por Nivel de Riesgo */
.kpi.k-critico {
  border-left: 3.5px solid var(--critico);
}
.kpi.k-critico b {
  color: var(--critico-ink);
}

.kpi.k-alto {
  border-left: 3.5px solid var(--alto);
}
.kpi.k-alto b {
  color: var(--alto-ink);
}

.kpi.k-medio {
  border-left: 3.5px solid var(--medio);
}
.kpi.k-medio b {
  color: var(--medio-ink);
}

.kpi.k-bajo {
  border-left: 3.5px solid var(--bajo);
}
.kpi.k-bajo b {
  color: var(--bajo-ink);
}

/* --------------------------------------------------------------------------
   7. Matriz de Calor 5×5 (Probabilidad × Impacto)
   -------------------------------------------------------------------------- */
.heatwrap {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 14px 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

.axisY {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.heat {
  display: grid;
  grid-template-columns: 24px repeat(5, minmax(44px, 1fr));
  gap: 5px;
  min-width: 260px;
}

.heat .ax {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  padding: 2px;
}

.heat .hc {
  aspect-ratio: 1 / 0.85;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 4px 5px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 3px;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  cursor: default;
}

.heat .hc:hover {
  transform: scale(1.03);
  z-index: 5;
  box-shadow: var(--shadow);
  border-color: var(--line-strong);
}

/* Niveles de la Matriz */
.heat .hc.bajo {
  background: var(--bajo-bg);
  border-color: var(--bajo-border);
}
.heat .hc.medio {
  background: var(--medio-bg);
  border-color: var(--medio-border);
}
.heat .hc.alto {
  background: var(--alto-bg);
  border-color: var(--alto-border);
}
.heat .hc.critico {
  background: var(--critico-bg);
  border-color: var(--critico-border);
}

/* Valor R dentro de la Celda */
.heat .hc small {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.heat .hc.bajo small { color: var(--bajo-ink); }
.heat .hc.medio small { color: var(--medio-ink); }
.heat .hc.alto small { color: var(--alto-ink); }
.heat .hc.critico small { color: var(--critico-ink); }

/* Pastillas de Riesgo dentro de la Celda */
.heat .pill {
  font-family: ui-monospace, "SF Mono", Monaco, Consolas, monospace;
  font-size: 0.64rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  line-height: 1.25;
  white-space: nowrap;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line-strong);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

:root[data-theme="dark"] .heat .pill {
  background: #111827;
  color: #f1f5f9;
  border-color: rgba(255, 255, 255, 0.15);
}

/* Leyenda de la Matriz */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* --------------------------------------------------------------------------
   8. Etiquetas y Pastillas de Estado (.chip)
   -------------------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 9999px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1.3;
  border: 1px solid transparent;
}

.chip::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.chip.bajo {
  background: var(--bajo-bg);
  color: var(--bajo-ink);
  border-color: var(--bajo-border);
}

.chip.medio {
  background: var(--medio-bg);
  color: var(--medio-ink);
  border-color: var(--medio-border);
}

.chip.alto {
  background: var(--alto-bg);
  color: var(--alto-ink);
  border-color: var(--alto-border);
}

.chip.critico {
  background: var(--critico-bg);
  color: var(--critico-ink);
  border-color: var(--critico-border);
}

.chip.ok {
  background: var(--ok-bg);
  color: var(--ok-ink);
  border-color: var(--bajo-border);
}

.chip.warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-color: var(--medio-border);
}

.chip.info {
  background: var(--info-bg);
  color: var(--info-ink);
  border-color: rgba(2, 132, 199, 0.3);
}

/* --------------------------------------------------------------------------
   9. Tablas de Datos (.tablewrap, table)
   -------------------------------------------------------------------------- */
.tablewrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  margin: 12px 0;
  box-shadow: var(--shadow-xs);
  box-sizing: border-box;
  min-width: 0;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.83rem;
  line-height: 1.45;
  text-align: left;
}

thead th {
  background: var(--bg-subtle);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  user-select: none;
}

thead th.num {
  text-align: right;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: var(--panel-hover);
}

tbody td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

tbody td.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  font-style: italic;
}

tbody td small {
  display: block;
  font-size: 0.77rem;
  color: var(--muted);
  margin-top: 3px;
}

/* Botones de Acción dentro de Tablas */
.tbl-act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tbl-act button {
  padding: 3px 8px;
  font-size: 0.75rem;
}

/* --------------------------------------------------------------------------
   10. Formularios y Controles (.crud-grid, input, select, textarea)
   -------------------------------------------------------------------------- */
.crud-form {
  background: var(--panel-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 14px 0 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  width: 100%;
}

.crud-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
  width: 100%;
}

@media (min-width: 768px) {
  .crud-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 20px;
  }
}

.crud-grid > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.crud-grid > div.f-textarea,
.crud-grid > div.f-checks {
  grid-column: 1 / -1;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 4px;
}

label.req::after {
  content: "*";
  color: var(--critico);
  font-weight: bold;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

/* Casillas de Verificación en Formularios */
.checks {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
}

@media (min-width: 640px) {
  .checks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.checks label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.checks input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--brand);
}

/* Mensajes de Validación */
.msg {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--critico-bg);
  color: var(--critico-ink);
  border: 1px solid var(--critico-border);
  display: none;
}

.msg:not(:empty) {
  display: block;
}

.msg.ok {
  background: var(--ok-bg);
  color: var(--ok-ink);
  border-color: var(--bajo-border);
}

/* Barra de Herramientas CRUD */
.crudbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filebox {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0 16px;
}

/* --------------------------------------------------------------------------
   11. Diagramas SVG de Red y Nube (.topo)
   -------------------------------------------------------------------------- */
#topo, #svg {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0;
  min-width: 0;
}

svg.topo {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  background: var(--panel-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}

/* Zonas de Red */
.zona {
  fill: var(--zone-bg);
  stroke: var(--zone-line);
  stroke-width: 1.2;
  stroke-dasharray: 4 4;
}

.zt {
  fill: var(--muted);
  font-family: ui-monospace, monospace;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* Nodos y Equipos */
.tn rect {
  fill: var(--node-bg);
  stroke: var(--node-line);
  transition: stroke 0.15s ease, fill 0.15s ease;
}

.tn:hover rect {
  stroke: var(--brand);
}

.tn text {
  fill: var(--node-text);
  font-family: inherit;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Colores de Equipos por Rol */
.t-ext rect { stroke: #3b82f6; fill: rgba(59, 130, 246, 0.08); }
.t-rt rect  { stroke: #f59e0b; fill: rgba(245, 158, 11, 0.08); }
.t-sw rect  { stroke: #6366f1; fill: rgba(99, 102, 241, 0.08); }
.t-host rect{ stroke: #10b981; fill: rgba(16, 185, 129, 0.08); }
.t-fw rect  { stroke: #ef4444; fill: rgba(239, 68, 68, 0.08); }

/* Líneas de Conexión */
.tl {
  stroke: var(--line-strong);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tt {
  fill: var(--text-dim);
  font-family: ui-monospace, monospace;
  font-weight: 600;
}

.tw {
  fill: var(--critico);
  font-weight: 600;
}

/* Listas de Verificación y Listados */
ul.list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

ul.list li {
  padding: 8px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   12. Estilos de Impresión Técnica PDF (window.print · documento.html)
   -------------------------------------------------------------------------- */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm 12mm 14mm 12mm;
  }

  html, body {
    background: #ffffff !important;
    color: #0f172a !important;
    font-size: 8.5pt !important;
    line-height: 1.4 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Ocultar elementos de interfaz no imprimibles */
  header.top,
  .noprint,
  .crudbar,
  form.crud-form,
  button,
  .filebox,
  .theme-toggle-btn {
    display: none !important;
  }

  main {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
    display: block !important;
  }

  /* Portada del Documento Técnico */
  .cover {
    min-height: 240mm !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    text-align: center !important;
    page-break-after: always !important;
    break-after: page !important;
    background: #ffffff !important;
    border: 1.5pt solid #0f172a !important;
    border-radius: 8pt !important;
    padding: 40mm 20mm !important;
    box-shadow: none !important;
    margin: 0 0 20mm 0 !important;
  }

  .cover h2 {
    font-size: 22pt !important;
    font-weight: 800 !important;
    color: #0f172a !important;
    margin-bottom: 20pt !important;
    line-height: 1.2 !important;
    letter-spacing: -0.02em !important;
    border: none !important;
  }

  .cover p {
    font-size: 10pt !important;
    color: #334155 !important;
    margin: 6pt 0 !important;
    line-height: 1.5 !important;
  }

  /* Secciones Técnicas */
  section.card {
    background: #ffffff !important;
    border: none !important;
    border-bottom: 1pt solid #cbd5e1 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 0 14pt 0 !important;
    margin-bottom: 16pt !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
  }

  section.card h2 {
    font-size: 12pt !important;
    color: #0f172a !important;
    border-bottom: 1.5pt solid #2563eb !important;
    padding-bottom: 4pt !important;
    margin-top: 14pt !important;
    margin-bottom: 8pt !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  section.card h3 {
    font-size: 9.5pt !important;
    color: #1e293b !important;
    margin-top: 10pt !important;
    margin-bottom: 5pt !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  /* Evitar Cortes Huérfanos de Filas en Tablas */
  .tablewrap {
    border: none !important;
    box-shadow: none !important;
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
    margin: 6pt 0 10pt 0 !important;
  }

  table {
    width: 100% !important;
    max-width: 100% !important;
    table-layout: auto !important;
    font-size: 7.2pt !important;
    border-collapse: collapse !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
  }

  thead {
    display: table-header-group !important;
  }

  thead th {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border-top: 1pt solid #0f172a !important;
    border-bottom: 1.5pt solid #0f172a !important;
    border-left: none !important;
    border-right: none !important;
    font-weight: 700 !important;
    padding: 4pt 3pt !important;
  }

  tbody td {
    border-bottom: 0.5pt solid #cbd5e1 !important;
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    color: #1e293b !important;
    padding: 3.5pt 3pt !important;
    word-break: break-word !important;
    vertical-align: top !important;
  }

  tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Diagramas en Impresión */
  svg.topo {
    max-width: 100% !important;
    height: auto !important;
    background: #ffffff !important;
    border: 1pt solid #cbd5e1 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin: 8pt 0 !important;
  }

  .tn rect {
    fill: #ffffff !important;
    stroke: #334155 !important;
  }

  .tn text {
    fill: #0f172a !important;
  }

  /* Matriz de Calor en Impresión */
  .heatwrap {
    background: #ffffff !important;
    border: 1pt solid #cbd5e1 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    padding: 6pt !important;
    margin: 8pt 0 !important;
  }

  .heat {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* KPIs en Impresión */
  .kpis {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 6pt !important;
    margin: 6pt 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .kpi {
    background: #f8fafc !important;
    border: 0.5pt solid #cbd5e1 !important;
    padding: 6pt 8pt !important;
    min-height: 40pt !important;
    box-shadow: none !important;
  }

  .kpi b {
    font-size: 11pt !important;
    color: #0f172a !important;
  }

  .kpi span {
    font-size: 6.8pt !important;
  }

  /* Chips en Impresión */
  .chip {
    font-size: 6.8pt !important;
    padding: 1.5pt 3.5pt !important;
    border-radius: 2.5pt !important;
    border: 0.5pt solid !important;
  }

  .chip.critico { background: #fef2f2 !important; color: #991b1b !important; border-color: #fca5a5 !important; }
  .chip.alto    { background: #fff7ed !important; color: #9a3412 !important; border-color: #fdba74 !important; }
  .chip.medio   { background: #fffbeb !important; color: #92400e !important; border-color: #fcd34d !important; }
  .chip.bajo    { background: #ecfdf5 !important; color: #065f46 !important; border-color: #6ee7b7 !important; }
  .chip.ok      { background: #ecfdf5 !important; color: #065f46 !important; border-color: #6ee7b7 !important; }
  .chip.warn    { background: #fffbeb !important; color: #92400e !important; border-color: #fcd34d !important; }
  .chip.info    { background: #f0f9ff !important; color: #0369a1 !important; border-color: #7dd3fc !important; }
}

/* --------------------------------------------------------------------------
   13. Adaptabilidad Responsiva para Pantallas Pequeñas (Mobile >= 360px)
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  header.top {
    padding: 10px 12px;
    gap: 8px;
    width: 100%;
    max-width: 100%;
  }

  .top-header-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
  }

  .brand {
    width: 100%;
    justify-content: flex-start;
  }

  .brand h1 {
    font-size: 1.15rem;
  }

  .brand svg {
    width: 34px;
    height: 34px;
  }

  .actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .actions button {
    width: 100%;
    font-size: 0.76rem;
    padding: 7px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    justify-content: center;
  }

  main {
    padding: 14px 10px 32px;
    gap: 14px;
    width: 100%;
    max-width: 100%;
  }

  .page-title {
    font-size: 1.35rem;
  }

  .page-desc {
    font-size: 0.84rem;
  }

  section.card {
    padding: 14px 12px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 100%;
  }

  section.card > h2,
  .card-header > h2 {
    font-size: 1.05rem;
  }

  .kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .kpi {
    padding: 10px 12px;
    min-height: 72px;
  }

  .kpi b {
    font-size: 1.35rem;
  }

  .kpi span {
    font-size: 0.72rem;
    margin-top: 4px;
  }

  .heatwrap {
    padding: 10px 6px;
    width: 100%;
    max-width: 100%;
  }

  .heat {
    gap: 3px;
    grid-template-columns: 20px repeat(5, minmax(36px, 1fr));
    min-width: 215px;
  }

  .heat .hc {
    min-height: 40px;
    padding: 2px 3px;
  }

  .heat .pill {
    font-size: 0.6rem;
    padding: 1px 3px;
  }

  thead th, tbody td {
    padding: 8px 10px;
    font-size: 0.78rem;
  }

  #topo, #svg {
    overflow-x: auto;
    padding-bottom: 6px;
    width: 100%;
    max-width: 100%;
  }

  svg.topo {
    min-width: 520px;
  }
}

/* ===== Correcciones de revisión ===== */
/* El formulario oculto del CRUD no debe mostrarse como barra vacía */
.crud-form[hidden] { display: none; }
/* Los identificadores (R-GN-01, A-01, V-01...) no se parten en varias líneas */
tbody td:first-child, thead th:first-child { white-space: nowrap; }
/* Mapa de calor: la celda crece según los riesgos que contiene */
.heat .hc { aspect-ratio: auto; min-height: 64px; overflow: visible; }
/* Diagramas: líneas y etiquetas con más contraste */
.tl { stroke: var(--text-dim); stroke-width: 2; opacity: .85; }
.tt { fill: var(--text); font-size: 10.5px; paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
.zt { fill: var(--text-dim); }
/* Insignias e ícono de aviso con contraste AA */
.brand-badge, .page-meta-badge { color: #1e40af; }
:root[data-theme="dark"] .brand-badge, :root[data-theme="dark"] .page-meta-badge { color: #93c5fd; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-badge, :root:not([data-theme="light"]) .page-meta-badge { color: #93c5fd; }
}
.callout-icon { color: var(--text); }

/* Diagrama on premise editable */
.topo.edit .tn { cursor: grab; }
.topo.edit .tn.drag { cursor: grabbing; }
.topo.edit .tn:focus-visible rect { stroke: var(--brand); stroke-width: 3; }
.topo.edit .tn:focus { outline: none; }
.topo-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 6px 0 10px; }
@media print { .topo-tools { display: none; } }
