/* ==========================================================================
   ISMS Manager — capa de diseño
   --------------------------------------------------------------------------
   Se apoya en Bootstrap 5.3 sobrescribiendo sus variables CSS (--bs-*), de modo
   que las ~123 plantillas existentes heredan el nuevo aspecto sin tocar su
   marcado. Estructura:
     1. Tokens (color, tipografía, espaciado, elevación)
     2. Tema oscuro
     3. Base y tipografía
     4. Estructura: barra lateral, barra superior, contenido
     5. Componentes: tarjetas, tablas, formularios, botones, badges, estados
     6. Utilidades, impresión y responsive
   ========================================================================== */

/* ============================ 1. TOKENS ================================== */
:root {
    /* Marca: azul de acción, más sobrio que el azul Bootstrap por defecto */
    --isms-brand: #1d4ed8;
    --isms-brand-strong: #1e40af;
    --isms-brand-soft: #eff4ff;

    /* Neutros fríos: sostienen la densidad sin ensuciar la pantalla */
    --isms-bg: #f6f7f9;
    --isms-surface: #ffffff;
    --isms-surface-alt: #fbfcfd;
    --isms-border: #e3e6ea;
    --isms-border-strong: #cdd3da;
    --isms-text: #1a1f27;
    --isms-text-muted: #667085;

    /* Semánticos de estado (cumplimiento, aviso, crítico, informativo) */
    --isms-ok: #0f7b4f;
    --isms-ok-soft: #e7f6ef;
    --isms-warn: #b45309;
    --isms-warn-soft: #fdf3e3;
    --isms-danger: #b42318;
    --isms-danger-soft: #fdeceb;
    --isms-info: #0b6bcb;
    --isms-info-soft: #e8f1fc;

    /* Barra lateral */
    --isms-sidebar-bg: #10151d;
    --isms-sidebar-text: #aeb7c4;
    --isms-sidebar-text-active: #ffffff;
    --isms-sidebar-active: rgba(255, 255, 255, .09);
    --isms-sidebar-width: 244px;
    --isms-sidebar-width-collapsed: 62px;
    --isms-topbar-height: 52px;

    /* Radios: compactos */
    --isms-radius-sm: 4px;
    --isms-radius: 6px;
    --isms-radius-lg: 10px;

    /* Elevación discreta: se prefiere borde a sombra */
    --isms-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --isms-shadow: 0 2px 6px rgba(16, 24, 40, .07);
    --isms-shadow-lg: 0 10px 28px rgba(16, 24, 40, .12);

    /* Variables de Bootstrap: aquí es donde se propaga el rediseño */
    --bs-primary: var(--isms-brand);
    --bs-primary-rgb: 29, 78, 216;
    --bs-body-bg: var(--isms-bg);
    --bs-body-color: var(--isms-text);
    --bs-body-font-size: .875rem;
    --bs-body-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
                           Roboto, "Helvetica Neue", Arial, sans-serif;
    --bs-border-color: var(--isms-border);
    --bs-border-radius: var(--isms-radius);
    --bs-border-radius-sm: var(--isms-radius-sm);
    --bs-border-radius-lg: var(--isms-radius-lg);
    --bs-link-color: var(--isms-brand);
    --bs-link-hover-color: var(--isms-brand-strong);
    --bs-secondary-color: var(--isms-text-muted);
}

/* ========================== 2. TEMA OSCURO =============================== */
[data-bs-theme="dark"] {
    --isms-bg: #0f141b;
    --isms-surface: #161d26;
    --isms-surface-alt: #1b232e;
    --isms-border: #273140;
    --isms-border-strong: #35435a;
    --isms-text: #e6eaf0;
    --isms-text-muted: #94a3b8;
    --isms-brand: #5b8dff;
    --isms-brand-strong: #7ea6ff;
    --isms-brand-soft: #16233d;

    --isms-ok: #4ade80;
    --isms-ok-soft: #10261d;
    --isms-warn: #fbbf24;
    --isms-warn-soft: #2a1f0e;
    --isms-danger: #f87171;
    --isms-danger-soft: #2c1512;
    --isms-info: #60a5fa;
    --isms-info-soft: #101f33;

    --isms-sidebar-bg: #0b1017;
    --bs-primary-rgb: 91, 141, 255;
    --bs-body-bg: var(--isms-bg);
    --bs-body-color: var(--isms-text);
    --bs-border-color: var(--isms-border);
    --bs-emphasis-color: #fff;
}

