/* ========================================
   SGND - Layout Styles
   ======================================== */

/* === App Container === */
.app-container {
    min-height: 100vh;
}

/* === Page === */
.page {
    display: none;
    min-height: 100vh;
}

.page.active {
    display: block;
}

/* === Login Page === */
.page-login {
    display: none;
}

.page-login.active {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-4);
}

.login-container {
    position: relative;
    width: 100%;
    max-width: 440px;
}

.login-background {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
}

.bg-shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s ease-in-out infinite;
}

.shape-1 {
    width: 400px;
    height: 400px;
    background: var(--primary-700);
    top: -100px;
    right: -100px;
}

.shape-2 {
    width: 300px;
    height: 300px;
    background: var(--secondary-600);
    bottom: -50px;
    left: -50px;
    animation-delay: -7s;
}

.shape-3 {
    width: 200px;
    height: 200px;
    background: #8b5cf6;
    top: 50%;
    left: 50%;
    animation-delay: -14s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(30px, -30px) scale(1.1);
    }

    66% {
        transform: translate(-20px, 20px) scale(0.9);
    }
}

.login-card {
    padding: var(--space-8);
}

.login-header {
    text-align: center;
    margin-bottom: var(--space-8);
}

.login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: var(--space-4);
}

.logo-circle {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    border-radius: 50%;
    box-shadow: var(--shadow-glow);
}

.logo-svg {
    width: 50px;
    height: 50px;
    color: white;
}

.login-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: var(--space-2);
}

