/* ===== Cipher Navigation Sidebar ===== */

/* Brief hide until nav.js reveals (with fast safety fallback) */
body:not(.nav-ready) {
    opacity: 0;
    animation: navSafetyReveal 0s ease-out 1.5s forwards;
}

@keyframes navSafetyReveal {
    to { opacity: 1; }
}

body.nav-ready {
    opacity: 1;
    animation: none;
    transition: opacity .25s ease-out;
}

/* ===== Page Exit Animation ===== */
.cipher-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);
    }
}

/* Stagger animations removed — single clean page reveal via body opacity */

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

@keyframes navActiveGlow {
    0% {
        box-shadow: inset 0 0 0 0 rgba(99, 102, 241, 0);
    }

    40% {
        box-shadow: inset 0 0 12px rgba(99, 102, 241, .15);
    }

    100% {
        box-shadow: none;
    }
}

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

    .cipher-app-content.page-exiting,
    .nav-item.active {
        animation: none !important;
    }

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

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

/* ===== Text selection styling ===== */
::selection {
    background: rgba(99, 102, 241, .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 */
.cipher-app-layout {
    display: flex;
    min-height: 100vh;
}

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

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

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

/* Debug drawer positioning is handled entirely by JS (_positionDebugDrawer) */

/* Sidebar */
.cipher-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    background: #0a0e17;
    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;
}

.cipher-app-layout.nav-collapsed .cipher-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, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99, 102, 241, .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: #141419;
    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: #1a1a24;
    color: #fff;
    border-color: rgba(99, 102, 241, .3);
}

/* Nav items */
.nav-items {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}
/* ── Collapsible Section Groups ── */
.nav-section-group {
    margin-bottom: 2px;
}

.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, color .15s;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    border-radius: 6px;
}

.nav-section-label:hover {
    color: var(--text-secondary, #94a3b8);
}

.nav-section-chevron {
    transition: transform .25s ease;
    opacity: .5;
    flex-shrink: 0;
}

.nav-section-group.collapsed .nav-section-chevron {
    transform: rotate(-90deg);
}

.nav-section-items {
    overflow: hidden;
    max-height: 500px;
    transition: max-height .3s ease, opacity .2s ease;
    opacity: 1;
}

.nav-section-group.collapsed .nav-section-items {
    max-height: 0;
    opacity: 0;
}

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

.nav-collapsed .nav-section-chevron {
    display: none;
}

.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(99, 102, 241, .12);
    color: #818cf8;
}

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

.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: #141419;
    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(99, 102, 241, .15);
}

/* 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;
}

/* Notification bell — integrated into user card */
.nav-notif-bell {
    background: none;
    border: none;
    color: var(--text-muted, #64748b);
    cursor: pointer;
    position: relative;
    padding: 4px;
    border-radius: 6px;
    transition: all .15s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: auto;
}
.nav-notif-bell:hover {
    background: rgba(255,255,255,.08);
    color: var(--text-primary, #f1f5f9);
}
.nav-notif-badge {
    position: absolute;
    top: 0; right: 0;
    background: #ef4444;
    color: #fff;
    font-size: 8px;
    font-weight: 700;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    text-align: center;
    line-height: 14px;
    padding: 0 3px;
}

/* Notification badge in profile menu */
.nav-notif-menu-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 8px;
    background: rgba(239, 68, 68, .15);
    color: #f87171;
}

/* Collapsed sidebar: hide bell text, show dot on avatar */
.nav-collapsed .nav-notif-bell {
    position: absolute;
    top: 4px;
    right: 4px;
    padding: 2px;
}
.nav-collapsed .nav-notif-bell i { width: 12px !important; height: 12px !important; }
.nav-collapsed .nav-notif-badge {
    width: 8px; height: 8px; min-width: 8px;
    font-size: 0; padding: 0;
    top: -1px; right: -1px;
}

.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: #141419;
    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, #6366f1, #818cf8);
}

.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 .cipher-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(99, 102, 241, .06);
}

.light-theme .nav-item.active {
    background: rgba(99, 102, 241, .1);
    color: #6366f1;
}

