/*
 * App shell layout (LactoSync SaaS dashboard)
 *
 * Scroll ownership:
 * - Desktop: Lock document scroll (html/body overflow hidden when .ls-mud-layout present).
 * - .ls-page-body-host: overflow hidden; flex column. .ls-page-body-inner passes height to children.
 * - List / grid pages: root .ls-page-sticky-layout (flex, min-height 0). KPI/tiles + filter bars use
 *   .ls-page-sticky-top (flex-shrink: 0). MudPaper.ls-page-grid-shell flex column; .ls-data-grid-scroll
 *   (flex 1, min-height 0) wraps MudDataGrid with FixedHeader="true" Height="100%" so only grid body
 *   scrolls; pager stays on the grid (not in .ls-global-footer).
 * - .ls-global-footer: sticky bottom of the main column + solid background so it stays visible.
 * - Pages without .ls-page-sticky-layout: .ls-page-body-inner > * gets overflow-y auto (fallback).
 * - Below ~768px: document may scroll; shell rules relax.
 */

@media (min-width: 768px) {
    html:has(.ls-mud-layout),
    body:has(.ls-mud-layout) {
        height: 100%;
        overflow: hidden;
    }
}

.ls-mud-layout.mud-layout {
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--mud-palette-background, #f5f6fa);
}

.ls-mud-layout .ls-app-bar.mud-appbar {
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06) !important;
    flex-shrink: 0;
}

.ls-mud-layout .ls-app-bar .mud-toolbar-appbar {
    padding: 0;
    min-height: 73px;
    width: 100%;
    max-width: 100%;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
}

.ls-mud-layout .ls-app-bar .navbar-custom {
    position: relative;
    top: auto;
    z-index: 1;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    align-self: stretch;
    display: flex;
    align-items: center;
}

.ls-mud-layout .ls-app-bar .navbar-custom .navbar-custom-actions {
    margin-left: auto;
}

.ls-mud-layout .ls-drawer.mud-drawer {
    border-right: 1px solid #e5e7eb;
    box-shadow: none;
}

.ls-mud-layout .mud-drawer .sidebar-react-style {
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    border-right: none !important;
    transition: none;
}

.ls-mud-layout .mud-drawer .sidebar-react-style.sidebar-open,
.ls-mud-layout .mud-drawer .sidebar-react-style.sidebar-closed {
    width: 100% !important;
}

.ls-mud-main.mud-main-content {
    flex: 1 1 0%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--mud-palette-background, #f5f6fa);
}

.ls-main-container.mud-container {
    flex: 1 1 0%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    width: 100%;
}

@media (min-width: 768px) {
    .ls-main-container.mud-container {
        padding-right: 6px !important;
    }
}

@media (min-width: 960px) {
    .ls-main-container.mud-container {
        padding-right: 5px !important;
    }
}

.ls-main-column {
    flex: 1 1 0%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.ls-page-shell.mud-paper {
    flex: 1 1 0%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 12px !important;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.04) !important;
    border: 1px solid #e8eaef !important;
}

