/* apps/web/public/css/mobile-shell.css
   Native-app-style mobile shell: bottom tab bar, "More" nav sheet,
   compact app bar, bottom-sheet modals, card tables, FAB.
   Every rule is gated behind the mobile breakpoint so desktop is untouched. */

:root {
    --mobile-tabbar-height: 60px;
    --mobile-appbar-height: 56px;
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-safe-top: env(safe-area-inset-top, 0px);
}

@media (max-width: 768px) {
    /* ==========================================
       App frame: fill the real viewport height
       ========================================== */
    html,
    body {
        height: 100%;
        overscroll-behavior-y: none;
    }

    body {
        -webkit-tap-highlight-color: transparent;
    }

    .app-container,
    .app-container .main-wrapper {
        height: 100dvh;
        overflow: hidden;
    }

    .app-container .main-content {
        height: 100dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Room for the tab bar + device home indicator */
        padding-bottom: calc(var(--mobile-tabbar-height) + var(--mobile-safe-bottom) + 1rem);
    }

    /* The two-column desktop sidebar becomes an off-canvas drawer already;
       on phones it simply stays hidden behind the new shell. */
    .app-container .sidebar-shell {
        z-index: 1200;
    }

    /* ==========================================
       Compact top app bar
       ========================================== */
    .app-container .top-bar {
        position: sticky;
        top: 0;
        z-index: 900;
        min-height: var(--mobile-appbar-height);
        padding: calc(0.35rem + var(--mobile-safe-top)) 0.75rem 0.35rem;
        gap: 0.5rem;
        flex-wrap: nowrap;
        align-items: center;
        border-radius: 0;
        margin-bottom: 0.85rem;
        background: color-mix(in srgb, var(--surface-1, var(--card)) 88%, transparent);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border-bottom: 1px solid var(--border, rgba(148, 163, 184, 0.25));
    }

    /* The off-canvas drawer is replaced by the tab bar + More sheet */
    .app-container .top-bar .menu-toggle,
    .app-container .sidebar-shell,
    .app-container .sidebar-overlay {
        display: none !important;
    }

    .app-container .top-bar .page-title {
        flex: 1 1 auto;
        min-width: 0;
        order: 0;
        width: auto;
    }

    .app-container .top-bar .page-title h1 {
        font-size: 1.05rem;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-container .top-bar .page-title p {
        display: none;
    }

    .app-container .top-bar .top-actions {
        flex: 0 0 auto;
        flex-wrap: nowrap;
        gap: 0.4rem;
        align-items: center;
    }

    .app-container .top-bar .top-actions .icon-btn,
    .app-container .top-bar .notification-btn,
    .app-container .top-bar .mobile-search-toggle {
        width: 40px;
        height: 40px;
        flex: 0 0 auto;
    }

    .app-container .top-bar .mobile-search-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(148, 163, 184, 0.2);
        border-radius: 12px;
        background: var(--surface-1, var(--card));
        color: var(--text, var(--text));
        cursor: pointer;
    }

    /* Search is hidden by default; the toggle opens it as an overlay card */
    .app-container .top-bar .search-box {
        display: none;
    }

    .app-container .top-bar .search-box.mobile-visible {
        display: block;
        position: fixed;
        top: calc(var(--mobile-appbar-height) + var(--mobile-safe-top) + 6px);
        left: 0.75rem;
        right: 0.75rem;
        z-index: 980;
        width: auto;
        max-width: none;
        padding: 0.35rem;
        background: var(--surface-1, var(--card));
        border: 1px solid var(--border, rgba(148, 163, 184, 0.25));
        border-radius: 14px;
        box-shadow: 0 12px 32px rgba(2, 8, 23, 0.18);
    }

    .app-container .top-bar .search-box input {
        min-width: 0;
    }

    .app-container .top-bar .user-dropdown-btn .user-name,
    .app-container .top-bar .user-dropdown-btn .fa-chevron-down {
        display: none;
    }

    .app-container .top-bar .user-dropdown-btn {
        padding: 0.15rem;
        gap: 0;
    }

    /* Dropdowns / notification panel go full-width below the app bar */
    .app-container .top-bar .user-dropdown-menu,
    .app-container .top-bar .notification-panel,
    .app-container .top-bar .search-results-dropdown {
        position: fixed;
        top: calc(var(--mobile-appbar-height) + var(--mobile-safe-top) + 6px);
        right: 0.5rem;
        left: 0.5rem;
        width: auto;
        max-height: 60dvh;
        overflow-y: auto;
        z-index: 950;
    }

    /* Content must clear the fixed tab bar — override the legacy
       `body .main-content { padding: … !important }` rules. */
    body .app-container .main-content {
        padding: 0.75rem 0.75rem calc(var(--mobile-tabbar-height) + var(--mobile-safe-bottom) + 1rem) !important;
    }

    /* The desktop sidebar offset (`body .main-content { margin-left/width:
       calc(100vw - sidebars) }`, layout.css) beats the ≤1024px reset by
       specificity whenever body lacks .submenu-hidden — i.e. every module
       with a submenu — shrinking content to ~46px on phones. Force the
       full-width mobile layout here. */
    body .app-container .main-content,
    body.submenu-hidden .app-container .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* ==========================================
       Bottom tab bar
       ========================================== */
    .mobile-tab-bar {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1000;
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        height: calc(var(--mobile-tabbar-height) + var(--mobile-safe-bottom));
        padding-bottom: var(--mobile-safe-bottom);
        background: color-mix(in srgb, var(--surface-1, var(--card)) 94%, transparent);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--border, rgba(148, 163, 184, 0.25));
        box-shadow: 0 -4px 24px rgba(2, 8, 23, 0.06);
    }

    .mobile-tab-bar[hidden] {
        display: none;
    }

    .mobile-tab,
    [data-ui-button="true"].mobile-tab,
    [data-action-button="true"].mobile-tab {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-width: 0;
        min-height: auto;
        padding: 6px 2px 4px;
        background: none;
        border: none;
        border-radius: 0;
        font-family: inherit;
        font-size: 0.62rem;
        font-weight: 600;
        color: var(--text-light, var(--text-light));
        cursor: pointer;
        position: relative;
        box-shadow: none;
    }

    .mobile-tab i {
        font-size: 1.15rem;
        line-height: 1;
        transition: transform 0.15s ease;
    }

    .mobile-tab:active i {
        transform: scale(0.88);
    }

    .mobile-tab.active {
        color: var(--primary, var(--primary));
    }

    .mobile-tab.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        width: 32px;
        height: 3px;
        border-radius: 0 0 3px 3px;
        background: linear-gradient(135deg, var(--ds-brand-solid), #06b6d4);
        transform: translateX(-50%);
    }

    .mobile-tab .mobile-tab-badge {
        position: absolute;
        top: 4px;
        left: calc(50% + 6px);
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        border-radius: 8px;
        background: var(--danger);
        color: #ffffff;
        font-size: 0.6rem;
        font-weight: 700;
        line-height: 16px;
        text-align: center;
    }

    /* ==========================================
       "More" navigation sheet
       ========================================== */
    .mobile-sheet-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1090;
        background: rgba(2, 8, 23, 0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    .mobile-sheet-backdrop.open {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-nav-sheet {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1100;
        display: flex;
        flex-direction: column;
        max-height: 78dvh;
        background: var(--surface-1, var(--card));
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -12px 40px rgba(2, 8, 23, 0.25);
        transform: translateY(105%);
        transition: transform 0.24s ease;
        padding-bottom: var(--mobile-safe-bottom);
    }

    .mobile-nav-sheet.open {
        transform: translateY(0);
    }

    .mobile-nav-sheet .sheet-handle {
        flex: 0 0 auto;
        padding: 10px 0 6px;
        display: flex;
        justify-content: center;
        cursor: grab;
        touch-action: none;
    }

    .mobile-nav-sheet .sheet-handle::before {
        content: '';
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--border, rgba(148, 163, 184, 0.5));
    }

    .mobile-nav-sheet .sheet-title {
        flex: 0 0 auto;
        padding: 0 1.25rem 0.5rem;
        font-size: 0.95rem;
        font-weight: 700;
        color: var(--text, var(--text));
    }

    .mobile-nav-sheet .sheet-body {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 0.75rem 1rem;
    }

    .mobile-nav-group {
        margin-bottom: 0.35rem;
    }

    .mobile-nav-group > .mobile-nav-group-header {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        width: 100%;
        padding: 0.7rem 0.75rem;
        background: none;
        border: none;
        border-radius: 10px;
        font-family: inherit;
        font-size: 0.82rem;
        font-weight: 700;
        color: var(--text, var(--text));
        cursor: pointer;
        text-align: left;
    }

    .mobile-nav-group > .mobile-nav-group-header i.group-icon {
        width: 20px;
        text-align: center;
        color: var(--primary, var(--primary));
    }

    .mobile-nav-group > .mobile-nav-group-header .group-chevron {
        margin-left: auto;
        font-size: 0.7rem;
        color: var(--text-light, var(--text-light));
        transition: transform 0.18s ease;
    }

    .mobile-nav-group.expanded > .mobile-nav-group-header .group-chevron {
        transform: rotate(180deg);
    }

    .mobile-nav-group .mobile-nav-items {
        display: none;
        padding: 0 0.25rem 0.35rem 1.6rem;
    }

    .mobile-nav-group.expanded .mobile-nav-items {
        display: block;
    }

    .mobile-nav-item {
        display: flex;
        align-items: center;
        width: 100%;
        padding: 0.68rem 0.75rem;
        background: none;
        border: none;
        border-radius: 10px;
        font-family: inherit;
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text, var(--text));
        cursor: pointer;
        text-align: left;
    }

    .mobile-nav-item:active {
        background: var(--hover-bg, rgba(91, 75, 245,  0.1));
    }

    .mobile-nav-item.active {
        background: var(--hover-bg, rgba(91, 75, 245,  0.1));
        color: var(--primary, var(--primary));
    }

    .mobile-nav-item i {
        margin-left: auto;
        font-size: 0.7rem;
        color: var(--text-light, var(--text-light));
    }

    /* ==========================================
       Modals become bottom sheets
       ========================================== */
    /* Dialogs must cover the tab bar (1000), FAB (1005) and nav
       sheet (1100) — legacy overlays sit at z-index 100. */
    .modal-overlay,
    .wizard-modal-overlay,
    .app-container .module-section .modal:not(.modal-overlay .modal) {
        z-index: 1300 !important;
    }

    .modal-overlay,
    .wizard-modal-overlay {
        align-items: flex-end;
        justify-content: center;
        padding: 0;
    }

    .modal-overlay .modal,
    .modal-overlay .modal-box,
    .modal-overlay .modal-content,
    .wizard-modal-overlay .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 88dvh;
        margin: 0;
        border-radius: 18px 18px 0 0;
        border-right: none;
        border-bottom: none;
        border-left: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: var(--mobile-safe-bottom);
        animation: mobile-sheet-up 0.22s ease;
    }

    @keyframes mobile-sheet-up {
        from {
            transform: translateY(24px);
            opacity: 0.6;
        }

        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    .modal-overlay .modal-header,
    .wizard-modal-overlay .modal-header {
        position: sticky;
        top: 0;
        z-index: 2;
        background: inherit;
    }

    /* Footer actions: wrap, primary action full-width first when crowded */
    .modal-overlay .modal-footer,
    .wizard-modal-overlay .modal-footer,
    .app-container .module-section .modal:not(.modal-overlay .modal) .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-overlay .modal-footer .btn,
    .wizard-modal-overlay .modal-footer .btn {
        flex: 1 1 40%;
    }

    .modal-overlay .modal-footer .btn:only-child {
        flex-basis: 100%;
    }

    .modal-overlay .modal-footer:has(.btn:nth-child(3)) .btn-primary,
    .wizard-modal-overlay .modal-footer:has(.btn:nth-child(3)) .btn-primary {
        order: -1;
        flex-basis: 100%;
    }

    /* Two-column form rows collapse inside dialogs */
    .modal-overlay .form-row,
    .modal-overlay .invite-grid,
    .wizard-modal-overlay .form-row,
    .app-container .module-section .modal:not(.modal-overlay .modal) .form-row {
        grid-template-columns: 1fr !important;
    }

    /* FAB source buttons are replaced by the floating action button */
    .app-container [data-mobile-fab] {
        display: none !important;
    }

    /* Dynamically-created inline overlays (settings.js invite modal,
       settings widget setup) become bottom sheets too */
    #inviteUserModal,
    #widgetSetupModal {
        padding: 0 !important;
        align-items: flex-end !important;
    }

    #inviteUserModal > div,
    #widgetSetupModal > div {
        max-width: 100% !important;
        max-height: 92dvh !important;
        border-radius: 18px 18px 0 0 !important;
    }

    #inviteUserModal div[style*="grid-template-columns"],
    #widgetSetupModal div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* ==========================================
       Tables become stacked cards
       (JS injects data-label on each td)
       ========================================== */
    .mobile-card-table {
        width: 100% !important;
        min-width: 0 !important;
    }

    .mobile-card-table thead {
        display: none;
    }

    .mobile-card-table,
    .mobile-card-table tbody,
    .mobile-card-table tr,
    .mobile-card-table td {
        display: block;
    }

    .mobile-card-table tbody {
        padding: 0.25rem 0;
    }

    .mobile-card-table tr {
        background: var(--card, var(--card));
        border: 1px solid var(--border, rgba(148, 163, 184, 0.25));
        border-radius: 12px;
        margin: 0 0 0.65rem;
        padding: 0.65rem 0.85rem;
        box-shadow: 0 1px 4px rgba(2, 8, 23, 0.05);
    }

    .mobile-card-table td {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.3rem 0;
        border: none;
        font-size: 0.85rem;
        text-align: right;
    }

    .mobile-card-table td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        font-size: 0.72rem;
        font-weight: 700;
        letter-spacing: 0.03em;
        text-transform: uppercase;
        color: var(--text-light, var(--text-light));
        text-align: left;
    }

    .mobile-card-table td[data-label=""]::before,
    .mobile-card-table td.mobile-card-actions::before {
        content: none;
    }

    .mobile-card-table td.mobile-card-actions {
        justify-content: flex-end;
        padding-top: 0.5rem;
    }

    /* ==========================================
       Floating action button
       ========================================== */
    .mobile-fab {
        position: fixed;
        right: 1rem;
        bottom: calc(var(--mobile-tabbar-height) + var(--mobile-safe-bottom) + 0.9rem);
        z-index: 1005;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 56px;
        height: 56px;
        min-width: 56px;
        padding: 0;
        border: none;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--ds-brand-solid), #06b6d4);
        color: #ffffff;
        font-family: inherit;
        font-size: 1.25rem;
        font-weight: 700;
        box-shadow: 0 8px 24px rgba(91, 75, 245,  0.4);
        cursor: pointer;
        transition: transform 0.15s ease;
    }

    .mobile-fab:active {
        transform: scale(0.94);
    }

    .mobile-fab[hidden] {
        display: none;
    }

    /* ==========================================
       Tab-level speed-dial sheet
       ========================================== */
    .mobile-speed-dial-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1006;
        background: transparent;
        opacity: 0;
        pointer-events: none;
    }

    .mobile-speed-dial-backdrop.open {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-speed-dial-sheet {
        position: fixed;
        right: 1rem;
        bottom: calc(var(--mobile-tabbar-height) + var(--mobile-safe-bottom) + 4rem);
        z-index: 1007;
        display: none;
        flex-direction: column;
        min-width: 180px;
        max-width: calc(100vw - 2rem);
        padding: 0.5rem;
        background: var(--surface-1, var(--card));
        border: 1px solid var(--border, rgba(148, 163, 184, 0.25));
        border-radius: 16px;
        box-shadow: 0 12px 32px rgba(2, 8, 23, 0.18);
    }

    .mobile-speed-dial-sheet.open {
        display: flex;
        animation: mobile-speed-dial-up 0.15s ease-out;
    }

    @keyframes mobile-speed-dial-up {
        from {
            opacity: 0;
            transform: translateY(8px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .mobile-speed-dial-item {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
        padding: 0.65rem 0.75rem;
        border: none;
        border-radius: 12px;
        background: none;
        font-family: inherit;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text, var(--text));
        text-align: left;
        cursor: pointer;
    }

    .mobile-speed-dial-item:active {
        background: var(--bg-light, var(--surface-2));
    }

    .mobile-speed-dial-icon {
        flex: none;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border-radius: 10px;
        background: linear-gradient(135deg, var(--ds-brand-solid), #06b6d4);
        color: #ffffff;
        font-size: 0.8rem;
    }

    body.dark .mobile-speed-dial-sheet {
        background: #1e293b;
        border-color: #334155;
    }

    body.dark .mobile-speed-dial-item {
        color: var(--text);
    }

    body.dark .mobile-speed-dial-item:active {
        background: #273449;
    }

    /* ==========================================
       Shared mobile card building blocks
       (used by polished modules; available to all)
       ========================================== */
    .mobile-stat-card {
        display: flex;
        align-items: center;
        gap: 0.85rem;
        padding: 0.95rem 1rem;
        background: var(--card, var(--card));
        border: 1px solid var(--border, rgba(148, 163, 184, 0.25));
        border-radius: 14px;
        box-shadow: 0 1px 6px rgba(2, 8, 23, 0.05);
        margin-bottom: 0.75rem;
    }

    .mobile-stat-card .stat-icon {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        border-radius: 12px;
        background: linear-gradient(135deg, rgba(91, 75, 245,  0.12), rgba(6, 182, 212, 0.12));
        color: var(--primary, var(--primary));
        font-size: 1.1rem;
    }

    .mobile-stat-card .stat-body {
        flex: 1 1 auto;
        min-width: 0;
    }

    .mobile-stat-card .stat-label {
        font-size: 0.78rem;
        font-weight: 700;
        color: var(--text, var(--text));
    }

    .mobile-stat-card .stat-sub {
        font-size: 0.7rem;
        color: var(--text-light, var(--text-light));
    }

    .mobile-stat-card .stat-value {
        font-size: 1.15rem;
        font-weight: 800;
        color: var(--text, var(--text));
        text-align: right;
    }

    .mobile-stat-card .stat-value small {
        display: block;
        font-size: 0.65rem;
        font-weight: 600;
        color: var(--text-light, var(--text-light));
    }

    .mobile-progress {
        height: 6px;
        border-radius: 3px;
        background: var(--surface-3, #dde7fb);
        overflow: hidden;
    }

    .mobile-progress > span {
        display: block;
        height: 100%;
        border-radius: 3px;
        background: linear-gradient(90deg, var(--ds-brand-solid), #06b6d4);
    }

    /* ==========================================
       Touch ergonomics
       ========================================== */
    .app-container .btn,
    .app-container button,
    .app-container select,
    .app-container input[type="checkbox"],
    .app-container input[type="radio"] {
        min-height: 40px;
    }

    .app-container input[type="text"],
    .app-container input[type="email"],
    .app-container input[type="password"],
    .app-container input[type="number"],
    .app-container input[type="date"],
    .app-container input[type="tel"],
    .app-container input[type="search"],
    .app-container select,
    .app-container textarea {
        font-size: 16px; /* prevents iOS auto-zoom on focus */
    }

    .app-container .module-section {
        padding-right: 0.75rem;
        padding-left: 0.75rem;
    }
}

/* ==========================================
   Mobile shell element visibility
   (elements exist in DOM at all sizes; only
   shown on phones — desktop never sees them)
   ========================================== */
.mobile-tab-bar,
.mobile-nav-sheet,
.mobile-sheet-backdrop,
.mobile-fab,
.mobile-search-toggle {
    display: none;
}

@media (max-width: 768px) {
    .mobile-tab-bar {
        display: flex;
    }

    .mobile-nav-sheet,
    .mobile-sheet-backdrop {
        display: flex;
    }

    .mobile-sheet-backdrop {
        display: block;
    }

    .mobile-fab {
        display: inline-flex;
    }

    /* ==========================================
       Module switch transition
       ========================================== */
    .app-container .module-section.active {
        animation: mobile-module-in 0.18s ease;
    }

    @keyframes mobile-module-in {
        from {
            opacity: 0;
            transform: translateY(8px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* ==========================================
       Pull-to-refresh indicator
       ========================================== */
    .mobile-ptr-indicator {
        position: fixed;
        top: calc(var(--mobile-appbar-height) + var(--mobile-safe-top) + 8px);
        left: 50%;
        z-index: 960;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        background: var(--surface-1, var(--card));
        border: 1px solid var(--border, rgba(148, 163, 184, 0.25));
        box-shadow: 0 4px 14px rgba(2, 8, 23, 0.14);
        color: var(--primary, var(--primary));
        opacity: 0;
        transform: translateX(-50%) translateY(-12px) scale(0.8);
        transition: opacity 0.15s ease, transform 0.15s ease;
        pointer-events: none;
    }

    .mobile-ptr-indicator.visible {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }

    .mobile-ptr-indicator.spinning i {
        animation: mobile-ptr-spin 0.8s linear infinite;
    }

    @keyframes mobile-ptr-spin {
        to {
            transform: rotate(360deg);
        }
    }

    /* ==========================================
       Skeleton loading blocks (shared)
       ========================================== */
    .mobile-skeleton {
        border-radius: 12px;
        background: linear-gradient(
            90deg,
            var(--surface-2, #f4f7fb) 25%,
            var(--surface-3, #dde7fb) 50%,
            var(--surface-2, #f4f7fb) 75%
        );
        background-size: 200% 100%;
        animation: mobile-skeleton-shimmer 1.4s ease infinite;
    }

    @keyframes mobile-skeleton-shimmer {
        from {
            background-position: 200% 0;
        }

        to {
            background-position: -200% 0;
        }
    }

    /* ==========================================
       Generic module patterns — apply to every
       module so un-audited screens still behave
       ========================================== */

    /* Stat grids: two-up compact cards */
    .app-container .module-section .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    .app-container .module-section .dashboard-grid .stat-card {
        padding: 0.625rem 0.65rem;
        border-radius: 12px;
    }

    .app-container .module-section .dashboard-grid .stat-header {
        gap: 0.4rem;
    }

    .app-container .module-section .dashboard-grid .stat-value {
        font-size: 1rem;
    }

    .app-container .module-section .dashboard-grid .stat-label {
        font-size: 0.65rem;
        margin-top: 0.15rem;
    }

    .app-container .module-section .dashboard-grid .stat-icon {
        width: 1.75rem;
        height: 1.75rem;
        font-size: 0.8rem;
    }

    /* Card headers: stack title above full-width actions/filters */
    .app-container .module-section .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
    }

    .app-container .module-section .card-header .form-input,
    .app-container .module-section .card-header .form-select {
        width: 100% !important;
    }

    .app-container .module-section .card-header > div:not(.meeting-tabs, .platform-tabs, .finance-tabs, .invoice-tabs, .recruitment-tabs, .messaging-tabs, .poll-detail-tabs, .detail-main-tabs) {
        flex-wrap: wrap;
    }

    /* Tab strips: single scrollable row */
    .app-container .module-section .meeting-tabs,
    .app-container .module-section .platform-tabs,
    .app-container .module-section .finance-tabs,
    .app-container .module-section .invoice-tabs,
    .app-container .module-section .recruitment-tabs,
    .app-container .module-section .messaging-tabs,
    .app-container .module-section .poll-detail-tabs,
    .app-container .module-section .detail-main-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .app-container .module-section .meeting-tab,
    .app-container .module-section .tab-btn,
    .app-container .module-section .finance-tab,
    .app-container .module-section .invoice-tab,
    .app-container .module-section .recruitment-tab,
    .app-container .module-section .messaging-tab,
    .app-container .module-section .poll-detail-tab,
    .app-container .module-section .detail-main-tab-btn {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    /* Finance has exactly four tabs: show them all as a 2x2 grid
       instead of a clipped horizontal scroll row. The strip sits
       inside a padding-less card-header, so drop its bottom margin. */
    .app-container .module-section .finance-tabs {
        flex-wrap: wrap;
        overflow-x: visible;
        margin-bottom: 0;
    }

    .app-container .module-section .finance-tab {
        flex: 1 1 calc(50% - 0.5rem);
        justify-content: center;
    }

    /* Finance page-header only holds "New Transaction", which becomes
       the FAB on mobile — hide the empty bar it leaves behind. */
    .app-container .module-section#finance .page-header {
        display: none;
    }

    /* Page headers with title + actions: stack */
    .app-container .module-section .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
    }

    /* Modules whose dialogs use class="modal" as the overlay
       (meetings, polls, finance, policies, people, ...) get the
       bottom-sheet treatment too. Cards inside .modal-overlay are
       already handled above and must be excluded here. */
    .app-container .module-section .modal:not(.modal-overlay .modal) {
        align-items: flex-end;
        padding: 0;
    }

    .app-container .module-section .modal:not(.modal-overlay .modal) > .modal-content,
    .app-container .module-section .modal:not(.modal-overlay .modal) > .modal-box {
        width: 100%;
        max-width: 100% !important;
        max-height: 92dvh;
        margin: 0;
        border-radius: 18px 18px 0 0;
    }

    .app-container .module-section .modal:not(.modal-overlay .modal) .modal-footer {
        flex-wrap: wrap;
    }

    .app-container .module-section .modal:not(.modal-overlay .modal) .modal-footer .btn {
        flex: 1 1 44%;
    }

    /* Neutralize inline desktop layouts that break on phones:
       multi-column grids collapse to one column, fixed widths clamp */
    .app-container .module-section div[style*="grid-template-columns"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    /* …except stat grids, which stay two-up */
    .app-container .module-section div[style*="grid-template-columns"].dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .app-container .module-section [style*="width:"],
    .app-container .module-section [style*="min-width:"] {
        max-width: 100%;
    }

    .app-container .module-section [style*="min-width"] {
        min-width: 0 !important;
    }
}

/* ==========================================
   Phone compaction (≤640px): shrink the shell's
   own gutters and card paddings. The ≤768px rules
   above use .app-container selectors, so these keep
   the same specificity and win by source order.
   Tab bar is left alone — its 60px height and
   touch targets are already at the minimum.
   ========================================== */
@media (max-width: 640px) {
    body .app-container .main-content {
        padding: 0.6rem 0.6rem calc(var(--mobile-tabbar-height) + var(--mobile-safe-bottom) + 0.75rem) !important;
    }

    .app-container .top-bar {
        margin-bottom: 0.6rem;
    }

    .app-container .module-section {
        padding-right: 0.6rem;
        padding-left: 0.6rem;
    }

    .mobile-stat-card {
        padding: 0.7rem 0.75rem;
    }

    .mobile-card-table tr {
        padding: 0.5rem 0.65rem;
    }

    .mobile-card-table td {
        padding: 0.25rem 0;
    }
}
