/* ═══════════════════════════════════════════
   LAYOUT PRINCIPAL — SIDEBAR + HEADER + MAIN
   Clases alineadas con app.js renderLayout()
═══════════════════════════════════════════ */

/* ── VARIABLES LOCALES DE LAYOUT ── */
:root {
    --sidebar-collapsed-width: 64px;
}

/* ── APP SHELL ── */
.app-shell {
    display: flex;
    min-height: 100vh;
    overflow: hidden;
    background: var(--color-bg);
}

/* ── ESTILOS GLOBALES PARA ICONOS (LUCIDE) ── */
[data-lucide] {
    stroke-width: 1.5px;
    width: 1.25rem;
    height: 1.25rem;
    display: inline-block;
    vertical-align: middle;
}

.nav-icon [data-lucide] {
    width: 1.125rem;
    height: 1.125rem;
    stroke-width: 2px;
}

.stat-card-icon [data-lucide],
.account-card-icon [data-lucide],
.tx-icon [data-lucide],
.cat-dot-icon [data-lucide],
.notif-icon [data-lucide],
.icon-container [data-lucide] {
    width: 1.125rem;
    height: 1.125rem;
    stroke-width: 2px;
}

.sidebar-logo-icon [data-lucide] {
    color: white;
    stroke-width: 2.5px;
    width: 20px;
    height: 20px;
}

/* ══════════════════════════════════════
   SIDEBAR
══════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width var(--transition-base), transform var(--transition-base);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
}

/* Sidebar colapsado (desktop) */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    min-width: var(--sidebar-collapsed-width);
}

/* Sidebar en mobile: oculto por defecto */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }
}

/* ── SIDEBAR HEADER (logo + toggle btn) ── */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem 0 1.25rem;
    height: var(--header-height);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    overflow: hidden;
}

.sidebar-logo-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--color-primary), #d4641e);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(232, 114, 42, 0.35);
}

.sidebar-brand-name {
    font-size: 1.125rem;
    font-weight: 800;
    color: white;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition-base);
}

.sidebar-brand-name span {
    color: var(--color-primary);
}

/* Ocultar textos cuando está colapsado */
.sidebar.collapsed .sidebar-brand-name,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .user-info {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
}

/* Botón de colapso */
.sidebar-collapse-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    background: transparent;
    border: none;
}

.sidebar-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* ── SIDEBAR BODY (navegación) ── */
.sidebar-body {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Título de sección */
.nav-section-title {
    font-size: 0.625rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.28);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 0.875rem 1.25rem 0.4rem;
    white-space: nowrap;
    transition: opacity var(--transition-base);
}

/* Ítem de navegación */
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    color: var(--sidebar-text);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.nav-item:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
    border-left-color: var(--sidebar-active-border);
    font-weight: 600;
}

.nav-icon {
    font-size: 1.0625rem;
    width: 22px;
    min-width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.nav-label {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition-base);
}

/* Colapsado → centrar ícono */
.sidebar.collapsed .nav-item {
    padding: 0.65rem;
    justify-content: center;
}

.sidebar.collapsed .nav-icon {
    width: 22px;
}

/* ── SIDEBAR FOOTER ── */
.sidebar-footer {
    padding: 0.75rem 0 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
}

/* Usuario en sidebar footer */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.25rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    overflow: hidden;
}

.sidebar-user:hover {
    background: rgba(255, 255, 255, 0.06);
}

.sidebar.collapsed .sidebar-user {
    padding: 0.5rem;
    justify-content: center;
}

/* ── USER AVATAR ── */
.user-avatar {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.user-info {
    overflow: hidden;
    transition: opacity var(--transition-base), width var(--transition-base);
    flex: 1;
}

.user-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-plan {
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.4);
}

/* ══════════════════════════════════════
   CONTENIDO PRINCIPAL
══════════════════════════════════════ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: margin-left var(--transition-base);
}

/* Cuando sidebar está colapsado */
.main-content.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

/* En mobile sin sidebar */
@media (max-width: 768px) {
    .main-content {
        margin-left: 0 !important;
    }
}