.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);
}


/* ===== Expandable Sub-Menu Items ===== */
.nav-item.has-children {
    cursor: pointer;
}
.nav-item.has-children .nav-chevron {
    margin-left: auto;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform .2s ease;
    color: var(--text-muted, #64748b);
}
.nav-item.has-children.expanded .nav-chevron {
    transform: rotate(90deg);
}
.nav-sub-items {
    margin-left: 26px;
    border-left: 1px solid rgba(255,255,255,.06);
    padding-left: 0;
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s cubic-bezier(.4,0,.2,1), opacity .2s;
    opacity: 0;
}
.nav-sub-items.open {
    max-height: 200px;
    opacity: 1;
}
.nav-sub-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px 7px 12px;
    border-radius: 8px;
    color: var(--text-secondary, #94a3b8);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    transition: all .15s;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
}
.nav-sub-item:hover {
    background: rgba(255,255,255,.05);
    color: var(--text-primary, #f1f5f9);
}
.nav-sub-item.active {
    background: rgba(59,130,246,.1);
    color: #60a5fa;
    font-weight: 600;
}
.nav-sub-item .nav-sub-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Collapsed sidebar: hide sub-menus */
.nav-collapsed .nav-sub-items {
    display: none;
}
.nav-collapsed .nav-chevron {
    display: none;
}

/* ===== Collapsed Sidebar: Hover Flyout Popover ===== */
.nav-flyout {
    position: fixed;
    left: 68px;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 12px;
    padding: 6px;
    min-width: 180px;
    z-index: 10000;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 255, 255, .04);
    opacity: 0;
    transform: translateX(-4px) scale(.97);
    pointer-events: none;
    transition: all .15s cubic-bezier(.4, 0, .2, 1);
}
.nav-flyout.visible {
    opacity: 1;
    transform: translateX(0) scale(1);
    pointer-events: all;
}

/* Flyout header (shows the parent group label) */
.nav-flyout-header {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--text-muted, #64748b);
    padding: 6px 10px 4px;
}

/* Flyout nav links */
.nav-flyout-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text-secondary, #94a3b8);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all .15s;
    cursor: pointer;
    white-space: nowrap;
}
.nav-flyout-link:hover {
    background: rgba(255, 255, 255, .08);
    color: #f1f5f9;
}
.nav-flyout-link.active {
    background: rgba(59, 130, 246, .12);
    color: #60a5fa;
    font-weight: 600;
}
.nav-flyout-link .nav-flyout-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nav-flyout-link .nav-flyout-badge {
    margin-left: auto;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(99, 102, 241, .12);
    color: var(--accent-primary, #818cf8);
}

/* Flyout caret/arrow pointing back to sidebar */
.nav-flyout::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 14px;
    width: 10px;
    height: 10px;
    background: #1e293b;
    border-left: 1px solid rgba(255, 255, 255, .1);
    border-bottom: 1px solid rgba(255, 255, 255, .1);
    transform: rotate(45deg);
}

/* Light theme flyout */
.light-theme .nav-flyout {
    background: #ffffff;
    border-color: rgba(0, 0, 0, .1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, .12), 0 0 0 1px rgba(0, 0, 0, .04);
}
.light-theme .nav-flyout::before {
    background: #ffffff;
    border-left-color: rgba(0, 0, 0, .1);
    border-bottom-color: rgba(0, 0, 0, .1);
}
.light-theme .nav-flyout-link:hover {
    background: rgba(59, 130, 246, .06);
    color: #0f172a;
}
.light-theme .nav-flyout-link.active {
    background: rgba(59, 130, 246, .1);
    color: #2563eb;
}

/* Light theme */
.light-theme .nav-sub-items {
    border-left-color: rgba(0,0,0,.08);
}
.light-theme .nav-sub-item:hover {
    background: rgba(59,130,246,.06);
}
.light-theme .nav-sub-item.active {
    background: rgba(59,130,246,.1);
    color: #2563eb;
}

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

    .cipher-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) {
    .cipher-sidebar {
        width: 0;
        overflow: hidden;
        border: none;
    }

    .cipher-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;
    }
}