/* ==========================================================================
   Threat Manager — Design System
   Light & Dark mode, accessible contrast, consistent spacing & typography
   ========================================================================== */

/* ----- Typography ----- */
:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
}

/* ----- Spacing (4px base) ----- */
:root {
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;   /* 24px */
  --space-8: 2rem;     /* 32px */
  --space-10: 2.5rem;
  --space-12: 3rem;
}

/* ----- Radii ----- */
:root {
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;
}

/* ----- Transitions ----- */
:root {
  --ease-out: cubic-bezier(0.33, 1, 0.68, 1);
  --duration-fast: 150ms;
  --duration-normal: 220ms;
  --duration-slow: 320ms;
}

/* ----- Shadows ----- */
:root {
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
  --shadow-focus: 0 0 0 3px rgba(14, 165, 233, 0.35);
}

/* ==========================================================================
   LIGHT THEME (default)
   ========================================================================== */
:root,
[data-theme="light"] {
  --tm-bg: #f1f5f9;
  --tm-bg-elevated: #ffffff;
  --tm-bg-overlay: #ffffff;
  --tm-border: #e2e8f0;
  --tm-border-strong: #cbd5e1;
  --tm-text: #0f172a;
  --tm-text-muted: #475569;
  --tm-text-subtle: #64748b;
  --tm-primary: #0284c7;
  --tm-primary-hover: #0369a1;
  --tm-primary-muted: rgba(2, 132, 199, 0.12);
  --tm-accent: #0ea5e9;
  --tm-table-bg: #f8fafc;
  --tm-table-hover: rgba(2, 132, 199, 0.06);
  --tm-input-bg: #ffffff;
  --tm-input-border: #e2e8f0;
  --tm-focus-ring: rgba(2, 132, 199, 0.4);
  --tm-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --tm-shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --tm-shadow-lg: 0 10px 28px rgba(0, 0, 0, 0.1);
  --tm-notification-dot: #dc2626;
}

/* ==========================================================================
   DARK THEME
   ========================================================================== */
[data-theme="dark"] {
  --tm-bg: #0f172a;
  --tm-bg-elevated: #1e293b;
  --tm-bg-overlay: #334155;
  --tm-border: #334155;
  --tm-border-strong: #475569;
  --tm-text: #f1f5f9;
  --tm-text-muted: #cbd5e1;
  --tm-text-subtle: #94a3b8;
  --tm-primary: #38bdf8;
  --tm-primary-hover: #7dd3fc;
  --tm-primary-muted: rgba(56, 189, 248, 0.18);
  --tm-accent: #0ea5e9;
  --tm-table-bg: rgba(30, 41, 59, 0.6);
  --tm-table-hover: rgba(56, 189, 248, 0.12);
  --tm-input-bg: #1e293b;
  --tm-input-border: #334155;
  --tm-focus-ring: rgba(56, 189, 248, 0.45);
  --tm-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --tm-shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --tm-shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);
  --tm-notification-dot: #f87171;
}

/* Legacy aliases for templates still using --em-* */
:root, [data-theme="light"], [data-theme="dark"] {
  --em-bg: var(--tm-bg);
  --em-bg-card: var(--tm-bg-elevated);
  --em-border: var(--tm-border);
  --em-text: var(--tm-text);
  --em-text-muted: var(--tm-text-muted);
  --em-primary: var(--tm-primary);
}

/* ----- Base ----- */
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--tm-text);
  background: var(--tm-bg);
  margin: 0;
  min-height: 100vh;
  transition: background-color var(--duration-normal) var(--ease-out), color var(--duration-normal) var(--ease-out);
}

