/*
 | Phase H.1 — Global Layout Responsive Foundation
 | Safe, additive layer only. No route or workflow changes.
 */

:root {
    --mf-shell-gap: 16px;
    --mf-shell-gap-lg: 20px;
    --mf-card-radius: 16px;
    --mf-card-radius-sm: 12px;
    --mf-border-soft: rgba(15, 23, 42, 0.08);
    --mf-surface-soft: #f8fafc;
    --mf-text-muted: #64748b;
}

body.mobile-foundation {
    -webkit-text-size-adjust: 100%;
}

body.mobile-foundation #main {
    padding-inline: var(--mf-shell-gap-lg);
}

body.mobile-foundation .pagetitle {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px 14px;
    margin-bottom: 16px;
}

body.mobile-foundation .pagetitle h1 {
    margin-bottom: 0;
    line-height: 1.25;
}

body.mobile-foundation .breadcrumb {
    margin-bottom: 0;
    flex-wrap: wrap;
    row-gap: 6px;
}

body.mobile-foundation .card,
body.mobile-foundation .modal-content,
body.mobile-foundation .dropdown-menu {
    border-radius: var(--mf-card-radius);
}

body.mobile-foundation .card-header,
body.mobile-foundation .card-footer,
body.mobile-foundation .modal-header,
body.mobile-foundation .modal-footer {
    padding: 14px 16px;
}

body.mobile-foundation .card-body,
body.mobile-foundation .modal-body {
    padding: 16px;
}

body.mobile-foundation .btn,
body.mobile-foundation .form-control,
body.mobile-foundation .form-select,
body.mobile-foundation .input-group-text,
body.mobile-foundation .form-control-color {
    min-height: 42px;
}

body.mobile-foundation .btn {
    border-radius: 12px;
    white-space: nowrap;
}

body.mobile-foundation .btn-group > .btn,
body.mobile-foundation .input-group > .btn {
    min-height: 42px;
}

body.mobile-foundation .form-label,
body.mobile-foundation label {
    margin-bottom: 6px;
}

body.mobile-foundation textarea.form-control {
    min-height: 96px;
}

body.mobile-foundation .table-responsive,
body.mobile-foundation .mobile-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

body.mobile-foundation .table-responsive {
    border-radius: var(--mf-card-radius-sm);
}

body.mobile-foundation .table > :not(caption) > * > * {
    vertical-align: middle;
}

body.mobile-foundation .page-toolbar,
body.mobile-foundation .report-toolbar,
body.mobile-foundation .filter-toolbar,
body.mobile-foundation .toolbar-row,
body.mobile-foundation .actions-row,
body.mobile-foundation .card-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

body.mobile-foundation .toolbar-row > *,
body.mobile-foundation .page-toolbar > *,
body.mobile-foundation .report-toolbar > *,
body.mobile-foundation .filter-toolbar > *,
body.mobile-foundation .actions-row > * {
    max-width: 100%;
}

body.mobile-foundation .mobile-stack > .row,
body.mobile-foundation .mobile-stack.row {
    row-gap: 12px;
}

body.mobile-foundation .mobile-card-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

body.mobile-foundation .tenant-context-card {
    border-radius: 16px;
}

body.mobile-foundation .small-muted,
body.mobile-foundation .text-muted {
    color: var(--mf-text-muted) !important;
}

body.mobile-foundation .alert,
body.mobile-foundation .badge {
    max-width: 100%;
}

body.mobile-foundation .header-nav .nav-link,
body.mobile-foundation .header-nav .nav-icon,
body.mobile-foundation .sidebar-nav .nav-link {
    min-height: 40px;
}

body.mobile-foundation .dropdown-menu {
    max-width: min(92vw, 420px);
}

body.mobile-foundation .input-group {
    flex-wrap: nowrap;
}

body.mobile-foundation .modal-dialog {
    margin: 0.75rem auto;
}

@media (max-width: 1199.98px) {
    body.mobile-foundation #main,
    body.mobile-foundation #footer {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    body.mobile-foundation #main {
        padding-inline: var(--mf-shell-gap);
    }

    body.mobile-foundation .header {
        padding-inline: 12px;
    }
}

