/* Global Layout System - Height Management
   ========================================
   This file provides a centralized solution for viewport height calculations
   throughout the application, eliminating the need for manual calc() values
   on each page.
*/

/* ============================================================================
   CSS Custom Properties for Layout Heights
   ============================================================================ */

:root {
    /* Base layout measurements */
    --app-header-height: 60px;
    --app-navigation-height: 50px;
    --app-breadcrumb-height: 40px;
    --app-footer-height: 30px;
    --app-toolbar-height: 50px;
    --app-filter-height: 80px;
    --app-pagination-height: 60px;
    --app-spacing-standard: 20px;
    --app-spacing-large: 40px;

    /* Common subtract values converted to semantic names */
    --layout-offset-minimal: 140px;
    /* Basic header + nav */
    --layout-offset-standard: 280px;
    /* Most common - header + nav + toolbar + spacing */
    --layout-offset-compact: 278px;
    /* Slightly smaller variant */
    --layout-offset-with-filters: 370px;
    /* With filter section */
    --layout-offset-with-breadcrumbs: 320px;
    /* With breadcrumb navigation */
    --layout-offset-popup-view: 440px;
    /* For popup/modal views */
    --layout-offset-extended: 420px;
    /* For pages with extra controls */
    --layout-offset-scheduler: 310px;
    /* For calendar/scheduler views */
    --layout-offset-summary-page: 480px;

    /* Responsive adjustments */
    --layout-mobile-adjustment: 20px;
    --layout-tablet-adjustment: 10px;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    :root {
        --app-header-height: 50px;
        --app-navigation-height: 45px;
        --app-toolbar-height: 45px;
        --layout-offset-standard: 260px;
        --layout-offset-with-filters: 340px;
        --layout-offset-popup-view: 400px;
    }
}

@media (max-width: 480px) {
    :root {
        --app-header-height: 45px;
        --app-navigation-height: 40px;
        --app-toolbar-height: 40px;
        --layout-offset-standard: 240px;
        --layout-offset-with-filters: 320px;
        --layout-offset-popup-view: 380px;
    }
}

/* ============================================================================
   Utility Classes for Viewport Heights
   ============================================================================ */

/* Standard viewport height utilities */
.vh-full-minimal {
    height: calc(100vh - var(--layout-offset-minimal)) !important;
}

.vh-full-standard {
    height: calc(100vh - var(--layout-offset-standard)) !important;
}

.vh-full-compact {
    height: calc(100vh - var(--layout-offset-compact)) !important;
}

.vh-full-with-filters {
    height: calc(100vh - var(--layout-offset-with-filters)) !important;
}

.vh-full-with-breadcrumbs {
    height: calc(100vh - var(--layout-offset-with-breadcrumbs)) !important;
}

.vh-full-popup {
    height: calc(100vh - var(--layout-offset-popup-view)) !important;
}

.vh-full-extended {
    height: calc(100vh - var(--layout-offset-extended)) !important;
}

.vh-full-scheduler {
    height: calc(100vh - var(--layout-offset-scheduler)) !important;
}

/* Conditional height classes for different view types */
.vh-conditional-popup {
    height: calc(100vh - var(--layout-offset-popup-view)) !important;
}

.vh-conditional-standard {
    height: calc(100vh - var(--layout-offset-standard)) !important;
}

/* ============================================================================
   Flex-based Auto Height System
   ============================================================================ */

/* Modern flex-based layout containers that automatically calculate heights */
.app-layout-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-header-section {
    flex-shrink: 0;
    height: var(--app-header-height);
}

.app-navigation-section {
    flex-shrink: 0;
    height: var(--app-navigation-height);
}

.app-toolbar-section {
    flex-shrink: 0;
    height: var(--app-toolbar-height);
}

.app-content-section {
    flex: 1;
    overflow: auto;
    min-height: 0;
    /* Important for flex child scrolling */
}

.app-footer-section {
    flex-shrink: 0;
    height: var(--app-footer-height);
}

/* ============================================================================
   Data Grid Specific Heights
   ============================================================================ */

/* Common data grid container heights */
.datagrid-container-standard {
    height: calc(100vh - var(--layout-offset-standard)) !important;
}

.datagrid-container-with-filters {
    height: calc(100vh - var(--layout-offset-with-filters)) !important;
}

.datagrid-container-popup {
    height: calc(100vh - var(--layout-offset-popup-view)) !important;
}

