/*
 * AURA — estructura de la aplicacion (usuarias autenticadas)
 * Menu lateral plegable + barra superior con buscador y selector de tema.
 * Colores via variables --shell-* para que el tema oscuro solo los redefina.
 */

:root {
    --sidebar-w: 16.5rem;
    --sidebar-w-collapsed: 4.9rem;
    --topbar-h: 4.25rem;

    --sidebar-bg: linear-gradient(180deg, #4a3228 0%, #36231b 100%);
    --sidebar-text: #f6eae0;
    --sidebar-muted: #cdb4a2;
    --sidebar-hover: rgba(255, 255, 255, 0.09);
    --sidebar-active: rgba(255, 255, 255, 0.15);
    --sidebar-line: rgba(255, 255, 255, 0.12);
    --sidebar-accent: #c7a35a;

    --topbar-bg: rgba(255, 249, 244, 0.92);
    --topbar-line: #dfcbbd;
    --search-bg: #ffffff;
    --search-border: #dfcbbd;
    --search-text: #3f2b23;
    --search-muted: #6a4a3a;
    --pop-bg: #ffffff;
    --pop-line: #dfcbbd;
    --pop-hover: #faefe4;
    --pop-shadow: 0 1.2rem 2.4rem rgba(63, 43, 35, 0.2);
}

/* ---------- Estructura ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.app-content {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-content > .app-main {
    flex: 1 0 auto;
    width: 100%;
}

.app-content > .app-site-footer {
    flex-shrink: 0;
}

/* ---------- Menu lateral ---------- */
.app-sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w);
    height: 100vh;
    /* En el móvil 100vh incluye la barra del navegador y el pie (Cerrar sesión) quedaba debajo de ella */
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-right: 1px solid var(--sidebar-line);
    transition: width 0.22s ease, flex-basis 0.22s ease, transform 0.25s ease;
    z-index: 1040;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    height: var(--topbar-h);
    padding: 0 1rem;
    border-bottom: 1px solid var(--sidebar-line);
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
    color: var(--sidebar-text);
    text-decoration: none;
}

.sidebar-brand:hover {
    color: #fff;
}

.sidebar-logo {
    width: 2.7rem;
    height: 2.7rem;
    flex: none;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(199, 163, 90, 0.6);
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.sidebar-brand-name {
    font-family: "Newsreader", serif;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.28em;
    color: #f3e5c4;
}

.sidebar-brand-kicker {
    margin-top: 0.2rem;
    font-size: 0.62rem;
    letter-spacing: 0.34em;
    text-transform: uppercase;
    color: var(--sidebar-accent);
}

.sidebar-close {
    display: none;
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    border-radius: 0.7rem;
    background: transparent;
    color: var(--sidebar-text);
    font-size: 1.1rem;
}

.sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.75rem 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.sidebar-group + .sidebar-group {
    margin-top: 0.35rem;
}

.sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin: 0.9rem 0 0.3rem;
    padding: 0 0.75rem;
    border: 0;
    background: transparent;
    font-family: "Instrument Sans", sans-serif;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    text-align: left;
}

.sidebar-heading-toggle {
    min-height: 2.5rem;
    margin: 0.5rem 0 0.1rem;
    border-radius: 0.6rem;
    cursor: pointer;
}

.sidebar-heading-toggle:hover {
    color: #fff;
    background: var(--sidebar-hover);
}

.sidebar-heading-toggle .bi {
    transition: transform 0.2s ease;
}

.sidebar-heading-toggle[aria-expanded="false"] .bi {
    transform: rotate(-90deg);
}

.sidebar-divider {
    display: block;
    height: 0;
    margin: 0.2rem 0;
}

.sidebar-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.15rem;
}

.sidebar-list[hidden] {
    display: none;
}