.login-description {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.login-badge {
    display: inline-block;
    margin-top: var(--space-3);
    padding: 4px 12px;
    background: rgba(59, 130, 246, 0.15);
    color: var(--primary-500);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-full);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.forgot-password-link {
    font-size: 0.875rem;
    color: var(--primary-500);
}

.forgot-password-link:hover {
    text-decoration: underline;
}

.login-footer {
    margin-top: var(--space-8);
    text-align: center;
}

.footer-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* === Dashboard Layout === */
.page-dashboard {
    display: none;
    flex-direction: column;
    min-height: 100vh;
}

.page-dashboard.active {
    display: flex;
}

/* === Dashboard Components (Shared) === */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.logo-mini-circle {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.logo-mini-circle svg {
    width: 24px;
    height: 24px;
    color: white;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
}

.user-avatar {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
    color: var(--text-secondary);
}

.nav-link:hover {
    background: rgba(49, 130, 206, 0.1);
    color: var(--primary-600);
}

.nav-link.active {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-glow);
}

.nav-icon {
    font-size: 1.1rem;
}

.nav-text {
    font-size: 0.85rem;
}

/* === Sidebar / Top Nav Layout === */
@media (min-width: 1025px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 72px;
        /* Collapsed width */
        height: 100vh;
        display: flex;
        flex-direction: column;
        align-items: center;
        /* Center items in collapsed mode */
        padding: 0;
        background: var(--bg-card);
        border-right: 1px solid rgba(0, 0, 0, 0.06);
        border-bottom: none;
        z-index: 1000;
        overflow-x: hidden;
        overflow-y: auto;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-sm);
    }

    .sidebar:hover {
        width: 260px;
        /* Expanded width */
        align-items: stretch;
        /* Stretch items in expanded mode */
        box-shadow: var(--shadow-2xl);
    }

    /* === Header === */
    .sidebar-header {
        width: 100%;
        padding: var(--space-4);
        margin-right: 0;
        border-bottom: 1px solid rgba(0, 0, 0, 0.03);
        display: flex;
        justify-content: center;
        /* Center logo initially */
        align-items: center;
        overflow: hidden;
        white-space: nowrap;
    }

    .sidebar:hover .sidebar-header {
        justify-content: flex-start;
        /* Align left on hover */
        padding-left: var(--space-6);
    }

    .sidebar-logo .logo-text {
        opacity: 0;
        width: 0;
        transition: opacity 0.2s;
        margin-left: 0;
    }

    .sidebar:hover .sidebar-logo .logo-text {
        opacity: 1;
        width: auto;
        margin-left: var(--space-3);
    }

    .sidebar-toggle {
        display: none;
    }

    /* === User Profile === */
    .sidebar-user {
        margin: var(--space-2) var(--space-2);
        padding: var(--space-2);
        background: transparent;
        border-radius: var(--radius-lg);
        justify-content: center;
        border-right: none;
        transition: all 0.2s;
        overflow: hidden;
        white-space: nowrap;
    }

    .sidebar:hover .sidebar-user {
        margin: var(--space-4);
        padding: var(--space-3);
        background: rgba(0, 0, 0, 0.02);
        justify-content: flex-start;
    }

    .user-info {
        opacity: 0;
        width: 0;
        display: none;
        /* Hide fully to avoid layout issues */
    }

    .sidebar:hover .user-info {
        display: flex;
        opacity: 1;
        width: auto;
        margin-left: var(--space-3);
        animation: fadeIn 0.3s forwards;
    }

    /* === Navigation === */
    .sidebar-nav {
        flex: 1;
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        padding: var(--space-2) 0;
    }

    .sidebar:hover .sidebar-nav {
        padding: var(--space-2) var(--space-3);
    }

    .nav-section {
        display: flex;
        flex-direction: column;
        margin-bottom: var(--space-2);
        width: 100%;
        align-items: center;
    }

    .sidebar:hover .nav-section {
        align-items: stretch;
        margin-bottom: var(--space-4);
    }

    .nav-section-title {
        display: none;
        /* Hide titles when collapsed */
        padding: var(--space-4) var(--space-3) var(--space-2);
        font-size: 0.75rem;
        font-weight: 700;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        white-space: nowrap;
    }

    .sidebar:hover .nav-section-title {
        display: block;
        animation: fadeIn 0.3s forwards;
    }

    .nav-list {
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        width: 100%;
        align-items: center;
    }

    .sidebar:hover .nav-list {
        align-items: stretch;
    }

    .nav-link {
        padding: var(--space-3);
        justify-content: center;
        width: 90%;
        /* Center nicely */
        border-radius: var(--radius-lg);
    }

    .sidebar:hover .nav-link {
        padding: var(--space-3) var(--space-4);
        justify-content: flex-start;
        width: 100%;
        gap: var(--space-3);
    }

    .nav-icon {
        font-size: 1.25rem;
        min-width: 24px;
        /* Ensure icon stability */
        text-align: center;
    }

    .nav-text {
        display: none;
        font-size: 0.9rem;
        white-space: nowrap;
    }

    .sidebar:hover .nav-text {
        display: block;
        animation: fadeIn 0.2s forwards;
    }

    /* Nav Badge logic for collapsed/expanded */
    .nav-badge {
        position: absolute;
        top: 4px;
        right: 4px;
        width: 16px;
        height: 16px;
        font-size: 0.6rem;
        padding: 0;
    }

    .sidebar:hover .nav-badge {
        position: static;
        /* Flow naturally in expanded */
        width: auto;
        height: 20px;
        padding: 0 6px;
        font-size: 0.75rem;
        margin-left: auto;
    }

    /* Ensure relative positioning for badge in collapsed mode */
    .nav-link {
        position: relative;
    }

    /* === Footer === */
    .sidebar-footer {
        width: 100%;
        margin-top: auto;
        padding: var(--space-4);
        border-top: 1px solid rgba(0, 0, 0, 0.03);
        display: flex;
        justify-content: center;
        overflow: hidden;
    }

    .sidebar:hover .sidebar-footer {
        justify-content: flex-start;
    }

    .btn-logout {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-3);
        width: 100%;
        color: var(--text-muted);
        font-size: 0.9rem;
    }

    .sidebar:hover .btn-logout {
        justify-content: flex-start;
        padding: var(--space-3) var(--space-4);
        gap: var(--space-3);
    }

    .btn-logout span:last-child {
        display: none;
    }

    .sidebar:hover .btn-logout span:last-child {
        display: inline;
    }

    .btn-logout:hover {
        background: rgba(239, 68, 68, 0.05);
        color: var(--error);
    }
}