.datagrid-container-extended {
    height: calc(100vh - var(--layout-offset-extended)) !important;
}

.datagrid-container-summary {
    height: calc(100vh - var(--layout-offset-summary-page)) !important;
}

/* ============================================================================
   Tab and Modal Specific Heights
   ============================================================================ */

.tab-content-standard {
    height: calc(100vh - var(--layout-offset-minimal)) !important;
}

/* When the tabs ARE the page (the task board), fill the layout's body instead of guessing its
   size. The 140px above assumes a 60px header and a 30px footer; the real ones are about 85px
   and 70px, so the tabs came out ~15px taller than the body and the whole page grew a vertical
   scrollbar that scrolled almost nothing. .rz-body is a grid row with a definite height, so 100%
   resolves. The calc stays as the fallback where :has() is missing or the tabs sit deeper. */
.rz-body > .app-content-reflow:has(> .tab-content-standard) {
    height: 100%;
}

.rz-body > .app-content-reflow > .tab-content-standard {
    height: 100% !important;
    box-sizing: border-box;
}

/* A tab whose content is "toolbar, cards, then a grid" (.rc-fill-tab). Radzen scrolls the whole
   tab panel, so a longer page of rows pushed the column headers and the pager out of sight. Here
   the panel hands its height down (and only scrolls on a window too short for the grid): the fixed parts keep their size, the grid
   takes what is left, and RadzenDataGrid — which scrolls its own rows once it has a definite
   height — keeps its header and pager in view. */
.rz-tabview-panels:has(> .rz-tabview-panel > .rc-fill-tab) {
    overflow: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.rz-tabview-panel:has(> .rc-fill-tab) {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.rc-fill-tab {
    flex: 1;
    min-height: 0;
    flex-wrap: nowrap;
}

.rc-fill-tab > * {
    flex-shrink: 0;
}

.rc-fill-tab > .rc-fill-tab-grid {
    flex: 1 1 0;
    /* Short windows: never squeeze the grid below a few rows; the panel scrolls instead. */
    min-height: 16rem;
}

/* The grid is sized by flex, not by its own height:100% — a percentage only resolves when every
   ancestor's height is definite, and that is what silently failed before. */
.rc-fill-tab > .rc-fill-tab-grid {
    display: flex;
    flex-direction: column;
}

.rc-fill-tab-grid > .rz-data-grid {
    flex: 1 1 0;
    min-height: 0;
    height: auto !important;
}

/* The same for every list view, matched by shape so no page needs an edit. A list view is a
   stack whose LAST row holds the grid's column (plus, on some pages, full-width filter cards
   above it). Before, the grid grew with its rows and the page — or the tab — scrolled, taking the
   column headers and the pager out of sight at 20+ rows a page; the pages that tried to size the
   grid did it with a guessed calc(100vh - N px) that was rarely right.

   Now the page body (or the tab panel, when a tab is the whole page) hands its height to that
   stack, the stack's other rows keep their natural size, the cards keep theirs, and the grid takes
   what is left and scrolls its own rows. The guessed heights (datagrid-container-*, inline
   height:calc) are overridden inside this shape only. A last row that splits its width (a grid
   beside something) is left alone: stacking it would change the page's layout, not its scroll.
   Dialogs are unaffected — the roots are the layout body and a page-level tab set. */
/* (No :has() inside :has() below — CSS forbids nesting it and silently drops the whole rule.) */
:is(.rz-body > .app-content-reflow, .tab-content-standard > .rz-tabview-panels > .rz-tabview-panel):has(> .rz-stack > .rz-row:last-child > .rz-col[class*="-12"] > .rz-data-grid) {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
}

.tab-content-standard > .rz-tabview-panels:has(> .rz-tabview-panel > .rz-stack > .rz-row:last-child > .rz-col[class*="-12"] > .rz-data-grid) {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tab-content-standard > .rz-tabview-panels > .rz-tabview-panel:has(> .rz-stack > .rz-row:last-child > .rz-col[class*="-12"] > .rz-data-grid) {
    flex: 1;
    height: auto;
}

:is(.rz-body > .app-content-reflow, .tab-content-standard > .rz-tabview-panels > .rz-tabview-panel) > .rz-stack:has(> .rz-row:last-child > .rz-col[class*="-12"] > .rz-data-grid) {
    flex: 1;
    min-height: 0;
    flex-wrap: nowrap;
    box-sizing: border-box;
}

:is(.rz-body > .app-content-reflow, .tab-content-standard > .rz-tabview-panels > .rz-tabview-panel) > .rz-stack:has(> .rz-row:last-child > .rz-col[class*="-12"] > .rz-data-grid) > * {
    flex-shrink: 0;
}

:is(.rz-body > .app-content-reflow, .tab-content-standard > .rz-tabview-panels > .rz-tabview-panel) > .rz-stack > .rz-row:last-child:not(:has(> .rz-col:not([class*="-12"]))):has(> .rz-col > .rz-data-grid) {
    flex: 1 1 0;
    /* Short windows: keep a few rows and let the page scroll, as before. */
    min-height: 16rem;
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
}

:is(.rz-body > .app-content-reflow, .tab-content-standard > .rz-tabview-panels > .rz-tabview-panel) > .rz-stack > .rz-row:last-child:not(:has(> .rz-col:not([class*="-12"]))) > .rz-col {
    flex: 0 0 auto;
    max-width: 100%;
    width: 100%;
}

:is(.rz-body > .app-content-reflow, .tab-content-standard > .rz-tabview-panels > .rz-tabview-panel) > .rz-stack > .rz-row:last-child:not(:has(> .rz-col:not([class*="-12"]))) > .rz-col:has(> .rz-data-grid) {
    flex: 1 1 0;
    min-height: 0;
    height: auto !important;
    display: flex;
    flex-direction: column;
}

:is(.rz-body > .app-content-reflow, .tab-content-standard > .rz-tabview-panels > .rz-tabview-panel) > .rz-stack > .rz-row:last-child:not(:has(> .rz-col:not([class*="-12"]))) > .rz-col > .rz-data-grid {
    flex: 1 1 0;
    min-height: 0;
    height: auto !important;
}

.modal-content-standard {
    max-height: calc(100vh - var(--layout-offset-standard)) !important;
}

/* ============================================================================
   Custom Height Calculation Helpers
   ============================================================================ */

/* For cases where you need custom calculations */
.vh-custom-small {
    height: calc(100vh - 200px) !important;
}

.vh-custom-medium {
    height: calc(100vh - 300px) !important;
}

.vh-custom-large {
    height: calc(100vh - 400px) !important;
}

/* ============================================================================
   Scrollable Content Areas
   ============================================================================ */

.scrollable-content {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 51, 153, 0.3) rgba(255, 255, 255, 0.1);
}

.scrollable-content::-webkit-scrollbar {
    width: 8px;
}

.scrollable-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.scrollable-content::-webkit-scrollbar-thumb {
    background: rgba(0, 51, 153, 0.3);
    border-radius: 4px;
    transition: background 0.3s ease;
}

.scrollable-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 51, 153, 0.5);
}