/* ====================== 3. BASE Y TIPOGRAFÍA ============================= */
body {
    background-color: var(--isms-bg);
    color: var(--isms-text);
    font-size: .875rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, .h1 { font-size: 1.5rem; }
h2, .h2 { font-size: 1.25rem; }
h3, .h3 { font-size: 1.125rem; }
h4, .h4 { font-size: 1rem; }
h5, .h5 { font-size: .9375rem; }
h6, .h6 { font-size: .8125rem; }

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    font-weight: 600;
    letter-spacing: -.011em;
    color: var(--isms-text);
}

.text-muted { color: var(--isms-text-muted) !important; }
code, kbd, pre, samp { font-size: .8125em; }

/* ==================== 4. ESTRUCTURA DE LA APLICACIÓN ==================== */
.app-shell { display: flex; min-height: 100vh; }

/* --- Barra lateral --- */
.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--isms-sidebar-width);
    background: var(--isms-sidebar-bg);
    color: var(--isms-sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: width .18s ease;
    overflow: hidden;
}

.app-sidebar__brand {
    display: flex;
    align-items: center;
    gap: .625rem;
    height: var(--isms-topbar-height);
    padding: 0 .875rem;
    color: #fff;
    font-weight: 600;
    font-size: .9375rem;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    white-space: nowrap;
    flex-shrink: 0;
}
.app-sidebar__brand i { color: var(--isms-brand); font-size: 1.125rem; }

.app-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: .5rem .5rem 1rem;
}

.app-sidebar__group {
    padding: .875rem .625rem .25rem;
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #64748b;
    white-space: nowrap;
}

.app-sidebar__link {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .4375rem .625rem;
    margin-bottom: 1px;
    border-radius: var(--isms-radius);
    color: var(--isms-sidebar-text);
    text-decoration: none;
    font-size: .8125rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background-color .12s ease, color .12s ease;
}
.app-sidebar__link i { width: 18px; text-align: center; font-size: .875rem; flex-shrink: 0; }
.app-sidebar__link:hover { background: rgba(255, 255, 255, .055); color: #fff; }
.app-sidebar__link.is-active {
    background: var(--isms-sidebar-active);
    color: var(--isms-sidebar-text-active);
    box-shadow: inset 2px 0 0 var(--isms-brand);
}

.app-sidebar__footer {
    padding: .5rem;
    border-top: 1px solid rgba(255, 255, 255, .07);
    flex-shrink: 0;
}

/* Estado colapsado: solo iconos */
.app-shell.is-collapsed .app-sidebar { width: var(--isms-sidebar-width-collapsed); }
.app-shell.is-collapsed .app-sidebar__brand span,
.app-shell.is-collapsed .app-sidebar__link span,
.app-shell.is-collapsed .app-sidebar__group { display: none; }
.app-shell.is-collapsed .app-sidebar__link { justify-content: center; padding-inline: 0; }
.app-shell.is-collapsed .app-main { margin-left: var(--isms-sidebar-width-collapsed); }

/* --- Contenido y barra superior --- */
.app-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--isms-sidebar-width);
    transition: margin-left .18s ease;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--isms-topbar-height);
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 1rem;
    background: var(--isms-surface);
    border-bottom: 1px solid var(--isms-border);
}

.app-topbar__toggle {
    border: 0;
    background: transparent;
    color: var(--isms-text-muted);
    padding: .375rem .5rem;
    border-radius: var(--isms-radius);
    line-height: 1;
}
.app-topbar__toggle:hover { background: var(--isms-bg); color: var(--isms-text); }

.app-content { padding: 1.25rem 1.25rem 2.5rem; }

/* 61 plantillas abren su contenido con su propio `.container-fluid`, a veces con
   `py-4` o `mt-4`. Al vivir ya dentro de `.app-content` ese relleno se duplicaba,
   así que se neutraliza aquí en lugar de editar cada fichero. */
.app-content > .container-fluid,
.app-content > .container {
    padding-left: 0;
    padding-right: 0;
    padding-top: 0;
    margin-top: 0;
    max-width: none;
}
.app-content > .container-fluid.py-4 { padding-bottom: 0; }

