/* =================================================================
   FamilyPhotoVault — mobile.css
   Loaded on every page. Rules fall into two buckets:

   1. Responsive shrinks — wrapped in `@media (max-width: 900px)` so
      they only kick in on narrow viewports. Desktop is untouched.

   2. Mobile chrome — bottom tab bar, FAB, select bar, search overlay,
      pull-to-refresh, etc. Gated by `body.is-mobile` which mobile.js
      toggles via matchMedia. All chrome elements have `display: none`
      at rest so desktop browsers never render them, regardless of
      whether mobile.js has run.
   ================================================================= */


/* --- iOS / Android safe-area + component sizing --------------------- */
:root {
    --fpv-safe-bot: env(safe-area-inset-bottom, 0px);
    --fpv-safe-top: env(safe-area-inset-top, 0px);
    --mtab-height: 58px;
    --mfab-size: 56px;
}


/* =========================================================
   1) Responsive shrinks — phone viewports only.
   ========================================================= */

@media (max-width: 900px) {

    .lib-main { padding: 0.7rem 0.75rem; }

    /* Sidebar replaced by the bottom tab bar on mobile. */
    .lib-sidebar, .lib-sidebar-backdrop { display: none !important; }
    .lib-layout { display: block; }

    /* Search bar collapses under the brand on narrow layouts. */
    .navbar .input-group { min-width: 0; }

    /* Apple HIG / Material: 44px minimum tap height. */
    .btn-sm, .btn, .form-control, .form-select, .form-check-input { min-height: 40px; }
    .btn-icon { width: 44px; height: 44px; }
    .icon-picker label { padding: 0.85rem 0.4rem; }

    /* Photo grid density. */
    .photo-grid { --tile-size: clamp(110px, 38vw, 180px); gap: 3px; }
    .photo-tile { border-radius: var(--radius-sm); }
    .photo-tile .photo-meta {
        opacity: 1;
        padding: 4px 6px;
        font-size: 0.68rem;
    }
    .photo-tile:hover { transform: none; box-shadow: none; }
    .photo-tile:hover img { transform: none; }

    /* Photo detail: collapse to a single stacked column. */
    .photo-layout { grid-template-columns: minmax(0, 1fr); }
    .photo-pane-grip { display: none; }
    .photo-pane { position: static; max-height: none; order: 2; }
    .photo-right { order: 1; padding-left: 0; }
    .photo-hero-wrap { max-height: 60vh; }
    .photo-hero-frame, .photo-hero-frame img.hero-img { max-height: 60vh; }

    .hero-nav { opacity: 0.85 !important; width: 44px; height: 44px; font-size: 1.6rem; }

    .timeline-header { padding: 0.35rem 0.5rem; min-height: 48px; }
    .timeline-header h3 { font-size: 1rem; }
    .date-section h5 { font-size: 0.66rem; padding: 0.22rem 0.2rem; }

    .slideshow-controls button { padding: 0.55rem 1.1rem; font-size: 1rem; }
    .slideshow-controls .ss-speed-group select { min-width: 72px; padding: 4px 6px; }
}

/* Hover animations off on touch-first devices regardless of viewport. */
@media (hover: none) {
    .card.card-hover:hover { transform: none; box-shadow: var(--shadow-1); }
    .person-card:hover, .place-card:hover { transform: none; }
    .ribbon-tile:hover { transform: none; }
}

@media (max-width: 640px) {
    .navbar .brand-sub { display: none; }
}
@media (max-width: 540px) {
    .navbar .navbar-brand span.brand-text { display: none; }
    .tile-size-control { display: none; }
    .navbar .dropdown .btn.dropdown-toggle .bi-person-circle + *:not(i) { display: none; }
    .photo-pane h6 { font-size: 0.66rem; padding: 0.4rem 0.5rem 0.3rem; }
    .photo-pane dl.row { font-size: 0.75rem; }
}


/* =========================================================
   2) Mobile chrome — gated on body.is-mobile.
   Every component is `display: none` at rest. mobile.js toggles
   body.is-mobile via matchMedia; if the JS fails / is blocked,
   the chrome stays hidden everywhere. No leaks onto desktop.
   ========================================================= */

