/**
 * AR-CICD Platform - Shell Styles
 * ================================
 * Application layout, sidebar, and navigation
 */

/* App Shell Layout */
.app-shell {
    display: flex;
    height: 100vh;
    height: 100dvh; /* excludes the mobile browser's collapsing address bar */
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--gray-200);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    color: var(--primary);
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4);
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    color: var(--gray-600);
    border-radius: var(--radius);
    transition: all var(--transition);
    cursor: pointer;
    text-decoration: none;
}

.nav-item:hover {
    background-color: var(--gray-100);
    color: var(--gray-900);
    text-decoration: none;
}

.nav-item.active {
    background-color: var(--primary-light);
    color: var(--primary);
}

.nav-icon {
    width: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg {
    width: 18px;
    height: 18px;
}

.nav-label {
    font-size: 0.875rem;
    font-weight: 500;
}

.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--gray-200);
}

.logout-btn {
    color: var(--error);
    width: 100%;
    background: none;
    border: none;
    text-align: left;
}

.logout-btn:hover {
    background-color: var(--error-light);
}

/* Hide role-specific nav items by default */
.supervisor-only,
.admin-only {
    display: none;
}

body.user-role-supervisor .supervisor-only,
body.user-role-admin .supervisor-only,
body.user-role-admin .admin-only {
    display: flex;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    background: var(--surface);
    border-bottom: 1px solid var(--gray-200);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.mobile-nav-toggle {
    display: none;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-backdrop {
    display: none;
    cursor: pointer; /* iOS Safari only fires delegated clicks on "clickable" elements */
}

body.nav-locked {
    overflow: hidden;
}

.topbar-left h1 {
    font-size: 1.25rem;
}

#breadcrumb {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.topbar-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
}

.topbar-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Notification Bell */
.notification-bell {
    position: relative;
}

.bell-icon svg {
    width: 20px;
    height: 20px;
}

.badge {
    position: absolute;
    top: -0.25rem;
    right: -0.25rem;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 var(--space-1);
    background-color: var(--error);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

#notification-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 320px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    margin-top: var(--space-2);
}

.dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--gray-200);
}

.dropdown-header h4 {
    font-size: 0.875rem;
}

.dropdown-header button {
    font-size: 0.75rem;
    color: var(--primary);
    background: none;
    border: none;
    cursor: pointer;
}

.notification-list {
    max-height: 320px;
    overflow-y: auto;
}

.notification-item {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background-color var(--transition);
}

.notification-item:hover {
    background-color: var(--gray-50);
}

.notification-item.unread {
    background-color: var(--primary-light);
}

.notification-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: var(--space-1);
}

.notification-message {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.notification-time {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: var(--space-1);
}

.dropdown-footer {
    display: block;
    padding: var(--space-3);
    text-align: center;
    font-size: 0.875rem;
    border-top: 1px solid var(--gray-200);
}

/* Screen Container */
.screen-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
    background-color: var(--gray-50);
}

.content-screen {
    animation: fadeIn var(--transition);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive adjustments
 * At or below 1024px (phones in portrait AND landscape, tablets, and phone
 * browsers in "desktop site" mode) the sidebar becomes an off-canvas drawer
 * opened by the hamburger. Above that it's the normal fixed sidebar. */
@media (max-width: 1024px) {
    .mobile-nav-toggle {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        width: 280px;
        max-width: 85vw;
        transform: translateX(-100%);
        visibility: hidden; /* keeps the closed drawer out of tab order / screen readers */
        transition: transform 0.25s ease, visibility 0s linear 0.25s;
        box-shadow: var(--shadow-lg);
        overscroll-behavior: contain;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
    }

    .app-shell.nav-open .sidebar {
        transform: translateX(0);
        visibility: visible;
        transition: transform 0.25s ease, visibility 0s;
    }

    .app-shell.nav-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 90;
    }

    /* Full-width content; comfortable touch targets in the drawer */
    .main-content {
        width: 100%;
        min-width: 0;
    }

    .sidebar .nav-item {
        min-height: 44px;
    }

    .sidebar-nav {
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    /* Keep the topbar visible and sticky */
    .topbar {
        position: sticky;
        top: 0;
        z-index: 60;
        padding: var(--space-3);
        padding-left: max(var(--space-3), env(safe-area-inset-left));
        padding-right: max(var(--space-3), env(safe-area-inset-right));
    }

    .screen-container {
        padding: var(--space-4);
    }

    /* Short screens (phones in landscape): scroll the whole drawer as one
     * piece so the pinned footer doesn't squeeze the menu to a few rows. */
    @media (max-height: 520px) {
        .sidebar {
            overflow-y: auto;
        }

        .sidebar-header {
            padding: var(--space-3) var(--space-4);
        }

        .sidebar-nav {
            flex: none;
            overflow: visible;
        }
    }

    /* The bell dropdown is anchored to the viewport rather than the bell, so
     * it can never be clipped off-screen on narrow phones. */
    #notification-dropdown {
        position: fixed;
        top: 60px;
        left: var(--space-3);
        right: var(--space-3);
        width: auto;
        max-height: calc(100dvh - 80px);
        overflow-y: auto;
    }
}
