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

/* ==========================================================================
   VA TOOL — SETUP SCREEN LAYOUT
   ========================================================================== */

/* The shell normally zeroes padding on .screen; we restore it for setup. */
#setup-screen {
    /* Ensure the screen itself scrolls so Start Test is always reachable */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 32px max(16px, env(safe-area-inset-right))
             calc(32px + env(safe-area-inset-bottom, 0px))
             max(16px, env(safe-area-inset-left)) !important;
    max-width: 600px;
    margin: 0 auto;
    box-sizing: border-box;
}

/* ==========================================================================
   VA TOOL — DISTANCE SEGMENTED CONTROL
   ========================================================================== */

/* Track (container) */
.segmented-control {
    background: var(--v11-bg-app);          /* light gray track */
    border-radius: var(--v11-radius-md);
    padding: 3px;
    display: flex;
    gap: 3px;
}

/* Unselected segment pill */
.segment {
    flex: 1;
    border: none;
    border-radius: calc(var(--v11-radius-md) - 2px);
    padding: 10px var(--v11-space-sm);
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--v11-text-primary);
    background: transparent;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

/* Selected segment: solid blue with white text + subtle shadow */
.segment.active {
    background: var(--v11-color-primary) !important;
    color: #ffffff !important;
    box-shadow: 0 1px 4px rgba(0, 122, 255, 0.35);
}

.segment:not(.active):hover {
    background: rgba(0, 0, 0, 0.06);
}

/* ==========================================================================
   VA TOOL — OPTOTYPE SELECTION CARDS
   ========================================================================== */

/* Card grid */
.cards-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--v11-space-sm);
}

/* Unselected card */
.cards-container .card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 80px;
    border-radius: var(--v11-radius-md);
    /* Visible neutral border so each card has a consistent frame */
    border: 2px solid var(--v11-border-medium) !important;
    background: var(--v11-bg-surface) !important;
    color: var(--v11-text-primary) !important;
    cursor: pointer;
    transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

/* Unselected hover */
.cards-container .card:not(.active):hover {
    border-color: var(--v11-color-primary) !important;
    background: rgba(0, 122, 255, 0.04) !important;
}

/* Selected card: blue border + very light blue tint — glyph remains legible */
.cards-container .card.active {
    border-color: var(--v11-color-primary) !important;
    background: rgba(0, 122, 255, 0.08) !important;
    color: var(--v11-text-primary) !important;
    box-shadow: 0 0 0 1px var(--v11-color-primary);
}

/* Keep text readable on selected card (do NOT invert to white) */
.cards-container .card.active .card-label,
.cards-container .card.active .card-icon {
    color: var(--v11-color-primary) !important;
}

/* ==========================================================================
   VA TOOL — BYPASS CRM PADDING FOR VA SCREENS
   ========================================================================== */
.v11-screens-container:has(#testing-screen:not(.hidden)),
.v11-screens-container:has(#setup-screen:not(.hidden)),
.v11-screens-container:has(#calibration-screen:not(.hidden)) {
    padding: 0 !important;
}

/* ==========================================================================
   VA TOOL — TESTING SCREEN
   ========================================================================== */
#testing-screen {
    touch-action: none;
    user-select: none;
    background-color: white;
    height: 100%;
    overflow: hidden;
}


/* ==========================================================================
   ACTIVE VA TEST OVERRIDES
   ========================================================================== */
body.test-active .v11-sidebar {
    position: fixed !important;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(280px, 80vw) !important;
    transform: translateX(-100%) !important;
    box-shadow: var(--v11-shadow-lg) !important;
    visibility: hidden !important;
    z-index: 100;
}

body.test-active .v11-sidebar.sidebar-open {
    transform: translateX(0) !important;
    visibility: visible !important;
}

body.test-active .v11-sidebar-overlay.active {
    opacity: 1 !important;
    visibility: visible !important;
}

body.test-active .v11-mobile-close-btn {
    display: block !important;
}
