/* ============================================================
   mobile-shell.css
   Phone / small-tablet shell: compact header, WhatsApp-style
   bottom tab bar and the "More" bottom sheet.

   Breakpoint (max-width: 991.98px) matches MainLayout.razor and
   wwwroot/js/mobile-shell.js. Overrides are prefixed with
   `.app-container` so they beat the inline <style> in MainLayout
   (which is emitted later in the document).
   ============================================================ */

/* ── Desktop: none of the mobile chrome is visible ───────── */
.m-back,
.m-brand,
.m-title,
.m-bottom-nav,
.m-sheet,
.m-scrim {
    display: none;
}

html.m-scroll-lock,
body.m-scroll-lock {
    overflow: hidden !important;
    touch-action: none;
}

@media (max-width: 991.98px) {

    /* ── Header ─────────────────────────────────────────── */
    .app-container .sidebar,
    .app-container .sidebar-overlay,
    .app-container .sidebar-toggle,
    .app-container .navbar-brand-section,
    .app-container .navbar-right,
    .app-container .main-footer {
        display: none !important;
    }

    .app-container .top-navbar {
        padding: 0 8px 0 12px;
    }

    .app-container .navbar-left {
        flex: 1 1 auto;
        gap: 10px;
        overflow: hidden;
    }

    .app-container .m-back,
    .app-container .m-brand {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        flex-shrink: 0;
        border: 0;
        border-radius: 50%;
        background: transparent;
        color: #fff;
        font-size: 1.05rem;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .app-container .m-back:active {
        background: rgba(255, 255, 255, 0.2);
    }

    .app-container .m-brand {
        cursor: default;
        opacity: 0.9;
    }

    .app-container .m-title {
        display: block;
        min-width: 0;
        color: #fff;
        font-size: 1.1rem;
        font-weight: 600;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-container .m-title::before {
        content: var(--page-title, "PCFMS");
    }

    .app-container .top-navbar .global-search-wrapper {
        flex: 0 0 auto;
    }

    /* ── Page area leaves room for the tab bar ──────────── */
    .app-container .main-content {
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    }

    /* ── Bottom tab bar ─────────────────────────────────── */
    .m-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        /* Under the top navbar (1000) and Radzen dialog masks (1001+), so dialogs
           and page modals still cover it. */
        z-index: 990;
        display: flex;
        align-items: stretch;
        background: #fff;
        border-top: 1px solid #e2e8f0;
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.06);
    }

    .m-tab {
        flex: 1 1 0;
        min-width: 0;
        min-height: 48px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        padding: 0;
        border: 0;
        background: none;
        color: #64748b;
        font: inherit;
        font-size: 11px;
        font-weight: 500;
        line-height: 1.1;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .m-tab:hover {
        color: #64748b;
        text-decoration: none;
    }

    .m-tab-ico {
        position: relative;
        width: 56px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 15px;
        font-size: 17px;
        transition: background 0.2s ease, color 0.2s ease;
    }

    .m-tab:active .m-tab-ico {
        background: #eef2f7;
    }

    .m-tab-label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .m-tab.active {
        color: #1e293b;
        font-weight: 700;
    }

    .m-tab.active .m-tab-ico {
        background: #d8ebc4;
        color: #2d5016;
    }

    .m-tab-badge {
        position: absolute;
        top: -3px;
        right: 5px;
        min-width: 18px;
        height: 18px;
        padding: 0 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2px solid #fff;
        border-radius: 9px;
        background: #16a34a;
        color: #fff;
        font-size: 10.5px;
        font-weight: 700;
        line-height: 1;
    }

    /* ── "More" bottom sheet ────────────────────────────── */
    .m-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1190;
        background: rgba(15, 23, 42, 0.45);
        animation: mFade 0.2s ease;
    }

    .m-sheet {
        display: flex;
        flex-direction: column;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1200;
        /* Fixed floor so the sheet doesn't jump in height when drilling into a short group */
        min-height: min(52vh, 460px);
        max-height: 88vh;
        max-height: 88dvh;
        /* On wide tablets keep it a centred card instead of edge to edge (auto margins centre it) */
        max-width: 560px;
        margin: 0 auto;
        background: #fff;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.2);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        animation: mUp 0.25s ease;
    }

    @keyframes mFade {
        from { opacity: 0; }
        to   { opacity: 1; }
    }

    @keyframes mUp {
        from { transform: translateY(40px); opacity: 0; }
        to   { transform: translateY(0); opacity: 1; }
    }

    .m-grip {
        flex-shrink: 0;
        width: 38px;
        height: 4px;
        margin: 8px auto 4px;
        border-radius: 2px;
        background: #cbd5e1;
    }

    .m-sheet-head {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 6px 14px 10px 18px;
    }

    .m-avatar {
        width: 40px;
        height: 40px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background: #d8ebc4;
        color: #2d5016;
        font-size: 0.9rem;
        font-weight: 700;
    }

    .m-who {
        min-width: 0;
        flex: 1;
        display: flex;
        flex-direction: column;
        line-height: 1.25;
    }

    .m-who strong {
        font-size: 0.95rem;
        color: #0f172a;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .m-who span {
        font-size: 0.75rem;
        color: #64748b;
    }

    .m-icon-btn {
        width: 40px;
        height: 40px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: 50%;
        background: transparent;
        color: #475569;
        font-size: 1rem;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .m-icon-btn:active {
        background: #eef2f7;
    }

    .m-sheet-title {
        flex: 1;
        min-width: 0;
        font-size: 1rem;
        font-weight: 700;
        color: #0f172a;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .m-sheet-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 8px;
    }

    .m-search {
        position: relative;
        margin: 0 14px 12px;
    }

    .m-search i {
        position: absolute;
        left: 14px;
        top: 50%;
        transform: translateY(-50%);
        color: #94a3b8;
        font-size: 0.85rem;
        pointer-events: none;
    }

    .m-search input {
        width: 100%;
        height: 42px;
        padding: 0 14px 0 38px;
        border: 1px solid #e2e8f0;
        border-radius: 21px;
        background: #f8fafc;
        color: #0f172a;
        /* 16px stops iOS Safari zooming the page when the field is focused */
        font-size: 16px;
        outline: none;
    }

    .m-search input:focus {
        border-color: #4a7c23;
        background: #fff;
    }

    /* Tiles: top-level menu groups */
    .m-tiles {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        padding: 0 14px 10px;
    }

    .m-tiles .m-tile,
    .m-tiles .nav-item {
        min-height: 84px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 10px 4px;
        border: 0;
        border-left: 0;
        border-radius: 14px;
        background: #f1f5f9;
        color: #1e293b;
        font: inherit;
        font-size: 12px;
        font-weight: 500;
        line-height: 1.25;
        text-align: center;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .m-tiles .m-tile:active,
    .m-tiles .nav-item:active,
    .m-tiles .nav-item:hover {
        background: #e4ecda;
        color: #1e293b;
        border-left-color: transparent;
    }

    .m-tiles .m-tile > i,
    .m-tiles .nav-item > i {
        min-width: 0;
        font-size: 22px;
        color: #4a7c23;
        opacity: 1;
    }

    .m-tiles .nav-text,
    .m-tiles .m-tile span {
        white-space: normal;
        overflow-wrap: anywhere;
        font-weight: 500;
    }

    .m-tiles .nav-item .fa-external-link-alt,
    .m-tiles .nav-item .spinner-border {
        display: none;
    }

    .m-tiles .nav-badge {
        margin: 0;
    }

    /* Rows: children inside a drilled-in group, and search results */
    .m-list {
        padding: 0 6px;
    }

    .m-list .m-row,
    .m-list .nav-item {
        width: 100%;
        min-height: 50px;
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 12px 14px;
        border: 0;
        border-left: 0;
        border-bottom: 1px solid #f1f5f9;
        border-radius: 0;
        background: transparent;
        color: #1e293b;
        font: inherit;
        font-size: 0.95rem;
        text-align: left;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .m-list .m-row:active,
    .m-list .nav-item:active,
    .m-list .nav-item:hover {
        background: #f1f5f9;
        color: #1e293b;
        border-left-color: transparent;
    }

    .m-list .m-row > i:first-child,
    .m-list .nav-item > i:first-child {
        width: 22px;
        min-width: 22px;
        text-align: center;
        font-size: 1.05rem;
        color: #4a7c23;
        opacity: 1;
    }

    .m-list .m-row .m-chev {
        margin-left: auto;
        font-size: 0.75rem;
        color: #94a3b8;
    }

    .m-list .nav-text,
    .m-list .m-row span {
        white-space: normal;
        font-weight: 500;
    }

    .m-list .nav-item.active {
        background: #eef6e6;
        color: #2d5016;
    }

    .m-crumb {
        padding: 8px 20px 0;
        font-size: 11.5px;
        color: #94a3b8;
    }

    .m-empty {
        padding: 28px 20px;
        text-align: center;
        color: #94a3b8;
        font-size: 0.9rem;
    }

    .m-sheet-foot {
        flex-shrink: 0;
        display: flex;
        border-top: 1px solid #e2e8f0;
        padding: 4px 6px;
    }

    .m-sheet-foot a,
    .m-sheet-foot button {
        flex: 1 1 0;
        min-width: 0;
        min-height: 48px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border: 0;
        background: none;
        color: #475569;
        font: inherit;
        font-size: 11.5px;
        font-weight: 500;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .m-sheet-foot i {
        font-size: 1rem;
    }

    .m-sheet-foot .danger {
        color: #dc2626;
    }
}

/* Tablet/desktop widths never show the sheet, even if it was left open across a resize */
@media (min-width: 992px) {
    .m-bottom-nav,
    .m-sheet,
    .m-scrim {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .m-scrim,
    .m-sheet {
        animation: none;
    }
}
