/* =========================================================================
   Blog Management page — mobile makeover. Same pattern as Reviews/Bookings:
     - Desktop header card + stats grid hidden
     - Fixed top bar: search input + filter button (Bookings pattern),
       opening a drawer with Status / Category filters + a "Categories"
       shortcut (categories management moves here since the desktop
       "Categories" button is gone on mobile)
     - "+ New Post" → purple FAB
     - Table → cards (CSS grid transform, same trick as reviews-management)
     - Post editor modal: full-viewport with sticky header/footer
     - Categories modal: bottom sheet (short content, no need for full height)

   Class prefix is `blogflt-` (not `bm-`) for the search/filter/drawer bits
   deliberately — bookings-mobile.css already owns a global (unscoped)
   `.bm-drawer-wrap` / `.bm-fab` / `.bm-sheet-*` component set appended to
   document.body, and reusing that same "bm" prefix here would collide with
   it site-wide, not just within #blog-management.
   ========================================================================= */

#bmMobileHeader { display: none; }

/* Both action variants are always rendered per row (see renderBlogPostsRows
   in blog-management.js) — visibility is a pure CSS/media-query decision,
   not something computed once at render time, so resizing across the
   breakpoint updates instantly without needing the table to re-render. */
#blog-management .bm-actions-mobile { display: none; }