.sidebar-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
    min-height: 2.9rem;
    padding: 0.55rem 0.8rem;
    border: 0;
    border-radius: 0.75rem;
    background: transparent;
    color: var(--sidebar-text);
    font-family: "Instrument Sans", sans-serif;
    font-size: 0.97rem;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-link .bi {
    flex: none;
    width: 1.5rem;
    font-size: 1.25rem;
    text-align: center;
    color: #e8d3b4;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-link:focus-visible,
.sidebar-heading-toggle:focus-visible,
.sidebar-close:focus-visible {
    outline: 3px solid #f3e5c4;
    outline-offset: -3px;
}

.sidebar-link.is-active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-link.is-active::before {
    content: "";
    position: absolute;
    left: -0.75rem;
    top: 0.45rem;
    bottom: 0.45rem;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--sidebar-accent);
}

.sidebar-link.is-active .bi {
    color: #f3dca0;
}

/* Pie del menu: usuaria y cierre de sesion */
.sidebar-foot {
    flex-shrink: 0;
    padding: 0.75rem;
    border-top: 1px solid var(--sidebar-line);
    display: grid;
    gap: 0.35rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.35rem 0.5rem;
    min-width: 0;
}

.sidebar-avatar {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: #9a5d44;
    color: #fff;
    font-weight: 800;
}

.sidebar-user-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.sidebar-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
    color: #fff;
}

.sidebar-user-role {
    font-size: 0.78rem;
    color: var(--sidebar-muted);
}

.sidebar-logout .bi {
    color: #f0b5a0;
}

/* ---------- Menu plegado (solo escritorio) ---------- */
@media (min-width: 992px) {
    html[data-sidebar="collapsed"] .app-sidebar {
        flex-basis: var(--sidebar-w-collapsed);
        width: var(--sidebar-w-collapsed);
    }

    html[data-sidebar="collapsed"] .sidebar-brand-text,
    html[data-sidebar="collapsed"] .sidebar-label,
    html[data-sidebar="collapsed"] .sidebar-user-text,
    html[data-sidebar="collapsed"] .sidebar-heading span,
    html[data-sidebar="collapsed"] .sidebar-heading .bi {
        display: none;
    }

    html[data-sidebar="collapsed"] .sidebar-head {
        justify-content: center;
        padding: 0;
    }

    html[data-sidebar="collapsed"] .sidebar-nav {
        padding-inline: 0.7rem;
    }

    html[data-sidebar="collapsed"] .sidebar-heading {
        font-size: 0;
        height: 1px;
        margin: 0.7rem 0.5rem;
        padding: 0;
        background: var(--sidebar-line);
        min-height: 0;
        pointer-events: none;
    }

    html[data-sidebar="collapsed"] .sidebar-link {
        justify-content: center;
        padding-inline: 0;
    }

    html[data-sidebar="collapsed"] .sidebar-link.is-active::before {
        left: -0.7rem;
    }

    html[data-sidebar="collapsed"] .sidebar-user {
        justify-content: center;
        padding-inline: 0;
    }

    /* Grupo de informes plegado: solo el primer informe, como acceso directo */
    html[data-sidebar="collapsed"] .sidebar-group.is-collapsible .sidebar-list {
        display: grid;
    }

    html[data-sidebar="collapsed"] .sidebar-group.is-collapsible .sidebar-list li:not(:first-child) {
        display: none;
    }
}

/* ---------- Barra superior ---------- */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--topbar-h);
    padding: 0.5rem 1.25rem;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-line);
    backdrop-filter: blur(10px);
}

.topbar-btn {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid var(--topbar-line);
    border-radius: 0.8rem;
    background: var(--search-bg);
    color: var(--search-text);
    font-size: 1.25rem;
}

.topbar-btn:hover {
    border-color: #c78d72;
}

.topbar-spacer {
    flex: 1 1 auto;
}

.topbar-search {
    position: relative;
    flex: 1 1 auto;
    max-width: 38rem;
}