/* ============================================================================
   Debug Helpers (remove in production)
   ============================================================================ */

.debug-height {
    border: 2px dashed red;
    position: relative;
}

.debug-height::before {
    content: 'Height: ' attr(data-height);
    position: absolute;
    top: 0;
    left: 0;
    background: red;
    color: white;
    padding: 2px 6px;
    font-size: 12px;
    z-index: 9999;
}

/* ============================================================================
   Print Styles
   ============================================================================ */

@media print {

    .vh-full-standard,
    .vh-full-compact,
    .vh-full-with-filters,
    .vh-full-popup,
    .vh-full-extended {
        height: auto !important;
        max-height: none !important;
    }

    .scrollable-content {
        overflow: visible !important;
    }
}

/* ============================================================================
   Legacy Support (for gradual migration)
   ============================================================================ */

/* Classes that can be used to replace inline styles gradually */
.legacy-height-280 {
    height: calc(100vh - 280px) !important;
}

.legacy-height-278 {
    height: calc(100vh - 278px) !important;
}

.legacy-height-370 {
    height: calc(100vh - 370px) !important;
}

.legacy-height-420 {
    height: calc(100vh - 420px) !important;
}

.legacy-height-440 {
    height: calc(100vh - 440px) !important;
}

.legacy-height-310 {
    height: calc(100vh - 310px) !important;
}

.legacy-height-320 {
    height: calc(100vh - 320px) !important;
}
/* An uploaded logo (the demo tenant's prospect) has no size of its own that suits the banner:
   fix its height, keep its proportions. Shipped tenant logos are sized by their SVG. */
.app-main-header img.uploaded-logo {
    height: 48px;
    width: auto;
    max-width: 240px;
    object-fit: contain;
    margin: 4px 0;
}
