/* ============================================================
   menu.css — MENÚ de navegación: top-bar, sidebar y drawer móvil
   ------------------------------------------------------------
   - Top menu (solo OSCURO; en claro se deja el menú clásico
     oscuro para no romper los iconos sprite blancos).
   - Layout lateral (sidebar) en escritorio (>=901px).
   - Hamburguesa + drawer en móvil (<=900px).
   El sidebar/drawer usa fondo OSCURO fijo (var(--nav-bg)/var(--nav-bg-2)) en
   AMBOS temas para que los iconos claros siempre se vean.
   Los iconos SVG del menú viven en icons.css; el conmutador de
   temas, en components.css. Clásico intacto (todo gateado).
   ============================================================ */

/* ----- Top menu (solo OSCURO) ----- */
html.theme-cg.theme-dark #head { background: var(--surface-2); border-color: var(--border); border-bottom-color: var(--accent); }
html.theme-cg.theme-dark #head a { color: var(--accent-2); }
html.theme-cg.theme-dark #menu { background: var(--surface-2); }
html.theme-cg.theme-dark #menu li a:link,
html.theme-cg.theme-dark #menu li a:visited { color: var(--text); }
html.theme-cg.theme-dark #menu li a:hover,
html.theme-cg.theme-dark #menu li a.menu_item_on { background: var(--accent); color: #fff; }
html.theme-cg.theme-dark #menu li ul { background: var(--surface); border: 1px solid var(--border); }
html.theme-cg.theme-dark #menu li ul li a,
html.theme-cg.theme-dark #menu li ul li a:link,
html.theme-cg.theme-dark #menu li ul li a:visited { background: var(--surface); color: var(--text); }
html.theme-cg.theme-dark #menu li ul > li:hover > a,
html.theme-cg.theme-dark #menu li ul > li > a:hover,
html.theme-cg.theme-dark #menu li ul > li > a:active { background: var(--surface-3); color: var(--text); }

/* ----- Sección ACTIVA (menu_item_on) — marcada con acento en TODOS los temas
   nuevos (barra superior clara y oscura, y sidebar). El :link/:visited es para
   ganar al estilo clásico en el tema claro. Hace que el ítem de la sección en
   la que estás (p. ej. Préstamos) se vea claramente distinto del resto. ----- */
html.theme-cg #menu > li > a.menu_item_on,
html.theme-cg #menu > li > a.menu_item_on:link,
html.theme-cg #menu > li > a.menu_item_on:visited { background: var(--accent); color: #fff; }
/* barra de acento: abajo en barra superior, a la izquierda en sidebar */
html.theme-cg:not(.layout-side) #menu > li > a.menu_item_on { box-shadow: inset 0 -3px 0 rgba(255, 255, 255, .55); }
html.theme-cg.layout-side #menu > li > a.menu_item_on { box-shadow: inset 3px 0 0 rgba(255, 255, 255, .6); }

/* ----- MENÚ SUPERIOR (desktop): submenús multinivel robustos -----
   Con :hover puro, al pasar el cursor del padre al submenú (o entre niveles) un
   mínimo hueco cierra el menú y no se llega a los hijos (p. ej. Sistema → Acceso
   → Usuarios). Solución (hover-intent en CSS puro): los submenús se ocultan con
   `visibility` y un RETARDO al cerrar (~0.3s), así da tiempo a recorrer el
   trayecto sin que se cierren; al entrar abren al instante. Como van en
   visibility (no display:none) siguen ocupando su posición absoluta, sin afectar
   el layout. Además .crr-flip (lo pone menu.js) abre a la IZQUIERDA los submenús
   de 3er nivel que se saldrían por la derecha. Solo menú superior (el lateral usa
   acordeón; el móvil, drawer). */