.topbar-search-icon {
    position: absolute;
    left: 0.95rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--search-muted);
    pointer-events: none;
}

.topbar-search-input {
    width: 100%;
    min-height: 2.9rem;
    padding: 0.5rem 2.9rem 0.5rem 2.7rem;
    border: 1px solid var(--search-border);
    border-radius: 0.9rem;
    background: var(--search-bg);
    color: var(--search-text);
    font-size: 1rem;
}

.topbar-search-input::placeholder {
    color: var(--search-muted);
    opacity: 0.85;
}

.topbar-search-input:focus {
    outline: 0;
    border-color: #a86b51;
    box-shadow: 0 0 0 0.22rem rgba(199, 141, 114, 0.28);
}

.topbar-search-input::-webkit-search-cancel-button {
    margin-right: 1.4rem;
}

.topbar-search-hint {
    position: absolute;
    right: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    min-width: 1.5rem;
    padding: 0.05rem 0.4rem;
    border: 1px solid var(--search-border);
    border-radius: 0.4rem;
    background: transparent;
    color: var(--search-muted);
    font-size: 0.78rem;
    text-align: center;
    pointer-events: none;
}

.topbar-search-input:focus ~ .topbar-search-hint {
    display: none;
}

.topbar-search-results {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 0.45rem);
    min-width: min(26rem, 90vw);
    max-height: min(70vh, 30rem);
    overflow-y: auto;
    padding: 0.4rem;
    border: 1px solid var(--pop-line);
    border-radius: 1rem;
    background: var(--pop-bg);
    box-shadow: var(--pop-shadow);
    z-index: 1060;
}

.topbar-search-results[hidden] {
    display: none;
}

.search-group-title {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0.4rem 0.6rem 0.2rem;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--search-muted);
}

.search-option {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    min-height: 2.9rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.7rem;
    color: var(--search-text);
    text-decoration: none;
}

.search-option:hover,
.search-option.is-selected {
    background: var(--pop-hover);
    color: var(--search-text);
}

.search-option.is-selected {
    outline: 2px solid #c78d72;
    outline-offset: -2px;
}

.search-option-title {
    font-weight: 700;
}

.search-option-sub {
    font-size: 0.85rem;
    color: var(--search-muted);
}

.search-all,
.search-empty {
    display: block;
    padding: 0.7rem 0.75rem;
    font-size: 0.92rem;
    color: var(--search-muted);
}

.search-all {
    margin-top: 0.25rem;
    border-top: 1px solid var(--pop-line);
    border-radius: 0 0 0.7rem 0.7rem;
    font-weight: 800;
    text-decoration: none;
    color: #8f5a43;
}

.search-all:hover,
.search-all.is-selected {
    background: var(--pop-hover);
}

/* Pagina de resultados */
.search-result-list {
    margin: 0;
    padding: 0.35rem;
    list-style: none;
}

.search-result {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 0.75rem;
    align-items: center;
    min-height: 3.2rem;
    padding: 0.55rem 0.8rem;
    border-radius: 0.7rem;
    color: inherit;
    text-decoration: none;
}

.search-result:hover {
    background: var(--pop-hover);
    color: inherit;
}

.search-result-title {
    font-weight: 800;
}

.search-result-sub {
    grid-column: 1;
    font-size: 0.88rem;
    color: var(--search-muted);
}

.search-result .bi {
    grid-row: 1 / span 2;
    grid-column: 2;
    color: var(--search-muted);
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: none;
}

/* ---------- Selector de tema ---------- */
.theme-switch {
    display: inline-flex;
    padding: 0.25rem;
    border: 1px solid var(--topbar-line);
    border-radius: 999px;
    background: var(--search-bg);
}

.theme-switch-btn {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--search-muted);
    font-size: 1.1rem;
    transition: background 0.15s ease, color 0.15s ease;
}

.theme-switch-btn:hover {
    color: var(--search-text);
}

