/* ===== PSIRT Navigation Sidebar ===== */

/* Hide body until nav.js reveals it (prevents sidebar flash) */
body:not(.nav-ready) {
    opacity: 0;
}

/* ===== Page Entry Animation ===== */
body.nav-ready .psirt-app-content {
    animation: pageEnter .2s cubic-bezier(.16, 1, .3, 1) both;
}

@keyframes pageEnter {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Page Exit Animation ===== */
.psirt-app-content.page-exiting {
    animation: pageExit .1s cubic-bezier(.4, 0, 1, 1) forwards !important;
    pointer-events: none;
}

@keyframes pageExit {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-4px);
    }
}

/* ===== Staggered Content Reveal ===== */
/* Add .stagger-children to a container to cascade its direct children */
.stagger-children>* {
    opacity: 0;
    animation: staggerFadeIn .2s cubic-bezier(.16, 1, .3, 1) forwards;
}

.stagger-children>*:nth-child(1) {
    animation-delay: .02s;
}

.stagger-children>*:nth-child(2) {
    animation-delay: .04s;
}

.stagger-children>*:nth-child(3) {
    animation-delay: .06s;
}

.stagger-children>*:nth-child(4) {
    animation-delay: .08s;
}

.stagger-children>*:nth-child(5) {
    animation-delay: .10s;
}

.stagger-children>*:nth-child(6) {
    animation-delay: .12s;
}

.stagger-children>*:nth-child(7) {
    animation-delay: .14s;
}

.stagger-children>*:nth-child(8) {
    animation-delay: .16s;
}

.stagger-children>*:nth-child(9) {
    animation-delay: .18s;
}

.stagger-children>*:nth-child(10) {
    animation-delay: .20s;
}

@keyframes staggerFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Active nav item entrance glow ===== */
.nav-item.active {
    animation: navActiveGlow .6s ease-out;
}

@keyframes navActiveGlow {
    0% {
        box-shadow: inset 0 0 0 0 rgba(59, 130, 246, 0);
    }

    40% {
        box-shadow: inset 0 0 12px rgba(59, 130, 246, .15);
    }

    100% {
        box-shadow: none;
    }
}

/* ===== Accessibility: prefers-reduced-motion ===== */
@media (prefers-reduced-motion: reduce) {

    body.nav-ready .psirt-app-content,
    .psirt-app-content.page-exiting,
    .stagger-children>*,
    .nav-item.active {
        animation: none !important;
    }

    .stagger-children>* {
        opacity: 1 !important;
    }

    * {
        transition-duration: 0.01ms !important;
    }
}

/* ===== Focus-visible for keyboard navigation ===== */
:focus-visible {
    outline: 2px solid rgba(59, 130, 246, .6);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ===== Text selection styling ===== */
::selection {
    background: rgba(59, 130, 246, .3);
    color: inherit;
}

/* ===== Skeleton shimmer utility ===== */
.skeleton {
    background: linear-gradient(90deg,
            rgba(100, 116, 139, .08) 25%,
            rgba(100, 116, 139, .15) 50%,
            rgba(100, 116, 139, .08) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 6px;
    color: transparent !important;
    user-select: none;
    pointer-events: none;
}

.skeleton * {
    visibility: hidden;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.skeleton-line {
    height: 12px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-line.short {
    width: 40%;
}

.skeleton-line.medium {
    width: 65%;
}

.skeleton-line.long {
    width: 90%;
}

/* Layout wrapper */
.psirt-app-layout {
    display: flex;
    min-height: 100vh;
}

.psirt-app-content {
    flex: 1;
    margin-left: 240px;
    transition: margin-left .25s cubic-bezier(.4, 0, .2, 1);
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: auto;
    position: relative;
    z-index: 1;
}

.psirt-app-layout.nav-collapsed .psirt-app-content {
    margin-left: 64px;
}

/* Adjust fixed-position panels when sidebar is collapsed */
.psirt-app-layout.nav-collapsed #runsPanel {
    left: 64px !important;
}

.psirt-app-layout.nav-collapsed #debugDrawer {
    left: 64px !important;
}

/* Sidebar */
.psirt-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    background: #0d1321;
    border-right: 1px solid rgba(255, 255, 255, .06);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width .25s cubic-bezier(.4, 0, .2, 1);
    overflow: visible;
}

.psirt-app-layout.nav-collapsed .psirt-sidebar {
    width: 64px;
}

/* Logo */
.nav-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    flex-shrink: 0;
    min-height: 64px;
}