/* ----- Layout ----- */
.app-body { display: flex; flex-direction: column; min-height: 100vh; margin: 0; }
.app-body > .app-header { flex-shrink: 0; }
.app-body > .app-footer { flex-shrink: 0; }
.app-wrapper {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.app-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.app-content {
  flex: 0 0 auto;
  padding: var(--space-6) var(--space-6) var(--space-8);
  color: var(--tm-text);
  transition: color var(--duration-normal) var(--ease-out);
}

/* Contenedor unificado para secciones (Dashboard, Activos, Identidades, Eventos, Administración) */
.section-container {
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

/* Cabecera compacta de sección (Activos, Identidades) */
.section-header-compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.section-header-compact .section-title-wrap {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.section-header-compact .section-title { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--tm-text); margin: 0; }
.section-header-compact .section-subtitle { font-size: var(--text-sm); color: var(--tm-text-muted); margin: 0; }
.section-header-compact .section-filter { display: flex; align-items: center; gap: var(--space-2); }
.section-header-compact .section-filter .form-select-modern { min-width: 180px; }

/* Barra de indicadores (KPI + gráficos) — altura fija, gráficos pequeños */
.section-indicators-bar {
  display: grid;
  grid-template-columns: 220px 280px 1fr;
  gap: var(--space-4);
  align-items: stretch;
  margin-bottom: var(--space-4);
  height: 100px;
  max-height: 100px;
}
.section-indicators-bar-4 { grid-template-columns: 220px 200px 200px 1fr; }
.section-indicators-bar-5 { grid-template-columns: 220px 180px 180px 180px 1fr; }
@media (max-width: 991.98px) {
  .section-indicators-bar { grid-template-columns: 1fr; height: auto; max-height: none; }
  .section-indicators-bar-4 { grid-template-columns: 1fr; }
  .section-indicators-bar-5 { grid-template-columns: 1fr; }
}
.section-indicators-bar .indicator-kpi {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  background: var(--tm-bg-elevated);
  border: 1px solid var(--tm-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--tm-shadow-sm);
}
.section-indicators-bar .indicator-kpi .kpi-value { font-size: 2rem; font-weight: var(--font-bold); color: var(--tm-primary); line-height: 1.2; }
.section-indicators-bar .indicator-kpi .kpi-label { font-size: 0.7rem; color: var(--tm-text-muted); margin-top: 0; text-align: center; }
.section-indicators-bar .chart-wrap {
  padding: var(--space-1);
  background: var(--tm-bg-elevated);
  border: 1px solid var(--tm-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--tm-shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
/* Tercera tarjeta (gráfico de barras): ocupa todo el espacio disponible */
.section-indicators-bar .chart-wrap.chart-wrap-bar {
  min-width: 0;
}
.section-indicators-bar .chart-wrap.chart-wrap-bar .chart-inner {
  flex: 1;
  min-height: 0;
  height: 72px;
  max-height: 72px;
}
.section-indicators-bar .chart-wrap .chart-title { font-size: 0.6rem; font-weight: var(--font-semibold); color: var(--tm-text-muted); margin-bottom: 0; text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0; }
.section-indicators-bar .chart-wrap .chart-inner {
  flex: 1;
  min-height: 0;
  height: 72px;
  max-height: 72px;
  position: relative;
}
.section-indicators-bar .chart-wrap .chart-inner canvas {
  max-height: 72px !important;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.app-header {
  background: var(--tm-bg-elevated);
  border-bottom: 1px solid var(--tm-border);
  padding: var(--space-2) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  transition: background-color var(--duration-normal) var(--ease-out), border-color var(--duration-normal) var(--ease-out);
  box-shadow: var(--tm-shadow-sm);
}
.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--tm-text);
  font-weight: var(--font-bold);
  font-size: var(--text-lg);
  transition: color var(--duration-fast) var(--ease-out), opacity var(--duration-fast) var(--ease-out);
}
.header-brand:hover { color: var(--tm-primary); }
.header-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--tm-primary);
  color: var(--tm-bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}
[data-theme="dark"] .header-brand-icon { color: #0f172a; }

.header-search-wrap {
  flex: 1;
  min-width: 200px;
  max-width: 420px;
}
.header-search {
  width: 100%;
  padding: var(--space-2) var(--space-4);
  padding-left: 2.5rem;
  font-size: var(--text-sm);
  color: var(--tm-text);
  background: var(--tm-input-bg);
  border: 1px solid var(--tm-input-border);
  border-radius: var(--radius-full);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.header-search::placeholder { color: var(--tm-text-subtle); }
.header-search:focus {
  border-color: var(--tm-primary);
  box-shadow: 0 0 0 3px var(--tm-primary-muted);
}
.header-search-icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--tm-text-subtle);
  pointer-events: none;
  font-size: var(--text-sm);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.header-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--tm-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}
.header-btn:hover {
  background: var(--tm-primary-muted);
  color: var(--tm-primary);
}
.header-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--tm-focus-ring);
}
.header-btn-icon { font-size: 1.15rem; }
.header-btn-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: var(--font-bold);
  line-height: 16px;
  text-align: center;
  color: #fff;
  background: var(--tm-notification-dot);
  border-radius: var(--radius-full);
}

