﻿/* Phase 4.3 — wrapped in @layer components to prevent cascade leakage */
@layer components {
/* ============================================
   SIDEBAR MÉDICO PROFESIONAL - TECSAS3 v3.0
   Inspirado en GE Healthcare y Siemens Healthineers
   Optimizado con persistencia de estado y UX mejorada
   ============================================ */

:root {
    /* Paleta TecsaS3 */
    --primary-color-rgb: 166, 218, 247;
    --secondary-color-rgb: 108, 175, 221;
    --tertiary-color-rgb: 69, 139, 186;
    --quaternary-color-rgb: 19, 77, 109;
    --quinternary-color-rgb: 4, 42, 58;
    --primary-color: var(--tecsa-secondary);
    --secondary-color: var(--tecsa-primary);
    --tertiary-color: var(--tecsa-primary);
    --quaternary-color: #134D6D;
    --quinternary-color: var(--tecsa-text);

    /* Sidebar específico */
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 70px;
    --sidebar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-bg: linear-gradient(180deg, rgba(19, 77, 109, 0.98) 0%, rgba(4, 42, 58, 0.98) 100%);
    --sidebar-border: rgba(166, 218, 247, 0.2);

    /* Primer plano PROPIO del sidebar.
       El sidebar tiene fondo oscuro fijo en los DOS temas: --sidebar-bg
       arranca justo en rgb(19 77 109). Por eso su tinta no puede resolverse a
       traves de un token de marca global: custom.css declara --tecsa-primary
       en @layer tokens, navbar.css lo REESCRIBE en @layer components (que gana
       por orden de capas) al mismo azul profundo con el que arranca
       --sidebar-bg, y navbar.css se carga en toda pagina autenticada
       (dashboard/header.html). El enlace activo quedaba con texto y fondo del
       MISMO color: 1.00:1 en tema claro y 1.65:1 en tricorder, medido.
       Estos tokens son locales y su contraste esta medido contra ese fondo; el
       override tricorder del final del fichero los redefine para ese tema.
       Notacion rgb() y no hex: es la ya dominante en este fichero para estos
       mismos colores (rgb(166 218 247) aparece 22 veces en forma rgba()). */
    --sidebar-fg-active: rgb(166 218 247);   /* 7.4:1 sobre el fondo */
    --sidebar-chip-fg: rgb(6 43 61);         /* tinta sobre chip claro */
    /* Texto normal de los botones de seccion (.btn-toggle). Su declaracion de
       color vivia aqui SIN !important y por tanto NUNCA se aplicaba: los
       botones son `class="btn btn-toggle"` y el `.btn` de bootstrap.min.css va
       sin capa, asi que gana a cualquier declaracion normal de
       @layer components. El color efectivo era --bs-btn-color, es decir
       --bs-body-color: en tema claro rgb(33 37 41) sobre el fondo oscuro del
       sidebar, 1.03:1 medido. En tricorder salia legible por accidente, porque
       la plantilla pone data-bs-theme="dark" y ahi ese token ya es claro. */
    --sidebar-fg: rgb(255 255 255 / 90%);    /* 9.09:1 sobre el fondo */
    --sidebar-fg-hover: rgb(255 255 255);    /* 10.4:1 sobre el fondo */
    /* Superficie de las tarjetas de seccion. Iban en un gradiente cuya segunda
       parada era var(--tecsa-primary); con el token reescrito, las dos paradas
       coincidian y el gradiente quedaba PLANO y del mismo color exacto que
       --sidebar-bg: la tarjeta desaparecia como superficie. Segunda parada un
       paso mas clara para que el borde se lea. */
    --sidebar-card-bg: linear-gradient(135deg, rgb(19 77 109) 0%, rgb(27 106 144) 100%);
}

/* -webkit-fill-available es el workaround de la barra de direcciones de Safari
   iOS (100vh mide de mas ahi). No es un prefijo "de transicion" que se pueda
   retirar: no hay equivalente estandar implementado. Se silencia la regla en
   estas dos lineas en vez de relajarla en .stylelintrc.json. Deuda
   preexistente: el fichero ya fallaba este check antes de este cambio. */
html {
    /* stylelint-disable-next-line value-no-vendor-prefix */
    height: -webkit-fill-available;
}

main {
    height: 100vh;
    /* stylelint-disable-next-line value-no-vendor-prefix */
    height: -webkit-fill-available;
    max-height: 100vh;
}

/* ============================================
   CONTENEDOR PRINCIPAL DEL SIDEBAR
   ============================================ */
#sidebar {
    position: fixed;
    /* Offset y alto derivados del header fijo: top = navbar + holgura,
       height = viewport - navbar - 2x holgura. Token canónico en
       theme-tokens.css (--app-header-height). */
    top: calc(var(--app-header-height, 90px) + 10px);
    left: 15px;
    width: var(--sidebar-width);
    height: calc(100vh - var(--app-header-height, 90px) - 30px);
    max-height: calc(100vh - var(--app-header-height, 90px) - 30px);
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2),
                0 2px 8px rgba(0, 0, 0, 0.1),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid var(--sidebar-border);
    overflow-y: auto;
    overflow-x: hidden;
    transition: var(--sidebar-transition);
    z-index: 900;
    padding: 20px 0;
}