/* Encabezado de página reutilizable */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.page-header__main { min-width: 0; }
.page-header__title { margin: 0; font-size: 1.375rem; font-weight: 650; display: flex; align-items: center; gap: .5rem; }
.page-header__icon { color: var(--isms-text-muted); font-size: 1.125rem; }
.page-header__subtitle { margin: .1875rem 0 0; color: var(--isms-text-muted); font-size: .8125rem; }
.page-header__actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* --- Ficha de indicador (macro ui.stat) --- */
.stat-tile {
    position: relative;
    display: flex;
    align-items: center;
    gap: .75rem;
    height: 100%;
    padding: .875rem 1rem;
    background: var(--isms-surface);
    border: 1px solid var(--isms-border);
    border-left: 3px solid var(--tono, var(--isms-brand));
    border-radius: var(--isms-radius-lg);
    box-shadow: var(--isms-shadow-sm);
}
.stat-tile--brand  { --tono: var(--isms-brand); }
.stat-tile--ok     { --tono: var(--isms-ok); }
.stat-tile--warn   { --tono: var(--isms-warn); }
.stat-tile--danger { --tono: var(--isms-danger); }
.stat-tile--info   { --tono: var(--isms-info); }
.stat-tile--neutro { --tono: var(--isms-border-strong); }

.stat-tile__body { min-width: 0; flex: 1; }
.stat-tile__label { font-size: .75rem; font-weight: 600; color: var(--isms-text-muted); }
.stat-tile__value { font-size: 1.625rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; }
.stat-tile__foot { font-size: .75rem; color: var(--isms-text-muted); }
.stat-tile__icon { font-size: 1.375rem; color: var(--tono); opacity: .9; }
.stat-tile:has(.stretched-link):hover { border-color: var(--tono); }

/* Migas de pan discretas */
.breadcrumb {
    font-size: .75rem;
    margin-bottom: .375rem;
    --bs-breadcrumb-divider-color: var(--isms-text-muted);
    --bs-breadcrumb-item-padding-x: .375rem;
}
.breadcrumb-item + .breadcrumb-item::before { content: "›"; }
.breadcrumb a { color: var(--isms-text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--isms-brand); }

/* ======================= 5. COMPONENTES ================================= */

/* --- Tarjetas: borde en vez de sombra --- */
.card {
    background: var(--isms-surface);
    border: 1px solid var(--isms-border);
    border-radius: var(--isms-radius-lg);
    box-shadow: var(--isms-shadow-sm);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--isms-border);
    padding: .75rem 1rem;
    font-weight: 600;
    font-size: .875rem;
}
.card-header h1, .card-header h2, .card-header h3,
.card-header h4, .card-header h5, .card-header h6 { margin: 0; font-size: .875rem; }

.card-body { padding: 1rem; }
.card-footer { background: var(--isms-surface-alt); border-top: 1px solid var(--isms-border); padding: .625rem 1rem; }

/* --- Fichas de indicador (KPI) ---
   Las plantillas usan `card bg-* text-white` (98 casos en 26 ficheros). En vez de
   editarlas una a una, se reinterpreta ese marcado como ficha sobria: fondo neutro,
   franja lateral y icono del color semántico, cifra legible sobre fondo claro.
   Se necesita !important porque .text-white y .opacity-75 son utilidades de Bootstrap. */
.card.bg-primary   { --stat-color: var(--isms-brand); }
.card.bg-success   { --stat-color: var(--isms-ok); }
.card.bg-danger    { --stat-color: var(--isms-danger); }
.card.bg-warning   { --stat-color: var(--isms-warn); }
.card.bg-info      { --stat-color: var(--isms-info); }
.card.bg-secondary { --stat-color: var(--isms-text-muted); }
.card.bg-dark      { --stat-color: var(--isms-text); }

.card.bg-primary, .card.bg-success, .card.bg-danger, .card.bg-warning,
.card.bg-info, .card.bg-secondary, .card.bg-dark {
    background-color: var(--isms-surface) !important;
    border: 1px solid var(--isms-border);
    border-left: 3px solid var(--stat-color);
    box-shadow: var(--isms-shadow-sm);
}

.card.bg-primary.text-white, .card.bg-success.text-white, .card.bg-danger.text-white,
.card.bg-warning.text-white, .card.bg-info.text-white, .card.bg-secondary.text-white,
.card.bg-dark.text-white { color: var(--isms-text) !important; }

/* Etiqueta, cifra e icono dentro de la ficha */
.card[class*="bg-"].text-white .card-title,
.card[class*="bg-"].text-white small,
.card[class*="bg-"].text-white .small {
    color: var(--isms-text-muted) !important;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .01em;
    text-transform: none;
}

.card[class*="bg-"].text-white h1, .card[class*="bg-"].text-white h2,
.card[class*="bg-"].text-white h3, .card[class*="bg-"].text-white h4 {
    color: var(--isms-text) !important;
    font-size: 1.625rem;
    font-weight: 650;
    letter-spacing: -.02em;
}