.nav-logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(59, 130, 246, .25);
}

.nav-logo-text {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .2s;
}

.nav-logo-text h2 {
    font-size: 15px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -.3px;
}

.nav-logo-text span {
    font-size: 10px;
    color: var(--text-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: .5px;
    font-weight: 600;
}

.nav-collapsed .nav-logo-text {
    opacity: 0;
    width: 0;
}

/* Collapse toggle */
.nav-collapse-btn {
    position: absolute;
    top: 42px;
    right: -12px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, .1);
    color: var(--text-secondary, #94a3b8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1001;
    transition: all .2s;
    font-size: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}

.nav-collapse-btn:hover {
    background: #334155;
    color: #fff;
    border-color: rgba(255, 255, 255, .2);
}

/* Nav items */
.nav-items {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted, #64748b);
    padding: 16px 12px 6px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .2s;
}

.nav-collapsed .nav-section-label {
    opacity: 0;
    height: 12px;
    padding: 6px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-secondary, #94a3b8);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all .15s;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
}

.nav-item:hover {
    background: rgba(255, 255, 255, .05);
    color: var(--text-primary, #f1f5f9);
}

.nav-item.active {
    background: rgba(59, 130, 246, .12);
    color: #60a5fa;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: #3b82f6;
}

.nav-item-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-item-label {
    overflow: hidden;
    transition: opacity .2s;
}

.nav-badge {
    margin-left: auto;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    padding: 0 5px;
    border-radius: 8px;
    background: #ef4444;
    color: #fff;
    flex-shrink: 0;
}

.nav-collapsed .nav-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 14px;
    height: 14px;
    line-height: 14px;
    font-size: 8px;
    padding: 0 3px;
}

.nav-collapsed .nav-item-label {
    opacity: 0;
    width: 0;
}

.nav-item-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(239, 68, 68, .15);
    color: #f87171;
    transition: opacity .2s;
}

.nav-collapsed .nav-item-badge {
    opacity: 0;
}

/* Tooltip for collapsed state */
.nav-collapsed .nav-item {
    justify-content: center;
    padding: 10px 0;
    gap: 0;
}

.nav-collapsed .nav-item-icon {
    width: 24px;
    height: 24px;
}

.nav-collapsed .nav-item-icon svg {
    width: 20px;
    height: 20px;
}

.nav-collapsed .nav-item:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 68px;
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #f1f5f9;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    z-index: 100;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
    border: 1px solid rgba(255, 255, 255, .1);
}

/* Theme toggle */
.nav-theme-toggle {
    padding: 4px 8px;
    flex-shrink: 0;
}

.theme-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .06);
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    transition: all .15s;
    white-space: nowrap;
}

.theme-btn:hover {
    background: rgba(255, 255, 255, .08);
    color: var(--text-primary, #f1f5f9);
}

.nav-collapsed .theme-btn {
    justify-content: center;
    padding: 8px;
}

.nav-collapsed .theme-btn .nav-item-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* User footer */
.nav-user {
    border-top: 1px solid rgba(255, 255, 255, .06);
    padding: 12px;
    flex-shrink: 0;
    position: relative;
}

.nav-user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 10px;
    transition: all .15s;
    cursor: pointer;
}

.nav-user-card:hover {
    background: rgba(255, 255, 255, .05);
}

.nav-collapsed .nav-user-card {
    justify-content: center;
    padding: 8px 4px;
    gap: 0;
}

.nav-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.nav-user-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    transition: opacity .2s;
}