/* ============================================
   AJUSTE DEL SIDEBAR SEGÚN ESTADO DEL NAVBAR
   ============================================ */
body.navbar-is-collapsed #sidebar {
    top: 30px;
    height: calc(100vh - 50px);
    max-height: calc(100vh - 50px);
}

body:not(.navbar-is-collapsed) #sidebar {
    top: calc(var(--app-header-height, 90px) + 10px);
    height: calc(100vh - var(--app-header-height, 90px) - 30px);
    max-height: calc(100vh - var(--app-header-height, 90px) - 30px);
}

html, body {
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

body {
    overflow-y: auto;
    overflow-x: hidden;
}

#main-content {
    margin-left: 295px;
    /* Sin 100vh puro: el body ya compensa el navbar fijo con padding-top
       (token --app-header-height), así que 100vh desbordaba el documento
       en >=90px incluso con contenido corto (doble scrollbar). Mismo
       criterio que #wrapper en dashboard/base.html. */
    min-height: calc(100vh - var(--app-header-height, 90px));
    min-height: calc(100dvh - var(--app-header-height, 90px));
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Con navbar colapsado el body no lleva padding-top (base.html), así que
   ahí sí cabe el viewport completo. */
body.navbar-is-collapsed #main-content {
    min-height: 100vh;
}

/* ============================================
   CONTROL PARA OCULTAR EL SIDEBAR (mayor visibilidad)
   ============================================ */
.sidebar-hide-toggle {
    position: fixed;
    top: calc(var(--app-header-height, 90px) + 20px);
    left: 283px;
    z-index: 950;
    width: 30px;
    height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--sidebar-border, rgba(166, 218, 247, 0.2));
    border-radius: 0 10px 10px 0;
    background: var(--quaternary-color, #134D6D);
    color: #fff;
    cursor: pointer;
    box-shadow: 4px 0 12px rgba(4, 42, 58, 0.25);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s ease;
}

.sidebar-hide-toggle:hover,
.sidebar-hide-toggle:focus-visible {
    background: var(--tertiary-color, #458BBA);
}

body.sidebar-hidden .sidebar-hide-toggle {
    left: 0;
}

body.sidebar-hidden #sidebar {
    transform: translateX(-115%);
}

body.sidebar-hidden #main-content {
    margin-left: 0;
}

@media (max-width: 768px) {
    /* En móvil el sidebar ya es overlay; el control de ocultar no aplica */
    .sidebar-hide-toggle {
        display: none;
    }
}

#content-wrapper {
    flex: 1;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.05);
    width: 100%;
    /* clip (no hidden): overflow-x hidden + overflow-y visible computa
       overflow-y:auto y convierte este wrapper en segundo scrollbar. */
    overflow-x: hidden;
    overflow-x: clip;
    overflow-y: visible;
}

/* ============================================
   SCROLLBAR MEJORADA
   ============================================ */
#sidebar::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(166, 218, 247, 0.3);
    border-radius: 10px;
    transition: background 0.3s ease;
}

#sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(166, 218, 247, 0.5);
}

/* ============================================
   BOTONES PRINCIPALES DE SECCIÓN (CARDS)
   ============================================ */
#sidebar .card {
    padding: 0;
    background: linear-gradient(135deg,
        rgba(166, 218, 247, 0.25) 0%,
        rgba(108, 175, 221, 0.2) 100%) !important;
    border-radius: 12px;
    border: 1px solid rgba(166, 218, 247, 0.3) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: var(--sidebar-transition);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

/* Borde izquierdo de acento */
#sidebar .card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, var(--tecsa-secondary) 0%, var(--sidebar-fg-active) 100%);
    opacity: 0.8;
    transition: all 0.3s ease;
}

#sidebar .card-body {
    padding: 14px 16px;
    background: transparent;
    border-radius: 12px;
    transition: var(--sidebar-transition);
    position: relative;
    z-index: 1;
}

/* Efecto hover en cards */
#sidebar .card:hover {
    background: linear-gradient(135deg,
        rgba(166, 218, 247, 0.35) 0%,
        rgba(108, 175, 221, 0.3) 100%) !important;
    transform: translateX(5px);
    border-color: rgba(166, 218, 247, 0.5) !important;
    box-shadow: 0 4px 16px rgba(166, 218, 247, 0.25),
                0 2px 8px rgba(0, 0, 0, 0.2),
                inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

#sidebar .card:hover::before {
    width: 5px;
    opacity: 1;
    box-shadow: 0 0 10px rgba(166, 218, 247, 0.5);
}

/* Texto en los botones principales */
#sidebar .card .sidebar-heading {
    color: #ffffff !important;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

#sidebar .card .sidebar-heading span {
    color: #ffffff !important;
    font-weight: 600;
    font-size: 0.95rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.3px;
}

#sidebar .card .sidebar-heading i {
    color: var(--tecsa-secondary) !important;
    filter: brightness(1.2) drop-shadow(0 0 2px rgba(166, 218, 247, 0.4));
}

/* Estados hover con contraste */
#sidebar .card:hover .sidebar-heading {
    color: #ffffff !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

