/* Root and typography */
html {
  font-size: 14px;
  position: relative;
  min-height: 100%;
}
/* Population total container (not a card anymore) */
.population-card { padding: 1rem; }

@media (min-width: 768px) {
  html { font-size: 16px; }
}

:root {
  --gd-bg: #0b1220;             /* fondo dark principal */
  --gd-surface: #0f1a2e;        /* paneles */
  --gd-surface-2: #12203a;      /* bordes/variaciones */
  --gd-border: #243046;         /* líneas suaves */
  --gd-text: #e6eefc;           /* texto principal */
  --gd-text-muted: #9fb2d0;     /* texto secundario */
  --gd-primary: #4da3ff;        /* acento azul */
  --gd-primary-strong: #2e8bff; /* azul más intenso */
  --gd-success: #38d39f;
  --gd-warning: #ffc861;
  --gd-info: #7ad0ff;
}

/* Focus styles */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem rgba(255,255,255,0.4), 0 0 0 0.25rem rgba(77,163,255,0.35);
}

/* Body / global */
body.dark-theme {
  background: radial-gradient(1200px 800px at 10% 10%, #0e1730 0%, var(--gd-bg) 60%), var(--gd-bg);
  color: var(--gd-text);
}

/* Sidebar layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  min-width: 240px;
  background-color: #0b162b;
  border-right: 1px solid var(--gd-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.25s ease, transform 0.25s ease;
}

.sidebar-brand {
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--gd-border);
  background: linear-gradient(180deg, rgba(16,28,54,0.9) 0%, rgba(11,18,32,0) 100%);
}

.sidebar-logo {
  max-height: 80px;
  width: auto;
  filter: drop-shadow(0 8px 24px rgba(0,0,0,0.35));
  transition: opacity 0.15s ease;
}

.sidebar-collapse-btn {
  border: 1px solid var(--gd-border);
  background: rgba(255,255,255,0.04);
  color: var(--gd-text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, transform 0.25s ease;
}
.sidebar-collapse-btn:hover { color: var(--gd-primary); border-color: var(--gd-primary); }

.sidebar-nav { flex: 1; padding: 0.5rem 0; }

.sidebar-nav-list { list-style: none; padding: 0; margin: 0; }

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: var(--gd-text);
  text-decoration: none;
  transition: background-color 0.2s, color 0.2s;
  font-size: 0.9rem;
}
.sidebar-nav-link:hover {
  background-color: rgba(77, 163, 255, 0.1);
  color: var(--gd-primary);
}
.sidebar-nav-link i { width: 1.2rem; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--gd-border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sidebar-time { color: var(--gd-text-muted); font-size: 0.85rem; }
.sidebar-user {
  color: var(--gd-text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main content area */
.main-content {
  margin-left: 240px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.25s ease;
}
.main-content main { flex: 1; padding: 1.5rem; }

/* Mobile hamburger toggle (hidden on desktop) */
.mobile-sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 101;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background-color: var(--gd-surface);
  border: 1px solid var(--gd-border);
  color: var(--gd-text);
  border-radius: 8px;
}
.mobile-sidebar-toggle:hover { color: var(--gd-primary); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* Collapsed sidebar (desktop only) */
@media (min-width: 992px) {
  body.sidebar-collapsed .sidebar { width: 72px; min-width: 72px; }
  body.sidebar-collapsed .sidebar-logo { display: none; }
  body.sidebar-collapsed .sidebar-brand { justify-content: center; }
  body.sidebar-collapsed .sidebar-collapse-btn i { transform: rotate(180deg); }
  body.sidebar-collapsed .sidebar-nav-link { justify-content: center; padding: 0.75rem; }
  body.sidebar-collapsed .sidebar-nav-link span { display: none; }
  body.sidebar-collapsed .sidebar-footer .sidebar-time span,
  body.sidebar-collapsed .sidebar-user span,
  body.sidebar-collapsed .sidebar-user,
  body.sidebar-collapsed .sidebar-footer form { display: none; }
  body.sidebar-collapsed .sidebar-footer { align-items: center; }
  body.sidebar-collapsed .main-content { margin-left: 72px; }
}

/* Off-canvas sidebar (mobile / tablet) */
@media (max-width: 991.98px) {
  .mobile-sidebar-toggle { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    min-width: 260px;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  .main-content { margin-left: 0 !important; }
  body.sidebar-mobile-open .sidebar { transform: translateX(0); }
  body.sidebar-mobile-open .sidebar-overlay { display: block; }
}

.footer {
  white-space: nowrap;
  line-height: 60px;
  background-color: var(--gd-surface);
  border-top: 1px solid var(--gd-border);
  color: var(--gd-text-muted);
}

/* Navbar */
.navbar.bg-dark {
  background-color: #0b162b !important;
  border-bottom: 1px solid var(--gd-border) !important;
}
.navbar .nav-link, .navbar .navbar-brand, .navbar .navbar-text { color: var(--gd-text) !important; }
.navbar .nav-link:hover { color: var(--gd-primary) !important; }

.navbar-brand { font-weight: 600; font-size: 1.25rem; }

/* Containers */
.gd-container { max-width: 1400px; }

/* Brand banner */
.brand-banner { 
  background: linear-gradient(180deg, rgba(16,28,54,0.9) 0%, rgba(11,18,32,0) 100%);
  border-bottom: 1px solid var(--gd-border);
  display: flex; align-items: center; justify-content: center;
}
.brand-banner .brand-logo { 
  max-height: 80px; 
  width: auto; 
  filter: drop-shadow(0 8px 24px rgba(0,0,0,0.35));
}

/* Cards */
.card {
  background-color: var(--gd-surface);
  border: 1px solid var(--gd-border);
  border-radius: 14px;
  transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out, border-color 0.2s;
  color: var(--gd-text);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.35) !important;
  border-color: var(--gd-surface-2);
}
.card-header { font-weight: 500; color: var(--gd-text); }
.card .text-muted { color: var(--gd-text-muted) !important; }

/* Dashboard frame and panels */
.card-frame { 
  background-color: var(--gd-surface);
  border: 1px solid var(--gd-border);
  padding: 1.25rem;
}
.panel-muted {
  background: #0e1a31;
  border: 1px solid var(--gd-border);
  border-radius: 12px;
}

/* GuardIAn Intelligence section title */
.gi-title {
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #4dd9c0;
}

/* Insight banner "Recintos sin movimiento" (contenedor original) */
.insight-icon {
  width: 48px;
  height: 48px;
  background: rgba(77, 217, 192, 0.15);
  color: #4dd9c0;
  font-size: 1.25rem;
}
.insight-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
  color: #4dd9c0;
}
/* Solo los chips de recinto en rojo */
.recinto-chip {
  display: inline-flex;
  align-items: center;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #ffbcbc;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.8rem;
}
.recinto-chip i { color: #ff6b6b; }
.map-panel {
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 1rem;
  width: 100%;
  /* Halved container width, reduced by an additional ~25% */
  max-width: clamp(150px, 16%, 210px);
  margin: 0 auto;
}
/* Responsive map sizing: fill the (constrained) container, limit height */
.map-panel img, .map-panel svg {
  width: 100%;
  max-width: 100%;
  max-height: 65vh;
  height: auto;
  opacity: 0.95;
}
@media (max-width: 576px) {
  /* Smaller map container and image on XS (more compact) */
  .map-panel { max-width: 24vw; padding: 0.25rem; }
  .map-panel img, .map-panel svg { max-width: 100%; max-height: 30vh; }
}

/* XS compaction for the 'Población Total' card */
@media (max-width: 576px) {
  .population-card { padding: 0.5rem; }
  .population-card .fs-hero { font-size: clamp(1.1rem, 6.5vw, 1.6rem); line-height: 1.1; }
  .population-card .text-muted { font-size: 0.8rem; }
  .population-card .d-flex.gap-3 { gap: 0.5rem !important; }
  .population-card .panel-muted { padding: 0.5rem !important; }
  /* Stack inner cols in the card on XS for better space usage */
  .population-card .col-xl-8, .population-card .col-xl-4 { flex: 0 0 100%; max-width: 100%; }
  .population-card .col-xl-4 { margin-top: 0.5rem !important; }
  /* Compact badges under total on XS */
  .kpi-badges-xs .badge { font-size: 0.7rem; padding: 0.25rem 0.4rem; }
}
.kpi-grid .card { background-color: #101d36; }

/* Accent circles */
.bg-gradient {
  background: linear-gradient(145deg, var(--gd-primary-strong), var(--gd-primary)) !important;
}

/* Progress */
.progress { border-radius: 10px; overflow: hidden; background-color: #0e1a31; }
.progress-bar { transition: width 0.6s ease; }

/* Headings */
.display-6 { font-weight: 600; color: var(--gd-text); }
.fs-hero { font-size: clamp(2.2rem, 6vw, 4rem); font-weight: 700; letter-spacing: 0.5px; }
.fs-kpi  { font-size: clamp(1.6rem, 4vw, 2.6rem); font-weight: 700; }

/* Badges override to fit dark scheme */
.badge.bg-primary { background-color: var(--gd-primary) !important; color: #0b1220; }
.badge.bg-success { background-color: var(--gd-success) !important; color: #072016; }
.badge.bg-warning { background-color: var(--gd-warning) !important; color: #3b2a00; }
.badge.bg-info    { background-color: var(--gd-info) !important; color: #082030; }

/* Buttons */
.btn { transition: all 0.2s ease-in-out; }
.btn:hover { transform: translateY(-1px); }
.btn-outline-primary { border-color: var(--gd-primary); color: var(--gd-primary); }
.btn-outline-primary:hover { background-color: var(--gd-primary); color: #0b1220; }

/* Scrollbar */
::-webkit-scrollbar { width: 14px; height: 14px; }
::-webkit-scrollbar-track { background: #0c1426; }
::-webkit-scrollbar-thumb { background: #2a3650; border-radius: 7px; border: 2px solid #0c1426; }
::-webkit-scrollbar-thumb:hover { background: #3a4870; }

/* Loading modal */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.loading-overlay .loading-modal {
    background: #12203a;
    border: 1px solid var(--gd-border);
    border-radius: 12px;
    padding: 2rem 3rem;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.loading-overlay .loading-modal .spinner-border {
    width: 3rem;
    height: 3rem;
    color: var(--gd-primary);
}
.loading-overlay .loading-modal p {
    margin-top: 1rem;
    margin-bottom: 0;
    font-size: 1.1rem;
    color: var(--gd-text);
}

/* Alerts */
.alert { animation: slideInDown 0.3s ease-out; background-color: #12203a; color: var(--gd-text); border: 1px solid var(--gd-border); }
@keyframes slideInDown { from { transform: translateY(-100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Loading */
@keyframes pulse { 0%{opacity:1;} 50%{opacity:0.5;} 100%{opacity:1;} }
.loading { animation: pulse 1.5s ease-in-out infinite; }

/* Responsive tweaks */
@media (max-width: 768px) {
  .display-6 { font-size: 1.75rem; }
  .fs-2 { font-size: 1.5rem !important; }
  .card-body { padding: 1rem; }
}

/*Tabla de Cotejos (#tablaCotejos) */
:root {
    --ctj-bg-input: #131E35;
    --ctj-nav-bg: #1A2744;
    --ctj-accent: #4A6FA5;
    --ctj-accent-light: #8BAFD0;
    --ctj-text-primary: #EFF5FA;
    --ctj-text-muted: #7A9BBF;
    --ctj-border: #1E2E50;
}

#tablaCotejos {
    color: var(--ctj-text-primary);
    --bs-table-bg: transparent;
    --bs-table-color: var(--ctj-text-primary);
    --bs-table-hover-bg: rgba(83, 116, 172, 0.15);
    --bs-table-hover-color: var(--ctj-text-primary);
    --bs-table-striped-color: var(--ctj-text-primary);
    --bs-table-border-color: var(--ctj-border);
}

    #tablaCotejos thead th {
        background-color: var(--ctj-nav-bg);
        color: var(--ctj-accent-light);
        border-color: var(--ctj-accent);
    }

    #tablaCotejos tbody td {
        color: var(--ctj-text-primary);
        border-color: var(--ctj-border);
    }

    #tablaCotejos .filter-input {
        background-color: var(--ctj-bg-input);
        color: var(--ctj-text-primary);
        border-color: var(--ctj-accent);
    }

        #tablaCotejos .filter-input::placeholder {
            color: var(--ctj-text-muted);
        }

        #tablaCotejos .filter-input:focus {
            background-color: var(--ctj-bg-input);
            color: var(--ctj-text-primary);
            border-color: var(--ctj-accent-light);
            box-shadow: 0 0 0 0.2rem rgba(74, 111, 165, 0.25);
        }

/* Selectores de la barra de filtros del dashboard (Unidad Penal / Tipo de Cotejo) - tema oscuro */
.gd-filter-select.form-select {
    background-color: var(--ctj-bg-input);
    color: var(--gd-text);
    border-color: var(--gd-border);
    /* Flecha (caret) en color claro para que se vea sobre el fondo oscuro */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23e6eefc' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

.gd-filter-select.form-select:focus {
    background-color: var(--ctj-bg-input);
    color: var(--gd-text);
    border-color: var(--gd-primary);
    box-shadow: 0 0 0 0.2rem rgba(77, 163, 255, 0.25);
}

/* Opciones desplegadas (respetado por Chromium en Windows) */
.gd-filter-select.form-select option {
    background-color: var(--ctj-bg-input);
    color: var(--gd-text);
}

/* Barra de filtros: se apila sobre las tarjetas siguientes para que el desplegable
   (unidad penal / tipo de cotejo) quede por encima del gráfico de abajo y no choque. */
.gd-filter-bar {
    position: relative;
    z-index: 10;
}

/* Selector buscable (reemplaza el <select> nativo de Unidad Penal / Tipo de Cotejo) */
.gd-searchable-select {
    position: relative;
}
.gd-searchable-input-wrap {
    position: relative;
}
.gd-searchable-input {
    padding-right: 2rem;
    cursor: text;
}
.gd-searchable-caret {
    position: absolute;
    right: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gd-text-muted);
    font-size: 0.75rem;
    pointer-events: none;
}
.gd-searchable-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 260px;
    overflow-y: auto;
    background-color: var(--ctj-bg-input);
    border: 1px solid var(--gd-border);
    border-radius: 8px;
    z-index: 1050;
    box-shadow: 0 12px 28px rgba(0,0,0,0.45);
}
.gd-searchable-dropdown.open {
    display: block;
}
.gd-searchable-option {
    padding: 0.5rem 0.85rem;
    color: var(--gd-text);
    font-size: 0.9rem;
    cursor: pointer;
}
.gd-searchable-option:hover,
.gd-searchable-option.highlight {
    background-color: rgba(77, 163, 255, 0.15);
    color: var(--gd-primary);
}
.gd-searchable-option.active {
    color: var(--gd-primary);
    font-weight: 600;
}
.gd-searchable-empty {
    padding: 0.5rem 0.85rem;
    color: var(--gd-text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* -------------------------------------------------------------------
   Matriz de calor (heatmap) de cotejos por rango horario y día
   ------------------------------------------------------------------- */
.heatmap-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 3px;
}
.heatmap-table thead th {
    color: var(--gd-text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: center;
    padding: 4px 6px;
    white-space: nowrap;
}
.heatmap-table thead th.hm-rowhead { text-align: left; }
.heatmap-table thead th.hm-avg-head { color: var(--gd-text); }
/* Fecha real bajo cada día (Lun..Dom) en la cabecera de la matriz */
.heatmap-table thead th .hm-date {
    display: block;
    font-size: 0.62rem;
    font-weight: 500;
    opacity: 0.65;
    margin-top: 2px;
}
/* Días de la semana en curso (ya transcurridos): se resaltan con un subrayado lima */
.heatmap-table thead th.hm-day-current {
    color: var(--gd-text);
    border-bottom: 2px solid rgba(140, 215, 70, 0.9);
}
.heatmap-table thead th.hm-day-current .hm-date { opacity: 0.95; }
/* Días aún no transcurridos: muestran la semana anterior (subrayado tenue) */
.heatmap-table thead th.hm-day-prev {
    border-bottom: 2px solid rgba(255, 255, 255, 0.08);
}
/* Llaves de la leyenda semana en curso / anterior */
.hm-key {
    display: inline-block;
    width: 22px;
    height: 3px;
    border-radius: 2px;
    vertical-align: middle;
    margin-right: 4px;
}
.hm-key-current { background: rgba(140, 215, 70, 0.9); }
.hm-key-prev { background: rgba(255, 255, 255, 0.18); }
.heatmap-table td { text-align: center; }
.heatmap-table td.hm-rowhead {
    color: var(--gd-text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    padding-right: 10px;
}
.heatmap-table td.hm-cell {
    color: #eaf2ff;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 8px 6px;
    border-radius: 5px;
    min-width: 46px;
    transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.heatmap-table td.hm-cell:hover {
    transform: scale(1.06);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
    cursor: default;
}
.heatmap-table td.hm-avg {
    color: var(--gd-text);
    font-weight: 700;
    font-size: 0.78rem;
    padding: 8px 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
}
.heatmap-legend {
    display: inline-block;
    width: 200px;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(
        90deg,
        rgb(18, 32, 58) 0%,
        rgb(22, 95, 105) 30%,
        rgb(26, 150, 120) 55%,
        rgb(60, 190, 95) 78%,
        rgb(140, 215, 70) 100%
    );
}
