/*
 * Website phone / tablet bar (below 1024px) on every template. Markup: resources/views/website/partials/mobile-nav.blade.php.
 * Same look as the app's own bar (public/assets/css/mobile-app-nav.css), coloured with the site's --ws-primary.
 * Below 1024px it takes over from each template's own burger / dock / tab strip and from the floating buttons
 * (search stack, contact / complaint FAB): those are listed in "Template menus handed over" below. A new template
 * with its own phone menu trigger adds its selector there (or puts data-wsmb-hide on the element).
 *
 * z-index: template headers / docks <= 50 < floating stack 55 < bar 56 < sheets 57 < palette 59 < form panels 60 / 70.
 */
#ws-root .wsmb { display: none; }

@media screen and (max-width: 1023.98px) {
    #ws-root {
        --wsmb-accent: var(--ws-primary, #059669);
        --wsmb-bg: rgb(255 255 255 / .96);
        --wsmb-panel: #ffffff;
        --wsmb-line: #e5e7eb;
        --wsmb-ink: #6b7280;
        --wsmb-ink-strong: #111827;
        --wsmb-soft: color-mix(in srgb, var(--wsmb-accent) 10%, #ffffff);
        --wsmb-tile: #ffffff;
        --wsmb-tile-line: #eef0f3;
        --wsmb-h: calc(3.9rem + env(safe-area-inset-bottom, 0px));
        /* the page ends above the bar; templates that lift their own bottom UI read this */
        --ws-float-bottom: calc(var(--wsmb-h) + .75rem);
        padding-bottom: var(--wsmb-h);
    }
    #ws-root.ws-dark {
        --wsmb-accent: color-mix(in srgb, var(--ws-primary, #059669) 70%, #ffffff);
        --wsmb-bg: rgb(15 23 42 / .96);
        --wsmb-panel: #111827;
        --wsmb-line: #1f2937;
        --wsmb-ink: #9ca3af;
        --wsmb-ink-strong: #f3f4f6;
        --wsmb-soft: color-mix(in srgb, var(--ws-primary, #059669) 18%, #111827);
        --wsmb-tile: #1f2937;
        --wsmb-tile-line: #273244;
    }
    html.wsmb-locked, html.wsmb-locked body { overflow: hidden; }

    #ws-root .wsmb {
        display: block;
        font-family: Poppins, Inter, ui-sans-serif, system-ui, sans-serif;
    }
    #ws-root .wsmb [x-cloak] { display: none !important; }
    #ws-root .wsmb .ws-np { display: none; }
    #ws-root .wsmb[data-lang="np"] .ws-np { display: inline; }
    #ws-root .wsmb[data-lang="np"] .ws-en { display: none; }

    /* ---------- the bar ---------- */
    #ws-root .wsmb-bar {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(0, 1fr);
        align-items: stretch;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 56;
        height: var(--wsmb-h);
        padding: 0 .25rem env(safe-area-inset-bottom, 0px);
        background: var(--wsmb-bg);
        border-top: 1px solid var(--wsmb-line);
        box-shadow: 0 -6px 20px -12px rgb(15 23 42 / .25);
        -webkit-backdrop-filter: saturate(1.4) blur(12px);
        backdrop-filter: saturate(1.4) blur(12px);
    }
    #ws-root.ws-dark .wsmb-bar { box-shadow: 0 -6px 20px -12px rgb(0 0 0 / .7); }
    #ws-root .wsmb-item {
        position: relative;
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: .2rem; min-width: 0;
        padding: .35rem .15rem .3rem;
        color: var(--wsmb-ink);
        font: inherit; font-size: .68rem; font-weight: 500; line-height: 1;
        text-decoration: none;
        background: transparent; border: 0; border-radius: 0;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color .15s ease;
    }
    #ws-root .wsmb-item > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #ws-root .wsmb-item > svg { width: 1.45rem; height: 1.45rem; transition: transform .15s ease; }
    #ws-root .wsmb-item:active > svg { transform: scale(.9); }
    #ws-root .wsmb-item.is-active { color: var(--wsmb-accent); font-weight: 600; }
    #ws-root .wsmb-item.is-active::before {
        content: ""; position: absolute; top: -1px; left: 50%;
        width: 2.4rem; height: 3px; border-radius: 0 0 3px 3px;
        background: var(--wsmb-accent); transform: translateX(-50%);
    }
    #ws-root .wsmb-item:focus-visible { outline: 2px solid var(--wsmb-accent); outline-offset: -4px; border-radius: .75rem; }

    /* ---------- sheets (end at the top of the bar, so the bar stays usable) ---------- */
    #ws-root .wsmb-sheet { position: fixed; inset: 0 0 var(--wsmb-h) 0; z-index: 57; }
    #ws-root .wsmb-sheet__backdrop { position: absolute; inset: 0; background: rgb(15 23 42 / .45); }
    #ws-root .wsmb-sheet__panel {
        position: absolute; left: 0; right: 0; bottom: 0;
        max-height: calc(100svh - var(--wsmb-h) - 3rem);
        overflow-y: auto; overscroll-behavior: contain;
        padding: .5rem 1rem 1rem;
        border-radius: 1.4rem 1.4rem 0 0;
        background: var(--wsmb-panel); color: var(--wsmb-ink-strong);
        box-shadow: 0 -18px 40px -16px rgb(15 23 42 / .35);
        outline: none;
    }
    #ws-root.ws-dark .wsmb-sheet__panel { box-shadow: 0 -18px 40px -16px rgb(0 0 0 / .8); }
    #ws-root .wsmb-slide { transition: transform .22s cubic-bezier(.2, .9, .3, 1); }
    #ws-root .wsmb-slide--from { transform: translateY(100%); }
    #ws-root .wsmb-slide--to { transform: none; }
    @media (min-width: 640px) { #ws-root .wsmb-sheet__panel { max-width: 40rem; margin: 0 auto; } }

    #ws-root .wsmb-grip { width: 2.6rem; height: .3rem; margin: .1rem auto .9rem; border-radius: 9999px; background: #d1d5db; }
    #ws-root.ws-dark .wsmb-grip { background: #374151; }
    #ws-root .wsmb-title {
        margin: 0 0 .6rem;
        color: #6b7280; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    }
    #ws-root.ws-dark .wsmb-title { color: #9ca3af; }
    #ws-root .wsmb-title--sub { margin-top: 1rem; }

    /* menu tree */
    #ws-root .wsmb-list, #ws-root .wsmb-sub { margin: 0; padding: 0; list-style: none; }
    #ws-root .wsmb-list { display: grid; gap: .25rem; }
    #ws-root .wsmb-sub {
        display: grid; gap: .15rem;
        margin: .2rem 0 .35rem .85rem; padding-left: .65rem;
        border-left: 2px solid var(--wsmb-line);
    }
    #ws-root .wsmb-link {
        display: flex; align-items: center; justify-content: space-between; gap: .75rem;
        width: 100%; min-height: 2.9rem; padding: .55rem .85rem;
        border: 0; border-radius: .9rem;
        background: transparent; color: var(--wsmb-ink-strong);
        font: inherit; font-size: .95rem; font-weight: 500; line-height: 1.3; text-align: left; text-decoration: none;
        cursor: pointer; -webkit-tap-highlight-color: transparent;
    }
    #ws-root .wsmb-sub .wsmb-link { min-height: 2.6rem; font-size: .9rem; }
    #ws-root .wsmb-link:hover, #ws-root .wsmb-link:focus-visible { background: var(--wsmb-soft); outline: none; }
    #ws-root .wsmb-link.is-here { background: var(--wsmb-soft); color: var(--wsmb-accent); font-weight: 600; }
    #ws-root .wsmb-link--parent[aria-expanded="true"] { color: var(--wsmb-accent); font-weight: 600; }
    #ws-root .wsmb-caret { flex: none; width: 1.1rem; height: 1.1rem; transition: transform .2s ease; }
    #ws-root .wsmb-caret.is-open { transform: rotate(180deg); }
    #ws-root .wsmb-account {
        display: flex; align-items: center; justify-content: center;
        min-height: 2.9rem; margin-top: 1rem; padding: .6rem 1rem;
        border-radius: 9999px;
        background: var(--wsmb-accent); color: #ffffff;
        font-size: .95rem; font-weight: 600; text-decoration: none;
    }
    #ws-root.ws-dark .wsmb-account { background: var(--ws-primary, #059669); }

    /* More tiles */
    #ws-root .wsmb-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; }
    @media (max-width: 359.98px) { #ws-root .wsmb-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
    #ws-root .wsmb-tile {
        display: flex; flex-direction: column; align-items: center; gap: .45rem;
        min-width: 0; padding: .75rem .25rem .65rem;
        border: 1px solid var(--wsmb-tile-line); border-radius: 1rem;
        background: var(--wsmb-tile); color: #374151;
        box-shadow: 0 1px 2px rgb(15 23 42 / .05);
        font: inherit; font-size: .7rem; font-weight: 500; line-height: 1.15; text-align: center;
        cursor: pointer; -webkit-tap-highlight-color: transparent;
        transition: transform .12s ease, background-color .12s ease;
    }
    #ws-root .wsmb-tile:active { transform: scale(.96); }
    #ws-root.ws-dark .wsmb-tile { color: #e5e7eb; box-shadow: none; }
    #ws-root .wsmb-tile__ic { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; border-radius: 9999px; }
    #ws-root .wsmb-tile__ic svg { width: 1.3rem; height: 1.3rem; }
    #ws-root .wsmb-c-emerald { background: #ecfdf5; color: #059669; }
    #ws-root .wsmb-c-sky { background: #f0f9ff; color: #0284c7; }
    #ws-root .wsmb-c-violet { background: #f5f3ff; color: #7c3aed; }
    #ws-root .wsmb-c-amber { background: #fffbeb; color: #d97706; }
    #ws-root .wsmb-c-slate { background: #f1f5f9; color: #334155; }
    #ws-root .wsmb-c-gray { background: #f3f4f6; color: #4b5563; }
    #ws-root.ws-dark .wsmb-tile__ic { background: rgb(255 255 255 / .06); }
    #ws-root.ws-dark .wsmb-c-emerald { color: #34d399; }
    #ws-root.ws-dark .wsmb-c-sky { color: #38bdf8; }
    #ws-root.ws-dark .wsmb-c-violet { color: #a78bfa; }
    #ws-root.ws-dark .wsmb-c-amber { color: #fbbf24; }
    #ws-root.ws-dark .wsmb-c-slate { color: #cbd5e1; }
    #ws-root.ws-dark .wsmb-c-gray { color: #d1d5db; }

    /* visitor theme list */
    #ws-root .wsmb-themes { display: grid; gap: .3rem; margin: .9rem 0 0; padding: 0; list-style: none; }
    #ws-root .wsmb-themes a {
        display: flex; align-items: center; gap: .7rem;
        padding: .55rem .75rem; border-radius: .8rem;
        color: var(--wsmb-ink-strong); font-size: .9rem; text-decoration: none;
    }
    #ws-root .wsmb-themes a.is-on { background: var(--wsmb-soft); color: var(--wsmb-accent); font-weight: 600; }
    #ws-root .wsmb-themes small { margin-left: auto; color: var(--wsmb-ink); font-size: .72rem; }
    #ws-root .wsmb-themes__sw { display: inline-flex; flex: none; }
    #ws-root .wsmb-themes__sw i { width: .9rem; height: .9rem; margin-right: -.25rem; border-radius: 9999px; border: 2px solid var(--wsmb-panel); }

    /* ---------- Search spotlight (shared palette) ----------
       Opens between the site header (--wsmb-top, measured by the partial when it opens) and the bar, so both stay
       on screen; the result list scrolls inside. The bar stays usable (z 56 is under the palette's 59, but the
       palette no longer covers it). */
    #ws-root .wsp-dialog {
        top: var(--wsmb-top, 0px);
        bottom: var(--wsmb-h);
        padding: .5rem .5rem .6rem;
        align-items: stretch;
    }
    #ws-root .wsp-box {
        height: auto; max-height: 100%;
        border: 1px solid var(--wsp-line, var(--wsmb-line));
        border-radius: 1.1rem;
    }
    @media (min-width: 48rem) {
        #ws-root .wsp-dialog { padding: 1rem; align-items: flex-start; }
        #ws-root .wsp-box { width: min(40rem, 100%); max-height: 100%; }
    }

    /* ---------- Template menus handed over to the bar ---------- */
    #ws-root .wsp-float,                        /* shared search / scroll stack: Search + Back to top live in the bar */
    #ws-root [data-wsmb-hide],                  /* default / civic / corporate burger + floating contact buttons */
    #ws-root .ch-fab,                           /* chautari floating forms */
    #ws-root .ch-tabs,                          /* chautari bottom tabs */
    #ws-root .dh-dock,                          /* dhaka floating dock */
    #ws-root .ak-burger,                        /* aakash */
    #ws-root .fc-burger,                        /* forest-canopy */
    #ws-root .ft-bar__menu,                     /* forest-trail */
    #ws-root .md-menu-btn,                      /* mandala */
    #ws-root .nd-handle,                        /* nadi */
    #ws-root .sj-menu-btn,                      /* sanjh */
    #ws-root .ta-strip-wrap,                    /* tara pill strip */
    /* header tools (search, language, light / dark, log in): all in the bar / More, so the header is logo + name */
    #ws-root :is(.ak-tools, .ch-tools, .dh-tools, .fc-tools, .gt-tools, .gt-search, .md-bar__side--end .md-tool, .nd-tools, .sj-tools, .ta-tools),
    #ws-root .ta-subbar                         /* tara sub-pages row (the Menu sheet lists them) */
    { display: none !important; }

    /* the organisation name always shows next to the logo (some templates hid it on narrow phones) */
    #ws-root [data-wsmb-name] { display: block !important; min-width: 0; max-width: none !important; }
    #ws-root [data-wsmb-name] p { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    #ws-root :is(.ta-brand__name, .md-brand__name) { display: -webkit-box !important; }
}