#sidebar .card:hover .sidebar-heading span {
    color: #ffffff !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.4px;
}

#sidebar .card:hover .sidebar-heading i {
    color: #ffffff !important;
    filter: brightness(1.4) drop-shadow(0 0 4px rgba(166, 218, 247, 0.6));
}

/* ============================================
   ESTILOS PARA SECCIONES DEL SIDEBAR (sidebar.html)
   ============================================ */

/* Brand/Header del sidebar */
#sidebar-container .sidebar-brand {
    padding: 1rem 0.75rem;
}

#sidebar-container .sidebar-brand-icon {
    padding: 0.5rem;
    background: var(--sidebar-card-bg);
    border-radius: 12px;
    color: #fff;
    box-shadow: 0 4px 15px rgba(19, 77, 109, 0.3);
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#sidebar-container .sidebar-brand-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#sidebar-container .sidebar-brand-text {
    margin-top: 0.5rem;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    font-size: 0.75rem;
}

#sidebar-container .sidebar-brand-text span {
    letter-spacing: 1.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
    font-size: 0.7rem;
}

#sidebar-container .sidebar-divider {
    width: 60%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #134D6D, transparent);
    opacity: 0.3;
    margin: 1rem auto 0;
}

/* Secciones principales (sidebar-section-card) */
#sidebar-container .sidebar-section-card {
    background: var(--sidebar-card-bg);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(19, 77, 109, 0.25);
}

#sidebar-container .sidebar-section-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(19, 77, 109, 0.35);
}

#sidebar-container .sidebar-section-card .card-body {
    padding: 0.75rem 1rem;
}

#sidebar-container .sidebar-section-title {
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
}

#sidebar-container .sidebar-section-icon {
    color: rgba(255, 255, 255, 0.9);
}

#sidebar-container .sidebar-section-arrow {
    color: rgba(255, 255, 255, 0.7);
    transition: transform 0.3s ease;
}

#sidebar-container .sidebar-section-card[aria-expanded="true"] .sidebar-section-arrow {
    transform: rotate(180deg);
}

/* ============================================
   BOTONES DE NAVEGACIÓN (COLAPSABLES)
   ============================================ */
.dropdown-toggle {
    outline: 0;
}

.btn-toggle {
    width: 100%;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    /* !important obligatorio, no cosmetico: sin el, gana el `.btn` sin capa de
       Bootstrap y el rotulo queda en --bs-body-color (1.03:1 en tema claro).
       El valor sale de un token del propio sidebar, que el bloque tricorder
       del final del fichero redefine. */
    color: var(--sidebar-fg) !important;
    background: transparent;
    border: none;
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
    transition: var(--sidebar-transition);
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-toggle:hover,
.btn-toggle:focus {
    background: rgba(166, 218, 247, 0.1);
    /* Mismo motivo que el estado normal: `.btn:hover` de Bootstrap va sin capa. */
    color: var(--sidebar-fg-hover) !important;
    transform: translateX(4px);
    box-shadow: inset 0 0 0 1px rgba(166, 218, 247, 0.2);
}

.btn-toggle[aria-expanded="true"] {
    background: rgba(166, 218, 247, 0.15);
    color: var(--sidebar-fg-hover) !important;
    box-shadow: 0 2px 8px rgba(166, 218, 247, 0.2);
}

/* Arrow indicator */
.btn-toggle::after {
    content: '\f054';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--tecsa-secondary);
    transition: transform 0.3s ease;
}

.btn-toggle[aria-expanded="true"]::after {
    transform: rotate(90deg);
}

/* Iconos dentro de botones toggle */
.btn-toggle i {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(166, 218, 247, 0.1);
    border-radius: 8px;
    font-size: 1rem;
    color: var(--tecsa-secondary);
    flex-shrink: 0;
    transition: var(--sidebar-transition);
}

.btn-toggle:hover i {
    background: linear-gradient(135deg, var(--tecsa-secondary) 0%, var(--sidebar-fg-active) 100%);
    color: var(--sidebar-chip-fg);
    transform: scale(1.1);
}

/* ============================================
   ENLACES DE NAVEGACIÓN (NAVLINK)
   ============================================ */
.nav-link {
    color: rgba(122, 208, 227, 0.95) !important;
    text-decoration: none !important;
    transition: var(--sidebar-transition);
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 10px 12px !important;
    border-radius: 8px !important;
    background: transparent !important;
    position: relative;
}

.nav-link:hover,
.nav-link:focus {
    color: #ffffff !important;
    background: rgba(166, 218, 247, 0.8) !important;
    transform: translateX(4px);
}

/* Estado activo - EFECTO DESTACADO */
.nav-link.active {
    background: linear-gradient(135deg,
        rgba(166, 218, 247, 0.25) 0%,
        rgba(108, 175, 221, 0.2) 100%) !important;
    /* El !important se conserva a proposito: bootstrap.min.css se carga SIN
       capa y una declaracion sin capa vence a cualquier declaracion normal de
       @layer components, sin importar la especificidad. Sin el, este enlace
       tomaria el azul de `.nav-link` de Bootstrap. El defecto era el VALOR
       -- var(--tecsa-primary), que navbar.css reescribe al propio fondo del
       sidebar -- no el !important. */
    color: var(--sidebar-fg-active) !important;
    font-weight: 600;
    padding-left: 16px !important;
    box-shadow:
        0 2px 8px rgba(166, 218, 247, 0.2),
        inset 0 0 0 1px rgba(166, 218, 247, 0.1);
    position: relative;
    animation: activeGlow 2s ease-in-out infinite;
}

