/* ==========================================================================
   AndesShield 2.0 — Tema Híbrido Bootstrap 5.3.9 + Identidad Clásica AndesShield
   Rust (Axum 0.8 + PostgreSQL 18) + Cloudflare Pages • Grupo 7 (TecnoNorte)
   ========================================================================== */

:root,
[data-bs-theme="light"] {
  --as-bg-app: #f1f5f9;
  --as-surface: #ffffff;
  --as-surface-2: #f8fafc;
  --as-border: #cbd5e1;
  --as-border-subtle: #e2e8f0;
  --as-accent: #0284c7;
  --as-accent-hover: #0369a1;
  --as-accent-soft: rgba(2, 132, 199, 0.12);

  /* Escala oficial de riesgo PAUTA EVA 3+4 */
  --risk-low: #16a34a;
  --risk-low-bg: rgba(22, 163, 74, 0.14);
  --risk-low-cell: #dcfce7;
  --risk-low-text: #14532d;

  --risk-med: #ca8a04;
  --risk-med-bg: rgba(234, 179, 8, 0.18);
  --risk-med-cell: #fef9c3;
  --risk-med-text: #713f12;

  --risk-high: #ea580c;
  --risk-high-bg: rgba(249, 115, 22, 0.18);
  --risk-high-cell: #ffedd5;
  --risk-high-text: #7c2d12;

  --risk-crit: #dc2626;
  --risk-crit-bg: rgba(220, 38, 38, 0.16);
  --risk-crit-cell: #fee2e2;
  --risk-crit-text: #7f1d1d;

  --as-nav-text: #1e293b;
  --bs-body-bg: var(--as-bg-app);
  --bs-body-color: #0f172a;
  --bs-secondary-color: #475569;
  --bs-tertiary-bg: var(--as-surface-2);
  --bs-border-color: var(--as-border);
  --bs-card-bg: var(--as-surface);
  --bs-modal-bg: var(--as-surface);
  --bs-primary: #0284c7;
  --bs-primary-rgb: 2, 132, 199;
}

[data-bs-theme="dark"] {
  --as-bg-app: #0b1120;
  --as-surface: #111827;
  --as-surface-2: #1e293b;
  --as-border: #334155;
  --as-border-subtle: #1f2937;
  --as-accent: #38bdf8;
  --as-accent-hover: #0ea5e9;
  --as-accent-soft: rgba(56, 189, 248, 0.14);

  --risk-low: #22c55e;
  --risk-low-bg: rgba(34, 197, 94, 0.18);
  --risk-low-cell: rgba(22, 163, 74, 0.28);
  --risk-low-text: #86efac;

  --risk-med: #facc15;
  --risk-med-bg: rgba(250, 204, 21, 0.18);
  --risk-med-cell: rgba(202, 138, 4, 0.32);
  --risk-med-text: #fef08a;

  --risk-high: #fb923c;
  --risk-high-bg: rgba(249, 115, 22, 0.22);
  --risk-high-cell: rgba(234, 88, 12, 0.36);
  --risk-high-text: #fed7aa;

  --risk-crit: #f87171;
  --risk-crit-bg: rgba(239, 68, 68, 0.22);
  --risk-crit-cell: rgba(220, 38, 38, 0.42);
  --risk-crit-text: #fecaca;

  --as-nav-text: #cbd5e1;
  --bs-body-bg: var(--as-bg-app);
  --bs-body-color: #f8fafc;
  --bs-secondary-color: #94a3b8;
  --bs-tertiary-bg: var(--as-surface-2);
  --bs-border-color: var(--as-border);
  --bs-card-bg: var(--as-surface);
  --bs-modal-bg: var(--as-surface);
  --bs-dropdown-bg: var(--as-surface);
  --bs-table-bg: transparent;
  --bs-table-hover-bg: rgba(56, 189, 248, 0.06);
  --bs-primary: #0ea5e9;
  --bs-primary-rgb: 14, 165, 233;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background-color: var(--as-bg-app);
  min-height: 100vh;
}

/* ==================== APP SHELL & SIDEBAR ==================== */
.as-shell {
  display: flex;
  min-height: 100vh;
}