.card[class*="bg-"].text-white i {
    color: var(--stat-color) !important;
    opacity: 1 !important;
}

.card[class*="bg-"].text-white a { color: var(--stat-color) !important; }

/* --- Cabeceras de tarjeta con color: tinte suave en vez de bloque saturado --- */
.card-header.bg-primary, .card-header.bg-success, .card-header.bg-danger,
.card-header.bg-warning, .card-header.bg-info, .card-header.bg-dark,
.card-header.bg-secondary {
    color: var(--tint-color) !important;
    background-color: var(--tint-bg) !important;
    border-bottom: 1px solid var(--isms-border);
}
.card-header.bg-primary   { --tint-color: var(--isms-brand);      --tint-bg: var(--isms-brand-soft); }
.card-header.bg-success   { --tint-color: var(--isms-ok);         --tint-bg: var(--isms-ok-soft); }
.card-header.bg-danger    { --tint-color: var(--isms-danger);     --tint-bg: var(--isms-danger-soft); }
.card-header.bg-warning   { --tint-color: var(--isms-warn);       --tint-bg: var(--isms-warn-soft); }
.card-header.bg-info      { --tint-color: var(--isms-info);       --tint-bg: var(--isms-info-soft); }
.card-header.bg-dark      { --tint-color: var(--isms-text);       --tint-bg: var(--isms-surface-alt); }
.card-header.bg-secondary { --tint-color: var(--isms-text-muted); --tint-bg: var(--isms-surface-alt); }
.card-header[class*="bg-"] i { color: inherit !important; }
.card-header[class*="bg-"].text-white,
.card-header[class*="bg-"] .text-white { color: var(--tint-color) !important; }

/* --- Tablas densas --- */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--isms-text);
    font-size: .8125rem;
    margin-bottom: 0;
}

.table > thead > tr > th {
    background: var(--isms-surface-alt);
    border-bottom: 1px solid var(--isms-border);
    color: var(--isms-text-muted);
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: .5rem .75rem;
    white-space: nowrap;
}

.table > tbody > tr > td {
    padding: .5rem .75rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--isms-border);
}

.table > tbody > tr:last-child > td { border-bottom: 0; }
.table-hover > tbody > tr:hover > * { background-color: var(--isms-brand-soft); }

/* Cabecera fija en listados largos (93 controles del SOA, catálogos de amenazas).
   `.table-responsive` es su propio contenedor de desplazamiento, así que para que la
   cabecera se ancle hay que limitar su altura: la tabla se desplaza por dentro y el
   encabezado de página, las fichas y los filtros permanecen a la vista. */
.table-responsive {
    max-height: calc(100vh - 15rem);
    overflow: auto;
}
.table-responsive > .table > thead > tr > th,
.table-sticky > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 2;
}
/* La celda pegajosa pierde su borde inferior al desplazar: se recrea con sombra */
.table-responsive > .table > thead > tr > th::after,
.table-sticky > thead > tr > th::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    border-bottom: 1px solid var(--isms-border);
}

.card > .table-responsive > .table > thead > tr > th:first-child,
.card > .table > thead > tr > th:first-child,
.card > .table-responsive > .table > tbody > tr > td:first-child,
.card > .table > tbody > tr > td:first-child { padding-left: 1rem; }

/* --- Formularios --- */
.form-label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--isms-text);
    margin-bottom: .25rem;
}

.form-control, .form-select {
    background-color: var(--isms-surface);
    border-color: var(--isms-border-strong);
    border-radius: var(--isms-radius);
    color: var(--isms-text);
    font-size: .8125rem;
    padding: .375rem .625rem;
    min-height: 34px;
}

.form-control::placeholder { color: var(--isms-text-muted); opacity: .8; }
.form-control:focus, .form-select:focus {
    border-color: var(--isms-brand);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .16);
}

.form-text { font-size: .75rem; color: var(--isms-text-muted); }
.input-group-text { background: var(--isms-surface-alt); border-color: var(--isms-border-strong); font-size: .8125rem; }

/* --- Botones --- */
.btn {
    --bs-btn-font-size: .8125rem;
    --bs-btn-padding-y: .375rem;
    --bs-btn-padding-x: .75rem;
    --bs-btn-border-radius: var(--isms-radius);
    font-weight: 500;
    line-height: 1.45;
}
.btn-sm { --bs-btn-font-size: .75rem; --bs-btn-padding-y: .25rem; --bs-btn-padding-x: .5rem; }
.btn-lg { --bs-btn-font-size: .875rem; --bs-btn-padding-y: .5rem; --bs-btn-padding-x: 1rem; }