/* Indicador izquierdo para activo */
.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    background: linear-gradient(180deg, var(--tecsa-secondary) 0%, var(--sidebar-fg-active) 100%);
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px rgba(166, 218, 247, 0.6);
}

/* Mini card en estado activo */
.nav-link.active .sidebar-mini-card {
    background: linear-gradient(135deg, var(--tecsa-secondary) 0%, var(--sidebar-fg-active) 100%);
    box-shadow: 0 2px 8px rgba(166, 218, 247, 0.4);
}

.nav-link.active .sidebar-mini-card i {
    color: var(--sidebar-chip-fg) !important;
}

/* Animación de brillo para activo */
@keyframes activeGlow {
    0%, 100% {
        box-shadow:
            0 2px 8px rgba(166, 218, 247, 0.2),
            inset 0 0 0 1px rgba(166, 218, 247, 0.1);
    }
    50% {
        box-shadow:
            0 2px 12px rgba(166, 218, 247, 0.3),
            inset 0 0 0 1px rgba(166, 218, 247, 0.2);
    }
}

.nav-link.disabled {
    color: rgba(255, 255, 255, 0.4) !important;
    pointer-events: none;
    cursor: not-allowed;
}

/* ============================================
   SUBMENÚS (DESPLEGABLES)
   ============================================ */
.btn-toggle-nav {
    list-style: none;
    padding: 8px 0 8px 20px;
    margin: 0;
}

.btn-toggle-nav li {
    margin-bottom: 4px;
}

.btn-toggle-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--sidebar-transition);
    position: relative;
    background: transparent;
}

.btn-toggle-nav a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 2px;
    background: var(--tecsa-secondary);
    transition: width 0.3s ease;
}

.btn-toggle-nav a:hover::before {
    width: 8px;
}

.btn-toggle-nav a:hover,
.btn-toggle-nav a:focus {
    background: rgba(166, 218, 247, 0.1);
    color: #ffffff;
    padding-left: 16px;
}

/* Estado activo en submenús */
.btn-toggle-nav a.active {
    background: linear-gradient(135deg, rgba(166, 218, 247, 0.2) 0%, rgba(108, 175, 221, 0.15) 100%);
    color: var(--tecsa-secondary);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(166, 218, 247, 0.15);
    padding-left: 16px;
}

.btn-toggle-nav a.active::before {
    width: 4px;
    height: 60%;
}

/* Links dentro de submenús */
.btn-toggle-nav a .nav-link {
    color: inherit !important;
}

/* ============================================
   ICONOS Y MINI CARDS
   ============================================ */
.icon-spacing {
    margin-right: 8px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.85rem;
}

.sidebar-mini-card {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(166, 218, 247, 0.08);
    border-radius: 6px;
    transition: var(--sidebar-transition);
    flex-shrink: 0;
}

.btn-toggle-nav a:hover .sidebar-mini-card {
    background: rgba(166, 218, 247, 0.2);
    transform: scale(1.1);
}

.sidebar-mini-card i {
    font-size: 0.9rem;
    color: var(--tecsa-secondary);
}

.btn-toggle-nav a:hover .sidebar-mini-card i {
    color: var(--sidebar-fg-active);
}

/* ============================================
   SIDEBAR HEADING
   ============================================ */
.sidebar-heading {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--tecsa-secondary);
    letter-spacing: 0.3px;
    transition: var(--sidebar-transition);
    cursor: pointer;
}

.sidebar-heading:hover {
    color: #ffffff;
    transform: scale(1.02);
}

.sidebar-heading i {
    color: var(--tecsa-secondary);
    transition: var(--sidebar-transition);
}

.sidebar-heading:hover i {
    color: var(--sidebar-fg-active);
    transform: rotate(-10deg) scale(1.1);
}

/* ============================================
   DIVIDERS
   ============================================ */
.sidebar-divider {
    height: 1px;
    margin: 20px 20px;
    background: linear-gradient(90deg, transparent 0%, rgba(166, 218, 247, 0.3) 50%, transparent 100%);
    border: none;
}

/* ============================================
   LINK BODY EMPHASIS
   ============================================ */
.link-body-emphasis {
    color: rgba(255, 255, 255, 0.85) !important;
    text-decoration: none !important;
    transition: var(--sidebar-transition);
}

.link-body-emphasis:hover,
.link-body-emphasis:focus {
    color: #ffffff !important;
    background: rgba(166, 218, 247, 0.1);
}

.link-body-emphasis.disabled {
    color: rgba(255, 255, 255, 0.4) !important;
    pointer-events: none;
    cursor: not-allowed;
}

/* ============================================
   PROFILE SECTION
   ============================================ */
#profile-sublist,
#developer-sublist {
    padding-left: 20px;
}