.as-sidebar {
  width: 274px;
  min-width: 274px;
  flex-shrink: 0;
  background: var(--as-surface);
  border-right: 1px solid var(--as-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1020;
  transition: width 0.24s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.24s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.2s ease,
              border-color 0.2s ease;
}

.as-sidebar > * {
  min-width: 274px;
}

.as-shell.as-sidebar-collapsed .as-sidebar {
  width: 0;
  min-width: 0;
  opacity: 0;
  border-right-color: transparent;
  pointer-events: none;
}

.as-sidebar-toggle {
  width: 34px;
  height: 34px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  border: 1px solid var(--as-border);
  background: var(--as-surface-2);
  color: var(--as-nav-text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
}

.as-sidebar-toggle:hover {
  background: var(--as-accent-soft);
  border-color: rgba(56, 189, 248, 0.45);
  color: var(--as-accent);
}

.as-sidebar-toggle:active {
  transform: scale(0.95);
}

.as-sidebar-toggle-icon {
  width: 18px;
  height: 18px;
}

.as-sidebar-toggle-pane {
  opacity: 0.34;
  transition: opacity 0.18s ease;
}

.as-shell.as-sidebar-collapsed .as-sidebar-toggle-pane {
  opacity: 0;
}

.as-shell.as-sidebar-collapsed .as-sidebar-toggle {
  border-color: rgba(56, 189, 248, 0.38);
  color: var(--as-accent);
}

.as-topbar-mini-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

@media (min-width: 992px) {
  .as-shell.as-sidebar-collapsed .as-topbar-mini-brand {
    display: inline-flex !important;
  }
}

.table code {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.as-brand {
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid var(--as-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.as-brand-logo {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.as-brand-tag {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.14rem 0.48rem;
  border-radius: 999px;
  background: var(--as-accent-soft);
  color: var(--as-accent);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.as-nav-section-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--bs-secondary-color);
  padding: 0.75rem 0.75rem 0.25rem;
}

.as-nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.52rem 0.75rem;
  border-radius: 0.55rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--as-nav-text);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  transition: all 0.15s ease;
}

.as-nav-btn:hover {
  background: var(--as-surface-2);
  color: var(--bs-body-color);
}

.as-nav-btn.active {
  background: var(--as-accent-soft);
  color: var(--as-accent);
  border-color: rgba(56, 189, 248, 0.32);
  opacity: 1;
}

.as-nav-btn i {
  font-size: 0.98rem;
  width: 1.2rem;
  text-align: center;
}

.as-topbar {
  position: sticky;
  top: 0;
  z-index: 1015;
  background: var(--as-surface);
  border-bottom: 1px solid var(--as-border);
  backdrop-filter: blur(8px);
}

.as-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.as-card {
  background: var(--as-surface);
  border: 1px solid var(--as-border);
  border-radius: 0.85rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.as-card > .card-header {
  background: transparent;
  border-bottom: 1px solid var(--as-border-subtle);
  padding: 0.9rem 1.15rem;
}

/* ==================== KPI CARDS (ESTILO CLÁSICO ANDESSHIELD) ==================== */
.as-kpi {
  background: var(--as-surface);
  border: 1px solid var(--as-border);
  border-radius: 0.85rem;
  padding: 1rem 1.1rem;
  height: 100%;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.as-kpi:hover {
  transform: translateY(-2px);
  border-color: var(--as-accent);
}

.as-kpi-crit { border-left: 4px solid var(--risk-crit); }
.as-kpi-high { border-left: 4px solid var(--risk-high); }
.as-kpi-med  { border-left: 4px solid var(--risk-med); }
.as-kpi-low  { border-left: 4px solid var(--risk-low); }
.as-kpi-info { border-left: 4px solid var(--as-accent); }

.as-kpi-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
}

.as-kpi-value {
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1.18;
  margin: 0.18rem 0;
}

/* ==================== RISK BADGES & CHIPS ==================== */
.as-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.22rem 0.56rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.as-badge-crit { background: var(--risk-crit-bg); color: var(--risk-crit); border: 1px solid rgba(220,38,38,0.32); }
.as-badge-high { background: var(--risk-high-bg); color: var(--risk-high); border: 1px solid rgba(234,88,12,0.32); }
.as-badge-med  { background: var(--risk-med-bg);  color: var(--risk-med);  border: 1px solid rgba(202,138,4,0.32); }
.as-badge-low  { background: var(--risk-low-bg);  color: var(--risk-low);  border: 1px solid rgba(22,163,74,0.32); }
.as-badge-info { background: var(--as-accent-soft); color: var(--as-accent); border: 1px solid rgba(56,189,248,0.32); }

.code-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.14rem 0.44rem;
  border-radius: 0.4rem;
  background: var(--as-surface-2);
  border: 1px solid var(--as-border);
  white-space: nowrap;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

/* ==================== ENGINE STATUS PILL (CLÁSICO HÍBRIDO) ==================== */
.as-engine-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.26rem 0.68rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  background: var(--as-surface-2);
  border: 1px solid var(--as-border);
}

.as-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.as-dot-rust  { background: #22c55e; box-shadow: 0 0 8px rgba(34, 197, 94, 0.7); }
.as-dot-local { background: #38bdf8; box-shadow: 0 0 8px rgba(56, 189, 248, 0.65); }

/* ==================== HEATMAP 5x5 ==================== */
.heatmap-dual {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(305px, 1fr));
  gap: 1.15rem;
}

.heatmap-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 4px;
  table-layout: fixed;
}

.heatmap-table th {
  font-size: 0.72rem;
  color: var(--bs-secondary-color);
  font-weight: 700;
  padding: 0.22rem;
  text-align: center;
}

.hm-cell {
  height: 60px;
  border-radius: 0.5rem;
  padding: 0.28rem;
  text-align: center;
  vertical-align: middle;
  border: 1px solid rgba(148, 163, 184, 0.22);
}

.hm-low  { background: var(--risk-low-cell);  color: var(--risk-low-text); }
.hm-med  { background: var(--risk-med-cell);  color: var(--risk-med-text); }
.hm-high { background: var(--risk-high-cell); color: var(--risk-high-text); }
.hm-crit { background: var(--risk-crit-cell); color: var(--risk-crit-text); }

.hm-score {
  font-size: 0.69rem;
  font-weight: 700;
  opacity: 0.75;
  display: block;
}

.hm-codes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  margin-top: 2px;
}

.hm-chip {
  font-size: 0.63rem;
  font-weight: 800;
  padding: 0.05rem 0.28rem;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.24);
  color: inherit;
}

/* ==================== CLASSIC DONUT CHART SVG ==================== */
.donut-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.donut-svg {
  width: 156px;
  height: 156px;
  flex-shrink: 0;
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
  min-width: 150px;
}

.donut-legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  font-size: 0.8rem;
}