@media (min-width: 901px) {
    /* Oculto = display:none del clásico (sin caja => NO intercepta el cursor ni
       tapa los enlaces; los desplegables son más anchos que los ítems y, si
       quedaran en el flujo, se solaparían). Se MUESTRA con :hover O con
       .crr-hover (hover-intent de menu.js: cierre diferido para no perder el
       submenú al recorrer los niveles). */
    html.theme-cg:not(.layout-side) #menu li.crr-hover > ul { display: block; }
    html.theme-cg:not(.layout-side) #menu ul ul.crr-flip { left: auto; right: 100%; }
}

/* ----- Elementos base de hamburguesa/overlay/toggle (los inyecta menu.js) ----- */
.crr-hamburger { display: none; }
.crr-nav-overlay { display: none; }
.crr-side-toggle { display: none; }

/* Ítem "Buscar" (abre el command palette): solo en temas nuevos. */
#menu li.crr-cmd-li { display: none; }
html.theme-cg #menu li.crr-cmd-li { display: block; }

/* Tooltip de etiqueta para el sidebar recogido (posición fija, fuera del
   overflow del #head). Lo inyecta y posiciona menu.js. */
.crr-side-tip {
    position: fixed; transform: translateY(-50%); z-index: 1400;
    background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
    padding: 6px 10px; border-radius: 8px; font-size: 13px; white-space: nowrap;
    box-shadow: var(--shadow); pointer-events: none; opacity: 0; transition: opacity .12s ease;
}
.crr-side-tip.show { opacity: 1; }

/* Color base del drawer (vertical + acordeón) */
html.theme-cg.layout-side #head,
html.theme-cg.crr-vnav #head { background: var(--nav-bg); }