.btn-primary {
    --bs-btn-bg: var(--isms-brand);
    --bs-btn-border-color: var(--isms-brand);
    --bs-btn-hover-bg: var(--isms-brand-strong);
    --bs-btn-hover-border-color: var(--isms-brand-strong);
    --bs-btn-active-bg: var(--isms-brand-strong);
}

.btn-outline-secondary {
    --bs-btn-color: var(--isms-text);
    --bs-btn-border-color: var(--isms-border-strong);
    --bs-btn-hover-bg: var(--isms-bg);
    --bs-btn-hover-color: var(--isms-text);
    --bs-btn-hover-border-color: var(--isms-border-strong);
}

/* --- Badges de estado: legibles, no chillones --- */
.badge {
    font-size: .6875rem;
    font-weight: 600;
    padding: .25em .5em;
    border-radius: var(--isms-radius-sm);
    letter-spacing: .01em;
}

.badge.bg-success   { background-color: var(--isms-ok-soft) !important; color: var(--isms-ok) !important; }
.badge.bg-danger    { background-color: var(--isms-danger-soft) !important; color: var(--isms-danger) !important; }
.badge.bg-warning   { background-color: var(--isms-warn-soft) !important; color: var(--isms-warn) !important; }
.badge.bg-info      { background-color: var(--isms-info-soft) !important; color: var(--isms-info) !important; }
.badge.bg-primary   { background-color: var(--isms-brand-soft) !important; color: var(--isms-brand) !important; }
.badge.bg-secondary { background-color: var(--isms-bg) !important; color: var(--isms-text-muted) !important; border: 1px solid var(--isms-border); }
.badge.bg-light     { background-color: var(--isms-bg) !important; color: var(--isms-text-muted) !important; }
.badge.bg-dark      { background-color: var(--isms-text) !important; color: var(--isms-surface) !important; }

/* Dentro de tarjetas de color pleno, los badges recuperan contraste propio */
.card.text-white .badge, [class*="bg-"].text-white .badge { background-color: rgba(255,255,255,.18) !important; color: #fff !important; border: 0; }

/* --- Alertas --- */
.alert {
    border: 1px solid transparent;
    border-radius: var(--isms-radius);
    font-size: .8125rem;
    padding: .625rem .875rem;
}
.alert-success { background: var(--isms-ok-soft); border-color: rgba(15, 123, 79, .25); color: var(--isms-ok); }
.alert-danger  { background: var(--isms-danger-soft); border-color: rgba(180, 35, 24, .25); color: var(--isms-danger); }
.alert-warning { background: var(--isms-warn-soft); border-color: rgba(180, 83, 9, .25); color: var(--isms-warn); }
.alert-info    { background: var(--isms-info-soft); border-color: rgba(11, 107, 203, .25); color: var(--isms-info); }

/* --- Modales, desplegables, pestañas --- */
.modal-content { border: 1px solid var(--isms-border); border-radius: var(--isms-radius-lg); box-shadow: var(--isms-shadow-lg); background: var(--isms-surface); }
.modal-header, .modal-footer { border-color: var(--isms-border); padding: .875rem 1rem; }
.modal-title { font-size: 1rem; }

.dropdown-menu {
    border: 1px solid var(--isms-border);
    border-radius: var(--isms-radius);
    box-shadow: var(--isms-shadow-lg);
    font-size: .8125rem;
    padding: .25rem;
    background: var(--isms-surface);
}
.dropdown-item { border-radius: var(--isms-radius-sm); padding: .375rem .625rem; }
.dropdown-header { font-size: .6875rem; text-transform: uppercase; letter-spacing: .04em; color: var(--isms-text-muted); }

.nav-tabs { border-bottom: 1px solid var(--isms-border); gap: .125rem; }
.nav-tabs .nav-link {
    border: 0;
    border-bottom: 2px solid transparent;
    color: var(--isms-text-muted);
    font-size: .8125rem;
    font-weight: 500;
    padding: .5rem .75rem;
}
.nav-tabs .nav-link:hover { color: var(--isms-text); border-bottom-color: var(--isms-border-strong); }
.nav-tabs .nav-link.active { color: var(--isms-brand); background: transparent; border-bottom-color: var(--isms-brand); }

/* --- Progreso y paginación --- */
.progress { height: .5rem; border-radius: 999px; background: var(--isms-bg); }
.progress-bar { border-radius: 999px; }

.pagination { --bs-pagination-font-size: .8125rem; --bs-pagination-border-color: var(--isms-border); }
.page-link { color: var(--isms-text); }
.page-item.active .page-link { background: var(--isms-brand); border-color: var(--isms-brand); }

/* --- Estado vacío y barra de filtros --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--isms-text-muted);
}
/* Solo el icono ilustrativo, no los que van dentro de botones o textos */
.empty-state__icon {
    font-size: 1.75rem;
    color: var(--isms-text-muted);
    opacity: .4;
    margin-bottom: .875rem;
}
.empty-state h5, .empty-state h6 { color: var(--isms-text); margin-bottom: .25rem; }
.empty-state p { max-width: 52ch; margin-bottom: 0; font-size: .8125rem; }

.filter-bar {
    background: var(--isms-surface);
    border: 1px solid var(--isms-border);
    border-radius: var(--isms-radius-lg);
    padding: .75rem;
    margin-bottom: 1rem;
}

/* ============ 6. UTILIDADES, IMPRESIÓN Y RESPONSIVE ===================== */
:focus-visible { outline: 2px solid var(--isms-brand); outline-offset: 2px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--isms-border-strong); border-radius: 999px; border: 3px solid var(--isms-bg); }
::-webkit-scrollbar-thumb:hover { background: var(--isms-text-muted); }
.app-sidebar ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-color: transparent; }