#profile-sublist .btn-toggle-nav a,
#developer-sublist .btn-toggle-nav a,
#mensajeria-collapse .btn-toggle-nav a {
    color: rgba(255, 255, 255, 0.85);
    background: transparent;
}

#profile-sublist .btn-toggle-nav a:hover,
#developer-sublist .btn-toggle-nav a:hover,
#mensajeria-collapse .btn-toggle-nav a:hover {
    background: rgba(166, 218, 247, 0.1);
    color: #ffffff;
    padding-left: 16px;
}

/* ============================================
   SECTIONS CON ICONOS
   ============================================ */
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #ffffff;
}

.sidebar-nav-item i {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(166, 218, 247, 0.1);
    border-radius: 8px;
    font-size: 1rem;
    color: var(--tecsa-secondary);
}

/* ============================================
   ANIMACIONES Y EFECTOS
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.collapse.show {
    animation: fadeIn 0.4s ease-out;
}

.sidebar-section {
    animation: slideIn 0.4s ease-out backwards;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Desktop Large (>1200px) */
@media (min-width: 1200px) {
    #sidebar {
        width: var(--sidebar-width);
    }
}

/* Tablet (768px - 1200px) → RAIL SOLO-ICONOS
   Oculta el texto y conserva los iconos; los nombres se ven vía tooltips
   (Bootstrap tooltips con container:'body', no se recortan). */
@media (max-width: 1200px) and (min-width: 768px) {
    #sidebar {
        width: var(--sidebar-collapsed-width, 70px);
        left: 8px;
        padding: 16px 4px;
    }

    #main-content {
        margin-left: 90px;
    }

    .sidebar-hide-toggle {
        left: calc(var(--sidebar-collapsed-width, 70px) + 0px);
    }

    /* Ocultar todo el texto */
    #sidebar-container .sidebar-brand-text,
    #sidebar-container .sidebar-section-title,
    #sidebar-container .sidebar-section-arrow,
    #sidebar .btn-toggle > span,
    #sidebar .nav-link > span {
        display: none !important;
    }

    /* Ocultar el caret del btn-toggle en modo rail */
    #sidebar .btn-toggle::after {
        display: none !important;
    }

    /* Centrar iconos */
    #sidebar-container .sidebar-brand {
        padding: 0.5rem 0;
    }

    #sidebar-container .sidebar-brand-icon {
        width: 44px;
        height: 44px;
        margin: 0 auto;
    }

    #sidebar-container .sidebar-section-card .card-body {
        justify-content: center;
        padding: 0.55rem 0;
    }

    #sidebar-container .sidebar-section-icon,
    #sidebar .sidebar-section-title.ms-3 {
        margin: 0 !important;
    }

    #sidebar .btn-toggle,
    #sidebar .nav-link {
        justify-content: center;
        gap: 0;
        padding: 0.5rem 0 !important;
    }

    /* Quitar la indentación de las sublistas anidadas en el rail */
    #sidebar .btn-toggle-nav {
        padding-left: 0 !important;
    }

    #sidebar-container .sidebar-mini-card {
        margin: 0 auto;
    }

    #sidebar-container .icon-spacing {
        width: auto;
        margin: 0;
    }

    #sidebar-container .sidebar-divider {
        margin: 0.75rem auto 0;
    }
}

/* Mobile Large (576px - 768px) */
@media (max-width: 768px) {
    #sidebar {
        transform: translateX(-100%);
        left: 0;
        width: 280px;
        transition: transform 0.3s ease;
        top: var(--app-header-height, 70px);
    }

    #sidebar.sidebar-open {
        transform: translateX(0);
        left: 15px;
    }

    /* Ajuste cuando navbar colapsado en mobile */
    body.navbar-is-collapsed #sidebar {
        top: 30px;
        height: calc(100vh - 50px);
        max-height: calc(100vh - 50px);
    }

    #main-content {
        margin-left: 0;
        /* Sin compensación de navbar: el desplazamiento bajo el header fijo
           lo aporta body.has-app-header { padding-top } en base.html; sumar
           aquí otro margen producía doble offset (contenido a 2x altura). */
        margin-top: 0;
    }

    .btn-toggle {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .btn-toggle-nav a {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .sidebar-brand-icon {
        width: 38px;
        height: 38px;
        font-size: 1.4rem;
    }

    .sidebar-brand-text {
        font-size: 1.2rem;
    }

    /* Ajustes para sidebar.html */
    #sidebar-container {
        padding: 0.5rem !important;
    }

    #sidebar-container .sidebar-brand {
        padding: 0.5rem 0.375rem;
    }

    #sidebar-container .sidebar-brand-icon {
        width: 82px;
        height: 82px;
        border-radius: 8px;
        padding: 0.3rem;
    }

    #sidebar-container .sidebar-brand-text {
        font-size: 0.65rem;
    }

    #sidebar-container .sidebar-brand-text span {
        font-size: 0.6rem;
        letter-spacing: 1px;
    }

    #sidebar-container .sidebar-section-card {
        border-radius: 8px;
    }

    #sidebar-container .sidebar-section-card .card-body {
        padding: 0.5rem 0.625rem;
    }

    #sidebar-container .sidebar-section-title {
        font-size: 0.75rem;
        font-weight: 500;
    }

    #sidebar-container .sidebar-section-icon {
        font-size: 0.85rem !important;
    }

    #sidebar-container .sidebar-section-arrow {
        font-size: 0.7rem !important;
    }

    #sidebar-container .btn-toggle {
        padding: 0.45rem 0.625rem;
        font-size: 0.75rem;
        border-radius: 5px;
    }

    #sidebar-container .nav-link {
        padding: 0.4rem 0.625rem;
        font-size: 0.75rem;
        border-radius: 5px;
    }

    #sidebar-container .sidebar-mini-card {
        width: 20px;
        height: 20px;
        border-radius: 5px;
    }

    #sidebar-container .icon-spacing {
        width: 16px;
        font-size: 0.75rem;
        margin-right: 0.35rem;
    }

    #sidebar-container ul.list-unstyled.ps-0 > li {
        margin-bottom: 0.25rem;
    }

    #sidebar-container .sidebar-divider {
        margin: 0.5rem auto 0;
        height: 1px;
    }
}