@media (max-width: 991.98px) {
    body.mobile-foundation .pagetitle {
        flex-direction: column;
        align-items: stretch;
    }

    body.mobile-foundation .pagetitle .btn,
    body.mobile-foundation .pagetitle .btn-group,
    body.mobile-foundation .pagetitle .dropdown,
    body.mobile-foundation .page-toolbar,
    body.mobile-foundation .report-toolbar,
    body.mobile-foundation .filter-toolbar,
    body.mobile-foundation .actions-row {
        width: 100%;
    }

    body.mobile-foundation .page-toolbar > .btn,
    body.mobile-foundation .report-toolbar > .btn,
    body.mobile-foundation .filter-toolbar > .btn,
    body.mobile-foundation .actions-row > .btn,
    body.mobile-foundation .page-toolbar > .btn-group,
    body.mobile-foundation .report-toolbar > .btn-group,
    body.mobile-foundation .filter-toolbar > .btn-group,
    body.mobile-foundation .actions-row > .btn-group {
        width: 100%;
    }

    body.mobile-foundation .page-toolbar .btn,
    body.mobile-foundation .report-toolbar .btn,
    body.mobile-foundation .filter-toolbar .btn,
    body.mobile-foundation .actions-row .btn {
        justify-content: center;
    }

    body.mobile-foundation .header .search-form,
    body.mobile-foundation .search-container,
    body.mobile-foundation .header-nav {
        max-width: 100%;
    }
}

@media (max-width: 767.98px) {
    body.mobile-foundation #main {
        padding-top: 16px;
        padding-inline: 12px;
    }

    body.mobile-foundation .card-header,
    body.mobile-foundation .card-footer,
    body.mobile-foundation .card-body,
    body.mobile-foundation .modal-header,
    body.mobile-foundation .modal-body,
    body.mobile-foundation .modal-footer {
        padding: 12px;
    }

    body.mobile-foundation .table {
        font-size: 0.92rem;
    }

    body.mobile-foundation .table > :not(caption) > * > * {
        padding: 0.7rem 0.6rem;
        white-space: nowrap;
    }

    body.mobile-foundation .form-control,
    body.mobile-foundation .form-select,
    body.mobile-foundation .input-group-text,
    body.mobile-foundation .btn {
        min-height: 44px;
    }

    body.mobile-foundation .mobile-stack .col,
    body.mobile-foundation .mobile-stack [class*="col-"] {
        width: 100%;
        flex: 0 0 100%;
    }

    body.mobile-foundation .header-nav .dropdown-menu,
    body.mobile-foundation .dropdown-menu {
        max-width: calc(100vw - 24px);
    }

    body.mobile-foundation .modal-dialog {
        margin: 0.5rem;
    }
}

@media (max-width: 575.98px) {
    body.mobile-foundation #main {
        padding-inline: 10px;
    }

    body.mobile-foundation .pagetitle h1 {
        font-size: 1.15rem;
    }

    body.mobile-foundation .breadcrumb {
        font-size: 0.85rem;
    }

    body.mobile-foundation .btn,
    body.mobile-foundation .form-control,
    body.mobile-foundation .form-select,
    body.mobile-foundation .input-group-text {
        font-size: 0.95rem;
    }
}

html[dir="rtl"] body.mobile-foundation .breadcrumb,
html[dir="rtl"] body.mobile-foundation .pagetitle,
html[dir="rtl"] body.mobile-foundation .card-header,
html[dir="rtl"] body.mobile-foundation .modal-header {
    text-align: right;
}

html[dir="rtl"] body.mobile-foundation .page-toolbar,
html[dir="rtl"] body.mobile-foundation .report-toolbar,
html[dir="rtl"] body.mobile-foundation .filter-toolbar,
html[dir="rtl"] body.mobile-foundation .actions-row {
    justify-content: flex-start;
}


/* Patch F1 — Mobile First Foundation Hotfix
   Scope: header, sidebar overlay, report tables, stacked filters.
   Additive only. No workflow or route changes. */
