/* ============================================================
   MNEMOS — Layout Principal
   Reset + Sidebar + Main + Header + Responsive
============================================================ */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-principal);
    color: var(--texto);
    min-height: 100vh;
    display: flex;
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: var(--acento); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---- Sidebar ---- */
.sidebar {
    width: 260px;
    min-width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--borde);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, min-width 0.3s ease, transform 0.3s ease;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar.colapsado {
    width: 60px;
    min-width: 60px;
}

.sidebar-logo {
    padding: 20px 16px;
    border-bottom: 1px solid var(--borde);
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}

.sidebar-logo .icono-logo {
    font-size: 24px;
    min-width: 28px;
    text-align: center;
}

.sidebar-logo .texto-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--acento);
    overflow: hidden;
    transition: opacity 0.2s ease;
}

.sidebar.colapsado .texto-logo {
    opacity: 0;
    width: 0;
}

.btn-colapsar {
    position: absolute;
    top: 20px;
    right: -14px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--acento);
    color: var(--bg-principal);
    border: 2px solid var(--bg-principal);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    z-index: 101;
    transition: transform 0.3s ease;
}

.sidebar.colapsado .btn-colapsar {
    transform: rotate(180deg);
}

/* Navegacion */
.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--borde) transparent;
}

.nav-seccion { margin-bottom: 8px; }

.nav-seccion-titulo {
    padding: 8px 16px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--texto-secundario);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.colapsado .nav-seccion-titulo {
    opacity: 0;
    height: 0;
    padding: 0;
}

.nav-enlace {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--texto-secundario);
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.nav-enlace:hover {
    background-color: var(--bg-card);
    color: var(--texto);
    text-decoration: none;
}

.nav-enlace.activo {
    color: var(--acento);
    border-left-color: var(--acento);
    background-color: var(--bg-card);
}

.nav-enlace .icono {
    font-size: 18px;
    min-width: 24px;
    text-align: center;
}

.nav-enlace .etiqueta {
    overflow: hidden;
    transition: opacity 0.2s ease;
}

.sidebar.colapsado .nav-enlace .etiqueta {
    opacity: 0;
    width: 0;
}

/* Pie sidebar */
.sidebar-pie {
    padding: 16px;
    border-top: 1px solid var(--borde);
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    flex-shrink: 0;
}

.sidebar-pie .avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: var(--acento);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: var(--bg-principal);
}

.sidebar-pie .info-usuario {
    overflow: hidden;
    transition: opacity 0.2s ease;
}

.sidebar.colapsado .sidebar-pie .info-usuario {
    opacity: 0;
    width: 0;
}

.sidebar-pie .nombre-usuario { font-size: 13px; font-weight: 600; }
.sidebar-pie .rol-usuario { font-size: 11px; color: var(--texto-secundario); }

/* ---- Contenido Principal ---- */
.contenido-principal {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-left: 260px;
    transition: margin-left 0.3s ease;
}

.sidebar.colapsado ~ .contenido-principal {
    margin-left: 60px;
}

/* Header */
.header {
    padding: 16px 24px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--borde);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-izq {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.header-titulo { font-size: 22px; font-weight: 700; }

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--texto-secundario);
}

.header-der {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Selector de tema */
.selector-tema { position: relative; }

.btn-tema {
    background: var(--bg-input);
    border: 1px solid var(--borde);
    color: var(--texto);
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-tema:hover { border-color: var(--acento); }

.menu-temas {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--sombra);
    min-width: 160px;
    z-index: 200;
    display: none;
}

.menu-temas.visible { display: block; }

.opcion-tema {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s ease;
}

.opcion-tema:hover { background-color: var(--bg-input); }
.opcion-tema:first-child { border-radius: 8px 8px 0 0; }
.opcion-tema:last-child { border-radius: 0 0 8px 8px; }

.punto-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid var(--borde);
}

/* Boton menu movil */
.btn-menu-movil {
    display: none;
    background: none;
    border: none;
    color: var(--texto);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
}

/* Area contenido */
.area-contenido {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ---- Loading & Empty States ---- */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--borde);
    border-top-color: var(--acento);
    border-radius: 50%;
    animation: girar 0.8s linear infinite;
}

@keyframes girar {
    to { transform: rotate(360deg); }
}

.estado-vacio {
    text-align: center;
    padding: 60px 20px;
    color: var(--texto-secundario);
}

.estado-vacio .icono-vacio {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* ---- Toast / Notificaciones ---- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-card);
    border: 1px solid var(--borde);
    box-shadow: 0 4px 12px var(--sombra);
    animation: toast-in 0.3s ease;
    max-width: 400px;
}

.toast.exito { border-left: 4px solid var(--exito); }
.toast.error { border-left: 4px solid var(--error); }
.toast.advertencia { border-left: 4px solid var(--advertencia); }
.toast.info { border-left: 4px solid var(--info); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---- Login (full page, no sidebar) ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    background: var(--bg-principal);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 32px var(--sombra);
}

.login-card h1 {
    text-align: center;
    font-size: 28px;
    margin-bottom: 8px;
    color: var(--acento);
}

.login-card .subtitulo {
    text-align: center;
    color: var(--texto-secundario);
    font-size: 14px;
    margin-bottom: 32px;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        position: fixed;
    }

    .sidebar.abierto {
        transform: translateX(0);
    }

    .contenido-principal {
        margin-left: 0 !important;
    }

    .btn-menu-movil {
        display: block;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
    }

    .sidebar.abierto ~ .sidebar-overlay {
        display: block;
    }
}

@media (max-width: 768px) {
    .area-contenido { padding: 16px; }
    .header { padding: 12px 16px; }
    .header-titulo { font-size: 18px; }
}

@media (max-width: 480px) {
    .area-contenido { padding: 12px; }
    .login-card { padding: 24px; margin: 16px; }
}