/* Mobile Small (<576px) */
@media (max-width: 576px) {
    #sidebar {
        width: calc(100vw - 30px);
        left: 15px;
        right: 15px;
        top: var(--app-header-height, 70px);
        height: calc(100vh - var(--app-header-height, 70px) - 20px);
    }

    /* Ajuste cuando navbar colapsado en mobile pequeño */
    body.navbar-is-collapsed #sidebar {
        top: 25px;
        height: calc(100vh - 45px);
        max-height: calc(100vh - 45px);
    }

    .sidebar-brand-text {
        font-size: 1.1rem;
    }

    .btn-toggle {
        font-size: 0.85rem;
        padding: 10px 12px;
    }

    .btn-toggle i {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }

    .sidebar-mini-card {
        width: 24px;
        height: 24px;
    }

    .sidebar-mini-card i {
        font-size: 0.8rem;
    }
}

/* Altura pequeña */
@media (max-height: 600px) {
    #sidebar {
        padding: 10px 0;
    }

    .sidebar-brand {
        padding: 10px 15px 15px;
        margin-bottom: 15px;
    }

    .sidebar-brand-icon {
        width: 35px;
        height: 35px;
        font-size: 1.4rem;
    }

    .sidebar-brand-text {
        font-size: 1.1rem;
    }

    .btn-toggle {
        padding: 8px 12px;
    }

    .btn-toggle i {
        width: 28px;
        height: 28px;
    }

    .btn-toggle-nav a {
        padding: 6px 10px;
    }

    .card-body {
        padding: 10px 12px !important;
    }
}

/* ============================================
   ADAPTACIÓN AL ESTADO DEL NAVBAR (sidebar.html)
   ============================================ */
/* Cuando navbar está colapsado - sidebar toma todo el espacio */
body.navbar-is-collapsed #sidebar-container {
    margin-top: 0 !important;
    padding-top: 0.5rem !important;
}

body.navbar-is-collapsed .sidebar-content {
    padding-top: 0 !important;
}

body.navbar-is-collapsed #sidebar-container .sidebar-brand {
    padding-top: 0.5rem !important;
}

/* Cuando navbar está colapsado - remover margin-top del contenido */
body.navbar-is-collapsed .content-area {
    margin-top: 0 !important;
    padding-top: 1rem !important;
}

body.navbar-is-collapsed #main-content {
    padding-top: 0 !important;
}

/* Ajuste del contenido del sidebar según estado navbar */
body.navbar-is-collapsed .sidebar-main-content {
    padding-top: 0.5rem !important;
}

body.navbar-is-expanded .sidebar-main-content {
    padding-top: 0 !important;
}

/* ============================================
   TOGGLES DE BOOTSTRAP
   ============================================ */
[data-bs-toggle="collapse"] {
    cursor: pointer;
}

/* ============================================
   SCROLLAREA
   ============================================ */
.scrollarea {
    overflow-y: auto;
}

/* ============================================
   BI (Bootstrap Icons)
   ============================================ */
.bi {
    vertical-align: -0.125em;
    fill: currentColor;
}

/* ============================================
   UTILIDADES ADICIONALES
   ============================================ */

/* Ocultar elemento */
.d-none {
    display: none !important;
}

/* Transiciones suaves para todos los elementos del sidebar */
#sidebar *,
#sidebar *::before,
#sidebar *::after {
    box-sizing: border-box;
}

/* Focus states para accesibilidad */
#sidebar a:focus-visible,
#sidebar button:focus-visible {
    outline: 2px solid var(--tecsa-secondary);
    outline-offset: 2px;
}

/* Selection color */
#sidebar ::selection {
    background: rgba(166, 218, 247, 0.3);
    color: #ffffff;
}

/* Espaciado entre elementos del sidebar */
#sidebar-container ul.list-unstyled.ps-0 > li {
    margin-bottom: 0.35rem;
}

/* Estilos para sub-secciones (btn-toggle) en sidebar.html */
#sidebar-container .btn-toggle {
    width: 100%;
    padding: 0.6rem 0.875rem;
    justify-content: flex-start;
    border-radius: 6px;
    margin-bottom: 0.2rem;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