.theme-switch-btn[aria-pressed="true"] {
    background: #9a5d44;
    color: #fff;
}

/* ---------- Movil / tablet: menu como panel deslizante ---------- */
.app-shell-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1045;
    background: rgba(43, 33, 28, 0.55);
}

.app-shell-backdrop[hidden] {
    display: none;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(18rem, 86vw);
        flex-basis: auto;
        transform: translateX(-100%);
        visibility: hidden;
        box-shadow: none;
        z-index: 1050;
    }

    body.sidebar-open .app-sidebar {
        transform: none;
        visibility: visible;
        box-shadow: 0 0 2.5rem rgba(0, 0, 0, 0.35);
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar-close {
        display: grid;
        place-items: center;
    }

    .app-topbar {
        padding-inline: 0.85rem;
    }
}

@media (max-width: 575.98px) {
    /* "Nueva cita" sigue en el menu lateral; aqui el buscador necesita el ancho */
    .topbar-cta {
        display: none;
    }

    .topbar-search {
        min-width: 0;
    }

    .topbar-actions {
        gap: 0.5rem;
    }

    .topbar-search-hint {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar {
        transition: none;
    }
}

@media print {
    .app-sidebar,
    .app-topbar,
    .app-shell-backdrop {
        display: none !important;
    }

    .app-shell,
    .app-content {
        display: block;
    }
}

/* ---------- Contenido: margenes junto al menu lateral ---------- */
.app-content > .app-main {
    padding-inline: clamp(1rem, 2.4vw, 2rem);
    max-width: 1560px;
    margin-inline: auto;
}

.app-content .app-site-footer-inner {
    padding-inline: clamp(1rem, 2.4vw, 2rem);
    max-width: 1560px;
}

/* Selector de tema: zona tactil de 44 px como minimo */
.theme-switch-btn {
    width: 2.75rem;
    height: 2.75rem;
}

.theme-switch {
    padding: 0.2rem;
}

/* Movil: boton de menu y tema arriba; buscador a ancho completo en su propia fila */
@media (max-width: 575.98px) {
    .app-topbar {
        flex-wrap: wrap;
        row-gap: 0.5rem;
    }

    .topbar-search {
        order: 3;
        flex: 1 1 100%;
        max-width: none;
    }
}

/* Cerrar sesión también en la barra superior, solo cuando el menú lateral está oculto (móvil y tableta) */
.topbar-logout {
    margin: 0;
}

@media (min-width: 992px) {
    .topbar-logout {
        display: none;
    }
}

/* ---------- Campana de avisos ---------- */
.topbar-avisos-btn {
    position: relative;
}

.topbar-avisos-badge {
    position: absolute;
    top: -0.35rem;
    right: -0.35rem;
    min-width: 1.3rem;
    height: 1.3rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: #96593f;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.3rem;
    text-align: center;
}

.topbar-avisos-menu {
    width: min(24rem, calc(100vw - 2rem));
    max-height: 70vh;
    overflow-y: auto;
    padding-block: 0.35rem;
}

.topbar-aviso {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    white-space: normal;
    padding-block: 0.55rem;
    border-left: 3px solid transparent;
}

.topbar-aviso small {
    color: var(--search-muted);
}

.topbar-aviso.is-nueva {
    border-left-color: #85621f;
    font-weight: 600;
}

.topbar-avisos-vacio {
    margin: 0;
    padding: 0.75rem 1rem;
    color: var(--search-muted);
}

.avisos-toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1090;
    max-width: min(24rem, calc(100vw - 2rem));
    padding: 0.85rem 1rem;
    border: 1px solid var(--pop-line);
    border-left: 4px solid #96593f;
    border-radius: 0.8rem;
    background: var(--pop-bg);
    color: var(--search-text);
    box-shadow: var(--pop-shadow);
    text-align: left;
}

.avisos-toast[hidden] {
    display: none;
}