/* ===================== SIDEBAR (escritorio >=901px) ===================== */
@media (min-width: 901px) {
    html.theme-cg.layout-side #content { margin: 0 0 0 230px; width: auto; }
    html.theme-cg.layout-side #head {
        position: fixed; top: 0; left: 0; width: 218px; height: 100vh; margin: 0;
        overflow-y: auto; border: 0; border-right: 1px solid rgba(255, 255, 255, .08);
        background: var(--nav-bg); z-index: 1000;
    }
    html.theme-cg.layout-side #menu { display: block; min-height: 0; background: var(--nav-bg); }
    /* common.css flota TODOS los #menu li; sin quitar el float a los anidados,
       los <ul> de submenú colapsan a height:0 y los submenús no se abren. */
    html.theme-cg.layout-side #menu li { float: none; }
    html.theme-cg.layout-side #menu > li,
    html.theme-cg.layout-side #menu li.right { width: 100%; height: auto; text-align: left; }
    html.theme-cg.layout-side #menu li a,
    html.theme-cg.layout-side #menu li a:link,
    html.theme-cg.layout-side #menu li a:visited { display: flex; align-items: center; text-align: left; padding: 11px 14px; height: auto; line-height: 1.25; white-space: normal; color: #e8edf7; }
    html.theme-cg.layout-side #menu li a:hover,
    html.theme-cg.layout-side #menu li a.menu_item_on { background: var(--accent); color: #fff; }
    html.theme-cg.layout-side #menu a span { display: inline-block; margin: 0 10px 0 0; flex: 0 0 auto; }
    html.theme-cg.layout-side #menu li ul { position: static; width: 100%; display: none; background: var(--nav-bg-2); border: 0; top: auto; left: auto; box-shadow: none; }
    html.theme-cg.layout-side #menu li:hover > ul { display: none; }
    html.theme-cg.layout-side #menu li.crr-open > ul { display: block; }
    html.theme-cg.layout-side #menu li ul li { width: 100%; height: auto; }
    html.theme-cg.layout-side #menu li ul li a,
    html.theme-cg.layout-side #menu li ul li a:link,
    html.theme-cg.layout-side #menu li ul li a:visited { background: transparent; color: #cdd6ec; padding: 9px 14px 9px 42px; }
    html.theme-cg.layout-side #menu li ul li a:hover { background: var(--surface-3); }
    /* Sangría progresiva por nivel para que se vea la jerarquía al desplegar.
       Incluye :link/:visited porque la regla base las usa (si no, gana 42px). */
    html.theme-cg.layout-side #menu li ul ul li a,
    html.theme-cg.layout-side #menu li ul ul li a:link,
    html.theme-cg.layout-side #menu li ul ul li a:visited { padding-left: 56px; }
    html.theme-cg.layout-side #menu li ul ul ul li a,
    html.theme-cg.layout-side #menu li ul ul ul li a:link,
    html.theme-cg.layout-side #menu li ul ul ul li a:visited { padding-left: 70px; }
    html.theme-cg.layout-side #menu li ul ul ul ul li a,
    html.theme-cg.layout-side #menu li ul ul ul ul li a:link,
    html.theme-cg.layout-side #menu li ul ul ul ul li a:visited { padding-left: 84px; }
    /* Submenú abierto: resalta el padre activo */
    html.theme-cg.layout-side #menu li.crr-open > a,
    html.theme-cg.layout-side #menu li.crr-open > a:link,
    html.theme-cg.layout-side #menu li.crr-open > a:visited { background: var(--surface-3); color: #fff; }

    /* ----- Botón recoger/expandir (cabecera del sidebar) ----- */
    html.theme-cg.layout-side .crr-side-toggle {
        display: flex; align-items: center; justify-content: flex-end;
        width: 100%; height: 40px; padding: 0 16px; box-sizing: border-box;
        background: transparent; border: 0; border-bottom: 1px solid rgba(255, 255, 255, .08);
        color: #94a3c4; cursor: pointer;
    }
    html.theme-cg.layout-side .crr-side-toggle:hover { color: #fff; }
    html.theme-cg.layout-side .crr-side-toggle svg { width: 20px; height: 20px; transition: transform .2s ease; }

    /* ============================================================
       SIDEBAR RECOGIDO (icon-only). El icono del menú (<span> 25x25
       con fondo SVG) no depende del font-size, así que ocultamos la
       etiqueta del <a> de 1er nivel con font-size:0 y centramos el
       icono. Solo tocamos #menu > li > a (los submenús se ocultan al
       recoger; así en el "peek" conservan su estilo/sangría normal). */
    html.theme-cg.layout-side.crr-side-collapsed #content { margin-left: 70px; }
    html.theme-cg.layout-side.crr-side-collapsed #head { width: 58px; }
    html.theme-cg.layout-side.crr-side-collapsed .crr-side-toggle { justify-content: center; padding: 0; }
    html.theme-cg.layout-side.crr-side-collapsed .crr-side-toggle svg { transform: rotate(180deg); }
    html.theme-cg.layout-side.crr-side-collapsed #menu > li > a,
    html.theme-cg.layout-side.crr-side-collapsed #menu > li > a:link,
    html.theme-cg.layout-side.crr-side-collapsed #menu > li > a:visited { font-size: 0; padding: 11px 0; justify-content: center; }
    html.theme-cg.layout-side.crr-side-collapsed #menu > li > a span { margin: 0; }
    html.theme-cg.layout-side.crr-side-collapsed #menu > li > a b { display: none; }
    /* recogido: ningún submenú desplegado (aunque tenga .crr-open).
       El sidebar SOLO se expande con el botón (sin "peek" al hover). */
    html.theme-cg.layout-side.crr-side-collapsed #menu li.crr-open > ul { display: none; }
}