#sidebar-container .btn-toggle:hover {
    background-color: rgba(19, 77, 109, 0.08);
    padding-left: 1rem;
}

#sidebar-container .btn-toggle::after {
    margin-left: auto;
    transition: transform 0.3s ease;
}

#sidebar-container .btn-toggle:not(.collapsed)::after {
    transform: rotate(90deg);
}

/* ============================================
   ESTILOS ESPECIALES PARA SIDEBAR-ACTIVE-LINK
   (Generados dinámicamente por JS)
   ============================================ */
.sidebar-active-link {
    background: linear-gradient(135deg,
        rgba(166, 218, 247, 0.25) 0%,
        rgba(108, 175, 221, 0.2) 100%) !important;
    color: var(--sidebar-fg-active) !important;
    font-weight: 600;
    border-left: 3px solid transparent;
    padding-left: 16px !important;
    box-shadow:
        0 2px 8px rgba(166, 218, 247, 0.2),
        inset 0 0 0 1px rgba(166, 218, 247, 0.1);
    position: relative;
}

.sidebar-active-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: linear-gradient(180deg, var(--tecsa-secondary) 0%, var(--sidebar-fg-active) 100%);
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px rgba(166, 218, 247, 0.6);
}

.sidebar-active-link .sidebar-mini-card {
    background: linear-gradient(135deg, var(--tecsa-secondary) 0%, var(--sidebar-fg-active) 100%);
    color: var(--sidebar-chip-fg) !important;
    box-shadow: 0 2px 8px rgba(166, 218, 247, 0.4);
}

.sidebar-active-link .sidebar-mini-card i {
    color: var(--sidebar-chip-fg) !important;
}

/* Efecto de brillo para activo */
.sidebar-active-link {
    animation: activeGlow 2s ease-in-out infinite;
}

/* Indicador activo izquierdo */
.active-indicator {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 70%;
    background: linear-gradient(180deg, var(--tecsa-secondary) 0%, var(--sidebar-fg-active) 100%);
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 10px rgba(166, 218, 247, 0.5);
    animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
    from {
        width: 0;
        opacity: 0;
    }
    to {
        width: 4px;
        opacity: 1;
    }
}

/* Ripple effect */
.ripple-effect {
    position: absolute;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    animation: ripple 0.6s ease-out;
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: translate(-50%, -50%) scale(4);
        opacity: 0;
    }
}

} /* end @layer components */

/* ==============================================================================
   OVERRIDE TRICORDER — scoped bajo html[data-app-theme="tricorder"]
   Reutiliza los tokens --tricorder-* de custom.css. El look azul legacy se
   conserva intacto fuera del tema. Especificidad elevada con el atributo + #id.
   ============================================================================== */