/* Superficies auxiliares en tema oscuro (clases de Bootstrap muy usadas) */
[data-bs-theme="dark"] .bg-white { background-color: var(--isms-surface) !important; }
[data-bs-theme="dark"] .bg-light { background-color: var(--isms-surface-alt) !important; }
[data-bs-theme="dark"] .text-dark { color: var(--isms-text) !important; }

/* Impresión: la aplicación genera evidencias para auditoría */
@media print {
    .app-sidebar, .app-topbar, .page-header__actions, .btn, .no-print { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .card { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; }
    body { background: #fff; }
}

/* Responsive: la lateral se oculta y se abre como panel */
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); transition: transform .18s ease; box-shadow: var(--isms-shadow-lg); }
    .app-shell.is-sidebar-open .app-sidebar { transform: translateX(0); }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 1rem .75rem 2rem; }
    .app-sidebar-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1035; }
}

/* ============ Ficha de documento ============ */
/* Metadatos en línea bajo el título: sustituyen a la tarjeta lateral de "Información" */
.doc-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1.25rem;
    font-size: .8125rem;
    color: var(--isms-text);
}
.doc-meta__item { display: inline-flex; align-items: center; gap: .375rem; }
.doc-meta__label { color: var(--isms-text-muted); }

/* Barra de flujo documental: estado actual y siguiente paso */
.workflow-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .625rem .875rem;
    background: var(--isms-surface);
    border: 1px solid var(--isms-border);
    border-radius: var(--isms-radius-lg);
    font-size: .8125rem;
}
.workflow-bar__actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

/* Puntuación de verificación */
.score-block__value { font-size: 1.75rem; font-weight: 650; line-height: 1.1; }

/* Fila de control dentro del acordeón */
.control-row { display: flex; align-items: center; gap: .625rem; width: 100%; padding-right: .5rem; }
.control-row__id { color: var(--isms-brand); font-size: .75rem; }
.control-row__title { flex: 1; font-weight: 500; }

.accordion-button { font-size: .8125rem; padding: .625rem .875rem; background: var(--isms-surface); }
.accordion-button:not(.collapsed) { background: var(--isms-brand-soft); color: var(--isms-text); box-shadow: none; }
.accordion-button:focus { box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .16); }
.accordion-item { background: var(--isms-surface); border-color: var(--isms-border); }
.accordion-body { font-size: .8125rem; }

/* Selector de controles SOA (detección asistida) */
.controls-picker { max-height: 52vh; overflow-y: auto; border: 1px solid var(--isms-border); border-radius: var(--isms-radius); }
.controls-picker__row {
    display: flex; align-items: flex-start; gap: .625rem;
    padding: .5rem .75rem; border-bottom: 1px solid var(--isms-border);
    cursor: pointer; font-size: .8125rem; margin: 0;
}
.controls-picker__row:last-child { border-bottom: 0; }
.controls-picker__row:hover { background: var(--isms-brand-soft); }
.controls-picker__check { margin-top: .175rem; flex-shrink: 0; }
.controls-picker__id { color: var(--isms-brand); font-size: .75rem; min-width: 3.5rem; }
.controls-picker__title { flex: 1; min-width: 0; }
.controls-picker__tag { margin-left: auto; flex-shrink: 0; }