.header-profile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2);
  padding-right: var(--space-3);
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--tm-text);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  transition: background-color var(--duration-fast) var(--ease-out);
}
.header-profile:hover { background: var(--tm-primary-muted); }
.header-profile-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--tm-primary-muted);
  color: var(--tm-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.header-profile-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-profile-caret { color: var(--tm-text-subtle); font-size: 0.65rem; transition: transform var(--duration-fast) var(--ease-out); }
.header-profile[aria-expanded="true"] .header-profile-caret { transform: rotate(180deg); }

/* Dropdowns in header */
.header-dropdown .dropdown-menu {
  margin-top: var(--space-2);
  padding: var(--space-2);
  min-width: 220px;
  background: var(--tm-bg-overlay);
  border: 1px solid var(--tm-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--tm-shadow-lg);
  transition: opacity var(--duration-fast) var(--ease-out);
}
.header-dropdown .dropdown-item {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--tm-text);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: background-color var(--duration-fast) var(--ease-out);
}
.header-dropdown .dropdown-item:hover { background: var(--tm-primary-muted); color: var(--tm-primary); }
.header-dropdown .dropdown-divider { border-color: var(--tm-border); margin: var(--space-2) 0; }
.notification-item {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--tm-text-muted);
  border-bottom: 1px solid var(--tm-border);
  transition: background-color var(--duration-fast) var(--ease-out);
}
.notification-item:last-child { border-bottom: none; }
.notification-item:hover { background: var(--tm-primary-muted); }
.notification-empty { padding: var(--space-6); text-align: center; color: var(--tm-text-subtle); font-size: var(--text-sm); }
.header-dropdown .dropdown-menu .border-bottom { border-color: var(--tm-border) !important; }

/* ==========================================================================
   HEADER MAIN NAV (enlaces principales en barra superior)
   ========================================================================== */
.header-main-nav {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}
.header-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}
.header-nav-item { margin: 0; }
.header-nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  color: var(--tm-text-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  white-space: nowrap;
  border-radius: 0;
  background: transparent;
  transition: color var(--duration-fast) var(--ease-out), font-weight var(--duration-fast) var(--ease-out);
}
.header-nav-link:hover {
  color: var(--tm-text);
  background: transparent;
}
.header-nav-link.active {
  color: var(--tm-primary);
  font-weight: var(--font-bold);
  background: transparent;
  box-shadow: none;
}
.header-nav-link.active .header-nav-icon {
  color: var(--tm-primary);
  opacity: 1;
}
.header-nav-icon {
  font-size: 1rem;
  opacity: 0.75;
  transition: color var(--duration-fast) var(--ease-out), opacity var(--duration-fast) var(--ease-out);
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.app-footer {
  flex-shrink: 0;
  width: 100%;
  background: var(--tm-bg-elevated);
  border-top: 1px solid var(--tm-border);
  padding: var(--space-3) var(--space-5);
  transition: background-color var(--duration-normal) var(--ease-out), border-color var(--duration-normal) var(--ease-out);
}
.app-footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--tm-text-subtle);
}
.app-footer-sep { opacity: 0.6; }
.app-footer-tagline { font-weight: var(--font-medium); }

/* ==========================================================================
   CARDS & SURFACES
   ========================================================================== */