/* ══════════════════════════════════════
   HEADER
══════════════════════════════════════ */
.top-header {
    height: var(--header-height);
    min-height: var(--header-height);
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

/* Lado izquierdo del header */
.header-left {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    min-width: 0;
    flex: 1;
}

.header-page-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-text-primary);
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-breadcrumb {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* Lado derecho del header */
.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Botón genérico del header (hamburguesa, tema, etc.) */
.header-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
    font-size: 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.header-btn:hover {
    background: var(--color-border-light);
    color: var(--color-text-primary);
}

/* Botón hamburguesa: visible solo en mobile */
#mobile-menu-btn {
    display: none;
}

@media (max-width: 768px) {
    #mobile-menu-btn {
        display: flex;
    }
}

/* Navegación de mes */
.header-month-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    padding: 0.3rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

@media (max-width: 580px) {
    .header-month-nav {
        display: none;
    }
}

/* Notificaciones */
.header-notif-wrapper {
    position: relative;
}

.notif-btn {
    position: relative;
}

.notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 16px;
    height: 16px;
    background: var(--color-danger);
    border-radius: 50%;
    font-size: 0.5625rem;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-bg-card);
}

/* Dropdown de notificaciones */
.notif-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    overflow: hidden;
    animation: scaleIn var(--transition-fast) ease;
}

.notif-dropdown.open {
    display: block;
}

.notif-header {
    padding: 0.875rem 1rem;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--color-text-primary);
    border-bottom: 1px solid var(--color-border-light);
}

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border-light);
    transition: background var(--transition-fast);
    cursor: pointer;
}

.notif-item:hover {
    background: var(--color-bg);
}

.notif-item:last-child {
    border-bottom: none;
}

.notif-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.notif-text {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 2px;
}

.notif-sub {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.notif-time {
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* Avatar header */
.header-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.header-user:hover {
    background: var(--color-border-light);
}

.header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

/* ══════════════════════════════════════
   MAIN AREA (donde va el contenido de páginas)
══════════════════════════════════════ */
.main-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--color-bg);
}

.page-content {
    padding: 1.75rem;
    max-width: 1400px;
    animation: fadeIn 0.3s ease;
}

/* ══════════════════════════════════════
   SIDEBAR OVERLAY (móvil)
══════════════════════════════════════ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.visible {
    display: block;
}

/* ══════════════════════════════════════
   PAGE LAYOUT HELPERS
══════════════════════════════════════ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-header-left h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.page-header-left p {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* ══════════════════════════════════════
   GRIDS RESPONSIVOS
══════════════════════════════════════ */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
}

.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.25rem;
}

.grid-1-2 {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.25rem;
}

.col-span-2 {
    grid-column: span 2;
}

.col-span-3 {
    grid-column: span 3;
}

/* Responsive grids */
@media (max-width: 1024px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-2-1,
    .grid-1-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .col-span-2,
    .col-span-3 {
        grid-column: span 1;
    }

    .page-content {
        padding: 1rem;
    }
}

/* ══════════════════════════════════════
   FAB (Botón flotante)
══════════════════════════════════════ */
.fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--color-primary), #d4641e);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.375rem;
    color: white;
    box-shadow: 0 6px 20px rgba(232, 114, 42, 0.5);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    z-index: 40;
}

.fab:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 28px rgba(232, 114, 42, 0.6);
}

.fab:active {
    transform: scale(0.96);
}

/* ═══════════════════════════════════════════
   EXTRAS DE RESPONSIVIDAD (LAYOUT)
   ═══════════════════════════════════════════ */
@media (max-width: 480px) {
    .top-header {
        padding: 0 1rem;
    }

    .header-breadcrumb {
        display: none;
        /* Ahorrar espacio en pantallas diminutas */
    }

    .header-page-title {
        font-size: 1rem;
    }

    .page-header-left h2 {
        font-size: 1.25rem;
    }

    .page-header-actions {
        width: 100%;
        margin-top: 0.5rem;
    }

    .page-header-actions .btn {
        flex: 1;
        /* Botones de acción ocupan todo el ancho en mobile */
    }

    .fab {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 48px;
        height: 48px;
    }
}