@import '../../../utils/shared-styles.scss';

// ===== LAYOUT VARIABLES =====
$sidebar-width: 220px;
$mobile-nav-height: 64px;
$transition-sidebar: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

// ===== BASE LAYOUT =====
.admin-layout {
    display: flex;
    min-height: 100vh;
    background: $gradient-bg;
}

// ===== SIDEBAR =====
.sidebar {
    position: fixed;
    top: 72px;
    left: 0;
    bottom: 0;
    width: $sidebar-width;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-right: 1px solid $glass-border;
    display: flex;
    flex-direction: column;
    z-index: 1001;
    transition: transform $transition-sidebar, opacity $transition-sidebar;
    box-shadow: $shadow-glass;

    @media (max-width: 1024px) {
        width: 280px;
        transform: translateX(-100%);
        opacity: 0;
        top: 72px;
        bottom: $mobile-nav-height;

        &.open {
            transform: translateX(0);
            opacity: 1;
        }
    }
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid rgba($color-gray-200, 0.5);

    .brand {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .brand-icon {
        font-size: 24px;
        color: #C2410C;
    }

    .brand-title {
        font-size: 1rem;
        font-weight: 800;
        color: #C2410C;
    }
}

.sidebar-close {
    display: none;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid $glass-border;
    border-radius: $radius-md;
    cursor: pointer;
    color: $color-text-secondary;
    transition: all 0.2s;

    .material-symbols-outlined {
        font-size: 18px;
    }

    &:hover {
        background: rgba($color-brand-primary, 0.08);
        color: $color-brand-primary;
        border-color: $color-brand-primary;
    }

    @media (max-width: 1024px) {
        display: flex;
    }
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    border-radius: $radius-md;
    text-decoration: none;
    color: $color-text-secondary;
    font-weight: 600;
    font-size: 0.8125rem;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
    animation: slideInNav 0.3s ease-out both;

    @keyframes slideInNav {
        from {
            opacity: 0;
            transform: translateX(-10px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    .nav-item-indicator {
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 3px;
        height: 0;
        background: $gradient-primary;
        border-radius: 0 2px 2px 0;
        transition: height 0.2s ease;
    }

    .nav-icon {
        font-size: 20px;
        transition: transform 0.2s, color 0.2s;
    }

    &:hover {
        background: rgba($color-brand-primary, 0.06);
        color: $color-brand-primary;

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

        .nav-item-indicator {
            height: 20px;
        }
    }

    &--active {
        background: linear-gradient(135deg, rgba($color-brand-primary, 0.1), rgba($color-brand-primary, 0.05));
        color: $color-brand-primary;
        font-weight: 700;

        .nav-item-indicator {
            height: 24px;
        }

        .nav-icon {
            color: $color-brand-primary;
        }

        &:hover {
            background: linear-gradient(135deg, rgba($color-brand-primary, 0.12), rgba($color-brand-primary, 0.08));
        }
    }
}

.sidebar-footer {
    padding: 0.5rem;
    border-top: 1px solid rgba($color-gray-200, 0.5);

    .nav-item--home {
        color: $color-text-tertiary;

        &:hover {
            background: rgba($color-gray-500, 0.08);
            color: $color-text-primary;
        }
    }
}

// ===== BACKDROP =====
.backdrop {
    position: fixed;
    inset: 0;
    top: 72px;
    bottom: $mobile-nav-height;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

// ===== MAIN CONTENT =====
.admin-main {
    flex: 1;
    margin-left: $sidebar-width;
    min-height: calc(100vh - 72px);
    transition: margin-left $transition-sidebar;
    display: flex;
    flex-direction: column;

    @media (max-width: 1024px) {
        margin-left: 0;
        padding-bottom: $mobile-nav-height;
    }
}

.admin-content {
    flex: 1;
    position: relative;
}

// ===== MOBILE BOTTOM NAVIGATION =====
// Positioned outside admin-main to prevent route animation interference
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: $mobile-nav-height;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    border-top: 1px solid $glass-border;
    z-index: 1002;
    padding: 0.5rem 0.25rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    // Prevent any inherited animations
    transform: translateZ(0);
    will-change: auto;

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

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0.375rem 0.75rem;
    border-radius: $radius-md;
    text-decoration: none;
    color: $color-text-tertiary;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 56px;

    .material-symbols-outlined {
        font-size: 22px;
        transition: transform 0.2s;
    }

    .mobile-nav-label {
        font-size: 0.625rem;
        font-weight: 600;
        letter-spacing: 0.2px;
    }

    &:hover, &:active {
        color: $color-brand-primary;

        .material-symbols-outlined {
            transform: scale(1.1);
        }
    }

    &.active {
        color: $color-brand-primary;
        background: rgba($color-brand-primary, 0.1);

        .material-symbols-outlined {
            transform: scale(1.05);
        }
    }

    &.mobile-nav-more {
        color: $color-text-secondary;

        &:hover {
            color: $color-brand-primary;
        }
    }
}

// ===== FAB MENU (Fallback) =====
.fab-menu {
    display: none;
    position: fixed;
    bottom: calc($mobile-nav-height + 1rem);
    right: 1rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: $gradient-primary;
    color: white;
    border: none;
    box-shadow: $shadow-brand, 0 4px 16px rgba($color-brand-primary, 0.3);
    cursor: pointer;
    z-index: 999;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;

    .material-symbols-outlined {
        font-size: 24px;
    }

    &:hover {
        transform: scale(1.05);
        box-shadow: $shadow-brand, 0 6px 20px rgba($color-brand-primary, 0.4);
    }

    &:active {
        transform: scale(0.95);
    }
}
