/* =============================================================================
   MERLOWS — Mobile / Tablet App Shell
   Loads AFTER main.css. Everything here is scoped to <=1024px so the desktop
   layout is never touched. Turns the responsive site into an app-like shell:
   compact hide-on-scroll top bar, bottom tab bar, slide-up sheets, card touch
   states, safe-area insets, and PWA standalone polish.
   ========================================================================== */

/* ---- App-shell design tokens ------------------------------------------- */
:root {
    --app-header-h: 56px;
    --app-tabbar-h: 58px;
    --sheet-radius: 22px;
    --app-ease: cubic-bezier(0.32, 0.72, 0, 1);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --app-z-tabbar: 1000;
    --app-z-scrim: 1090;
    --app-z-sheet: 1100;
}

/* Accessible visually-hidden utility (theme doesn't define one) */
.screen-reader-text {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

/* Below this width we render the app shell (covers phones + iPad portrait). */
@media (max-width: 1024px) {

    /* ---- Base: keep content clear of the fixed top bar + bottom tab bar -- */
    html { -webkit-text-size-adjust: 100%; }

    body {
        /* Override main.css's 64px; add safe-area + room for the tab bar. */
        padding-top: calc(var(--app-header-h) + var(--safe-top)) !important;
        padding-bottom: calc(var(--app-tabbar-h) + var(--safe-bottom)) !important;
        overflow-x: hidden;
        overscroll-behavior-y: none;
    }
    body.mlws-sheet-open { overflow: hidden; }

    /* Hide the CookieAdmin floating "re-consent" launcher on mobile — it pins
       to the bottom-left and collides with the app tab bar. Consent is popup
       only; remove globally via the CookieAdmin plugin settings if desired. */
    .cookieadmin_re_consent,
    .cookieadmin_reconsent_img { display: none !important; }

    /* Momentum scrolling feel */
    body, .mlws-sheet__body { -webkit-overflow-scrolling: touch; }

    /* ---- Compact app top bar -------------------------------------------- */
    .site-header {
        height: calc(var(--app-header-h) + var(--safe-top)) !important;
        min-height: calc(var(--app-header-h) + var(--safe-top)) !important;
        padding-top: var(--safe-top) !important;
        position: fixed !important;
        top: 0; left: 0; width: 100%;
        z-index: 1001;
        background: rgba(255, 255, 255, 0.82);
        -webkit-backdrop-filter: saturate(180%) blur(18px);
        backdrop-filter: saturate(180%) blur(18px);
        border-bottom: 1px solid rgba(15, 23, 42, 0.08);
        box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
        transition: transform 0.3s var(--app-ease);
        will-change: transform;
    }
    @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
        .site-header { background: #ffffff; }
    }

    /* Hide-on-scroll: JS toggles .mlws-bar-hidden when scrolling down */
    .site-header.mlws-bar-hidden { transform: translateY(-100%); }

    /* Center the logo, app-style; drop desktop nav + actions + hamburger */
    .header-content { justify-content: center !important; position: relative; }
    .logo-area { margin: 0 auto; }
    .logo-area img { height: 34px !important; max-width: 200px !important; }

    .main-nav,
    .header-actions,
    .mobile-menu-toggle { display: none !important; }

    /* =========================================================================
       BOTTOM TAB BAR
       ====================================================================== */
    .mlws-tabbar {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: var(--app-z-tabbar);
        display: flex;
        height: calc(var(--app-tabbar-h) + var(--safe-bottom));
        padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
        background: rgba(255, 255, 255, 0.86);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
        backdrop-filter: saturate(180%) blur(20px);
        border-top: 1px solid rgba(15, 23, 42, 0.08);
        box-shadow: 0 -1px 12px rgba(15, 23, 42, 0.05);
    }
    @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
        .mlws-tabbar { background: #ffffff; }
    }

    .mlws-tab {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: 44px;
        padding: 6px 2px;
        border: none;
        background: none;
        color: var(--text-light);
        font-family: var(--font-main);
        font-size: 10.5px;
        font-weight: 600;
        letter-spacing: 0.1px;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.18s ease, transform 0.12s ease;
    }
    .mlws-tab svg {
        width: 24px; height: 24px;
        stroke-width: 1.9;
        display: block;
    }
    .mlws-tab span { line-height: 1; }
    .mlws-tab:active { transform: scale(0.92); }
    .mlws-tab.is-active { color: var(--primary-color); }
    .mlws-tab.is-active svg { stroke-width: 2.3; }

    /* Little active dot under the icon */
    .mlws-tab .mlws-tab__dot {
        width: 4px; height: 4px; border-radius: 50%;
        background: transparent;
        margin-top: 1px;
    }
    .mlws-tab.is-active .mlws-tab__dot { background: var(--accent-color); }

    /* =========================================================================
       SHEETS (Topics + Search) — slide up from the bottom
       ====================================================================== */
    .mlws-scrim {
        position: fixed; inset: 0;
        z-index: var(--app-z-scrim);
        background: rgba(15, 23, 42, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s var(--app-ease), visibility 0.3s var(--app-ease);
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
    }
    .mlws-scrim.is-open { opacity: 1; visibility: visible; }

    .mlws-sheet {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: var(--app-z-sheet);
        max-height: 86vh;
        display: flex;
        flex-direction: column;
        background: #ffffff;
        border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
        box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.22);
        transform: translateY(101%);
        transition: transform 0.36s var(--app-ease);
        padding-bottom: var(--safe-bottom);
        overscroll-behavior: contain;
    }
    .mlws-sheet.is-open { transform: translateY(0); }

    .mlws-sheet__handle {
        flex: 0 0 auto;
        width: 40px; height: 5px;
        border-radius: 99px;
        background: #CBD5E1;
        margin: 10px auto 4px;
    }
    .mlws-sheet__head {
        flex: 0 0 auto;
        display: flex; align-items: center; justify-content: space-between;
        padding: 6px 20px 12px;
    }
    .mlws-sheet__title {
        font-family: var(--font-heading);
        font-size: 19px; font-weight: 700;
        color: var(--text-main);
        margin: 0;
    }
    .mlws-sheet__close {
        width: 36px; height: 36px;
        display: flex; align-items: center; justify-content: center;
        border: none; background: #F1F5F9; color: var(--text-light);
        border-radius: 50%; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .mlws-sheet__close:active { background: #E2E8F0; }
    .mlws-sheet__close svg { width: 18px; height: 18px; }

    .mlws-sheet__body {
        flex: 1 1 auto;
        overflow-y: auto;
        padding: 4px 16px calc(20px + var(--safe-bottom));
    }

    /* Topics sheet: category / menu grid */
    .mlws-topic-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin: 0 0 18px;
        padding: 0; list-style: none;
    }
    .mlws-topic-grid a {
        display: flex; align-items: center; gap: 10px;
        padding: 15px 14px;
        background: #F8FAFC;
        border: 1px solid #EEF2F7;
        border-radius: var(--radius-md);
        color: var(--text-main);
        font-weight: 600; font-size: 14.5px;
        text-decoration: none;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
        transition: background 0.18s ease, transform 0.12s ease;
    }
    .mlws-topic-grid a:active { transform: scale(0.97); background: #EEF4FB; }
    .mlws-topic-grid a .mlws-topic-ico {
        width: 30px; height: 30px; flex: 0 0 auto;
        display: flex; align-items: center; justify-content: center;
        border-radius: 8px;
        background: rgba(27, 79, 138, 0.10);
        color: var(--primary-color);
    }
    .mlws-topic-grid a .mlws-topic-ico svg { width: 17px; height: 17px; }

    .mlws-sheet__section-label {
        font-size: 12px; font-weight: 700; letter-spacing: 0.06em;
        text-transform: uppercase; color: var(--text-light);
        margin: 4px 2px 10px;
    }
    .mlws-sheet__links { list-style: none; margin: 0 0 8px; padding: 0; }
    .mlws-sheet__links li { margin: 0; }
    .mlws-sheet__links a {
        display: flex; align-items: center; justify-content: space-between;
        padding: 14px 8px;
        color: var(--text-main); font-weight: 500; font-size: 15px;
        text-decoration: none;
        border-bottom: 1px solid #F1F5F9;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }
    .mlws-sheet__links a:active { color: var(--primary-color); }
    .mlws-sheet__links a::after {
        content: ""; width: 7px; height: 7px;
        border-right: 2px solid #CBD5E1; border-top: 2px solid #CBD5E1;
        transform: rotate(45deg); flex: 0 0 auto;
    }

    .mlws-sheet__social {
        display: flex; gap: 14px; justify-content: center;
        padding: 18px 0 6px;
    }
    .mlws-sheet__social a {
        width: 44px; height: 44px; border-radius: 50%;
        display: flex; align-items: center; justify-content: center;
        background: #F1F5F9; color: var(--primary-color);
    }
    .mlws-sheet__social a:active { background: #E2E8F0; }
    .mlws-sheet__social svg { width: 20px; height: 20px; }

    /* Search sheet */
    .mlws-search-form { display: flex; gap: 10px; margin: 2px 0 16px; }
    .mlws-search-field {
        flex: 1 1 auto;
        display: flex; align-items: center; gap: 10px;
        padding: 0 14px;
        background: #F1F5F9;
        border: 1.5px solid transparent;
        border-radius: var(--radius-md);
        transition: border-color 0.18s ease, background 0.18s ease;
    }
    .mlws-search-field:focus-within {
        border-color: var(--primary-color);
        background: #fff;
    }
    .mlws-search-field svg { width: 20px; height: 20px; color: var(--text-light); flex: 0 0 auto; }
    .mlws-search-field input {
        flex: 1 1 auto;
        border: none; background: none; outline: none;
        font-family: var(--font-main); font-size: 16px; /* >=16px: no iOS zoom */
        color: var(--text-main);
        padding: 14px 0;
        min-width: 0;
    }
    .mlws-search-submit {
        flex: 0 0 auto;
        padding: 0 20px;
        background: var(--primary-color); color: #fff;
        border: none; border-radius: var(--radius-md);
        font-weight: 700; font-size: 15px; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .mlws-search-submit:active { background: var(--primary-hover); }
    .mlws-search-hint { font-size: 13px; color: var(--text-light); margin: 0 2px; }

    /* =========================================================================
       CARD / TOUCH POLISH — turn hover effects into tap feedback
       ====================================================================== */
    /* Neutralize desktop hover-lift (sticky on touch) and give a press state */
    .portal-card:hover,
    .news-card:hover,
    .bento-cell:hover,
    .tool-card:hover,
    .quick-nav-card:hover {
        transform: none;
    }
    .portal-card, .news-card, .bento-cell, .tool-card, .quick-nav-card {
        -webkit-tap-highlight-color: transparent;
        transition: transform 0.12s ease, box-shadow 0.2s ease;
    }
    .portal-card:active,
    .news-card:active,
    .bento-cell:active,
    .tool-card:active,
    .quick-nav-card:active {
        transform: scale(0.985);
    }

    /* Ensure interactive controls hit the 44px target */
    .btn, .button, button, .quick-nav-card, .tool-card a {
        min-height: 44px;
    }

    /* Slightly larger, more readable body text in the app shell */
    p { font-size: 16px; }
}

/* ---- Phone-only tightening --------------------------------------------- */
@media (max-width: 560px) {
    .mlws-topic-grid { grid-template-columns: 1fr 1fr; }
    .mlws-tab { font-size: 10px; }
}

/* ---- Tablet: don't stretch the tab bar edge-to-edge on wide iPads ------- */
@media (min-width: 700px) and (max-width: 1024px) {
    .mlws-tabbar { justify-content: center; }
    .mlws-tab { flex: 0 1 130px; }
    .mlws-sheet { left: 50%; right: auto; width: min(560px, 100%); transform: translate(-50%, 101%); }
    .mlws-sheet.is-open { transform: translate(-50%, 0); }
    .mlws-topic-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* =============================================================================
   PWA STANDALONE — when launched from the home screen
   ========================================================================== */
@media (display-mode: standalone), (display-mode: minimal-ui) {
    /* Hide the in-page install hint once installed */
    .mlws-install-banner { display: none !important; }
    /* A touch more breathing room under the status bar */
    @media (max-width: 1024px) {
        .site-header { padding-top: calc(var(--safe-top) + 2px) !important; }
    }
}

/* Install banner (shown by JS only when installable, phones/tablets) */
.mlws-install-banner {
    display: none;
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(var(--app-tabbar-h) + var(--safe-bottom) + 12px);
    z-index: 1095;
    align-items: center; gap: 12px;
    padding: 12px 14px;
    background: #0F172A; color: #fff;
    border-radius: var(--radius-md);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.30);
}
.mlws-install-banner.is-visible { display: flex; }
.mlws-install-banner img { width: 38px; height: 38px; border-radius: 9px; flex: 0 0 auto; }
.mlws-install-banner .mlws-install-txt { flex: 1 1 auto; min-width: 0; }
.mlws-install-banner strong { display: block; font-size: 14px; font-weight: 700; }
.mlws-install-banner span { display: block; font-size: 12px; color: #94A3B8; }
.mlws-install-banner button {
    flex: 0 0 auto; border: none; cursor: pointer;
    font-weight: 700; font-size: 13px; border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
}
.mlws-install-banner .mlws-install-go { padding: 9px 14px; background: var(--accent-color); color: #1F2937; }
.mlws-install-banner .mlws-install-x { padding: 9px 8px; background: transparent; color: #94A3B8; }

/* Only ever show app-shell chrome on small screens */
@media (min-width: 1025px) {
    .mlws-tabbar, .mlws-scrim, .mlws-sheet, .mlws-install-banner {
        display: none !important;
    }
}

/* ---- Reduced motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .site-header, .mlws-sheet, .mlws-scrim, .mlws-tab,
    .portal-card, .news-card, .bento-cell, .tool-card, .quick-nav-card {
        transition: none !important;
    }
}