.ls-page-body-host {
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ls-page-body-inner {
    flex: 1 1 0%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Fallback: forms / simple pages without ls-page-sticky-layout */
.ls-page-body-inner > *:not(.ls-page-sticky-layout) {
    flex: 1 1 0%;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.ls-page-body-inner > .ls-page-sticky-layout {
    flex: 1 1 0%;
    min-height: 0;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

/* Sticky list / grid page root */
.ls-page-sticky-layout {
    display: flex;
    flex-direction: column;
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
}

.ls-page-sticky-top {
    flex-shrink: 0;
}

.ls-page-grid-shell.mud-paper {
    flex: 1 1 0%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ls-data-grid-scroll {
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* MudDataGrid may be wrapped; flex-basis 0 lets Height="100%" resolve (not routes SimpleTable) */
.ls-data-grid-scroll:not(.ls-routes-scroll) > * {
    flex: 1 1 0%;
    min-height: 0;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    align-self: stretch;
}

/* MudBlazor 8+: DataGrid root is .mud-table.mud-data-grid (Height applies to .mud-table-container) */
@media (min-width: 768px) {
    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table.mud-data-grid,
    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-datagrid {
        flex: 1 1 0% !important;
        min-height: 0 !important;
        max-height: 100% !important;
        align-self: stretch;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    /* Only the table body area scrolls; pager toolbar stays fixed below */
    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table.mud-data-grid .mud-table-container,
    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-datagrid .mud-table-container {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        height: auto !important;
        max-height: none !important;
        overflow-x: auto !important;
        overflow-y: auto !important;
    }

    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table-pagination,
    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table-pagination-toolbar {
        flex-shrink: 0 !important;
        flex-grow: 0 !important;
    }

    /* Reduce MudDataGrid pagination/footer footprint (Rows per page + pager) */
    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table-pagination-toolbar {
        padding: 2px 8px !important;
        height: 32px;
        align-items: center !important;
    }

    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table-pagination {
        min-height: 32px !important;
        padding: 0 !important;
        align-items: center !important;
    }

    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table-pagination-toolbar .mud-typography {
        font-size: 0.75rem !important;
        line-height: 1.1 !important;
    }

    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table-pagination-toolbar .mud-button-root {
        min-height: 28px !important;
        height: 28px !important;
    }

    .ls-data-grid-scroll:not(.ls-routes-scroll) .mud-table-pagination-toolbar .mud-select {
        min-height: 28px !important;
    }
}

/* Delivery routes: SimpleTable scrolls in region; sticky header row */
.ls-routes-scroll {
    flex: 1 1 0%;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.ls-routes-scroll .mud-simple-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--mud-palette-surface, #fff);
    box-shadow: 0 1px 0 #e5e7eb;
}

.ls-page-frame {
    display: flex;
    flex-direction: column;
    flex: 1 1 0%;
    min-height: 0;
    height: 100%;
}

.ls-page-toolbar {
    flex-shrink: 0;
}

.ls-page-scroll {
    flex: 1 1 0%;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* Full-page body scroll inside shell (customer panel, onboarding, etc.) */
.ls-panel-body-scroll.mud-container {
    flex: 1 1 0%;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100% !important;
    width: 100%;
}

.ls-table-sticky-head .mud-table-head .mud-table-cell {
    position: sticky;
    top: 0;
    z-index: 3;
    background-color: var(--mud-palette-table-lines, #f9fafb);
    box-shadow: 0 1px 0 #e5e7eb;
}

.ls-global-footer {
    --ls-footer-blue: #2563eb;
    --ls-footer-teal: #0d9488;
    --ls-footer-violet: #7c3aed;
    flex-shrink: 0;
    width: 100%;
    margin-top: 0.375rem;
    position: sticky;
    bottom: 0;
    z-index: 8;
    border-radius: 8px;
    overflow: hidden;
    background: linear-gradient(135deg, #f8fafc 0%, #eff6ff 45%, #f5f3ff 100%);
    border: 1px solid #e2e8f0;
    border-top: none;
    box-shadow: 0 -1px 0 rgba(37, 99, 235, 0.12);
}

.ls-global-footer-accent {
    height: 3px;
    width: 100%;
    background: linear-gradient(90deg, var(--ls-footer-blue) 0%, var(--ls-footer-teal) 50%, var(--ls-footer-violet) 100%);
}

.ls-global-footer-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    padding: 0.25rem 0.25rem 0.25rem;
}

.ls-global-footer-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.ls-global-footer-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.375rem;
    background: linear-gradient(145deg, var(--ls-footer-blue), #1d4ed8);
    color: #fff !important;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

.ls-global-footer-mark .mud-icon-root {
    font-size: 1rem !important;
}

.ls-global-footer-titles {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
}

.ls-global-footer-app {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #0f172a;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.ls-global-footer-tagline {
    font-size: 0.65rem;
    font-weight: 500;
    color: #64748b;
    line-height: 1.2;
}

.ls-global-footer-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}

.ls-global-footer .ls-footer-chip.mud-chip {
    height: 26px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: none;
    border-radius: 9999px;
}

.ls-global-footer-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.ls-global-footer-copy {
    font-size: 0.65rem;
    color: #64748b;
    font-weight: 500;
}

.ls-global-footer-pill {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.45rem;
    border-radius: 9999px;
    background: linear-gradient(135deg, #dbeafe, #e0e7ff);
    color: #3730a3;
    border: 1px solid rgba(99, 102, 241, 0.25);
}

.mud-theme-dark .ls-global-footer {
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    border-color: #334155;
    box-shadow: 0 -1px 0 rgba(96, 165, 250, 0.2);
}

.mud-theme-dark .ls-global-footer-app {
    color: #f1f5f9;
}

.mud-theme-dark .ls-global-footer-tagline,
.mud-theme-dark .ls-global-footer-copy {
    color: #94a3b8;
}

.mud-theme-dark .ls-global-footer-pill {
    background: rgba(99, 102, 241, 0.2);
    color: #c7d2fe;
    border-color: rgba(129, 140, 248, 0.35);
}

/* Collapsible page metrics (list pages + dashboard) */
.ls-collapsible-metrics {
    margin-bottom: 0.2rem;
}

.ls-collapsible-metrics__chrome {
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 14px rgba(37, 99, 235, 0.06);
    overflow: hidden;
}

.ls-collapsible-metrics__header-hit {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
    border-radius: 0;
}

.ls-collapsible-metrics__header-hit:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: -2px;
}

.ls-collapsible-metrics__accent {
    display: block;
    height: 3px;
    width: 100%;
    background: linear-gradient(90deg, #2563eb 0%, #0d9488 45%, #7c3aed 100%);
    opacity: 0.92;
}

.ls-collapsible-metrics__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem 0.5rem 0.75rem;
    min-height: 2.75rem;
}

.ls-collapsible-metrics__chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #64748b;
    width: 2rem;
    height: 2rem;
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.12);
}

.ls-collapsible-metrics__label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
}

.ls-collapsible-metrics__icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.875rem;
    height: 1.875rem;
    border-radius: 0.5rem;
    background: linear-gradient(145deg, #eff6ff, #e0e7ff);
    color: #2563eb;
    flex-shrink: 0;
}

.ls-collapsible-metrics__icon-wrap .mud-icon-root {
    font-size: 1.05rem !important;
}

.ls-collapsible-metrics__title {
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #0f172a;
}

.ls-collapsible-metrics__hint {
    font-size: 0.7rem;
    font-weight: 500;
    margin-left: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ls-collapsible-metrics__body {
    padding: 0.3rem 0.3rem 0.3rem;
    border-top: 1px solid #f1f5f9;
    background: #fff;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* MudCollapse inside flex scroll regions: allow measured height so outer scroll works */
.ls-dashboard-scroll .mud-collapse-container,
.ls-page-scroll .mud-collapse-container {
    overflow: visible !important;
}

.mud-theme-dark .ls-collapsible-metrics__chrome {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    border-color: #334155;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.mud-theme-dark .ls-collapsible-metrics__title {
    color: #f1f5f9;
}

.mud-theme-dark .ls-collapsible-metrics__icon-wrap {
    background: rgba(37, 99, 235, 0.2);
    color: #93c5fd;
}

.mud-theme-dark .ls-collapsible-metrics__body {
    background: #0f172a;
    border-top-color: #334155;
}

.mud-theme-dark .ls-collapsible-metrics__chevron {
    color: #94a3b8;
    background: rgba(148, 163, 184, 0.15);
}

.mud-theme-dark .ls-collapsible-metrics__header-hit:focus-visible {
    outline-color: #93c5fd;
}

@media (max-width: 767.98px) {
    html:has(.ls-mud-layout),
    body:has(.ls-mud-layout) {
        height: auto;
        overflow: auto;
    }

    .ls-mud-layout.mud-layout {
        height: auto;
        min-height: 100vh;
        max-height: none;
        overflow: visible;
    }

    .ls-mud-main.mud-main-content {
        overflow: visible !important;
        min-height: auto;
    }

    .ls-main-column {
        min-height: auto !important;
    }

    .ls-page-shell.mud-paper {
        flex: 1 1 auto;
        min-height: auto !important;
        overflow: visible !important;
    }

    .ls-page-body-host {
        overflow: visible !important;
        min-height: auto;
    }

    .ls-page-body-inner {
        overflow: visible !important;
        min-height: auto;
    }

    .ls-page-body-inner > *:not(.ls-page-sticky-layout) {
        overflow: visible !important;
        min-height: auto;
    }

    .ls-page-body-inner > .ls-page-sticky-layout {
        overflow: visible !important;
        min-height: auto !important;
    }

    .ls-page-sticky-layout {
        overflow: visible !important;
        min-height: auto !important;
    }

    .ls-page-grid-shell.mud-paper {
        overflow: visible !important;
        min-height: auto !important;
    }

    .ls-data-grid-scroll {
        overflow: visible !important;
        min-height: auto !important;
    }

    .ls-data-grid-scroll:not(.ls-routes-scroll) > * {
        flex: none;
        max-height: none;
        overflow: visible;
    }

    .ls-data-grid-scroll .mud-table.mud-data-grid,
    .ls-data-grid-scroll .mud-datagrid {
        height: auto !important;
        max-height: none !important;
        min-height: 0 !important;
    }

    .ls-data-grid-scroll .mud-table.mud-data-grid .mud-table-container,
    .ls-data-grid-scroll .mud-datagrid .mud-table-container {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    .ls-global-footer {
        position: relative;
        bottom: auto;
    }
}