@media print { #ws-root .wsmb { display: none !important; } }

/* ── Tables as cards on phones (labels added by public/website/shared/table-cards.js) ── */
#ws-root .ws-tcard-label { display: none; }
@media screen and (max-width: 639.98px) {
    #ws-root .wsf-table-wrap:has(> .ws-tcard) { overflow: visible; border: 0; background: transparent; }
    #ws-root table.ws-tcard,
    #ws-root table.ws-tcard > tbody { display: block; width: 100%; border: 0; }
    #ws-root table.ws-tcard > thead,
    #ws-root table.ws-tcard tr.ws-tcard-head { display: none; }
    #ws-root table.ws-tcard > tbody { display: grid; gap: .6rem; }
    #ws-root table.ws-tcard tr {
        display: block;
        padding: .35rem .9rem;
        border: 1px solid var(--wsf-line, rgba(15, 23, 42, .12));
        border-radius: var(--wsf-radius, 12px);
        background: var(--wsf-surface, #ffffff);
        box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
    }
    #ws-root.ws-dark table.ws-tcard tr { background: var(--wsf-surface, #1e293b); border-color: var(--wsf-line, #334155); box-shadow: none; }
    #ws-root table.ws-tcard td {
        display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
        padding: .5rem 0 !important;
        border: 0; border-bottom: 1px dashed var(--wsf-line, rgba(15, 23, 42, .12));
        text-align: right !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
    }
    #ws-root table.ws-tcard td:last-child { border-bottom: 0; }
    #ws-root table.ws-tcard .ws-tcard-label {
        display: block; flex: none; max-width: 48%;
        color: var(--wsf-muted, #64748b);
        font-size: .82rem; font-weight: 600; text-align: left;
    }
    /* a cell with no value keeps its row */
    #ws-root table.ws-tcard td:empty::after { content: "—"; }
}
