/* Portal mobile home: icon-grid launcher shown on phones (<= 767px) in place of the stacked desktop panels.
   Built by assets/js/portal-mobile-home.js from the existing menu, stats and favorites DOM. */
.portal-mh,
.portal-mh-sheet-layer { display: none; }

@media (max-width: 1199.98px) {
    body.portal-mh-on .portal-dashboard-v2 > .portal-mobile-topbar,
    body.portal-mh-on .portal-dashboard-v2 > .portal-topbar,
    body.portal-mh-on .portal-dashboard-v2 > .portal-shell { display: none !important; }
    body.portal-mh-on .portal-dashboard-wrapper.portal-dashboard-v2 { padding: 0 !important; gap: 0; }

    body.portal-mh-on .portal-mh {
        --mh-page: #0f172a;
        --mh-panel: #17233a;
        --mh-input: #0f172a;
        --mh-line: rgba(148, 163, 184, .24);
        --mh-text: #e2e8f0;
        --mh-muted: #94a3b8;
        --mh-top: linear-gradient(90deg, #0d477a, #0f5b94);
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        height: 100%;
        background: var(--mh-page);
        color: var(--mh-text);
    }
    [data-theme="light"] body.portal-mh-on .portal-mh {
        --mh-page: #e8e3d9;
        --mh-panel: #f5f1ea;
        --mh-input: #faf8f4;
        --mh-line: #dcd4c6;
        --mh-text: #1e293b;
        --mh-muted: #6b6457;
        --mh-top: linear-gradient(90deg, #3d82b5, #2f6f9f);
    }

    .portal-mh-top {
        flex: 0 0 auto;
        padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 16px;
        border-radius: 0 0 20px 20px;
        background: var(--mh-top);
        color: #fff;
    }
    .portal-mh-top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
    .portal-mh-top-row > :first-child { flex:1 1 auto; min-width:0; }
    .portal-mh-hello { font-size: .8rem; opacity: .85; line-height: 1.2; }
    .portal-mh-name { font-size: 1.15rem; font-weight: 800; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
    .portal-mh-top-actions { display: flex; gap: 8px; flex: 0 0 auto; }
    .portal-mh-icon-btn {
        position: relative;
        width: 44px; height: 44px;
        display: inline-flex; align-items: center; justify-content: center;
        border: 0; border-radius: 13px;
        background: rgba(255, 255, 255, .16);
        color: #fff; font-size: 1.15rem;
    }
    .portal-mh-icon-btn:active { background: rgba(255, 255, 255, .28); }
    .portal-mh-dot {
        position: absolute; top: -5px; right: -5px;
        min-width: 19px; height: 19px; padding: 0 5px;
        display: none; align-items: center; justify-content: center;
        border-radius: 999px; background: #dc2626; color: #fff;
        font-size: .68rem; font-weight: 800; line-height: 1;
    }
    .portal-mh-dot.show { display: inline-flex; }
    .portal-mh-search {
        margin-top: 12px; height: 48px;
        display: flex; align-items: center; gap: 10px; padding: 0 14px;
        border-radius: 14px; background: var(--mh-input); color: var(--mh-muted);
    }
    .portal-mh-search input {
        flex: 1 1 auto; min-width: 0; height: 100%;
        border: 0; outline: 0; background: transparent !important;
        color: var(--mh-text) !important; font-size: 1rem; /* 16px keeps iOS from zooming on focus */
        box-shadow: none !important;
    }
    .portal-mh-search input::placeholder { color: var(--mh-muted); }
    .portal-mh-search-clear { border: 0; background: transparent; color: var(--mh-muted); font-size: 1.05rem; padding: 6px; display: none; }
    .portal-mh.is-searching .portal-mh-search-clear { display: inline-flex; }

    .portal-mh-body {
        flex: 1 1 auto; min-height: 0;
        overflow-y: auto; -webkit-overflow-scrolling: touch;
        padding: 14px 14px calc(20px + env(safe-area-inset-bottom, 0px));
    }
    .portal-mh-sec { margin: 16px 2px 8px; font-size: .78rem; font-weight: 800; color: var(--mh-muted); display: flex; justify-content: space-between; align-items: center; }
    .portal-mh-sec button { border: 0; background: transparent; color: var(--mh-muted); font-size: .78rem; font-weight: 700; padding: 4px 2px; }

    .portal-mh-quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
    .portal-mh-q {
        position: relative; min-height: 64px; padding: 9px 4px;
        border: 1px solid var(--mh-line); border-radius: 14px;
        background: var(--mh-panel); color: var(--mh-text);
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    }
    .portal-mh-q:active, .portal-mh-tile:active, .portal-mh-chip:active, .portal-mh-row:active { filter: brightness(.95); }
    .portal-mh-q b { font-size: 1.3rem; line-height: 1.1; font-weight: 800; }
    .portal-mh-q span { font-size: .7rem; color: var(--mh-muted); white-space: nowrap; }

    .portal-mh-strip { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
    .portal-mh-strip::-webkit-scrollbar { display: none; }
    .portal-mh-chip {
        flex: 0 0 auto; min-height: 40px; padding: 8px 14px;
        display: inline-flex; align-items: center; gap: 7px;
        border: 1px solid var(--mh-line); border-radius: 999px;
        background: var(--mh-panel); color: var(--mh-text);
        font-size: .8rem; font-weight: 700; white-space: nowrap;
    }
    .portal-mh-chip b { font-weight: 800; }
    .portal-mh-chip .bi-star-fill { color: #e0a100; }
    .portal-mh-more { margin-top: 8px; }
    .portal-mh-empty { font-size: .8rem; color: var(--mh-muted); padding: 6px 2px; }

    .portal-mh-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
    .portal-mh-tile {
        position: relative; min-height: 92px; padding: 11px 6px 9px;
        border: 1px solid var(--mh-line); border-radius: 16px;
        background: var(--mh-panel); color: var(--mh-text);
        display: flex; flex-direction: column; align-items: center; gap: 6px;
        font-size: .8rem; font-weight: 700; line-height: 1.25; text-align: center;
    }
    .portal-mh-tile small { display: block; font-weight: 400; font-size: .68rem; color: var(--mh-muted); }
    .portal-mh-ic {
        flex: 0 0 auto; width: 42px; height: 42px; border-radius: 13px;
        display: inline-flex; align-items: center; justify-content: center;
        color: #fff; font-size: 1.25rem;
    }
    .portal-mh-tile .portal-mh-dot { top: 6px; right: 6px; }
    .portal-mh-c0 { background: #3d82b5; } .portal-mh-c1 { background: #d9822b; } .portal-mh-c2 { background: #5b7083; }
    .portal-mh-c3 { background: #0f9d7a; } .portal-mh-c4 { background: #d1477a; } .portal-mh-c5 { background: #7c5cd6; }
    .portal-mh-c6 { background: #2c8a9b; } .portal-mh-c7 { background: #c0392b; } .portal-mh-c8 { background: #557d36; }

    .portal-mh-list { border: 1px solid var(--mh-line); border-radius: 16px; background: var(--mh-panel); padding: 0 8px; }
    .portal-mh-row {
        width: 100%; min-height: 58px; padding: 9px 6px;
        display: flex; align-items: center; gap: 12px;
        border: 0; border-bottom: 1px solid var(--mh-line);
        background: transparent; color: var(--mh-text); text-align: left;
    }
    .portal-mh-row:last-child { border-bottom: 0; }
    .portal-mh-row .portal-mh-ic { width: 40px; height: 40px; font-size: 1.15rem; }
    .portal-mh-row-text { flex: 1 1 auto; min-width: 0; font-size: .9rem; font-weight: 700; line-height: 1.3; }
    .portal-mh-row-text small { display: block; font-weight: 400; font-size: .74rem; color: var(--mh-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .portal-mh-row-badge { flex: 0 0 auto; padding: 2px 8px; border-radius: 999px; background: #dc2626; color: #fff; font-size: .7rem; font-weight: 800; }
    .portal-mh-star {
        flex: 0 0 auto; width: 44px; height: 44px; margin-right: -6px;
        display: inline-flex; align-items: center; justify-content: center;
        border: 0; background: transparent; color: var(--mh-muted); font-size: 1.15rem;
    }
    .portal-mh-star.on { color: #e0a100; }
    .portal-mh-row > .bi-chevron-right { color: var(--mh-muted); }

    .portal-mh-results { display: none; }
    .portal-mh.is-searching .portal-mh-results { display: block; }
    .portal-mh.is-searching .portal-mh-home { display: none; }

    /* Bottom sheet with a group's menus */
    .portal-mh-sheet-layer.show {
        display: block; position: fixed; inset: 0; z-index: 1040;
        background: rgba(15, 23, 42, .5);
    }
    .portal-mh-sheet {
        --mh-panel: #17233a; --mh-line: rgba(148, 163, 184, .24); --mh-text: #e2e8f0; --mh-muted: #94a3b8;
        position: absolute; left: 0; right: 0; bottom: 0; max-height: 82dvh;
        display: flex; flex-direction: column;
        padding: 10px 14px calc(14px + env(safe-area-inset-bottom, 0px));
        border-radius: 24px 24px 0 0;
        background: var(--mh-panel); color: var(--mh-text);
        animation: portalMhSheetUp .2s ease-out;
    }
    [data-theme="light"] .portal-mh-sheet { --mh-panel: #f5f1ea; --mh-line: #dcd4c6; --mh-text: #1e293b; --mh-muted: #6b6457; }
    .portal-mh-sheet-grab { flex: 0 0 auto; width: 42px; height: 5px; margin: 0 auto 10px; border-radius: 3px; background: var(--mh-line); }
    .portal-mh-sheet-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 1.05rem; font-weight: 800; }
    .portal-mh-sheet-head span { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
    .portal-mh-sheet-head .portal-mh-ic { width: 34px; height: 34px; font-size: 1rem; border-radius: 11px; }
    .portal-mh-sheet-close { width: 44px; height: 44px; margin-right: -8px; border: 0; background: transparent; color: var(--mh-muted); font-size: 1.1rem; }
    .portal-mh-sheet-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
    @keyframes portalMhSheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
    @media (prefers-reduced-motion: reduce) { .portal-mh-sheet { animation: none; } }
}