@media (max-width: 1199.98px) {
    body.mobile-foundation #sidebar {
        display: block !important;
        position: fixed !important;
        top: 60px !important;
        bottom: 0 !important;
        left: 0 !important;
        right: auto !important;
        width: min(86vw, 320px) !important;
        max-width: 320px !important;
        margin: 0 !important;
        transform: translateX(-108%);
        transition: transform .24s ease, box-shadow .24s ease;
        z-index: 1040 !important;
        box-shadow: none;
        visibility: visible !important;
    }

    html[dir="rtl"] body.mobile-foundation #sidebar {
        left: auto !important;
        right: 0 !important;
        transform: translateX(108%);
    }

    body.mobile-foundation.toggle-sidebar #sidebar,
    body.mobile-foundation.sidebar-open #sidebar {
        transform: translateX(0);
        box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
    }

    body.mobile-foundation #main,
    body.mobile-foundation #footer,
    body.mobile-foundation.toggle-sidebar #main,
    body.mobile-foundation.toggle-sidebar #footer,
    body.mobile-foundation.sidebar-open #main,
    body.mobile-foundation.sidebar-open #footer {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    body.mobile-foundation .mobile-sidebar-backdrop {
        position: fixed;
        inset: 60px 0 0 0;
        background: rgba(15, 23, 42, 0.44);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
        z-index: 1035;
    }

    body.mobile-foundation.toggle-sidebar .mobile-sidebar-backdrop,
    body.mobile-foundation.sidebar-open .mobile-sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    body.mobile-foundation .header {
        min-height: 60px;
        padding-inline: 10px !important;
    }

    body.mobile-foundation .header > .d-flex.align-items-center.justify-content-between {
        flex: 0 0 auto;
        min-width: 0;
        gap: .5rem;
    }

    body.mobile-foundation .logo {
        min-width: 0;
        gap: .5rem;
    }

    body.mobile-foundation .logo span {
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.mobile-foundation .header-nav {
        min-width: 0;
    }

    body.mobile-foundation .header-nav > ul {
        gap: .25rem;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    body.mobile-foundation .header-nav .nav-link {
        padding-inline: .65rem !important;
        border-radius: 10px;
        white-space: nowrap;
    }

    body.mobile-foundation .header-nav .nav-link.nav-icon {
        gap: .35rem;
    }

    body.mobile-foundation .search-bar {
        max-width: 300px;
        margin-inline: .5rem;
    }

    body.mobile-foundation .search-bar .search-form input {
        min-width: 0;
    }
}

@media (max-width: 991.98px) {
    body.mobile-foundation .header {
        flex-wrap: wrap;
        align-items: center;
        row-gap: .6rem;
    }

    body.mobile-foundation .search-bar {
        order: 3;
        flex: 1 1 100%;
        max-width: 100%;
        width: 100%;
        margin: 0;
    }

    body.mobile-foundation .search-bar .search-form {
        width: 100%;
    }

    body.mobile-foundation .header-nav {
        margin-left: auto !important;
    }

    html[dir="rtl"] body.mobile-foundation .header-nav {
        margin-right: auto !important;
        margin-left: 0 !important;
    }

    body.mobile-foundation .header-nav > ul {
        justify-content: flex-end;
    }

    body.mobile-foundation .header-nav .nav-link.nav-icon {
        font-size: .92rem;
    }

    body.mobile-foundation .report-filter-form > [class*="col-"],
    body.mobile-foundation .report-summary-row > [class*="col-"],
    body.mobile-foundation .report-actions > * {
        width: 100%;
        flex: 0 0 100%;
    }

    body.mobile-foundation .report-actions {
        display: flex;
        flex-wrap: wrap;
        gap: .75rem;
    }

    body.mobile-foundation .report-actions .btn {
        width: 100%;
        justify-content: center;
    }

    body.mobile-foundation .report-table-wrap {
        border: 1px solid rgba(15, 23, 42, 0.08);
        border-radius: 14px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        background: #fff;
    }

    body.mobile-foundation .report-table-wrap table {
        min-width: 720px;
        margin-bottom: 0;
    }
}

@media (max-width: 767.98px) {
    body.mobile-foundation .logo span,
    body.mobile-foundation .header-nav .nav-link.nav-icon .nav-label,
    body.mobile-foundation .header-nav .nav-link.nav-icon .link-label {
        display: none !important;
    }

    body.mobile-foundation .header-nav .nav-link.nav-icon {
        min-width: 42px;
        justify-content: center;
        padding-inline: .75rem !important;
    }

    body.mobile-foundation .header-nav .badge-number {
        inset-inline-end: 0;
    }

    body.mobile-foundation .search-bar {
        display: none;
    }

    body.mobile-foundation .search-bar.search-bar-show {
        display: block;
    }

    body.mobile-foundation .report-table-wrap table {
        min-width: 640px;
    }
}

html[dir="rtl"] body.mobile-foundation .report-actions,
html[dir="rtl"] body.mobile-foundation .report-summary-row {
    justify-content: flex-start;
}
