/* ============================================================
   SHELL.CSS - Header de navegación unificado (catálogo y pagos)
   Depende de: common.css (debe cargarse ANTES)
   Lo monta js/app-shell.js en páginas con <body class="shell-app">.
   Estas páginas navegan solo por header con iconos; el área
   personal conserva su sidebar (sidebar.css).
   Secciones:
     1. Tokens de layout
     2. Neutralización del layout heredado
     3. Header y logo
     4. Ruta de navegación, botones de icono y acciones
     5. Menú de usuario y selector de tema
     6. Responsive
   ============================================================ */

/* ------------------------------------------------------------
   1. Tokens de layout
   ------------------------------------------------------------ */
:root
{
    /* Alto del header superior */
    --shell-header-height: 4rem;
}

/* ------------------------------------------------------------
   2. Neutralización del layout heredado
   ------------------------------------------------------------ */
/* El contenedor heredado ya no es un layout de columnas con sidebar */
.shell-app .main-container
{
    display: block;
    min-height: 0;
}

/* El contenido ya no se desplaza por un sidebar ni por un header fijo */
.shell-app .main-content
{
    max-width: 80rem;
    margin: 0 auto;
}

/* El contenido principal recibe foco al usar "Saltar al contenido" sin mostrar anillo */
.shell-app [tabindex="-1"]:focus
{
    outline: none;
}

/* ------------------------------------------------------------
   3. Header y logo
   ------------------------------------------------------------ */
/* Header unificado (especificidad alta para ganar a overrides antiguos de modes.css) */
.shell-app .app-header.shell-header
{
    position: sticky;
    top: 0;
    left: auto;
    z-index: var(--z-header);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: var(--space-4);
    width: 100%;
    height: var(--shell-header-height);
    padding: 0 max(var(--space-6), calc((100% - 80rem) / 2 + var(--space-6)));
    background-color: var(--color-bg-header);
    border-bottom: var(--border-width) solid var(--color-border);
    box-shadow: none;
    -webkit-backdrop-filter: var(--backdrop-header);
    backdrop-filter: var(--backdrop-header);
}

/* Logo enlazado a cursos */
.shell-header-logo
{
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Imagen del logo */
.shell-header-logo img
{
    height: 2rem;
    width: auto;
}

/* En tema oscuro aclaramos el logo (sus tonos granate pierden contraste sobre fondo oscuro) */
:root[data-theme="dark"] .shell-header-logo img
{
    filter: brightness(1.45) saturate(1.1);
}

/* En pantallas táctiles el enlace del logo alcanza 44px de alto (la imagen no cambia de tamaño) */
@media (pointer: coarse)
{
    .shell-header-logo
    {
        min-height: 2.75rem;
    }
}

/* ------------------------------------------------------------
   4. Ruta de navegación, botones de icono y acciones
   ------------------------------------------------------------ */
/* Contenedor de la ruta de navegación */
.shell-breadcrumb
{
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
    min-width: 0;
    padding-left: var(--space-4);
    border-left: var(--border-width) solid var(--color-border);
}

/* Botón de volver al nivel padre (visible en pantallas medianas y pequeñas) */
.shell-back
{
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    flex-shrink: 0;
    border-radius: 50%;
    color: var(--color-text-dark);
    text-decoration: none;
}

/* Hover del botón de volver */
.shell-back:hover
{
    background-color: var(--color-primary-alpha-05);
}

/* Lista de niveles de la ruta */
.shell-crumbs
{
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    list-style: none;
}

/* Nivel de la ruta */
.shell-crumb
{
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    white-space: nowrap;
}

/* Enlace a un nivel padre */
.shell-crumb-parent a
{
    color: var(--color-text-light);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 14rem;
}

/* Hover del enlace a un nivel padre */
.shell-crumb-parent a:hover
{
    color: var(--color-primary);
    text-decoration: underline;
    text-underline-offset: var(--underline-offset);
}

/* Separador entre niveles */
.shell-crumb-parent i
{
    font-size: var(--icon-size-xs);
    color: var(--color-text-light);
    opacity: 0.7;
}

/* Nivel actual (título de la página) */
.shell-crumb-current span
{
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--font-family-heading);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-dark);
}

/* Acciones del header alineadas a la derecha */
.shell-header-actions
{
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-left: auto;
    flex-shrink: 0;
}

/* Grupo de botones de las secciones principales */
.shell-nav
{
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding-right: var(--space-2);
    margin-right: var(--space-1);
    border-right: var(--border-width) solid var(--color-border);
}

/* Sección activa: fondo tintado y color de marca */
.shell-nav-link[aria-current="page"]
{
    background-color: var(--color-primary-alpha);
    color: var(--color-primary-dark);
}

/* ------------------------------------------------------------
   5. Menú de usuario y selector de tema
   ------------------------------------------------------------ */
/* Contenedor relativo del menú */
.shell-user
{
    position: relative;
}

/* Botón del avatar */
.shell-avatar-button
{
    display: flex;
    padding: var(--space-0-5);
    border: var(--border-width-lg) solid transparent;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    transition: border-color var(--duration-fast) ease;
}

/* Hover y estado abierto del avatar */
.shell-avatar-button:hover,
.shell-avatar-button[aria-expanded="true"]
{
    border-color: var(--color-primary-alpha-30);
}

/* Avatar circular con iniciales y foto superpuesta */
.shell-avatar
{
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 50%;
    background-color: var(--color-primary-fill);
    color: var(--color-white);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    letter-spacing: var(--letter-spacing-wide);
}