.card {
  background: var(--tm-bg-elevated);
  border: 1px solid var(--tm-border);
  border-radius: var(--radius-lg);
  color: var(--tm-text);
  box-shadow: var(--tm-shadow-sm);
  transition: box-shadow var(--duration-normal) var(--ease-out), border-color var(--duration-normal) var(--ease-out), background-color var(--duration-normal) var(--ease-out);
}
.card:hover { box-shadow: var(--tm-shadow-md); }
/* Light theme: tarjetas con hover acorde a tablas (excl. gráficos para no afectar canvas) */
[data-theme="light"] .app-content .card:not(.chart-card):hover,
body:not([data-theme="dark"]) .app-content .card:not(.chart-card):hover {
  background: #fffbeb;
  border-color: rgba(2, 132, 199, 0.4);
  box-shadow: 0 0 0 1px rgba(2, 132, 199, 0.28), var(--tm-shadow-md);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--tm-border);
  color: var(--tm-text);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  padding: var(--space-4);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.card-body { padding: var(--space-4); }

.integration-card {
  border-radius: var(--radius-lg);
  min-height: 12rem;
}
.integration-card .card-body {
  padding: 0.625rem 0.875rem;
  flex: 1 1 auto;
}
.integration-card .card-title {
  font-size: 1rem;
  line-height: 1.25;
}
.integration-card .card-text {
  margin-bottom: 0;
  margin-top: 0.2rem;
  line-height: 1.35;
  font-size: 0.8125rem;
}
.integration-card .integration-logo {
  padding: 0.45rem !important;
}
.integration-card .integration-logo .fa-2x {
  font-size: 1.35em;
  line-height: 1;
  vertical-align: -0.05em;
}
.integration-card .form-label {
  margin-bottom: 0.15rem;
}
.integration-card .form-control-sm {
  margin-bottom: 0.35rem;
}
.integration-card pre.small {
  padding: 0.35rem 0.5rem !important;
  line-height: 1.35;
  margin-bottom: 0;
}
.integration-card-soon { opacity: 0.85; }
.integration-card-soon .card-title { color: var(--tm-text-muted); }