/* ===================== MÓVIL (hamburguesa + drawer <=900px) ===================== */
@media (max-width: 900px) {
    html.theme-cg .crr-hamburger {
        display: inline-flex; align-items: center; justify-content: center;
        position: fixed; top: 8px; left: 8px; z-index: 1200; width: 42px; height: 36px;
        border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
    }
    html.theme-cg .crr-hamburger svg { width: 22px; height: 22px; }
    html.theme-cg #content { margin-left: 0; width: auto; }
    html.theme-cg #inner_content { margin-top: 46px; }
    html.theme-cg #head {
        position: fixed; top: 0; left: 0; width: 252px; max-width: 82vw; height: 100vh; margin: 0;
        overflow-y: auto; border: 0; border-right: 1px solid rgba(255, 255, 255, .08); background: var(--nav-bg);
        transform: translateX(-100%); transition: transform .22s ease; z-index: 1200;
    }
    html.theme-cg.crr-nav-open #head { transform: none; }
    html.theme-cg.crr-nav-open .crr-nav-overlay { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 1150; }
    html.theme-cg #menu { display: block; min-height: 0; background: var(--nav-bg); }
    /* common.css flota TODOS los #menu li; sin quitar el float a los anidados,
       los <ul> de submenú colapsan a height:0 y los submenús no se abren. */
    html.theme-cg #menu li { float: none; }
    html.theme-cg #menu > li,
    html.theme-cg #menu li.right { width: 100%; height: auto; text-align: left; }
    html.theme-cg #menu li a,
    html.theme-cg #menu li a:link,
    html.theme-cg #menu li a:visited { display: flex; align-items: center; text-align: left; padding: 12px 14px; height: auto; line-height: 1.25; white-space: normal; color: #e8edf7; }
    html.theme-cg #menu li a:hover,
    html.theme-cg #menu li a.menu_item_on { background: var(--accent); color: #fff; }
    html.theme-cg #menu a span { display: inline-block; margin: 0 10px 0 0; flex: 0 0 auto; }
    html.theme-cg #menu li ul { position: static; width: 100%; display: none; background: var(--nav-bg-2); border: 0; top: auto; left: auto; box-shadow: none; }
    html.theme-cg #menu li:hover > ul { display: none; }
    html.theme-cg #menu li.crr-open > ul { display: block; }
    html.theme-cg #menu li ul li { width: 100%; height: auto; }
    html.theme-cg #menu li ul li a,
    html.theme-cg #menu li ul li a:link,
    html.theme-cg #menu li ul li a:visited { background: transparent; color: #cdd6ec; padding: 10px 14px 10px 42px; }
    html.theme-cg #menu li ul li a:hover { background: var(--surface-3); }
    /* Sangría progresiva por nivel para que se vea la jerarquía al desplegar.
       Incluye :link/:visited porque la regla base las usa (si no, gana 42px). */
    html.theme-cg #menu li ul ul li a,
    html.theme-cg #menu li ul ul li a:link,
    html.theme-cg #menu li ul ul li a:visited { padding-left: 56px; }
    html.theme-cg #menu li ul ul ul li a,
    html.theme-cg #menu li ul ul ul li a:link,
    html.theme-cg #menu li ul ul ul li a:visited { padding-left: 70px; }
    html.theme-cg #menu li ul ul ul ul li a,
    html.theme-cg #menu li ul ul ul ul li a:link,
    html.theme-cg #menu li ul ul ul ul li a:visited { padding-left: 84px; }
    /* Submenú abierto: resalta el padre activo */
    html.theme-cg #menu li.crr-open > a,
    html.theme-cg #menu li.crr-open > a:link,
    html.theme-cg #menu li.crr-open > a:visited { background: var(--surface-3); color: #fff; }
    html.theme-cg .crr-search { width: 120px; }
}

/* ============================================================
   PÁGINAS SIN MENÚ (p. ej. autenticación / login)
   ------------------------------------------------------------
   #menu solo se renderiza autenticado (va dentro de {IsAuth} en
   header.tpl); en login #head queda vacío. Con :has() detectamos
   la ausencia de #menu y evitamos la barra lateral vacía + el
   margen sobrante de #content (sin parpadeo, sin tocar el clásico).
   ============================================================ */
@media (min-width: 901px) {
    html.theme-cg.layout-side:not(:has(#menu)) #head { display: none; }
    html.theme-cg.layout-side:not(:has(#menu)) #content { margin-left: 0; width: auto; }
}
@media (max-width: 900px) {
    html.theme-cg:not(:has(#menu)) #head { display: none; }
    html.theme-cg:not(:has(#menu)) #content { margin-left: 0; }
    html.theme-cg:not(:has(#menu)) #inner_content { margin-top: 0; }
}