@layer components {

    html[data-app-theme="tricorder"] #sidebar {
        /* Los tokens de primer plano del sidebar se redefinen AQUI, no en
           reglas por selector: el enlace activo se pinta con `!important`
           (necesario frente al Bootstrap sin capa) y una redefinicion por
           selector no podria vencerlo desde la misma capa. La resolucion de
           una custom property no la afecta el !important del consumidor, asi
           que una sola declaracion sirve a los dos temas. */
        --sidebar-fg-active: var(--tricorder-primary, #00E5FF);
        --sidebar-fg: var(--tricorder-muted, #82B4C7);
        --sidebar-fg-hover: var(--tricorder-primary, #00E5FF);
        --sidebar-chip-fg: var(--tricorder-surface-0, #061322);
        --sidebar-card-bg: var(--tricorder-surface-1, rgba(15, 30, 50, 0.85));

        background: var(--tricorder-card-bg, linear-gradient(180deg, rgba(10, 22, 40, 0.96) 0%, rgba(6, 19, 34, 0.96) 100%));
        backdrop-filter: blur(20px) saturate(160%);
        -webkit-backdrop-filter: blur(20px) saturate(160%);
        border: 1px solid var(--tricorder-border-soft, rgba(0, 229, 255, 0.15));
        box-shadow: var(--shadow-3, 0 12px 32px rgba(0, 0, 0, 0.4)),
                    inset 0 1px 0 rgba(0, 229, 255, 0.08);
    }

    /* Cards / secciones internas */
    html[data-app-theme="tricorder"] #sidebar .card,
    html[data-app-theme="tricorder"] #sidebar-container .sidebar-section-card {
        background: var(--tricorder-surface-1, rgba(15, 30, 50, 0.85));
        border: 1px solid var(--tricorder-border-soft, rgba(0, 229, 255, 0.15));
    }

    html[data-app-theme="tricorder"] #sidebar .card:hover,
    html[data-app-theme="tricorder"] #sidebar-container .sidebar-section-card:hover {
        border-color: var(--tricorder-border, rgba(0, 229, 255, 0.3));
        background: var(--tricorder-surface-2, rgba(20, 40, 60, 0.9));
    }

    /* Marca */
    html[data-app-theme="tricorder"] #sidebar-container .sidebar-brand-text span {
        color: var(--tricorder-text, #E0F7FA);
        font-family: var(--font-display, 'Space Grotesk', system-ui, sans-serif);
    }

    html[data-app-theme="tricorder"] #sidebar-container .sidebar-divider {
        background: linear-gradient(90deg, transparent, var(--tricorder-primary, #00E5FF), transparent);
        opacity: 0.5;
    }

    /* Títulos / iconos de sección */
    html[data-app-theme="tricorder"] #sidebar-container .sidebar-section-title {
        color: var(--tricorder-text, #E0F7FA);
    }

    html[data-app-theme="tricorder"] #sidebar-container .sidebar-section-icon,
    html[data-app-theme="tricorder"] #sidebar-container .sidebar-section-arrow {
        color: var(--tricorder-primary, #00E5FF);
    }

    /* Botones de toggle y enlaces de navegación */
    /* Sin `color` a proposito. Tanto `.btn-toggle` como `#sidebar .nav-link`
       se pintan con !important desde la base del fichero (obligatorio frente
       al `.btn`/`.nav-link` sin capa de Bootstrap), asi que una declaracion
       normal aqui no puede aplicarse: seria codigo muerto que invita a
       "ajustar el tema" en el sitio equivocado. El color de este tema entra
       por los tokens --sidebar-fg / --sidebar-fg-hover, redefinidos arriba en
       el bloque html[data-app-theme="tricorder"] #sidebar. */
    html[data-app-theme="tricorder"] .btn-toggle,
    html[data-app-theme="tricorder"] #sidebar .nav-link {
        min-height: var(--touch-target, 44px);
    }

    html[data-app-theme="tricorder"] .btn-toggle:hover,
    html[data-app-theme="tricorder"] .btn-toggle:focus,
    html[data-app-theme="tricorder"] #sidebar .nav-link:hover,
    html[data-app-theme="tricorder"] #sidebar .nav-link:focus-visible {
        color: var(--tricorder-primary, #00E5FF);
        background: rgba(0, 229, 255, 0.1);
    }

    html[data-app-theme="tricorder"] .btn-toggle i,
    html[data-app-theme="tricorder"] #sidebar .nav-link i {
        color: var(--tricorder-primary, #00E5FF);
        opacity: 0.9;
    }

    /* Enlace activo: glow cyan */
    html[data-app-theme="tricorder"] #sidebar .nav-link.active,
    html[data-app-theme="tricorder"] #sidebar .nav-link[aria-current="page"] {
        color: var(--tricorder-primary, #00E5FF);
        background: rgba(0, 229, 255, 0.14);
        box-shadow: inset 3px 0 0 var(--tricorder-primary, #00E5FF),
                    0 0 12px rgba(0, 229, 255, 0.18);
    }

    /* Mini-cards de icono */
    html[data-app-theme="tricorder"] .sidebar-mini-card {
        background: rgba(0, 229, 255, 0.1);
        border: 1px solid var(--tricorder-border-soft, rgba(0, 229, 255, 0.15));
        color: var(--tricorder-primary, #00E5FF);
    }

    html[data-app-theme="tricorder"] .sidebar-hide-toggle {
        background: var(--tricorder-surface-2, rgba(20, 40, 60, 0.92));
        border-color: var(--tricorder-border-soft, rgba(0, 229, 255, 0.15));
        color: var(--tricorder-primary, #00E5FF);
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.4), 0 0 10px rgba(0, 229, 255, 0.15);
    }

    html[data-app-theme="tricorder"] .sidebar-hide-toggle:hover,
    html[data-app-theme="tricorder"] .sidebar-hide-toggle:focus-visible {
        background: rgba(0, 229, 255, 0.16);
    }

    /* ====== Rail 2026: jerarquía tipográfica + chevrons + focus ====== */

    /* Títulos de sección estilo rail: uppercase mono con tracking amplio */
    html[data-app-theme="tricorder"] #sidebar-container .sidebar-section-title {
        font-family: var(--font-mono, ui-monospace, monospace);
        font-size: var(--fs-2xs, 0.72rem);
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: var(--tracking-wider, 0.08em);
    }

    /* Chevron de sección rota 180° al expandir (CSS puro vía aria-expanded) */
    #sidebar-container .sidebar-section-arrow,
    #sidebar .sidebar-section-arrow {
        transition: transform 0.2s var(--ease-out-quart, ease-out);
    }

    #sidebar-container [aria-expanded="true"] .sidebar-section-arrow,
    #sidebar [aria-expanded="true"] .sidebar-section-arrow {
        transform: rotate(180deg);
    }

    /* Focus visible consistente en toda la navegación lateral */
    #sidebar a:focus-visible,
    #sidebar button:focus-visible,
    #sidebar [role="button"]:focus-visible {
        outline: 2px solid var(--tricorder-primary, #00E5FF);
        outline-offset: 2px;
        border-radius: var(--radius-xs, 4px);
    }

    /* Reduced motion */
    html[data-reduced-motion] #sidebar-container .sidebar-section-arrow,
    html[data-reduced-motion] #sidebar .sidebar-section-arrow {
        transition: none;
    }

    @media (prefers-reduced-motion: reduce) {
        #sidebar-container .sidebar-section-arrow,
        #sidebar .sidebar-section-arrow {
            transition: none;
        }
    }

} /* end @layer components (tricorder overrides) */
