/* =====================================================================
   DOLLVALE — MOBILE GLOW-UP LAYER
   Loaded after css/style.php so it wins the cascade on small screens.
   Page-level inline <style> blocks are beaten with specificity +
   !important where needed.
   ===================================================================== */

/* =====================  PHONES & SMALL TABLETS  ===================== */
@media (max-width: 768px) {

    /* ---------- 1. Base & guardrails ---------- */
    html {
        -webkit-text-size-adjust: 100%;
        overflow-x: hidden;
        overflow-x: clip;
    }
    body { overflow-x: hidden; overflow-x: clip; }

    body img,
    body video,
    body iframe,
    body canvas,
    body svg {
        max-width: 100% !important;
        height: auto;
    }
    body pre,
    body code {
        white-space: pre-wrap;
        word-break: break-word;
        max-width: 100%;
    }
    body .content table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    body h1 { font-size: clamp(22px, 6vw, 28px) !important; line-height: 1.2; overflow-wrap: anywhere; }
    body h2 { font-size: clamp(19px, 5vw, 24px) !important; line-height: 1.25; overflow-wrap: anywhere; }
    body h3 { font-size: clamp(17px, 4.5vw, 20px) !important; line-height: 1.3; }

    /* 16px inputs stop iOS from zooming the page on focus */
    body input,
    body select,
    body textarea,
    body .form-control {
        font-size: 16px !important;
    }
    body .form-control,
    body input:not([type="checkbox"]):not([type="radio"]),
    body select {
        min-height: 44px;
    }

    /* Comfortable thumb targets */
    body .btn,
    body .button-group button,
    body button[type="submit"],
    body .create-thread-btn,
    body .dropdown-toggle {
        min-height: 44px;
    }
    /* ...except compact controls that must stay small */
    body .ql-toolbar button,
    body .ql-toolbar.ql-snow button {
        min-height: 0 !important;
    }
    body .close,
    body #dollCardModal .close {
        min-height: 0;
    }
    body .dropdown-item {
        padding: 12px 14px !important;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Edge-to-edge shell */
    body .container,
    body .container.custom-container {
        width: 100% !important;
        margin: 0 !important;
        border-left: 0 !important;
        border-right: 0 !important;
        border-radius: 0 !important;
    }

    /* ---------- 2. Header: top bar (new icon-rail chrome) ---------- */
    /* Breathing room above the sticky top bar so it isn't jammed against
       the very top of the screen, and clears the status bar / notch. */
    body .container.custom-container {
        padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    }
    body .site-header.dv-topbar-wrap {
        top: env(safe-area-inset-top, 0px);
    }
    body .navbar,
    body .navbar.navbar-custom.dv-topbar {
        padding: 4px 12px !important;
        gap: 10px !important;
        height: 56px !important;
        min-height: 56px !important;
    }
    .site-brand { font-size: 16px; }
    .site-brand-mark { width: 28px; height: 28px; }
    .mobile-nav-toggle { display: none !important; } /* replaced by bottom-nav "More" */

    /* Keep the top-bar tools on a single horizontal row */
    body .dv-topbar .nav-right {
        display: flex !important;
        grid-template-columns: none !important;
        width: auto !important;
        margin-left: auto;
        gap: 8px;
    }
    body .dv-topbar .nav-utilities {
        width: auto !important;
        padding: 0 !important;
        gap: 8px;
    }
    body .dv-topbar .utility-btn,
    body .dv-topbar .bell-btn {
        flex: 0 0 auto !important;
        width: 40px !important;
        height: 40px !important;
        font-size: 16px;
    }

    /* Verify-email alert: stack instead of jumble */
    body .alert-warning {
        display: block;
        padding: 14px !important;
    }
    body .alert-warning .resend-verification {
        display: block;
        width: 100%;
        margin: 10px 0 6px !important;
    }

    /* ---------- 3. Profile cover banner ---------- */
    body .dv-profile-banner { padding: 12px 12px 0 !important; }
    body .dv-profile-banner .banner-image {
        aspect-ratio: auto !important;
        height: 170px !important;
        min-height: 170px !important;
        max-height: 170px !important;
    }
    .edit-cover-photo {
        top: auto !important;
        bottom: 10px;
        right: 10px !important;
        padding: 6px 12px !important;
        min-height: 36px;
        font-size: 13px !important;
    }

    /* ---------- 4. Content rhythm & cards ---------- */
    body .content { padding: 16px 12px !important; }
    body .sidebar { padding: 12px !important; margin-bottom: 12px !important; }

    body .features,
    body .invitation,
    body .closing,
    body .settings-panel,
    body #settings-form,
    body #display-settings-form,
    body #signup-form,
    body .new-post,
    body .post,
    body .user-info-item,
    body .thread-post,
    body .reply-item,
    body .filter-section,
    body .filter-example,
    body .market-card,
    body .new-market-listing {
        padding: 14px !important;
    }

    /* Comments: drop the desktop indent so bubbles get full width */
    body .speech-bubble { margin: 6px 0 0 !important; }
    body .post-interactions { gap: 8px !important; }

    body .user-info-row { grid-template-columns: 1fr !important; }
    body .profile-actions .btn { flex: 1 1 auto; }

    /* Bootstrap modals & lightbox fit the screen */
    body .modal-dialog {
        max-width: calc(100vw - 16px) !important;
        width: auto !important;
        margin: 8px auto !important;
    }
    .bjd-lightbox { padding: 12px; }
    .bjd-lightbox-close { top: 10px; right: 16px; }
    #dollCardModal { padding: 12px !important; }
    #dollCardModal .doll-card-modal-content { padding: 20px 16px !important; margin-top: 4vh !important; }

    /* ---------- 5. Dolls / browse / galleries / profiles ---------- */
    /* Two tidy columns of doll cards (collection + browse) */
    body .content .doll-gallery { gap: 12px !important; padding: 0 !important; justify-content: space-between !important; }
    body .content .doll-gallery .doll-card,
    body .content .doll-gallery .doll-card-link,
    body .content .doll-gallery .doll-sort-placeholder {
        width: calc(50% - 6px) !important;
        flex: 0 0 calc(50% - 6px) !important;
        max-width: calc(50% - 6px) !important;
    }
    body .content .doll-gallery .doll-card-link .doll-card {
        width: 100% !important;
        flex-basis: auto !important;
        max-width: none !important;
    }
    body .doll-card > img { height: 190px !important; object-fit: cover; }

    /* Browse: filter chips become a swipeable row */
    body .material-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        scrollbar-width: none;
    }
    body .material-tabs::-webkit-scrollbar { display: none; }
    body .material-tab { flex: 0 0 auto; white-space: nowrap; }

    /* Gallery: two aligned columns, no stray left margin */
    body .gallery-grid {
        margin-left: 0 !important;
        gap: 12px !important;
    }
    body .gallery-item {
        flex: 0 0 calc(50% - 6px) !important;
        max-width: calc(50% - 6px);
        margin-bottom: 0 !important;
    }
    body .gallery-image { height: 44vw !important; max-height: 220px; }

    /* Doll profile header sits nicely over the cover photo */
    body .doll-header { margin-top: -60px !important; }
    body .doll-profile-image-container { width: 120px !important; height: 120px !important; }
    body .doll-favorite-row { gap: 8px; }

    /* Profile shell: never let the page shell grow wider than the screen.
       The profile sub-nav strip (My Feed / My Dolls / …) can otherwise force
       .dv-main's min-content width past the viewport, cutting off the banner,
       search form and friend cards on the right. */
    body .dv-shell,
    body .dv-main,
    body .main-content,
    body .dv-profile-banner {
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    body .dv-shell,
    body .dv-main { width: 100% !important; }
    body .main-content > .sidebar {
        min-width: 0 !important;
        max-width: 100% !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    body .main-content > .sidebar::-webkit-scrollbar { display: none; }
    /* Pin the profile sub-nav strip flush under the 56px sticky header
       (1px overlap hides any rounding seam; env() matches the header's
       safe-area offset on notched phones). */
    body .dv-main .main-content > .sidebar {
        top: calc(55px + env(safe-area-inset-top, 0px)) !important;
    }
    body .dv-main .main-content.home-feed-page {
        padding-top: 0 !important;
        gap: 0 !important;
    }
    body .dv-main .main-content.home-feed-page > .home-content-subnav {
        position: sticky !important;
        top: calc(55px + env(safe-area-inset-top, 0px)) !important;
        z-index: 900 !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        transform: none !important;
    }

    /* Friends: match the compact two-column browse-card rhythm */
    body .friends-list {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    body .friend-item { min-width: 0 !important; }
    body .friend-card { width: 100% !important; max-width: 100% !important; box-sizing: border-box !important; }
    body .member-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    body .member-card { width: 100% !important; max-width: 100% !important; box-sizing: border-box !important; }

    /* Feedback / reviews */
    body .reviews-list { gap: 12px !important; }
    body .review-item { flex: 1 1 100% !important; }
    body .content .search-bar { flex-wrap: wrap; }
    body .content .search-bar input[type="text"],
    body .content .search-bar select {
        flex: 1 1 100%;
        width: 100% !important;
    }

    /* ---------- 6. Community / threads / chat / messages ---------- */
    body .forum-section h2 {
        font-size: 16px !important;
        padding: 12px 14px !important;
    }
    body .subforum ul li {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 6px !important;
        padding: 14px 14px !important;
    }
    body .subforum ul li .info {
        text-align: left !important;
        white-space: normal !important;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    body .subforum ul li .info .posts-count { margin-bottom: 0 !important; }
    body .thread-list ul li { padding: 12px 14px !important; }

    /* Messages: inbox becomes a swipeable strip above the conversation */
    body .messages-wrap { flex-direction: column !important; gap: 12px !important; }
    body .msg-inbox {
        flex: none !important;
        width: 100%;
        flex-direction: row !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
    }
    body .msg-thread { flex: 0 0 auto; min-width: 210px; }
    body .msg-convo { min-height: 55vh !important; }

    /* Marketplace listing: gallery on top, details below */
    body .market-detail-layout { grid-template-columns: 1fr !important; }
    body .market-detail-price {
        justify-items: start !important;
        font-size: 24px !important;
        white-space: normal !important;
    }

    /* ---------- 7. Footer ---------- */
    body .site-footer { padding: 26px 16px 22px; }
    body .footer-inner { gap: 14px; }
    body .footer-nav { gap: 2px; }
    body .footer-nav a { font-size: 13px; padding: 9px 12px; }
    body .footer-actions {
        width: 100%;
        flex-direction: column;
        gap: 10px;
    }
    body .footer-discord-link,
    body .site-footer .footer-theme-toggle {
        width: 100%;
        max-width: 280px;
        justify-content: center;
        text-align: center;
    }
}

/* =========================  SMALL PHONES  ========================= */
@media (max-width: 480px) {
    body .dv-profile-banner .banner-image {
        height: 140px !important;
        min-height: 140px !important;
        max-height: 140px !important;
    }
    body .content { padding: 14px 10px !important; }
    body .doll-card > img { height: 160px !important; }
    body .gallery-image { max-height: 190px; }
    body .profile-header { padding-left: 12px !important; padding-right: 12px !important; }
    body .post-interactions span,
    body .post-interactions .pi-btn { font-size: 12px; padding: 7px 12px; }
}