/* Navbar hide-on-scroll — only when body.is-mobile is set. */
body.is-mobile .navbar { transition: transform .22s ease; will-change: transform; }
body.is-mobile .navbar.nav-hidden { transform: translateY(-100%); }

/* ---- Bottom tab bar ------------------------------------- */
.mtab-bar { display: none; }
body.is-mobile .mtab-bar {
    position: fixed;
    left: 0; right: 0;
    bottom: 0;
    z-index: 1040;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    background: var(--fpv-panel, #fff);
    border-top: 1px solid var(--fpv-border);
    padding-bottom: var(--fpv-safe-bot);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
}
/* Legacy (non-app-shell) pages — the whole body scrolls, so the tab-bar
 * clearance lives on body. App-shell pages override this and apply the
 * same clearance to .lib-main instead (see app.css). */
body.is-mobile:not(.msearch-open):not(.app-shell) {
    padding-bottom: calc(var(--mtab-height) + var(--fpv-safe-bot));
}

body.is-mobile .mtab-bar a {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 4px;
    text-decoration: none;
    color: var(--fpv-muted);
    font-size: 0.68rem;
    line-height: 1;
    min-height: 44px;
}
body.is-mobile .mtab-bar a i { font-size: 1.35rem; }
body.is-mobile .mtab-bar a:active { background: var(--fpv-surface); }
body.is-mobile .mtab-bar a.active {
    color: var(--fpv-accent, #6b8afd);
    font-weight: 600;
}

/* ---- FAB ------------------------------------------------- */
.mfab, .mfab-backdrop { display: none; }
body.is-mobile .mfab {
    position: fixed;
    right: 18px;
    bottom: calc(var(--mtab-height) + var(--fpv-safe-bot) + 16px);
    z-index: 1050;
    display: block;
}

body.is-mobile .mfab-trigger {
    width: var(--mfab-size);
    height: var(--mfab-size);
    border-radius: 50%;
    border: 0;
    background: var(--fpv-accent, #6b8afd);
    color: #fff;
    font-size: 1.8rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    transition: transform .2s ease, background .2s ease;
    cursor: pointer;
}
body.is-mobile .mfab.open .mfab-trigger {
    transform: rotate(45deg);
    background: #cc3b3b;
}
body.is-mobile .mfab-trigger:active { transform: scale(0.96); }
body.is-mobile .mfab.open .mfab-trigger:active { transform: rotate(45deg) scale(0.96); }

body.is-mobile .mfab-menu {
    position: absolute;
    right: 0;
    bottom: calc(var(--mfab-size) + 12px);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .18s ease, transform .18s ease;
}
body.is-mobile .mfab.open .mfab-menu {
    pointer-events: auto;
    opacity: 1;
    transform: translateY(0);
}
body.is-mobile .mfab-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--fpv-panel, #fff);
    color: var(--fpv-text);
    padding: 10px 14px;
    border-radius: 26px;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-size: 0.92rem;
    min-height: 44px;
}
body.is-mobile .mfab-item i { color: var(--fpv-accent, #6b8afd); font-size: 1.15rem; }
body.is-mobile .mfab-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    z-index: 1049;
    display: block;
}
body.is-mobile .mfab.open + .mfab-backdrop,
body.is-mobile .mfab.open ~ .mfab-backdrop { opacity: 1; pointer-events: auto; }

/* ---- Floating multi-select bar -------------------------- */
.mselect-bar { display: none; }
body.is-mobile .mselect-bar {
    position: fixed;
    left: 8px; right: 8px;
    bottom: calc(var(--mtab-height) + var(--fpv-safe-bot) + 8px);
    z-index: 1055;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 14px;
    background: var(--fpv-panel, #fff);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transform: translateY(calc(100% + 20px));
    transition: transform .22s ease;
}
body.is-mobile .mselect-bar.visible { transform: translateY(0); }

body.is-mobile .mselect-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
body.is-mobile .mselect-count {
    background: var(--fpv-accent, #6b8afd);
    color: #fff;
    border-radius: 999px;
    min-width: 26px;
    height: 26px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 600;
}
body.is-mobile .mselect-bar .mselect-actions {
    display: flex;
    gap: 4px;
    overflow-x: auto;
}
body.is-mobile .mselect-bar .mselect-actions > * {
    min-width: 44px;
    min-height: 44px;
    border: 0;
    background: transparent;
    color: var(--fpv-text);
    border-radius: 8px;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
body.is-mobile .mselect-bar .mselect-actions > *:active { background: var(--fpv-surface); }

/* ---- Full-screen mobile search overlay ------------------ */
.msearch-overlay { display: none; }
body.is-mobile .msearch-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: var(--fpv-panel, #fff);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform .22s ease;
    padding-top: var(--fpv-safe-top);
    visibility: hidden;
}
body.is-mobile .msearch-overlay.visible { transform: translateY(0); visibility: visible; }
body.is-mobile .msearch-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--fpv-border);
}
body.is-mobile .msearch-head .msearch-close {
    border: 0;
    background: transparent;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.4rem;
    color: var(--fpv-text);
}
body.is-mobile .msearch-head form { flex: 1 1 auto; display: flex; gap: 6px; }
body.is-mobile .msearch-head input[name="q"] {
    flex: 1 1 auto;
    border: 1px solid var(--fpv-border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 1rem;
    background: var(--fpv-surface);
    color: var(--fpv-text);
}
body.is-mobile .msearch-head .msearch-mic {
    border: 0;
    background: transparent;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.25rem;
    color: var(--fpv-muted);
}
body.is-mobile .msearch-head .msearch-mic.listening { color: #cc3b3b; animation: mic-pulse 1s ease-in-out infinite; }
@keyframes mic-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

body.is-mobile .msearch-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 10px 12px;
}
body.is-mobile .msearch-section-title {
    font-size: 0.72rem;
    color: var(--fpv-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: .75rem 0 .25rem;
}
body.is-mobile .msearch-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: .75rem;
}
body.is-mobile .msearch-chip {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--fpv-border);
    background: var(--fpv-surface);
    color: var(--fpv-text);
    font-size: 0.85rem;
    text-decoration: none;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

/* ---- Pull-to-refresh indicator -------------------------- */
.fpv-ptr { display: none; }
body.is-mobile .fpv-ptr {
    position: fixed;
    left: 50%;
    top: 8px;
    transform: translateX(-50%) translateY(-60px);
    z-index: 1045;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--fpv-panel, #fff);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}
body.is-mobile .fpv-ptr-spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--fpv-border);
    border-top-color: var(--fpv-accent, #6b8afd);
    border-radius: 50%;
    transform: rotate(0deg);
    transition: transform .2s ease;
}
body.is-mobile .fpv-ptr.pull-ready .fpv-ptr-spinner { transform: rotate(180deg); border-top-color: #2a9d45; }
body.is-mobile .fpv-ptr.pull-loading .fpv-ptr-spinner {
    border-top-color: var(--fpv-accent, #6b8afd);
    animation: ptr-spin 0.9s linear infinite;
}
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* ---- Touch-target bump + desktop-bulk-bar hide --------- */
body.is-mobile .btn-icon,
body.is-mobile button[aria-label],
body.is-mobile a[aria-label] {
    min-width: 44px;
    min-height: 44px;
}
body.is-mobile .dropdown-item { min-height: 44px; display: flex; align-items: center; }
body.is-mobile .form-check-input { min-width: 22px; min-height: 22px; }

/* Desktop #bulk-bar is redundant on mobile; mobile proxies through it. */
body.is-mobile #bulk-bar { display: none !important; }

/* Reduced motion override for all mobile components. */
@media (prefers-reduced-motion: reduce) {
    body.is-mobile .navbar,
    body.is-mobile .mfab-menu,
    body.is-mobile .msearch-overlay,
    body.is-mobile .mselect-bar { transition: none; }
    @keyframes mic-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 1; } }
    @keyframes ptr-spin { to { transform: rotate(0deg); } }
}