/* Lista "Requiere tu atención": trabajo pendiente con recuento y urgencia */
.attention-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--isms-border);
    color: var(--isms-text);
    text-decoration: none;
    border-left: 3px solid var(--tono, var(--isms-border-strong));
    transition: background-color .12s ease;
}
.attention-row:last-child { border-bottom: 0; }
.attention-row:hover { background: var(--isms-surface-alt); color: var(--isms-text); }
.attention-row--danger { --tono: var(--isms-danger); }
.attention-row--warn   { --tono: var(--isms-warn); }
.attention-row--info   { --tono: var(--isms-info); }
.attention-row--neutro { --tono: var(--isms-border-strong); }
.attention-row__icon { color: var(--tono); width: 18px; text-align: center; }
.attention-row__body { flex: 1; min-width: 0; }
.attention-row__title { display: block; font-size: .8125rem; font-weight: 600; }
.attention-row__detail { display: block; font-size: .75rem; color: var(--isms-text-muted); }
.attention-row__count { font-size: 1.125rem; font-weight: 650; color: var(--tono); }

/* ============ Calendarios (FullCalendar) ============ */
/* Estilos compartidos por los calendarios de Cambios y Tareas: antes cada uno tenía
   su propia implementación y aspecto. */
.isms-calendar { max-width: 100%; }
.isms-calendar .fc { font-size: .8125rem; }
.isms-calendar .fc .fc-toolbar-title { font-size: 1.0625rem; font-weight: 650; }
.isms-calendar .fc .fc-button {
    background: var(--isms-surface);
    border-color: var(--isms-border-strong);
    color: var(--isms-text);
    font-size: .75rem;
    font-weight: 500;
    padding: .3125rem .625rem;
    text-transform: capitalize;
    box-shadow: none;
}
.isms-calendar .fc .fc-button:hover { background: var(--isms-bg); }
.isms-calendar .fc .fc-button-primary:not(:disabled).fc-button-active,
.isms-calendar .fc .fc-button-primary:not(:disabled):active {
    background: var(--isms-brand);
    border-color: var(--isms-brand);
    color: #fff;
}
.isms-calendar .fc .fc-button:focus { box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .16); }
.isms-calendar .fc-theme-standard td,
.isms-calendar .fc-theme-standard th,
.isms-calendar .fc-theme-standard .fc-scrollgrid { border-color: var(--isms-border); }
.isms-calendar .fc .fc-col-header-cell-cushion {
    color: var(--isms-text-muted);
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: .5rem;
}
.isms-calendar .fc .fc-daygrid-day-number { color: var(--isms-text); font-size: .75rem; padding: .375rem .5rem; }
.isms-calendar .fc .fc-day-today { background: var(--isms-brand-soft) !important; }
.isms-calendar .fc .fc-day-other .fc-daygrid-day-number { color: var(--isms-text-muted); opacity: .55; }
.isms-calendar .fc-event { cursor: pointer; border-radius: var(--isms-radius-sm); font-size: .75rem; padding: 1px 4px; }
.isms-calendar .fc-event-title { font-weight: 500; }
.isms-calendar .fc .fc-list-event:hover td { background: var(--isms-brand-soft); }
.isms-calendar .fc .fc-more-link { font-size: .6875rem; color: var(--isms-brand); }

/* Leyenda común a ambos calendarios */
.calendar-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; font-size: .75rem; }
.calendar-legend__label { color: var(--isms-text-muted); font-weight: 600; }
.calendar-legend__item { display: inline-flex; align-items: center; gap: .375rem; }
.calendar-legend__item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Aviso de enfoque en el grafo de activos (?focus=<id>) */
.focus-banner {
    position: absolute;
    top: .75rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--isms-surface);
    border: 1px solid var(--isms-border);
    border-left: 3px solid var(--isms-brand);
    border-radius: var(--isms-radius);
    box-shadow: var(--isms-shadow);
    padding: .375rem .75rem;
    font-size: .75rem;
    z-index: 300;
}