/* === Sidebar (Mobile Default) === */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: var(--sidebar-width);
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        z-index: 10001;
        /* Above mobile bottom nav */
        background: var(--bg-card);
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
        /* Prevent full sidebar scroll */
        box-shadow: var(--shadow-xl);
    }

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

    .sidebar-header {
        padding: var(--space-6);
        justify-content: space-between;
        flex-shrink: 0;
        flex-wrap: wrap;
    }

    .sidebar-user {
        margin: var(--space-4);
        background: rgba(0, 0, 0, 0.02);
        flex-shrink: 0;
    }

    .sidebar-nav {
        padding: var(--space-4);
        flex: 1;
        overflow-y: auto;
        /* Scroll ONLY the nav list */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        min-height: 0;
        /* Critical for flex scrolling */
    }

    .nav-list {
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        padding-bottom: var(--space-4);
        /* Extra padding at end of scroll */
    }

    .nav-section-title {
        display: block;
        padding: var(--space-4) var(--space-4) var(--space-2);
        font-size: 0.7rem;
        font-weight: 700;
        color: var(--text-muted);
        text-transform: uppercase;
    }

    .sidebar-footer {
        padding: var(--space-6);
        margin-top: auto;
        flex-shrink: 0;
        border-top: 1px solid rgba(0, 0, 0, 0.05);
        /* Separator */
        background: var(--bg-card);
        /* Ensure no transparency overlap */
    }

    /* Wrap buttons on mobile footers to prevent overflow */
    .card-footer,
    .list-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    .card-footer button,
    .list-header button {
        flex: 1 1 auto;
        /* Allow buttons to grow and shrink */
        min-width: 120px;
        /* Minimum width for touch targets */
    }
}

/* === Main Content === */
.main-content {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
}

.top-header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-8);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    z-index: 400;
}

/* === Main Content Adjustments for Hover Sidebar === */
@media (min-width: 1025px) {
    .main-content {
        margin-left: 72px;
        /* Default collapsed width */
        width: calc(100% - 72px);
        min-height: 100vh;
        transition: margin-left 0.3s ease, width 0.3s ease;
    }

    /* Note: We DO NOT expand margin-left on hover, 
       because the sidebar floats OVER the content to prevent layout shifts */

    .top-header {
        position: sticky;
        top: 0;
        right: 0;
        width: 100%;
        padding: var(--space-3) var(--space-6);
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(12px);
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        z-index: 900;
    }
}

.mobile-menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    background: var(--primary-600);
    border-radius: var(--radius-md);
    cursor: pointer;
    border: none;
}

.header-title {
    flex: 1;
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-base);
}

.header-subtitle {
    display: none;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: var(--space-2);
}

.header-btn {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.03);
    border-radius: var(--radius-md);
    font-size: 1.1rem;
    transition: var(--transition-fast);
}

.header-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.notification-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--error);
    border-radius: 50%;
    border: 2px solid white;
}

.content-area {
    flex: 1;
    padding: var(--space-3) var(--space-6);
}

/* === Views === */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* === Barra de navegación inferior (móvil) === */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding: var(--space-1) var(--space-2);
    padding-bottom: calc(var(--space-1) + env(safe-area-inset-bottom));
    z-index: 1000;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
}

@media (max-width: 1024px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    /* Ocultar hamburguesa ya que tenemos bottom nav */
    .mobile-menu-toggle {
        display: none !important;
    }

    /* Agregar padding inferior al contenido para que no quede tapado */
    .content-area {
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--space-2);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    min-width: 64px;
}

.bottom-nav-item .nav-icon {
    font-size: 1.25rem;
}

.bottom-nav-item .nav-label {
    font-size: 0.65rem;
    font-weight: 600;
}

.bottom-nav-item.active {
    color: var(--primary-600);
}

.bottom-nav-item.active .nav-icon {
    transform: scale(1.1);
}

.bottom-nav-item:active {
    transform: scale(0.95);
}

/* Media Queries Specifics */
@media (max-width: 640px) {
    .top-header {
        padding: var(--space-3) var(--space-4);
    }

    .header-title h1 {
        font-size: 1.1rem;
    }
}

/* Allow horizontal scroll for overflow nav items in desktop sidebar */
@media (min-width: 1025px) {
    .sidebar-nav {
        overflow-x: auto;
        /* Hide scrollbar but allow scroll */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }
}