/* Logos con colores de marca */
.integration-logo-whatsapp {
  background: #25d366;
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 211, 102, 0.35);
}
.integration-logo-checkpoint {
  background: linear-gradient(135deg, #00a651 0%, #008c44 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 166, 81, 0.3);
}
.integration-logo-azure {
  background: linear-gradient(135deg, #0078d4 0%, #005a9e 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 120, 212, 0.35);
}
.integration-logo-aws {
  background: linear-gradient(135deg, #ff9900 0%, #ea8600 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255, 153, 0, 0.35);
}
.integration-logo-gcp {
  background: linear-gradient(135deg, #4285f4 0%, #3367d6 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(66, 133, 244, 0.35);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn-primary,
.btn-primary-modern {
  background: var(--tm-primary);
  border: none;
  color: #fff;
  font-weight: var(--font-medium);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  transition: background-color var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}
.btn-primary:hover,
.btn-primary-modern:hover {
  background: var(--tm-primary-hover);
  color: #fff;
}
[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .btn-primary-modern:hover { background: var(--tm-primary-hover); color: #0f172a; }
.btn-outline-primary {
  border: 1px solid var(--tm-primary);
  color: var(--tm-primary);
  background: transparent;
  border-radius: var(--radius-md);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.btn-outline-primary:hover { background: var(--tm-primary-muted); color: var(--tm-primary); }
.btn-outline-secondary {
  border: 1px solid var(--tm-border-strong);
  color: var(--tm-text-muted);
  background: transparent;
  border-radius: var(--radius-md);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.btn-outline-secondary:hover { background: var(--tm-border); color: var(--tm-text); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.text-primary { color: var(--tm-primary) !important; }
.border-primary { border-color: var(--tm-primary) !important; }

/* ==========================================================================
   FORMS
   ========================================================================== */
.form-control-modern,
.form-select-modern {
  background: var(--tm-input-bg);
  border: 1px solid var(--tm-input-border);
  color: var(--tm-text);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.form-control-modern:focus,
.form-select-modern:focus {
  border-color: var(--tm-primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--tm-primary-muted);
}
.form-label.text-muted,
.form-label { color: var(--tm-text-muted); font-size: var(--text-sm); font-weight: var(--font-medium); }
.text-muted { color: var(--tm-text-muted) !important; }
.login-card-modern {
  background: var(--tm-bg-elevated);
  border: 1px solid var(--tm-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  max-width: 400px;
  box-shadow: var(--tm-shadow-lg);
}

/* ==========================================================================
   TABLES
   ========================================================================== */
.table {
  color: var(--tm-text);
  font-size: var(--text-sm);
}
.table-dark,
.table.table-dark {
  --bs-table-bg: var(--tm-table-bg);
  --bs-table-border-color: var(--tm-border);
  background: var(--tm-table-bg);
}
.table-dark thead th,
.table.table-dark thead th {
  background: var(--tm-bg-elevated);
  color: var(--tm-text-muted);
  border-color: var(--tm-border);
  font-weight: var(--font-semibold);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--space-3) var(--space-4);
}
.table-dark tbody td,
.table.table-dark tbody td {
  background: var(--tm-table-bg);
  color: var(--tm-text);
  border-color: var(--tm-border);
  padding: var(--space-3) var(--space-4);
  transition: background-color var(--duration-fast) var(--ease-out);
}
.table-dark tbody tr:hover td,
.table.table-dark tbody tr:hover td { background: var(--tm-table-hover); }

/* Light theme: hover blanco-amarillento (BS5 usa box-shadow inset en .table-hover; sin forzarlo se ve oscuro) */
[data-theme="light"] .table-dark.table-hover,
body:not([data-theme="dark"]) .table-dark.table-hover {
  --bs-table-hover-bg: #fffbeb;
  --bs-table-hover-color: #0f172a;
}
[data-theme="light"] .table-dark.table-hover > tbody > tr:hover > td,
[data-theme="light"] .table.table-dark.table-hover > tbody > tr:hover > td,
[data-theme="light"] .table-dark.table-hover > tbody > tr:hover > th,
[data-theme="light"] .table.table-dark.table-hover > tbody > tr:hover > th,
body:not([data-theme="dark"]) .table-dark.table-hover > tbody > tr:hover > td,
body:not([data-theme="dark"]) .table.table-dark.table-hover > tbody > tr:hover > td,
body:not([data-theme="dark"]) .table-dark.table-hover > tbody > tr:hover > th,
body:not([data-theme="dark"]) .table.table-dark.table-hover > tbody > tr:hover > th {
  --bs-table-bg-state: #fffbeb !important;
  --bs-table-accent-bg: #fffbeb !important;
  background-color: #fffbeb !important;
  color: #0f172a !important;
  box-shadow: inset 0 0 0 9999px #fffbeb !important;
}
[data-theme="light"] .table-dark.table-hover > tbody > tr:hover .text-muted,
[data-theme="light"] .table.table-dark.table-hover > tbody > tr:hover .text-muted,
body:not([data-theme="dark"]) .table-dark.table-hover > tbody > tr:hover .text-muted,
body:not([data-theme="dark"]) .table.table-dark.table-hover > tbody > tr:hover .text-muted {
  color: #475569 !important;
}
[data-theme="light"] .table-dark.table-hover > tbody > tr:hover,
body:not([data-theme="dark"]) .table-dark.table-hover > tbody > tr:hover {
  outline: 2px solid #0284c7;
  outline-offset: -2px;
  border-radius: var(--radius-md, 8px);
}
/* Tablas sin .table-hover (p. ej. algunas vistas): mismo fondo en hover */
[data-theme="light"] .table-dark:not(.table-hover) tbody tr:hover > td,
[data-theme="light"] .table.table-dark:not(.table-hover) tbody tr:hover > td,
body:not([data-theme="dark"]) .table-dark:not(.table-hover) tbody tr:hover > td,
body:not([data-theme="dark"]) .table.table-dark:not(.table-hover) tbody tr:hover > td {
  background-color: #fffbeb !important;
  color: #0f172a !important;
  box-shadow: inset 0 0 0 9999px #fffbeb !important;
}

/* My Fleet: tabla embebida sin table-hover */
[data-theme="light"] .fleet-table-wrap .table tbody tr:hover td,
body:not([data-theme="dark"]) .fleet-table-wrap .table tbody tr:hover td {
  background-color: #fffbeb !important;
  color: #0f172a !important;
  box-shadow: inset 0 0 0 9999px #fffbeb !important;
}
.alert-danger { background: rgba(220, 38, 38, 0.12); border: 1px solid rgba(220, 38, 38, 0.4); color: #b91c1c; border-radius: var(--radius-md); }
[data-theme="dark"] .alert-danger { color: #fca5a5; }

/* ==========================================================================
   TABS (Administración)
   ========================================================================== */
.nav-tabs-modern { border-bottom: 1px solid var(--tm-border); gap: var(--space-1); }
.nav-tabs-modern .nav-link {
  color: var(--tm-text-muted);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-weight: var(--font-medium);
  font-size: var(--text-sm);
  transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.nav-tabs-modern .nav-link:hover { color: var(--tm-text); background: var(--tm-primary-muted); }
.nav-tabs-modern .nav-link.active { color: var(--tm-primary); background: var(--tm-primary-muted); }

/* ==========================================================================
   KPI & CHARTS (Dashboard)
   ========================================================================== */
.kpi-row .col { min-width: 0; }
.kpi-card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--tm-border);
  transition: box-shadow var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}
.kpi-card:hover { box-shadow: var(--tm-shadow-md); }
.kpi-card .card-body { min-height: 64px; padding: var(--space-4); }
.kpi-value { font-size: var(--text-xl); font-weight: var(--font-bold); line-height: var(--leading-tight); }
.kpi-label { font-size: var(--text-xs); color: var(--tm-text-muted); line-height: var(--leading-tight); }
.chart-doughnut-wrap { width: 240px; height: 240px; margin: 0 auto; flex-shrink: 0; }
.chart-doughnut-wrap canvas { display: block; }
.chart-card .card-header { font-weight: var(--font-semibold); }

/* Severity bar */
.sev-bar-wrap { display: flex; gap: 2px; width: 70px; }
.sev-bar-wrap .sev-segment { height: 14px; flex: 1; border-radius: 2px; transition: opacity 0.15s; }
.sev-bar-wrap .sev-segment.filled { opacity: 1; }
.sev-bar-wrap .sev-segment.unfilled { opacity: 0.25; }
/* Misma paleta que el gráfico circular "Por severidad" (Baja, Media, Alta, Crítica, Crítica) */
.sev-bar-wrap .sev-1.filled { background: #22c55e; }
.sev-bar-wrap .sev-2.filled { background: #eab308; }
.sev-bar-wrap .sev-3.filled { background: #f97316; }
.sev-bar-wrap .sev-4.filled { background: #ef4444; }
.sev-bar-wrap .sev-5.filled { background: #dc2626; }
.sev-bar-wrap .sev-1.unfilled { background: #22c55e; }
.sev-bar-wrap .sev-2.unfilled { background: #eab308; }
.sev-bar-wrap .sev-3.unfilled { background: #f97316; }
.sev-bar-wrap .sev-4.unfilled { background: #ef4444; }
.sev-bar-wrap .sev-5.unfilled { background: #dc2626; }

/* Criticidad activo activos.crit (1–10), mismo patrón que la barra de severidad */
.crit-bar-wrap { display: flex; gap: 2px; width: 120px; min-width: 100px; }
.crit-bar-wrap .crit-segment { height: 14px; flex: 1; border-radius: 2px; transition: opacity 0.15s; }
/* Listado activos: barra vertical compacta (bajo = 1, alto = 10) */
.crit-bar-wrap.crit-bar-wrap--vertical {
  flex-direction: column-reverse;
  width: 7px;
  min-width: 7px;
  height: 40px;
  gap: 1px;
  align-items: stretch;
  margin-left: auto;
  margin-right: auto;
}
.crit-bar-wrap.crit-bar-wrap--vertical .crit-segment {
  width: 100%;
  height: auto;
  flex: 1 1 0;
  min-height: 0;
  border-radius: 1px;
}
.crit-bar-wrap .crit-segment.filled { opacity: 1; }
.crit-bar-wrap .crit-segment.unfilled { opacity: 0.22; }
.crit-bar-wrap .crit-1.filled { background: #16a34a; }
.crit-bar-wrap .crit-2.filled { background: #22c55e; }
.crit-bar-wrap .crit-3.filled { background: #4ade80; }
.crit-bar-wrap .crit-4.filled { background: #84cc16; }
.crit-bar-wrap .crit-5.filled { background: #ca8a04; }
.crit-bar-wrap .crit-6.filled { background: #eab308; }
.crit-bar-wrap .crit-7.filled { background: #f97316; }
.crit-bar-wrap .crit-8.filled { background: #fb7185; }
.crit-bar-wrap .crit-9.filled { background: #ef4444; }
.crit-bar-wrap .crit-10.filled { background: #991b1b; }
.crit-bar-wrap .crit-1.unfilled { background: #16a34a; }
.crit-bar-wrap .crit-2.unfilled { background: #22c55e; }
.crit-bar-wrap .crit-3.unfilled { background: #4ade80; }
.crit-bar-wrap .crit-4.unfilled { background: #84cc16; }
.crit-bar-wrap .crit-5.unfilled { background: #ca8a04; }
.crit-bar-wrap .crit-6.unfilled { background: #eab308; }
.crit-bar-wrap .crit-7.unfilled { background: #f97316; }
.crit-bar-wrap .crit-8.unfilled { background: #fb7185; }
.crit-bar-wrap .crit-9.unfilled { background: #ef4444; }
.crit-bar-wrap .crit-10.unfilled { background: #991b1b; }

/* Origen sync Bitdefender (sync_desde = SYNC_DESDE_GZ): gris claro sobre tabla oscura */
.sync-src-bitdefender {
  color: #e2e8f0;
}

/* Activos: columna Fuente (solo icono; el texto va en title) */
.activo-fuente-cell {
  width: 1%;
  white-space: nowrap;
  vertical-align: middle;
}
.activo-src-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.35rem;
  font-size: 1rem;
  line-height: 1;
}
.activo-src-icon.activo-src--bdz {
  background: rgba(37, 99, 235, 0.2);
  color: #93c5fd;
}
.activo-src-icon.activo-src--endpoint {
  background: rgba(234, 179, 8, 0.2);
  color: #facc15;
}
.activo-src-icon.activo-src--google {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}
.activo-src-icon.activo-src--otro {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
}
.activo-src-icon.activo-src--empty {
  background: transparent;
  color: #64748b;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Activos: columna Tipo — solo icono SVG o solo texto */
.activo-tipo-cell {
  max-width: 10rem;
  vertical-align: middle;
}
.activo-os-icon-only {
  display: flex;
  align-items: center;
  justify-content: center;
}
.activo-os-thumb {
  width: 26px;
  height: 26px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  padding: 2px;
  box-sizing: border-box;
}
.activo-tipo-text-only {
  display: inline-block;
  max-width: 9rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* Activos: vista por identidad (bloques apilados) */
.activos-identidad-bloque .card-header.chart-card-header {
  font-size: 0.95rem;
}

/* Listados: editar / eliminar solo iconos */
.table-actions-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.btn-icon-action {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0 !important;
  line-height: 1;
}
.btn-icon-action i {
  font-size: 0.72rem;
}

/* Integraciones: estado Activada (inte_gz_bd / inte_google_cloud configuradas) */
.integration-badge-activa {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  font-weight: var(--font-semibold, 600);
  letter-spacing: 0.02em;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.35);
}

/* ==========================================================================
   CLOCK (header)
   ========================================================================== */
.clock-modern {
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  color: var(--tm-text-subtle);
}

/* ==========================================================================
   THEME TOGGLE button
   ========================================================================== */
.theme-toggle {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--tm-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.theme-toggle:hover { background: var(--tm-primary-muted); color: var(--tm-primary); }
.theme-toggle .icon-sun,
.theme-toggle .icon-moon { position: absolute; transition: opacity var(--duration-normal) var(--ease-out), transform var(--duration-normal) var(--ease-out); }
.theme-toggle .icon-moon { opacity: 0; }
[data-theme="dark"] .theme-toggle .icon-sun { opacity: 0; }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 1; }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 991.98px) {
  .header-search-wrap { max-width: 100%; }
  .header-main-nav {
    order: 3;
    flex-basis: 100%;
    padding-top: var(--space-2);
    margin-top: var(--space-1);
    border-top: 1px solid var(--tm-border);
  }
  .header-nav-list {
    justify-content: center;
    width: 100%;
  }
  .header-nav-link { padding: var(--space-1) 0; font-size: var(--text-xs); }
  .header-nav-link span { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; }
  .header-profile-name { display: none; }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   RESTS — extensión Threat Manager (layout y vistas propias)
   ========================================================================== */
.header-brand-sub {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--tm-text-muted);
  margin-left: 0.25rem;
  letter-spacing: 0.02em;
}
.app-header .header-brand-text-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  line-height: 1.25;
}
.app-header .header-brand-text-wrap .header-brand-text {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--tm-text);
}
.app-header .header-brand-text-wrap .header-brand-line2 {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--tm-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Pestañas operador (alineadas con nav-tabs-modern) */
.nav-tabs-operador.nav-tabs {
  border-bottom: 1px solid var(--tm-border);
  gap: var(--space-1);
  flex-wrap: wrap;
}
.nav-tabs-operador .nav-link {
  color: var(--tm-text-muted);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-weight: var(--font-medium);
  font-size: var(--text-sm);
  transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.nav-tabs-operador .nav-link:hover {
  color: var(--tm-text);
  background: var(--tm-primary-muted);
}
.nav-tabs-operador .nav-link.active {
  color: var(--tm-primary);
  background: var(--tm-primary-muted);
}
.link-neon {
  color: var(--tm-primary);
  text-decoration: none;
  font-weight: var(--font-medium);
}
.link-neon:hover {
  color: var(--tm-primary-hover);
  text-decoration: underline;
}

/* Tablas operador: sin fondos forzados; heredan .table-dark del tema */
#operadorTabContent .vehicle-table h3 {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--tm-text);
  margin-bottom: var(--space-2);
}
#operadorTabContent .form-select,
#operadorTabContent .form-control:not(.form-check-input) {
  background: var(--tm-input-bg);
  border: 1px solid var(--tm-input-border);
  color: var(--tm-text);
  border-radius: var(--radius-md);
}
#operadorTabContent .form-select:focus,
#operadorTabContent .form-control:focus {
  border-color: var(--tm-primary);
  box-shadow: 0 0 0 3px var(--tm-primary-muted);
  outline: none;
}
[data-theme="dark"] #operadorTabContent input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] #operadorTabContent input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: 0.85;
}

/* Alertas RESTS: paleta sobria (acento + grises + rojo semántico) */
.card-alert-base {
  background: var(--tm-bg-elevated);
  color: var(--tm-text);
  border-width: 2px;
  border-style: solid;
  border-color: var(--tm-border);
}
.card-alert-rojo {
  border-color: rgba(220, 38, 38, 0.45);
  background: rgba(220, 38, 38, 0.07);
}
.card-alert-azul {
  border-color: rgba(2, 132, 199, 0.45);
  background: rgba(2, 132, 199, 0.08);
}
[data-theme="dark"] .card-alert-azul {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.08);
}
.card-alert-gris {
  border-color: var(--tm-border-strong);
  background: rgba(148, 163, 184, 0.08);
}
.card-alert-sin-op {
  border-color: rgba(234, 179, 8, 0.45);
  background: rgba(234, 179, 8, 0.08);
}
.graph-container-rests {
  background: var(--tm-bg-elevated);
  border: 1px solid var(--tm-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.sla-circle-rests {
  text-align: center;
  min-width: 100px;
}
.sla-circle-inner {
  width: 90px;
  height: 90px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 6px auto;
  font-size: 1.2rem;
  font-weight: var(--font-bold);
  box-shadow: var(--tm-shadow-sm);
  border: 1px solid var(--tm-border);
}
.login-body-rests {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--tm-bg);
}
.login-body-rests .login-actions-secondary .btn {
  border-color: var(--tm-border-strong);
  color: var(--tm-text-muted);
}
.login-body-rests .login-actions-secondary .btn:hover {
  background: var(--tm-primary-muted);
  color: var(--tm-primary);
  border-color: transparent;
}

/* Alertas: listas e historial coherentes con el tema */
.alertas-page-wrap .historial-list .list-group-item,
.alertas-page-wrap .comentarios-list .list-group-item {
  background: transparent !important;
  color: var(--tm-text) !important;
  border-color: var(--tm-border);
}
.alertas-page-wrap .historial-item {
  color: var(--tm-text);
}
.alertas-page-wrap #mapAlertas {
  border-radius: var(--radius-md);
}
.alertas-page-wrap.section-container {
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}