@media (max-width: 767px) {

    #blog-management {
        padding-top: 56px !important;
        padding-bottom: 90px !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* Hide the whole desktop header card (title + Categories/New Post buttons) */
    #blog-management > .modern-content-card.u-mb-4 {
        display: none !important;
    }

    /* Fixed mobile top bar — search + filter button, same shape as the
       Bookings page. New Post moves to the FAB; Categories moves into the
       filter drawer (see .blogflt-drawer below). */
    #bmMobileHeader {
        display: flex !important;
        gap: 0.5rem;
        position: fixed !important;
        top: 56px; left: 0; right: 0;
        z-index: 990;
        padding: 0.55rem 0.75rem;
        background: #fff;
        border-bottom: 1px solid #e5e7eb;
    }
    #bmMobileHeader .blogflt-search {
        flex: 1;
        min-width: 0;
        padding: 0.55rem 0.75rem;
        border: 1px solid #d1d5db;
        border-radius: 8px;
        font-size: 0.9rem;
        background: #fff;
        color: #111827;
        outline: none;
    }
    #bmMobileHeader .blogflt-search:focus { border-color: #6366f1; }
    #bmMobileHeader .blogflt-btn {
        flex-shrink: 0;
        width: 40px; height: 40px;
        border-radius: 8px;
        border: 1px solid #d1d5db;
        background: #fff;
        color: #4b5563;
        display: inline-flex;
        align-items: center; justify-content: center;
        cursor: pointer;
        position: relative;
    }
    #bmMobileHeader .blogflt-btn[data-has-filters="1"]::after {
        content: "";
        position: absolute; top: 6px; right: 6px;
        width: 8px; height: 8px;
        border-radius: 50%;
        background: #6366f1;
    }

    /* Purple FAB — New Post (matches Bookings / Reviews / Gallery) */
    #blog-management .bm-fab {
        display: inline-flex !important;
        position: fixed !important;
        bottom: 90px !important;
        right: 16px !important;
        z-index: 900 !important;
        width: 56px !important;
        height: 56px !important;
        border-radius: 12px !important;
        background: linear-gradient(135deg, #667eea, #764ba2) !important;
        color: #fff !important;
        border: 2px solid rgba(255, 255, 255, 0.2) !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4) !important;
        cursor: pointer !important;
        padding: 0 !important;
    }
    #blog-management .bm-fab svg { width: 22px !important; height: 22px !important; color: #fff !important; }
    #blog-management .bm-fab:active { transform: scale(0.95); }

    /* Stats grid — hidden on mobile; the top bar takes that space instead. */
    #blog-management .stats-grid {
        display: none !important;
    }

    /* Table card — strip wrapper, compact title */
    #blog-management > .modern-content-card:last-of-type {
        background: transparent !important;
        border: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
    }
    /* "All Posts" section title — dropped entirely on mobile rather than
       compacted; the search/filter bar already establishes context. */
    #blog-management .modern-section-header {
        display: none !important;
    }

    /* Table → cards. Columns: Post | Category | Status | Date | Actions
       Layout: [Title ......... Actions]
               [Category ...... Status ]
               [Date (full width, muted)] */
    #blog-management .table-container { overflow-x: visible !important; padding: 0 !important; border: none !important; }
    #blog-management .data-table { display: block !important; width: 100% !important; min-width: 0 !important; background: transparent !important; border: none !important; }
    #blog-management .data-table thead { display: none !important; }
    #blog-management .data-table tbody { display: flex !important; flex-direction: column !important; gap: 8px !important; }
    #blog-management .data-table tbody tr {
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        gap: 6px 12px !important;
        background: #fff !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 10px !important;
        padding: 12px !important;
    }
    #blog-management .data-table tbody td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
    }
    /* Post title + slug (col 1) — top-left */
    #blog-management .data-table tbody td:nth-child(1) {
        grid-row: 1 !important;
        grid-column: 1 !important;
    }
    /* Actions (col 5) — top-right */
    #blog-management .data-table tbody td:nth-child(5) {
        grid-row: 1 !important;
        grid-column: 2 !important;
        justify-self: end !important;
        align-self: start !important;
    }
    /* 3-dot "more" button replacing the two icon buttons — both variants are
       in the DOM (see renderBlogPostsRows), this media query just swaps
       which one is visible. */
    #blog-management .bm-actions-desktop { display: none !important; }
    #blog-management .blogflt-more-btn {
        display: inline-flex !important;
        width: 36px !important;
        height: 36px !important;
        border: none !important;
        background: #f3f4f6 !important;
        color: #4b5563 !important;
        border-radius: 8px !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        padding: 0 !important;
    }
    #blog-management .blogflt-more-btn:active { background: #e5e7eb !important; }
    /* Category chip (col 2) — row 2, left */
    #blog-management .data-table tbody td:nth-child(2) {
        grid-row: 2 !important;
        grid-column: 1 !important;
    }
    /* Status pill (col 3) — row 2, right */
    #blog-management .data-table tbody td:nth-child(3) {
        grid-row: 2 !important;
        grid-column: 2 !important;
        justify-self: end !important;
    }
    /* Date (col 4) — row 3, full width, muted */
    #blog-management .data-table tbody td:nth-child(4) {
        grid-row: 3 !important;
        grid-column: 1 / -1 !important;
        font-size: 0.75rem !important;
        color: #9ca3af !important;
    }

    /* Empty state — tighten */
    #blog-management #blogPostsEmpty { padding: 32px 20px !important; }
    #blog-management #blogPostsEmpty .btn {
        width: 100% !important;
        height: 44px !important;
        border-radius: 10px !important;
        justify-content: center !important;
        background: linear-gradient(135deg, #667eea, #764ba2) !important;
        color: #fff !important;
        border: none !important;
    }

    /* -----------------------------------------------------------------
       Post Editor modal — full-viewport, sticky header/footer
       ----------------------------------------------------------------- */
    #blogPostModal.modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }
    #blogPostModal .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        background: #fff !important;
    }
    #blogPostModal .modal-header {
        padding: 14px 20px !important;
        background: #fff !important;
        color: #111827 !important;
        border-bottom: 1px solid #f3f4f6 !important;
        flex-shrink: 0 !important;
        border-radius: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    #blogPostModal .modal-header h2 { font-size: 1.05rem !important; margin: 0 !important; color: #111827 !important; }
    #blogPostModal .modal-close {
        background: #f3f4f6 !important; color: #6b7280 !important; border: none !important;
        width: 32px !important; height: 32px !important; border-radius: 50% !important;
    }
    #blogPostModal .modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        overflow-y: auto !important;
        flex: 1 !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }
    #blogPostModal .form-group { margin-bottom: 12px !important; }
    #blogPostModal .form-group > label {
        font-size: 0.85rem !important; font-weight: 600 !important; color: #374151 !important;
        display: block !important; margin-bottom: 4px !important;
    }
    #blogPostModal .form-group input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    #blogPostModal .form-group select,
    #blogPostModal .form-group textarea {
        width: 100% !important;
        min-height: 42px !important;
        padding: 8px 12px !important;
        border: 1px solid #d1d5db !important;
        border-radius: 8px !important;
        font-size: 0.95rem !important;
        background: #fff !important;
        box-sizing: border-box !important;
    }
    #blogPostModal .form-group textarea { min-height: 80px !important; resize: vertical !important; }
    #blogPostModal .bm-publish-modes { flex-wrap: wrap !important; gap: 0.75rem 1.25rem !important; }
    #blogPostModal .modal-footer {
        padding: 10px 14px calc(10px + env(safe-area-inset-bottom)) !important;
        background: #fff !important;
        border-top: 1px solid #f3f4f6 !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
    }
    /* admin-styles.css has a global mobile rule forcing .modal-footer into a
       column with full-width buttons (most modals want stacked buttons on
       phone) — flex-direction above overrides the stacking, width here
       overrides the "full width per button" so they end up side by side
       instead of stacked, matching the Reviews modal. */
    #blogPostModal .modal-footer .btn {
        flex: 1 1 0 !important;
        width: 50% !important;
        min-width: 0 !important;
        margin: 0 !important;
        height: 44px !important;
        border-radius: 10px !important;
        font-weight: 600 !important;
        font-size: 0.9rem !important;
        padding: 0 8px !important;
    }

    /* -----------------------------------------------------------------
       Categories modal — bottom sheet (short content, no full height)
       ----------------------------------------------------------------- */
    #blogCategoriesModal.modal {
        padding: 0 !important;
        align-items: flex-end !important;
    }
    #blogCategoriesModal .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        /* height (not just max-height) must be overridden — mobile-optimized.css's
           generic .modal-content sets height: 100vh with no !important, and
           since nothing here countered `height` itself before, that 100vh
           won by default, stretching the sheet full-screen and leaving a
           large empty gap above the footer. auto lets it hug its content up
           to the max-height cap instead. */
        height: auto !important;
        max-height: 80vh !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
    #blogCategoriesModal .modal-body {
        overflow-y: auto !important;
    }
    /* Same header/footer overrides as blogPostModal above — otherwise this
       modal inherits the same generic purple-gradient header and stacked
       full-width footer buttons. */
    #blogCategoriesModal .modal-header {
        background: #fff !important;
        color: #111827 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        border-radius: 16px 16px 0 0 !important;
    }
    #blogCategoriesModal .modal-header h2 { color: #111827 !important; font-size: 1.05rem !important; margin: 0 !important; }
    #blogCategoriesModal .modal-close {
        background: #f3f4f6 !important; color: #6b7280 !important; border: none !important;
        width: 32px !important; height: 32px !important; border-radius: 50% !important;
    }
    #blogCategoriesModal .modal-footer {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
    }
    #blogCategoriesModal .modal-footer .btn {
        flex: 1 1 0 !important;
        width: 50% !important;
        min-width: 0 !important;
        margin: 0 !important;
        height: 44px !important;
        border-radius: 10px !important;
    }
    #blogCategoriesModal .form-group,
    #blogNewCategoryForm input {
        font-size: 0.95rem !important;
    }
    #blogNewCategoryForm { flex-wrap: wrap !important; }
    #blogNewCategoryForm input {
        min-height: 42px !important;
        padding: 8px 12px !important;
        border: 1px solid #d1d5db !important;
        border-radius: 8px !important;
        box-sizing: border-box !important;
    }
}