/* Foto del avatar cubriendo las iniciales */
.shell-avatar img
{
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Avatar grande de la cabecera del menú */
.shell-avatar-lg
{
    width: 2.75rem;
    height: 2.75rem;
    font-size: var(--font-size-md);
}

/* Panel desplegable del menú */
.shell-menu
{
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    z-index: var(--z-dropdown);
    display: flex;
    flex-direction: column;
    gap: var(--space-0-5);
    width: 17rem;
    padding: var(--space-2);
    background-color: var(--color-bg-elevated);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-lg);
    animation: modal-fade-in var(--duration-fast) var(--ease-out) both;
    transform-origin: top right;
}

/* Menú oculto */
.shell-menu[hidden]
{
    display: none;
}

/* Cabecera del menú con la identidad del usuario */
.shell-menu-header
{
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
    border-bottom: var(--border-width) solid var(--color-border);
}

/* Nombre y correo del usuario */
.shell-menu-identity
{
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: var(--line-height-snug);
}

/* Nombre del usuario */
.shell-menu-identity strong
{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text-dark);
}

/* Correo del usuario */
.shell-menu-identity small
{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text-light);
    font-size: var(--font-size-sm);
}

/* Elemento del menú (enlace o botón) */
.shell-menu-item
{
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: 2.5rem;
    padding: 0 var(--space-2);
    border: none;
    border-radius: var(--border-radius);
    background: transparent;
    color: var(--color-text-dark);
    font-family: inherit;
    font-size: var(--font-size-md);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

/* Icono del elemento del menú */
.shell-menu-item i
{
    width: 1.25rem;
    text-align: center;
    color: var(--color-text-light);
}

/* Hover y foco del elemento del menú */
.shell-menu-item:hover,
.shell-menu-item:focus-visible
{
    background-color: var(--color-primary-alpha-05);
}

/* Acción destructiva (cerrar sesión) */
.shell-menu-danger,
.shell-menu-danger i
{
    color: var(--color-danger-text);
}

/* Sección del menú con etiqueta (selector de tema) */
.shell-menu-section
{
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2);
    margin: var(--space-1) 0;
    border-top: var(--border-width) solid var(--color-border);
    border-bottom: var(--border-width) solid var(--color-border);
}

/* Etiqueta de la sección */
.shell-menu-label
{
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wider);
    color: var(--color-text-light);
}

/* Control segmentado del tema */
.shell-theme-switch
{
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-0-5);
    padding: var(--space-1);
    border-radius: var(--border-radius);
    background-color: var(--color-inactive-bg);
}

/* Opción del control de tema */
.shell-theme-option
{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-0-5);
    padding: var(--space-2) var(--space-1);
    border: none;
    border-radius: calc(var(--border-radius) - var(--space-0-5));
    background: transparent;
    color: var(--color-text-light);
    font-family: inherit;
    font-size: var(--font-size-xs);
    cursor: pointer;
}

/* Opción del tema seleccionada */
.shell-theme-option[aria-checked="true"]
{
    background-color: var(--color-bg-card);
    color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
    box-shadow: var(--shadow-sm);
}

/* ------------------------------------------------------------
   6. Responsive
   ------------------------------------------------------------ */
/* Tablet: la ruta se reduce al título actual con botón de volver */
@media screen and (max-width: 64rem)
{
    /* Solo el título actual; los padres se omiten por espacio */
    .shell-crumb-parent
    {
        display: none;
    }

    /* Botón de volver visible cuando hay un nivel padre */
    .shell-back
    {
        display: flex;
    }
}

/* Móvil (en cualquier orientación): header compacto */
@media screen and (max-width: 48rem)
{
    /* Header más bajo y con menos margen */
    :root
    {
        --shell-header-height: 3.5rem;
    }

    /* Header compacto */
    .shell-app .app-header.shell-header
    {
        gap: var(--space-2);
        padding: 0 var(--space-2);
    }

    /* La ruta ya no necesita separador */
    .shell-breadcrumb
    {
        padding-left: 0;
        border-left: none;
    }

    /* El título de la página ya está en su cabecera; en el header solo queda volver */
    .shell-crumbs
    {
        display: none;
    }

    /* Con botón de volver ocultamos el logo para ganar espacio */
    .shell-header:has(.shell-back) .shell-header-logo
    {
        display: none;
    }

    /* Logo algo más pequeño */
    .shell-header-logo img
    {
        height: 1.6rem;
    }

    /* Botones sin separador y más juntos */
    .shell-nav
    {
        gap: 0;
        padding-right: 0;
        margin-right: 0;
        border-right: none;
    }

    /* El selector de tema sigue disponible en el menú del avatar */
    .shell-theme-toggle
    {
        display: none;
    }

    /* El menú de usuario ocupa casi todo el ancho */
    .shell-menu
    {
        position: fixed;
        top: calc(var(--shell-header-height) + var(--space-2));
        right: var(--space-2);
        width: min(20rem, calc(100vw - 2 * var(--space-2)));
    }
}

/* Móvil: botones de icono más compactos para que quepan todos */
@media screen and (max-width: 30rem)
{
    /* Botones algo más pequeños */
    .shell-icon-button
    {
        width: 2.25rem;
        height: 2.25rem;
        font-size: var(--icon-size-lg);
    }

    /* Avatar más pequeño */
    .shell-avatar
    {
        width: 2rem;
        height: 2rem;
    }
}

/* Impresión: sin navegación */
@media print
{
    /* Ocultamos las acciones del header */
    .shell-header-actions
    {
        display: none !important;
    }
}