.donut-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

/* ==================== TABLES & ARCHITECTURE SVG ==================== */
.as-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
  background: var(--as-surface-2) !important;
  white-space: nowrap;
}

.as-table td {
  font-size: 0.82rem;
}

.arch-svg-wrap {
  background: var(--as-surface-2);
  border: 1px solid var(--as-border);
  border-radius: 0.7rem;
  padding: 0.75rem;
  overflow-x: auto;
}

.arch-svg-wrap svg {
  width: 100%;
  height: auto;
  min-width: 640px;
  display: block;
}

/* ==================== TECHNICAL PDF DOCUMENT (SECCIONES 0-9) ==================== */
.pdf-doc {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  border-radius: 0.85rem;
  padding: 2rem 2.2rem;
  font-size: 0.88rem;
  line-height: 1.55;
}

.pdf-cover {
  border: 2px solid #0f172a;
  border-top: 10px solid #0284c7;
  padding: 1.8rem;
  margin-bottom: 1.8rem;
  background: #f8fafc;
}

.pdf-cover h1 {
  margin: 0.4rem 0 0.6rem;
  font-size: 1.58rem;
  color: #0f172a;
}

.pdf-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 1.2rem;
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px solid #cbd5e1;
  font-size: 0.83rem;
}

.pdf-section {
  margin-top: 1.7rem;
  padding-top: 0.95rem;
  border-top: 2px solid #e2e8f0;
}

.pdf-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.12rem;
  color: #0369a1;
  border-left: 4px solid #0284c7;
  padding-left: 0.6rem;
}

.pdf-section h3 {
  margin: 0.95rem 0 0.45rem;
  font-size: 0.95rem;
  color: #0f172a;
}

.pdf-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0 1rem;
  font-size: 0.76rem;
}

.pdf-table th,
.pdf-table td {
  border: 1px solid #cbd5e1;
  padding: 0.42rem 0.5rem;
  text-align: left;
  vertical-align: top;
  color: #0f172a;
}

.pdf-table th {
  background: #f1f5f9;
  font-weight: 700;
}

.pdf-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
  margin: 0.8rem 0;
}

.pdf-kpi-box {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.6rem;
  background: #f8fafc;
}

.pdf-kpi-box strong {
  display: block;
  font-size: 1.22rem;
  color: #0f172a;
}

.pdf-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.72rem;
}

.pdf-badge-crit { background: #fee2e2; color: #991b1b; }
.pdf-badge-high { background: #ffedd5; color: #9a3412; }
.pdf-badge-med  { background: #fef9c3; color: #854d0e; }
.pdf-badge-low  { background: #dcfce7; color: #166534; }

.print-only-container {
  display: none;
}

/* ==================== PRINT / PDF ==================== */
@page {
  size: A4 portrait;
  margin: 14mm 12mm;
}

@media print {
  html, body {
    background: #ffffff !important;
    color: #0f172a !important;
  }
  .as-shell, .modal, .modal-backdrop, .offcanvas, .toast-container, .no-print {
    display: none !important;
  }
  .print-only-container {
    display: block !important;
  }
  .pdf-doc {
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
  }
  .pdf-page-break {
    page-break-before: always;
    break-before: page;
  }
  .pdf-table { page-break-inside: auto; }
  .pdf-table tr { page-break-inside: avoid; break-inside: avoid; }
  .pdf-table thead { display: table-header-group; }
  .hm-cell, .pdf-badge, .pdf-cover, .pdf-table th, .pdf-kpi-box {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
