.pwa-install[hidden], .pwa-help[hidden] { display: none !important; }
.pwa-install { touch-action: manipulation; }
.mobile-table-pager { display: none; }

@media screen and (max-width: 991.98px) {
    body.mobile-nav-open { overflow: hidden; }
    .app-shell {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    .content, .content.with-mini { min-width: 0; transition: none; }
    .sidebar {
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
        bottom: max(8px, env(safe-area-inset-bottom));
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        visibility: hidden;
    }
    .sidebar.mobile-open { visibility: visible; }
    .sidebar ul li a, .sidebar-logout { min-height: 44px; }
    .mobile-menu-close { flex: 0 0 44px; min-height: 44px; margin-inline-start: auto; }
}

@media screen and (max-width: 767.98px) {
    .top-navbar { border-radius: 16px; padding: .25rem .45rem; }
    .topbar-shell, .topbar-left, .topbar-right { flex-wrap: nowrap; gap: .45rem; min-width: 0; }
    .topbar-left { flex: 1 1 auto; }
    .topbar-titles { min-width: 0; }
    .page-title { line-height: 1.35; overflow-wrap: anywhere; }
    .topbar-chip, .topbar-right .user-meta, .user-chip.dropdown-toggle::after { display: none; }
    .topbar-toggler, .user-chip { min-width: 44px; min-height: 44px; justify-content: center; flex-shrink: 0; }
    .user-chip { padding: .15rem; }
    .user-avatar { width: 34px; height: 34px; }

    .page-container { padding: 6px 0 10px; }
    .page-surface { padding: 8px; border-radius: 17px; min-width: 0; min-height: calc(100svh - 100px); }
    .page-surface > .container-fluid, .page-surface > .container { padding-inline: 2px; }
    .page-surface :is(h3, h4) { font-size: 1.18rem; line-height: 1.4; }
    .page-surface :is(.card, .metric-card, .info-card, .accounting-card, .alert) { border-radius: 16px !important; }
    .page-surface :is(.row > *, .card-body, .input-group, fieldset, .filter-bar) { min-width: 0; }
    .page-surface > :is(.container, .container-fluid) > .d-flex.justify-content-between { flex-wrap: wrap; gap: .5rem; }
    .page-surface :is(.form-control, .form-select), .modal :is(.form-control, .form-select) {
        min-height: 44px;
        font-size: 1rem;
        max-width: 100%;
    }
    .page-surface .btn, .modal .btn, .dropdown-item { min-height: 44px; }
    .page-surface .btn, .modal .btn { padding: .45rem .75rem; touch-action: manipulation; }
    .page-surface .btn-sm { min-width: 44px; }
    .page-surface .badge { padding: .4rem .6rem; }
    .page-surface .settings-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .3rem; }
    .page-surface .settings-nav .nav-link { margin: 0; min-height: 44px; padding: .45rem .55rem; font-size: .88rem; }
    .page-surface .nav-tabs { gap: .15rem; }
    .page-surface .nav-tabs .nav-link { padding: .5rem .65rem; min-height: 44px; }
    .modal-dialog { margin: max(8px, env(safe-area-inset-top)) 8px; }
    .modal-content { border-radius: 16px; }
    .modal-title { font-size: 1.05rem; }

    .mobile-records-wrapper { overflow: visible; max-height: none; }
    .mobile-table-pager:not([hidden]) {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: .4rem;
        margin-bottom: .45rem;
        padding: .3rem;
        border: 1px solid var(--line);
        border-radius: 12px;
        background: #fff;
        font-size: .85rem;
    }
    .page-surface :is(.card, .info-card):has(.mobile-records) { overflow: visible; }
    .page-surface table.mobile-records { display: block; width: 100%; min-width: 0 !important; white-space: normal !important; }
    .mobile-records > thead { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .mobile-records > tbody, .mobile-records > tfoot { display: grid; gap: .45rem; width: 100%; }
    .mobile-records > tfoot { margin-top: .45rem; }
    .mobile-records > :is(tbody, tfoot) > tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .35rem .65rem;
        padding: .55rem .7rem;
        border: 1px solid var(--line);
        border-radius: 14px;
        background: rgba(255, 255, 255, .8);
    }
    .mobile-records.mobile-paged > tbody > tr:not([data-mobile-visible]) { display: none; }
    .mobile-records > :is(tbody, tfoot) > tr > td {
        display: block;
        min-width: 0;
        width: auto !important;
        padding: 0 !important;
        border: 0;
        background: none;
        box-shadow: none;
        text-align: start !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
        font-size: .92rem;
    }
    .mobile-records > :is(tbody, tfoot) > tr > td.num-ltr { text-align: right !important; }
    .mobile-records td[data-mobile-label]:not([data-mobile-label=""])::before {
        content: attr(data-mobile-label);
        display: block;
        direction: rtl;
        color: var(--ink-600);
        font-weight: 700;
        font-size: .76rem;
        margin-bottom: .08rem;
    }
    .mobile-records td[data-mobile-wide] { grid-column: 1 / -1; }
    .mobile-records > :is(tbody, tfoot) > tr > td[data-mobile-empty] { display: none; }
    .mobile-records td[data-mobile-wide] :is(.btn-group, .d-inline-flex) { flex-wrap: wrap; }
    .mobile-records td[data-mobile-wide] .btn { margin-block: .1rem; }

    .mobile-work-page { padding-block: .5rem !important; }
    .mobile-work-page .mobile-compact-panel, .mobile-work-page .mobile-compact-metrics { margin-bottom: .75rem !important; }
    .mobile-work-page .mobile-compact-panel > .card-body,
    .mobile-payment-form :is(.card-body, .payment-summary) { padding: .7rem !important; }
    .mobile-work-page .mobile-compact-metrics,
    .mobile-work-page .mobile-compact-fields { --bs-gutter-x: .5rem; --bs-gutter-y: .5rem; }
    .mobile-compact-metrics > *,
    .mobile-compact-fields > :not(.mobile-field-wide, .mobile-filter-actions) { flex: 0 0 auto; width: 50%; }
    .mobile-compact-fields > :is(.mobile-field-wide, .mobile-filter-actions) { flex: 0 0 auto; width: 100%; }
    .mobile-compact-fields .form-label { margin-bottom: .2rem; }
    .mobile-compact-fields .mobile-filter-actions { flex-wrap: wrap; }
    .mobile-filter-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: .5rem;
        min-height: 44px;
        padding: .45rem .7rem;
        font-weight: 700;
        cursor: pointer;
        list-style: none;
    }
    .mobile-filter-toggle::-webkit-details-marker { display: none; }
    .mobile-filter-toggle::after {
        content: "";
        flex: 0 0 .45rem;
        height: .45rem;
        border: solid currentColor;
        border-width: 0 .12rem .12rem 0;
        transform: rotate(45deg);
    }
    details[open] > .mobile-filter-toggle::after { transform: rotate(225deg); }
    details[open] > .mobile-filter-toggle { border-bottom: 1px solid var(--line); }
    .mobile-compact-metrics .kpi-card { height: 100%; padding: .5rem .6rem; }
    .mobile-compact-metrics .kpi-value { font-size: 1.13rem; overflow-wrap: anywhere; }
    .mobile-payment-form .payment-actions-rule { margin-block: .75rem !important; }
    .mobile-payment-form .payment-actions { gap: .4rem !important; }
    .mobile-payment-form .payment-actions > button { width: 100%; }

    .page-surface .mobile-list-surface { background: none; box-shadow: none !important; }
    .mobile-records:is(.mobile-invoices, .mobile-receipts) > tbody > tr {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: .3rem .55rem;
        background: #fff;
    }
    .mobile-records:is(.mobile-invoices, .mobile-receipts) .record-name {
        grid-area: 1 / 1 / 2 / 3;
        min-width: 0;
        line-height: 1.35;
        font-size: 1rem;
    }
    .record-meta { color: var(--ink-600); font-size: .8rem; font-weight: 500; }
    .mobile-records:is(.mobile-invoices, .mobile-receipts) td:is(.record-name, .record-status, .record-actions)::before { content: none; }
    .mobile-invoices .record-status { grid-area: 1 / 3; justify-self: end; }
    .mobile-invoices .record-status .badge { max-width: 100%; white-space: normal; }
    .mobile-invoices .record-number { grid-area: 2 / 1 / 3 / 3; }
    .mobile-invoices .record-period { grid-area: 2 / 3; }
    .mobile-invoices .record-total { grid-area: 3 / 1; }
    .mobile-invoices .record-paid { grid-area: 3 / 2; }
    .mobile-invoices .record-balance { grid-area: 3 / 3; }
    .mobile-invoices .record-actions { grid-area: 4 / 1 / 5 / 4; }
    .mobile-invoices > tfoot { display: none; }
    .mobile-receipts .record-total { grid-area: 1 / 3; }
    .mobile-receipts .record-period { grid-area: 2 / 1; }
    .mobile-receipts .record-method { grid-area: 2 / 2; }
    .mobile-receipts .record-method .badge { white-space: normal; }
    .mobile-receipts .record-receipt { grid-area: 2 / 3; }
    .mobile-receipts .record-number { grid-area: 3 / 1; }
    .mobile-receipts .record-reference { grid-area: 3 / 2; max-width: none !important; }
    .mobile-receipts .record-user { grid-area: 3 / 3; }
    .mobile-records.mobile-receipts > tbody > tr > td.record-zone { display: none; }
    .mobile-receipts .record-actions { grid-area: 4 / 1 / 5 / 4; }

    .mobile-reading-page .reading-tools { padding: .55rem !important; }
    .mobile-reading-page .reading-excel-form { flex-wrap: nowrap; flex-basis: 100%; }
    .mobile-reading-page .reading-excel-file { flex: 1 1 0; }
    .mobile-reading-page .reading-excel-form .btn { width: auto !important; }
    .mobile-reading-page .reading-excel-form button { white-space: normal; max-width: 44%; }
    .mobile-reading-page .reading-tools-fields { width: 100%; }
    .mobile-reading-page .reading-search { flex: 0 0 100%; min-width: 0; }
    .mobile-reading-page .reading-search .input-group-text { padding-inline: .5rem; }
    .mobile-reading-page .reading-search input { min-width: 0; }
    .mobile-reading-page .reading-search button { min-width: 44px; }
    .mobile-reading-page .mobile-reading-list { margin-bottom: .6rem !important; overflow: visible; }
    .mobile-reading-page .reading-tools + .table-responsive { overflow: visible; }
    .reading-grid { display: block; width: 100%; min-width: 0 !important; }
    .reading-grid thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    .reading-grid tbody { display: grid; gap: .45rem; }
    .reading-grid tbody > tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
        gap: .3rem .6rem;
        padding: .55rem .7rem;
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 14px;
    }
    .reading-grid tbody > tr > td {
        display: block;
        background: none !important;
        box-shadow: none;
        border: 0;
        padding: 0;
        min-width: 0;
        text-align: start !important;
        overflow-wrap: anywhere;
    }
    .reading-grid tbody > tr > td.reading-code { display: none; }
    .reading-grid :is(.cell-subscriber, td[colspan]) { grid-column: 1 / -1; }
    .reading-grid .sub-name { font-size: 1rem; font-weight: 800; line-height: 1.35; }
    .reading-grid .sub-code { color: var(--ink-600); font-size: .8rem; }
    .reading-grid td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-block-end: .15rem;
        color: var(--ink-600);
        font-size: .78rem;
        font-weight: 700;
    }
    .reading-grid .reading-value {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 44px;
        background: #f4f7f6;
        border-radius: .5rem;
        font-weight: 700;
    }
    .reading-grid .current-index-input { scroll-margin-block: .75rem; }
    .mobile-reading-page .sticky-footer { position: static; padding: .5rem; }
    .mobile-reading-page .sticky-footer .footer-actions { flex-wrap: wrap; }
    .mobile-reading-page .sticky-footer .footer-actions .btn { flex: 1 1 8rem; width: auto; }
}

.reading-search { min-width: 260px; max-width: 720px; }
