/* i-Screening V1.1 Application Shell */

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* App Shell controls scrolling */
}

.v11-app-shell {
    display: flex;
    height: 100vh;
    width: 100vw;
    background-color: var(--v11-bg-app);
    overflow: hidden;
    position: relative;
}

/* ==========================================================================
   SIDEBAR (DESKTOP)
   ========================================================================== */
.v11-sidebar {
    width: var(--v11-width-sidebar);
    flex-shrink: 0;
    background-color: var(--v11-bg-sidebar);
    color: var(--v11-nav-text);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--v11-border-light);
    z-index: 100;
    transition: transform var(--v11-transition-base);
}

.v11-sidebar-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 var(--v11-space-lg);
    border-bottom: 1px solid var(--v11-border-light);
}

.v11-sidebar-logo {
    height: 24px;
    margin-right: var(--v11-space-sm);
}

.v11-sidebar-brand {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--v11-text-primary);
    letter-spacing: -0.02em;
}

.v11-mobile-close-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--v11-nav-text);
    font-size: 1.5rem;
    margin-left: auto;
    cursor: pointer;
}

.v11-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--v11-space-md) var(--v11-space-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.v11-sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: var(--v11-space-sm) var(--v11-space-md);
    border-radius: var(--v11-radius-md);
    color: var(--v11-nav-text);
    text-decoration: none;
    font-size: 0.95rem; /* larger readability */
    font-weight: 500;
    transition: all var(--v11-transition-fast);
}

.v11-sidebar-nav .nav-link:hover {
    background-color: rgba(0, 0, 0, 0.04);
    color: var(--v11-text-primary);
}

.v11-sidebar-nav .nav-link:focus-visible {
    outline: 2px solid var(--v11-color-primary);
    outline-offset: -2px;
}

.v11-sidebar-nav .nav-link:active {
    background-color: rgba(0, 0, 0, 0.08);
}

.v11-sidebar-nav .nav-link.active {
    background-color: var(--v11-bg-info);
    color: var(--v11-color-primary);
    font-weight: 600;
}

.v11-sidebar-nav .nav-link .nav-icon {
    width: 20px;
    height: 20px;
    margin-right: var(--v11-space-md);
    fill: currentColor;
}

/* ==========================================================================
   MAIN WORKSPACE
   ========================================================================== */
.v11-main-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.v11-mobile-header {
    display: none;
    height: 56px;
    background-color: var(--v11-bg-surface);
    border-bottom: 1px solid var(--v11-border-light);
    align-items: center;
    padding: 0 var(--v11-space-md);
    z-index: 90;
}

.v11-mobile-brand {
    font-weight: 600;
    font-size: 1.125rem;
    margin-left: var(--v11-space-sm);
    color: var(--v11-text-primary);
}

.v11-screens-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

/* ==========================================================================
   INTEGRATION: Existing .screen and .section-header adjustments
   ========================================================================== */
/* We keep the .screen architecture but remove its full viewport sizing */
.v11-screens-container .screen {
    width: 100%;
    min-height: 100%;
    /* Reset Phase 1 padding, we rely on inner component spacing now */
    padding: 0 !important; 
}

/* -----------------------------------------------------------------------
   WORKSPACE CONTENT GUTTER
   Apply consistent horizontal padding to all standard screens.
   This is the single source of workspace padding — not per-screen.
   ----------------------------------------------------------------------- */
.v11-screens-container .screen:not(#setup-screen):not(#testing-screen):not(#calibration-screen) > *:not(.section-header):not(.v11-page-header) {
    padding-left: var(--v11-space-xl);
    padding-right: var(--v11-space-xl);
}

/* The section-header already has its own horizontal padding from its rule below.
   Ensure it matches the workspace gutter for visual alignment. */

/* Convert the existing headers into sticky configurable page headers */
.v11-screens-container .section-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background-color: var(--v11-bg-surface);
    border-bottom: 1px solid var(--v11-border-light);
    padding: var(--v11-space-md) var(--v11-space-xl);
    margin-bottom: var(--v11-space-lg);
    
    /* V1.1 Page Header Typography & Layout */
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.v11-screens-container .section-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--v11-text-primary);
    margin: 0;
    letter-spacing: -0.02em;
}

/* Ensure #app-alerts sit above the workspace but below mobile header */
#app-alerts {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}


/* ==========================================================================
   RESPONSIVE / MOBILE  (portrait + landscape)
   ========================================================================== */

.v11-sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 95;
    opacity: 0;
    visibility: hidden;
    transition: all var(--v11-transition-base);
}

/* ---- Portrait mobile ≤ 768px ---- */
@media (max-width: 768px) {
    .v11-sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .v11-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        /* Cap drawer width so it never overwhelms narrow screens */
        width: min(280px, 80vw);
        transform: translateX(-100%);
        box-shadow: var(--v11-shadow-lg);
        visibility: hidden;
    }

    .v11-sidebar.sidebar-open {
        transform: translateX(0);
        visibility: visible;
    }

    .v11-mobile-close-btn {
        display: block;
    }

    .v11-mobile-header {
        display: flex;
    }

    .v11-screens-container .section-header {
        padding: var(--v11-space-md);
        height: auto;
        min-height: 56px;
    }
}

/* ---- Landscape mobile / tablet landscape ≤ 1024px ---- */
/* Force sidebar to off-canvas in landscape just as in portrait.           */
/* Desktop (≥ 1025px) keeps the persistent sidebar.                        */
@media (max-width: 1024px) {
    .v11-sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .v11-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(280px, 75vw);
        transform: translateX(-100%);
        box-shadow: var(--v11-shadow-lg);
        visibility: hidden;
    }

    .v11-sidebar.sidebar-open {
        transform: translateX(0);
        visibility: visible;
    }

    .v11-mobile-close-btn {
        display: block;
    }

    .v11-mobile-header {
        display: flex;
    }
}