/* ============ Panel de administración ============ */
/* Rejilla de áreas: sustituye a los botones de colores sin jerarquía */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    border-top: 1px solid var(--isms-border);
}
.admin-tile {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    padding: 1rem;
    /* Separadores en la propia celda: las posiciones sobrantes de la rejilla
       quedan vacías en lugar de pintarse como un bloque de color. */
    border-right: 1px solid var(--isms-border);
    border-bottom: 1px solid var(--isms-border);
    background: var(--isms-surface);
    color: var(--isms-text);
    text-decoration: none;
    transition: background-color .12s ease;
}
.admin-tile:hover { background: var(--isms-brand-soft); color: var(--isms-text); }
.admin-tile__icon { font-size: 1.125rem; color: var(--isms-brand); margin-bottom: .25rem; }
.admin-tile__title { font-size: .8125rem; font-weight: 600; }
.admin-tile__text { font-size: .75rem; color: var(--isms-text-muted); line-height: 1.4; }

/* Estado de las medidas de seguridad */
.security-row {
    display: flex;
    align-items: flex-start;
    gap: .625rem;
    padding: .5rem 0;
    border-bottom: 1px solid var(--isms-border);
    /* Ancla de `.stretched-link`: las medidas que se configuran desde el panel
       hacen clicable la fila entera. Sin esto el enlace se estiraría hasta la
       tarjeta y una sola fila se comería el clic de todas las demás. */
    position: relative;
}
.security-row:last-child { border-bottom: 0; }
.security-row > i { margin-top: .125rem; }
.security-row:has(.stretched-link):hover { background: var(--isms-surface-alt, rgba(0,0,0,.02)); }

/* Lista de catálogos de la pantalla de configuración */
.settings-list { border-top: 1px solid var(--isms-border); }
.settings-item {
    display: flex;
    align-items: center;
    gap: .875rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--isms-border);
    color: var(--isms-text);
    text-decoration: none;
    transition: background-color .12s ease;
}
.settings-item:last-child { border-bottom: 0; }
.settings-item:hover { background: var(--isms-brand-soft); color: var(--isms-text); }
.settings-item__icon {
    width: 2rem;
    text-align: center;
    font-size: 1.0625rem;
    color: var(--isms-brand);
    flex-shrink: 0;
}
.settings-item__body { min-width: 0; flex: 1; }
.settings-item__title { font-size: .8125rem; font-weight: 600; }
.settings-item__text { font-size: .75rem; color: var(--isms-text-muted); line-height: 1.4; }
.settings-item__count {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.1;
    font-size: 1.125rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}
.settings-item__count small {
    font-size: .6875rem;
    font-weight: 400;
    color: var(--isms-text-muted);
}
/* Un catálogo vacío rompe el cálculo de riesgo: se señala */
.settings-item__count.is-empty { color: var(--isms-danger); }
.settings-item__go { color: var(--isms-text-muted); font-size: .75rem; flex-shrink: 0; }

@media (max-width: 575.98px) {
    .settings-item__text { display: none; }
}

/* Barra de acciones de formulario: siempre visible al pie del área de contenido,
   para no obligar a bajar hasta el final en formularios largos. */
.form-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: 1rem;
    padding: .75rem 1rem;
    background: var(--isms-surface);
    border: 1px solid var(--isms-border);
    border-radius: var(--isms-radius);
    box-shadow: 0 -2px 6px rgba(16, 24, 40, .05);
}
.form-actions .me-auto { margin-right: auto; }

/* Encabezado de sección dentro de un formulario */
.form-section-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: 0 0 .875rem;
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--isms-text-muted);
}

/* ============ Select2 en tema oscuro ============
   El tema bootstrap-5 de Select2 fija colores claros y no reacciona a
   data-bs-theme, así que el desplegable quedaba blanco sobre fondo oscuro. */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-search__field {
    background-color: var(--isms-surface);
    border-color: var(--isms-border);
    color: var(--isms-text);
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__rendered,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option {
    color: var(--isms-text);
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__placeholder {
    color: var(--isms-text-muted);
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted {
    background-color: var(--isms-brand);
    color: #fff;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option[aria-selected="true"] {
    background-color: var(--isms-brand-soft);
}

/* ============ Pantallas de error ============
   Centrado y estrecho: en un 404 no hay nada que leer en diagonal, y una línea
   de 38rem se lee de una pasada. El código del error va arriba y pequeño porque
   no es lo que le importa a quien lo ve; el título sí. */
.error-pagina {
    max-width: 38rem;
    margin: 0 auto;
    padding: 3rem 1rem;
    text-align: center;
}

.error-icono {
    font-size: 2.5rem;
    line-height: 1;
    margin-bottom: 1rem;
}

.error-codigo {
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--isms-text-muted);
    margin-bottom: .35rem;
}

.error-pagina code {
    background: var(--isms-surface-alt);
    border: 1px solid var(--isms-border);
    border-radius: var(--isms-radius-sm);
    padding: .05rem .3rem;
}
