/**
 * OptimaDrywall Flow — application viewport shell (100vh, internal scroll only).
 * Baseline target: 1366×768. Browser window must not scroll during normal use.
 */

:root {
    --app-navbar-height: 56px;
    --app-tab-bar-height: 52px;
    --app-sidebar-footer-height: 52px;
    --app-page-header-gap: 1rem;
    --app-scroll-padding: 1rem;
}

/* ----- Shell: lock document scroll ----- */

html.app-shell-document,
html.app-shell-document body.app-shell-active {
    height: 100%;
    overflow: hidden;
}

body.app-shell-active {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100dvh;
}

body.app-shell-active > .navbar {
    flex-shrink: 0;
    min-height: var(--app-navbar-height);
}

body.app-shell-active > .app-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.app-shell-active .app-shell > .container-fluid {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-left: 0;
    padding-right: 0;
    max-width: 100%;
    overflow: hidden;
}

body.app-shell-active .app-shell-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-wrap: nowrap;
    margin-left: 0;
    margin-right: 0;
    overflow: hidden;
}

/* ----- Sidebar: fixed footer, scrollable menu ----- */

body.app-shell-active .app-sidebar {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
    min-height: unset !important;
}

body.app-shell-active .app-sidebar-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

body.app-shell-active .app-sidebar-scroll .nav.flex-column {
    flex: none;
    padding-bottom: 0.5rem;
}

body.app-shell-active .app-sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    background-color: var(--card-background);
    z-index: 2;
}

body.app-shell-active .app-sidebar-footer .sidebar-toggle-btn {
    width: 100%;
    text-align: left;
    border: none;
    background: none;
    color: var(--text-color);
    padding: 0.75rem 1rem;
    border-radius: 0;
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.2s ease, color 0.2s ease;
}

body.app-shell-active .app-sidebar-footer .sidebar-toggle-btn:hover {
    background-color: var(--background-color);
    color: var(--primary-color);
}

body.app-shell-active .sidebar.collapsed .app-sidebar-footer .sidebar-toggle-btn {
    justify-content: center;
    font-size: 0;
}

body.app-shell-active .sidebar.collapsed .app-sidebar-footer .sidebar-toggle-btn .sidebar-toggle-text {
    display: none !important;
}

/* Legacy: toggle was inside ul — hide if duplicate markup remains */
body.app-shell-active .sidebar .sidebar-toggle-item {
    display: none !important;
}

body.app-shell-active .sidebar .position-sticky {
    position: static;
    min-height: unset !important;
    padding-bottom: 0;
    display: contents;
}

/* ----- Main + tab workspace ----- */

body.app-shell-active .app-main-area {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: 0 !important;
    min-height: unset !important;
}

body.app-shell-active .app-tab-bar {
    flex-shrink: 0;
    position: static;
    top: auto;
    z-index: 10;
}

body.app-shell-active .app-tab-panels {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.app-shell-active .app-tab-panel {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    display: none !important;
    flex-direction: column;
    overflow: hidden;
    padding-top: 0;
}

body.app-shell-active .app-tab-panel.active {
    display: flex !important;
}

/* Primary scroll region (all module pages) */
body.app-shell-active .app-page-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: var(--app-scroll-padding) 1rem 1.25rem;
    max-width: 100%;
    box-sizing: border-box;
}

body.app-shell-active .app-tab-panel > .tab-messages {
    flex-shrink: 0;
    margin: 0.5rem 1rem 0;
}

body.app-shell-active .app-tab-panel > .tab-messages + .app-page-scroll {
    padding-top: 0.25rem;
}

/* Compact page headers inside scroll area */
body.app-shell-active .app-page-scroll > .page-header {
    flex-shrink: 0;
    margin-bottom: var(--app-page-header-gap);
}

/* ----- Sticky form actions ----- */

body.app-shell-active .app-page-scroll .form-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin-top: 1.25rem;
    margin-bottom: -0.25rem;
    padding: 0.75rem 0;
    background: linear-gradient(
        to top,
        var(--card-background) 70%,
        rgba(255, 255, 255, 0.97) 85%,
        transparent
    );
    border-top: 1px solid var(--border-color);
}

[data-theme="dark"] body.app-shell-active .app-page-scroll .form-actions {
    background: linear-gradient(
        to top,
        var(--card-background) 70%,
        rgba(31, 41, 55, 0.97) 85%,
        transparent
    );
}

body.app-shell-active .app-page-scroll .card .form-actions {
    margin-left: 0;
    margin-right: 0;
}

/* ----- Tables: scroll inside card, not the browser ----- */

body.app-shell-active .app-page-scroll .table-responsive {
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: min(60vh, calc(100dvh - var(--app-navbar-height) - var(--app-tab-bar-height) - 14rem));
    overscroll-behavior: contain;
}

body.app-shell-active .app-page-scroll .card > .table-responsive {
    border-radius: 0 0 1rem 1rem;
}

/* List/report pages with filters + table */
body.app-shell-active .app-page-scroll .app-table-card .table-responsive {
    max-height: min(55vh, calc(100dvh - var(--app-navbar-height) - var(--app-tab-bar-height) - 18rem));
}

/* ----- Timesheet-only layout ----- */

body.layout-timesheet-only .app-sidebar,
body.layout-timesheet-only .app-tab-bar {
    display: none !important;
}

body.layout-timesheet-only.app-shell-active .app-main-area--timesheet-only {
    flex: 1 1 100%;
    max-width: 100%;
}

body.layout-timesheet-only.app-shell-active .app-page-scroll {
    padding-left: 1rem;
    padding-right: 1rem;
}

/* ----- Tablet / small laptop ----- */

@media (max-width: 991.98px) {
    body.app-shell-active .app-page-scroll .table-responsive {
        max-height: min(50vh, calc(100dvh - var(--app-navbar-height) - var(--app-tab-bar-height) - 12rem));
    }
}

@media (max-width: 767.98px) {
    :root {
        --app-scroll-padding: 0.75rem;
    }

    body.app-shell-active .app-page-scroll {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* ----- Print / PDF generation in browser ----- */

@media print {
    html.app-shell-document,
    html.app-shell-document body.app-shell-active {
        height: auto;
        overflow: visible;
    }

    body.app-shell-active > .app-shell,
    body.app-shell-active .app-page-scroll,
    body.app-shell-active .app-tab-panels,
    body.app-shell-active .app-tab-panel.active {
        overflow: visible !important;
        height: auto !important;
        max-height: none !important;
        display: block !important;
    }

    body.app-shell-active .app-page-scroll .form-actions {
        position: static;
    }

    body.app-shell-active .app-page-scroll .table-responsive {
        max-height: none;
        overflow: visible;
    }
}