/* ---------------------------------------------------------------------
   Filter drawer — appended to document.body when opened (see
   window.openBlogFilterDrawer in blog-management.js), so it's styled
   outside the #blog-management-scoped media query above, same as the
   Reviews/Bookings drawers. Deliberately prefixed `blogflt-`, not `bm-` —
   see the file header note on the bookings-mobile.css naming collision.
   --------------------------------------------------------------------- */
.blogflt-drawer-wrap {
    position: fixed;
    inset: 0;
    z-index: 10000;
}
.blogflt-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 0.2s;
}
.blogflt-drawer-wrap.is-open .blogflt-drawer-backdrop { background: rgba(0, 0, 0, 0.35); }
.blogflt-drawer {
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 88%;
    max-width: 380px;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.22s ease-out;
    display: flex;
    flex-direction: column;
}
.blogflt-drawer-wrap.is-open .blogflt-drawer { transform: translateX(0); }
.blogflt-drawer-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 700;
    font-size: 1.05rem;
    color: #111827;
}
.blogflt-drawer-close {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    color: #6b7280;
    cursor: pointer;
    line-height: 1;
}
.blogflt-drawer-body {
    padding: 1rem 1.15rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.blogflt-drawer-body .form-group {
    display: block;
    width: 100%;
    margin: 0 0 14px 0;
}
.blogflt-drawer-body .form-group > label {
    font-size: 0.85rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 6px;
    display: block;
}
.blogflt-drawer-body select {
    width: 100%;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    font-size: 0.95rem;
    box-sizing: border-box;
}
/* Categories + Clear Filters actions, pinned to the bottom of the drawer */
.blogflt-drawer-actions {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.blogflt-drawer-actions button {
    width: 100%;
    min-height: 42px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    border: 1px solid #e5e7eb;
    background: #f3f4f6;
    color: #374151;
}

/* ---------------------------------------------------------------------
   Bottom action sheet (Edit/Delete) — appended to document.body when a
   post's 3-dot button is tapped (see window.openBlogPostActionSheet in
   blog-management.js). Same component shape as bookings/reviews, own
   `blogflt-` prefix for the same collision-avoidance reason as the drawer.
   --------------------------------------------------------------------- */
.blogflt-sheet-wrap {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
}
.blogflt-sheet-wrap.is-open { pointer-events: auto; }
.blogflt-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 0.2s;
    pointer-events: auto;
}
.blogflt-sheet-wrap.is-open .blogflt-sheet-backdrop { background: rgba(0, 0, 0, 0.4); }
.blogflt-sheet {
    position: relative;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.22s ease-out;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    max-height: 85vh;
    overflow-y: auto;
}
.blogflt-sheet-wrap.is-open .blogflt-sheet { transform: translateY(0); }
.blogflt-sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #e5e7eb;
    margin: 4px auto 12px;
}
.blogflt-sheet-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: #111827;
    text-align: center;
    margin-bottom: 8px;
    padding: 0 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.blogflt-sheet-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}
.blogflt-sheet-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: #111827;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    border-radius: 10px;
}
.blogflt-sheet-item:active { background: #f3f4f6; }
.blogflt-sheet-item.is-danger { color: #991b1b; }
.blogflt-sheet-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.blogflt-sheet-divider {
    height: 1px;
    background: #f3f4f6;
    margin: 6px 8px;
}
.blogflt-sheet-cancel {
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    background: #f3f4f6;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
}
