/* resp-shell — app shell, page chrome and shared finance UI. Loaded after app.css. */

/* ───────────────────────── Header ───────────────────────── */

/* Left part (menu button + logo) takes what is left, the toolbar keeps its natural width and never wraps */
.app-shell__header-inner {
    flex-wrap: nowrap;
}

.app-shell__header-inner > .rz-col-6:first-child,
.app-shell__header-inner > [class*="rz-col-md"]:first-child {
    flex: 1 1 0;
    width: auto;
    max-width: none;
    min-width: 0;
}

.app-shell__header-inner > .rz-col-6:last-child,
.app-shell__header-inner > [class*="rz-col-md"]:last-child {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
}

.app-shell__toolbar {
    width: auto;
}

.app-shell__toolbar-context .rz-button,
.app-shell__branch-add.rz-button {
    flex-shrink: 0;
    white-space: nowrap;
}

/* ───────────────────────── Page frame ───────────────────────── */

/* The page animation used `forwards`, which left a transform on .app-page and made it the
   containing block for every fixed/absolute popup inside it. Run it once, then drop it. */
.app-page {
    max-width: 1680px;
    padding: 1.25rem 1.5rem 2rem;
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.app-shell {
    /* The page frame (.app-page) owns the spacing; Radzen's own body padding only added a second gutter */
    --rz-layout-body-padding: 0;
}

.app-shell__body {
    min-width: 0;
}

.app-page > * {
    min-width: 0;
}

/* Never let a form control push the page wider than the screen. */
.app-page .rz-form-field,
.app-page .rz-dropdown,
.app-page .rz-textbox,
.app-page .rz-textarea,
.app-page .rz-numeric,
.app-page .rz-datepicker,
.app-page .rz-multiselect,
.app-page .rz-autocomplete,
.app-page .rz-chkbox-box + label {
    max-width: 100%;
}

.rz-dialog .rz-form-field,
.rz-dialog .rz-dropdown,
.rz-dialog .rz-textbox,
.rz-dialog .rz-textarea,
.rz-dialog .rz-numeric,
.rz-dialog .rz-datepicker {
    max-width: 100%;
}

.app-page img,
.app-page video,
.app-page canvas {
    max-width: 100%;
}

/* Page header: title + actions wrap cleanly */
.app-page__header {
    gap: 0.75rem 1rem;
    margin-bottom: 1.25rem;
}

.app-page__title {
    overflow-wrap: anywhere;
}

.app-page__actions {
    min-width: 0;
    max-width: 100%;
}

/* A Radzen stack dropped into the header actions wraps instead of overflowing */
.app-page__actions .rz-stack.rz-flex-row,
.app-card-header .app-page__actions .rz-stack.rz-flex-row {
    flex-wrap: wrap;
    max-width: 100%;
}

/* Cards */
.app-page__card {
    padding: 1.25rem;
    min-width: 0;
}

.app-page__card--flush {
    padding: 0;
}

.app-page__card .app-card-header {
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.app-page__card--flush .app-card-header {
    padding: 0.9rem 1.25rem;
}

/* Tables and grids scroll inside their own card, never the page */
.app-page .app-datagrid,
.app-page .rz-data-grid {
    max-width: 100%;
}

.app-page .rz-data-grid .rz-data-grid-data,
.app-page .rz-data-grid .rz-datatable-scrollable-wrapper {
    overflow-x: auto;
    max-width: 100%;
}

.app-page .rz-data-grid .rz-paginator {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem;
}

/* Radzen tab strips scroll sideways instead of widening the page */
.rz-tabview-nav {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

.rz-tabview-nav > li {
    flex: 0 0 auto;
}

.rz-tabview-panels {
    min-width: 0;
}

/* ───────────────────────── Tab bar (finance sub navigation) ───────────────────────── */

.finance-subnav {
    position: relative;
    align-items: center;
    gap: 0.35rem;
}

@media (min-width: 900px) and (max-width: 1199.98px) {
    /* Tablet landscape: slightly tighter tabs keep the whole bar on one row */
    .finance-subnav__item {
        padding-inline: 0.65rem;
    }
}

.finance-subnav__item {
    white-space: nowrap;
    min-height: 2.25rem;
}

.finance-subnav__menu {
    max-width: calc(100vw - 2rem);
    max-height: 70vh;
    overflow-y: auto;
}

/* ───────────────────────── Finance hub cards, stat tiles ───────────────────────── */

.finance-hub-card {
    min-width: 0;
    align-items: center;
}

.finance-hub-card__title,
.finance-hub-card__desc {
    overflow-wrap: anywhere;
}

.finance-hub-card__chevron {
    margin-top: 0;
    align-self: center;
}

.finance-hub-grid,
.app-kpi-grid,
.pos-bill-list-stats {
    min-width: 0;
}

.app-page .finance-hub-grid > *,
.app-page .app-kpi-grid > *,
.app-page .pos-bill-list-stats > * {
    min-width: 0;
}

.app-stat-card {
    min-width: 0;
}

.app-stat-card__inner > div:first-child {
    min-width: 0;
}

.app-stat-card__value,
.pos-bill-list-stat__value {
    overflow-wrap: anywhere;
}

.app-stat-card__label,
.pos-bill-list-stat__label {
    overflow-wrap: anywhere;
}

.finance-status-pill {
    white-space: nowrap;
}

/* To-do list and links under it */
.stf-todo__heading {
    flex-wrap: wrap;
    gap: 0.15rem 0.6rem;
}

.stf-todo__item > .rz-button {
    flex: none;
}

.stf-more {
    row-gap: 0.5rem;
}

.staff-attention .rz-button {
    flex: none;
}

.acc-quick > * {
    min-width: 0;
}

/* ── Grids: 1 column on phones, 2 on tablets, 3-4 on desktop. Every row is filled (no orphan gap). ── */

.app-page .finance-hub-grid,
.app-page .app-kpi-grid,
.app-page .pos-bill-list-stats {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.875rem;
    margin-bottom: 1.25rem;
    align-items: stretch;
}

/* Tablets: two columns; a last card that would sit alone spans the row */
@media (min-width: 480px) {
    .app-page .app-kpi-grid,
    .app-page .pos-bill-list-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .app-page .app-kpi-grid > :last-child:nth-child(odd),
    .app-page .pos-bill-list-stats > :last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }
}

@media (min-width: 640px) {
    .app-page .finance-hub-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .app-page .finance-hub-grid > :last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }
}

/* Desktop: a 12-column track, each count of cards gets a balanced layout */
@media (min-width: 1200px) {
    .app-page .finance-hub-grid,
    .app-page .app-kpi-grid,
    .app-page .pos-bill-list-stats {
        grid-template-columns: repeat(12, minmax(0, 1fr));
    }

    .app-page .finance-hub-grid > *,
    .app-page .app-kpi-grid > *,
    .app-page .pos-bill-list-stats > * {
        grid-column: span 3;
    }

    /* 1 card */
    .app-page .finance-hub-grid:has(> :first-child:last-child) > *,
    .app-page .app-kpi-grid:has(> :first-child:last-child) > *,
    .app-page .pos-bill-list-stats:has(> :first-child:last-child) > * { grid-column: 1 / -1; }

    /* 2 cards */
    .app-page .finance-hub-grid:has(> :nth-child(2):last-child) > *,
    .app-page .app-kpi-grid:has(> :nth-child(2):last-child) > *,
    .app-page .pos-bill-list-stats:has(> :nth-child(2):last-child) > * { grid-column: span 6; }

    /* 3 cards */
    .app-page .finance-hub-grid:has(> :nth-child(3):last-child) > *,
    .app-page .app-kpi-grid:has(> :nth-child(3):last-child) > *,
    .app-page .pos-bill-list-stats:has(> :nth-child(3):last-child) > * { grid-column: span 4; }

    /* 4 hub cards: 2 x 2 until the screen is wide enough for four across */
    .app-page .finance-hub-grid:has(> :nth-child(4):last-child) > * { grid-column: span 6; }

    /* 5 cards: 3 + 2 */
    .app-page .finance-hub-grid:has(> :nth-child(5):last-child) > *,
    .app-page .app-kpi-grid:has(> :nth-child(5):last-child) > *,
    .app-page .pos-bill-list-stats:has(> :nth-child(5):last-child) > * { grid-column: span 4; }

    .app-page .finance-hub-grid:has(> :nth-child(5):last-child) > :nth-child(n + 4),
    .app-page .app-kpi-grid:has(> :nth-child(5):last-child) > :nth-child(n + 4),
    .app-page .pos-bill-list-stats:has(> :nth-child(5):last-child) > :nth-child(n + 4) { grid-column: span 6; }

    /* 6 and 9 cards: three across */
    .app-page .finance-hub-grid:has(> :nth-child(6):last-child) > *,
    .app-page .app-kpi-grid:has(> :nth-child(6):last-child) > *,
    .app-page .pos-bill-list-stats:has(> :nth-child(6):last-child) > *,
    .app-page .finance-hub-grid:has(> :nth-child(9):last-child) > *,
    .app-page .app-kpi-grid:has(> :nth-child(9):last-child) > *,
    .app-page .pos-bill-list-stats:has(> :nth-child(9):last-child) > * { grid-column: span 4; }

    /* 7 cards: 4 + 3 */
    .app-page .app-kpi-grid:has(> :nth-child(7):last-child) > :nth-child(n + 5),
    .app-page .pos-bill-list-stats:has(> :nth-child(7):last-child) > :nth-child(n + 5),
    .app-page .finance-hub-grid:has(> :nth-child(7):last-child) > :nth-child(n + 5) { grid-column: span 4; }
}

@media (min-width: 1500px) {
    .app-page .finance-hub-grid:has(> :nth-child(4):last-child) > * { grid-column: span 3; }
}

/* ───────────────────────── Phones and small tablets ───────────────────────── */

@media (max-width: 899.98px) {
    /* Tab bar: tabs share each row evenly (no gaps); the More menu hangs under the whole bar */
    .finance-subnav {
        gap: 0.35rem;
        padding: 0.35rem;
    }

    .finance-subnav__item {
        flex: 1 1 auto;
        justify-content: center;
        min-height: 2.5rem;
        min-width: 0;
        padding: 0.4rem 0.55rem;
    }

    .finance-subnav__item > span {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .finance-subnav__more {
        position: static;
        display: flex;
        flex: 1 1 auto;
        min-width: 0;
    }

    .finance-subnav__menu {
        right: 0;
        left: auto;
        top: calc(100% + 0.35rem);
    }
}

@media (max-width: 639.98px) {
    .finance-subnav {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(6.75rem, 1fr));
    }

    .finance-subnav__item {
        width: 100%;
    }
}

@media (max-width: 768px) {
    /* Sidebar becomes a drawer on top of the page instead of squeezing it */
    .app-shell > .rz-sidebar.app-shell__sidebar {
        position: fixed !important;
        top: var(--app-header-height);
        bottom: 0;
        left: 0;
        z-index: 1001;
        height: auto !important;
        max-height: none !important;
        width: min(86vw, 320px) !important;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.22);
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .app-shell > .rz-sidebar.app-shell__sidebar.rz-sidebar-collapsed {
        width: min(86vw, 320px) !important;
        transform: translateX(-105%);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        box-shadow: none;
    }

    .app-shell__scrim {
        display: block;
        position: fixed;
        top: var(--app-header-height);
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1000;
        background: rgba(15, 23, 42, 0.45);
    }

    .app-shell__nav-menu.rz-panel-menu .rz-navigation-item-link {
        min-height: 44px;
    }
}

.app-shell__scrim {
    display: none;
}

@media (min-width: 769px) and (max-width: 1100px) {
    .app-shell {
        --rz-sidebar-width: 264px;
    }
}

@media (max-width: 767.98px) {
    .app-page {
        padding: 1rem 0.875rem 1.5rem;
    }

    .app-page__header {
        margin-bottom: 1rem;
    }

    .app-page__intro {
        flex-basis: 100%;
    }

    .app-page__actions {
        width: 100%;
    }

    .app-page__actions > .rz-button,
    .app-page__actions > .rz-splitbutton {
        flex: 1 1 auto;
    }

    .app-page__card {
        padding: 1rem;
        margin-bottom: 0.875rem;
    }

    .app-page__card--flush {
        padding: 0;
    }

    .app-page__card--form {
        padding: 1.1rem;
    }

    .app-page__card--narrow,
    .app-page__card--medium {
        max-width: none;
    }

    .app-page__form-actions {
        justify-content: stretch;
    }

    .app-page__form-actions > .rz-button {
        flex: 1 1 auto;
    }

    .app-card-header {
        padding: 0.85rem 1rem;
    }

    .app-page__card--flush .app-card-header {
        padding: 0.85rem 1rem;
    }

    .app-stat-card {
        padding: 1rem;
    }

    .app-stat-card__value {
        font-size: 1.5rem;
    }

    .finance-hub-card {
        padding: 1rem 0.9rem;
    }

    /* To-do rows: text first, button underneath */
    .stf-todo__item {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: start;
        gap: 0.4rem 0.6rem;
    }

    .stf-todo__item > .rz-button {
        grid-column: 2;
        justify-self: start;
    }

    .staff-attention {
        align-items: flex-start;
    }

    .staff-attention .rz-button {
        margin-left: 0;
    }

    .stf-more {
        gap: 0.6rem 1.1rem;
    }

    .stf-more__link {
        min-height: 2.5rem;
    }

    .acc-quick {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    }

    .acc-quick > .rz-button {
        width: 100%;
    }

    /* Touch targets */
    .rz-button,
    .rz-button:is(.rz-button-md, .rz-button-sm, .rz-button-xs, .rz-button-lg) {
        min-height: 40px;
    }

    .rz-button.rz-button-icon-only,
    .rz-button:is(.rz-button-md, .rz-button-sm, .rz-button-xs).rz-button-icon-only {
        min-width: 40px;
    }

    .rz-paginator .rz-pager-element,
    .rz-paginator .rz-pager-page {
        min-width: 40px;
        min-height: 40px;
    }

    .rz-textbox,
    .rz-numeric input,
    .rz-dropdown,
    .rz-datepicker input,
    .rz-form-field-input {
        min-height: 40px;
    }

    .app-shell__sidebar-toggle.rz-sidebar-toggle,
    .app-shell__sidebar-toggle.rz-button,
    .app-shell__toolbar-theme .theme-toggle-btn.rz-button,
    .app-shell__toolbar-theme .rz-appearance-toggle.rz-button,
    .app-shell__toolbar-theme .alert-sound-toggle.rz-button {
        min-width: 40px;
        min-height: 40px;
    }

    .app-shell__toolbar {
        gap: 0.25rem;
    }

    .app-shell__toolbar-actions {
        gap: 0.25rem;
    }

    .app-shell__profile-chip {
        min-height: 40px;
    }

    /* Dialogs fit the phone */
    .rz-dialog-wrapper {
        padding: 0.5rem;
    }

    .rz-dialog {
        width: calc(100vw - 1rem) !important;
        max-width: calc(100vw - 1rem) !important;
        max-height: calc(100dvh - 1rem) !important;
    }

    .rz-dialog .rz-dialog-content {
        max-width: 100%;
        overflow-x: auto;
        overflow-y: auto;
    }

    .rz-dialog .rz-dialog-titlebar {
        padding-inline: 1rem;
    }

    .rz-dialog .rz-dialog-titlebar .rz-dialog-titlebar-close {
        min-width: 40px;
        min-height: 40px;
    }
}

@media (max-width: 400px) {
    .app-page {
        padding-inline: 0.75rem;
    }

    /* Small phones: label-only tabs so three fit across */
    .finance-subnav {
        grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr));
    }

    .finance-subnav__item > .finance-subnav__icon:first-child {
        display: none;
    }

    .app-shell__profile-text {
        display: none !important;
    }
}

/* ───────────────────────── Wide screens ───────────────────────── */

@media (min-width: 1800px) {
    .app-page {
        padding-inline: 2rem;
    }
}