.nav-collapsed .nav-user-info {
    opacity: 0;
    width: 0;
}

.nav-user-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-user-role {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 1px 6px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 2px;
}

.nav-user-role.super_admin {
    background: rgba(245, 158, 11, .15);
    color: #fbbf24;
}

.nav-user-role.admin {
    background: rgba(139, 92, 246, .15);
    color: #a78bfa;
}

.nav-user-role.analyst {
    background: rgba(59, 130, 246, .15);
    color: #60a5fa;
}

.nav-user-role.viewer {
    background: rgba(16, 185, 129, .15);
    color: #34d399;
}

/* Profile Popover Menu */
.nav-profile-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 8px;
    right: 8px;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 14px;
    padding: 6px;
    z-index: 2000;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, .4), 0 0 0 1px rgba(255, 255, 255, .04);
    opacity: 0;
    transform: translateY(8px) scale(.97);
    pointer-events: none;
    transition: all .2s cubic-bezier(.4, 0, .2, 1);
}

.nav-profile-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.nav-collapsed .nav-profile-menu {
    left: 4px;
    min-width: 220px;
}

.profile-menu-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 8px;
}

.profile-menu-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.profile-menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, .06);
    margin: 4px 6px;
}

.profile-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all .15s;
    text-decoration: none;
}

.profile-menu-item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.profile-menu-item.danger:hover {
    background: rgba(239, 68, 68, .1);
    color: #f87171;
}

/* Theme Toggle Switch */
.theme-toggle-track {
    margin-left: auto;
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .1);
    position: relative;
    transition: background .3s;
    flex-shrink: 0;
}

.theme-toggle-track.light {
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
}

.theme-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

.theme-toggle-track.light .theme-toggle-thumb {
    transform: translateX(16px);
}

.theme-toggle-thumb i {
    color: #334155;
}

/* Light Theme Overrides */
.light-theme {
    --bg-primary: #f1f5f9;
    --bg-secondary: #e2e8f0;
    --bg-card: #ffffff;
    --bg-elevated: #f8fafc;
    --border-subtle: rgba(0, 0, 0, .08);
    --border-accent: rgba(59, 130, 246, .3);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
}

.light-theme .psirt-sidebar {
    background: #ffffff;
    border-right-color: rgba(0, 0, 0, .08);
}

.light-theme .nav-collapse-btn {
    background: #f1f5f9;
    border-color: rgba(0, 0, 0, .1);
    color: #475569;
}

.light-theme .nav-item:hover {
    background: rgba(59, 130, 246, .06);
}

.light-theme .nav-item.active {
    background: rgba(59, 130, 246, .1);
    color: #2563eb;
}

.light-theme .nav-profile-menu {
    background: #ffffff;
    border-color: rgba(0, 0, 0, .1);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, .12);
}

.light-theme .nav-profile-menu .profile-menu-item:hover {
    background: rgba(0, 0, 0, .04);
    color: #0f172a;
}

.light-theme .nav-profile-menu .profile-menu-divider {
    background: rgba(0, 0, 0, .06);
}

.light-theme .nav-user-card:hover {
    background: rgba(0, 0, 0, .04);
}


/* Responsive — Tablet */
@media (max-width: 768px) {
    .psirt-sidebar {
        width: 64px;
    }

    .psirt-app-content {
        margin-left: 64px !important;
    }

    .nav-logo-text,
    .nav-item-label,
    .nav-section-label,
    .nav-user-info,
    .nav-item-badge {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 10px;
    }

    .nav-collapse-btn {
        display: none;
    }
}

/* Responsive — Mobile */
@media (max-width: 480px) {
    .psirt-sidebar {
        width: 0;
        overflow: hidden;
        border: none;
    }

    .psirt-app-content {
        margin-left: 0 !important;
    }

    /* Reduce page padding */
    .admin-page,
    .analytics-page,
    .settings-page {
        padding: 16px !important;
    }

    /* Stack metric stat cards */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}