/* =========================================================================
   Gallery Management page — mobile makeover.
     - Title/subtitle hidden
     - "Upload Image" → purple FAB in the bottom-right
     - Stats grid compacted to a 3-column tight row
     - Gallery grid: 2 columns on phone
     - Upload / Edit modals full-viewport with sticky footer
   ========================================================================= */

@media (max-width: 767px) {

    #gallery-management {
        padding: 8px !important;
        padding-bottom: 100px !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    /* Nuke the whole desktop header (title/subtitle + Upload button).
       A dedicated .gm-fab element in the HTML handles the mobile FAB.
       Needs the [style] attribute selector to beat mobile-optimized.css
       :3423 which forces display: block via the same attribute trick. */
    #gallery-management > .page-header,
    #gallery-management > .page-header[style],
    #gallery-management .page-header,
    #gallery-management .page-header[style] {
        display: none !important;
    }
    /* Also cancel the button width: 100% override from mobile-optimized.css
       so it can't leak through if the page-header ever re-appears. */
    #gallery-management .page-header > button {
        width: auto !important;
    }

    /* Mobile-only FAB — purple rounded square with a bold "+" glyph */
    #gallery-management > .gm-fab {
        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;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4) !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 28px !important;
        font-weight: 400 !important;
        line-height: 1 !important;
        cursor: pointer !important;
    }
    #gallery-management > .gm-fab:active {
        transform: scale(0.95);
    }

    /* Stats grid — 3 columns tight */
    #gallery-management .stats-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr 1fr !important;
        gap: 6px !important;
        margin: 0 0 10px 0 !important;
    }
    #gallery-management .stat-card {
        padding: 10px 8px !important;
        border-radius: 10px !important;
        text-align: center !important;
        background: #fff !important;
        border: 1px solid #e5e7eb !important;
    }
    #gallery-management .stat-label {
        font-size: 0.65rem !important;
        color: #6b7280 !important;
        margin-bottom: 2px !important;
        font-weight: 600 !important;
    }
    #gallery-management .stat-value {
        font-size: 1.1rem !important;
        font-weight: 700 !important;
        color: #111827 !important;
    }

    /* Gallery grid — 2 columns on phone */
    #gallery-management .gallery-management-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }
    #gallery-management .gallery-item-card {
        border-radius: 10px !important;
        box-shadow: none !important;
        border: 1px solid #e5e7eb !important;
    }
    #gallery-management .gallery-item-card:hover {
        box-shadow: none !important;
    }
    #gallery-management .gallery-item-content {
        padding: 8px !important;
    }
    #gallery-management .gallery-item-title {
        font-size: 0.85rem !important;
        margin: 0 0 4px 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    #gallery-management .gallery-item-meta {
        gap: 4px !important;
        margin-bottom: 8px !important;
    }
    #gallery-management .gallery-badge {
        font-size: 0.6rem !important;
        padding: 2px 6px !important;
    }
    #gallery-management .gallery-item-actions {
        gap: 4px !important;
    }
    #gallery-management .gallery-item-actions button {
        padding: 8px 4px !important;
        font-size: 0.75rem !important;
        border-radius: 8px !important;
        min-height: 36px !important;
    }

    /* Empty state — tighten */
    #gallery-management #galleryEmpty {
        padding: 32px 20px !important;
    }
    #gallery-management #galleryEmpty .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;
    }

    /* -----------------------------------------------------------------
       Upload + Edit Gallery modals — full-viewport
       ----------------------------------------------------------------- */
    #uploadGalleryModal.modal,
    #editGalleryModal.modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }
    #uploadGalleryModal .modal-content,
    #editGalleryModal .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;
    }
    #uploadGalleryModal .modal-header,
    #editGalleryModal .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;
    }
    #uploadGalleryModal .modal-header h2,
    #editGalleryModal .modal-header h2 {
        color: #111827 !important;
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
    }
    #uploadGalleryModal .modal-close,
    #editGalleryModal .modal-close {
        background: #f3f4f6 !important;
        color: #6b7280 !important;
        border: none !important;
        width: 32px !important;
        height: 32px !important;
        border-radius: 50% !important;
    }
    #uploadGalleryModal .modal-body,
    #editGalleryModal .modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        overflow-y: auto !important;
        flex: 1 !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }
    /* Preview image bounds — full-width, capped height */
    #uploadGalleryModal #galleryPreviewImg,
    #editGalleryModal #editGalleryCurrentImage {
        width: 100% !important;
        max-height: 200px !important;
    }
    /* Form fields */
    #uploadGalleryModal .form-group,
    #editGalleryModal .form-group {
        margin-bottom: 12px !important;
    }
    #uploadGalleryModal .form-group > label,
    #editGalleryModal .form-group > label {
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        color: #374151 !important;
        display: block !important;
        margin-bottom: 4px !important;
    }
    #uploadGalleryModal .form-group input:not([type="checkbox"]):not([type="file"]),
    #uploadGalleryModal .form-group select,
    #uploadGalleryModal .form-group textarea,
    #editGalleryModal .form-group input:not([type="checkbox"]):not([type="file"]),
    #editGalleryModal .form-group select,
    #editGalleryModal .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;
    }
    #uploadGalleryModal .form-group textarea,
    #editGalleryModal .form-group textarea {
        min-height: 80px !important;
        resize: vertical !important;
    }
    #uploadGalleryModal .form-group input:focus,
    #uploadGalleryModal .form-group select:focus,
    #uploadGalleryModal .form-group textarea:focus,
    #editGalleryModal .form-group input:focus,
    #editGalleryModal .form-group select:focus,
    #editGalleryModal .form-group textarea:focus {
        outline: none !important;
        border-color: #6366f1 !important;
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
    }
    #uploadGalleryModal .form-group small,
    #editGalleryModal .form-group small {
        display: block !important;
        margin-top: 4px !important;
        font-size: 0.75rem !important;
        color: #6b7280 !important;
    }
    /* File input — bigger tap area */
    #uploadGalleryModal input[type="file"] {
        width: 100% !important;
        padding: 10px !important;
        border: 1px dashed #d1d5db !important;
        border-radius: 8px !important;
        background: #fff !important;
        font-size: 0.9rem !important;
    }
    /* Checkbox tile */
    #uploadGalleryModal .checkbox-group,
    #editGalleryModal .checkbox-group {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        background: #fff !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 10px !important;
        padding: 10px 12px !important;
    }
    #uploadGalleryModal .checkbox-group input[type="checkbox"],
    #editGalleryModal .checkbox-group input[type="checkbox"] {
        width: 18px !important;
        height: 18px !important;
        min-height: 0 !important;
        padding: 0 !important;
        accent-color: #6366f1 !important;
        flex-shrink: 0 !important;
    }
    #uploadGalleryModal .checkbox-group label,
    #editGalleryModal .checkbox-group label {
        font-size: 0.9rem !important;
        color: #111827 !important;
        margin: 0 !important;
        cursor: pointer !important;
    }

    /* Sticky footer (Cancel + Upload/Save) */
    #uploadGalleryModal .modal-footer,
    #editGalleryModal .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;
    }
    #uploadGalleryModal .modal-footer .btn,
    #editGalleryModal .modal-footer .btn {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        width: 50% !important;
        margin: 0 !important;
        height: 44px !important;
        border-radius: 10px !important;
        font-weight: 600 !important;
        font-size: 0.9rem !important;
        padding: 0 8px !important;
    }
    #uploadGalleryModal .modal-footer .btn-secondary,
    #editGalleryModal .modal-footer .btn-secondary {
        background: #f3f4f6 !important;
        color: #374151 !important;
        border: 1px solid #e5e7eb !important;
    }
    #uploadGalleryModal .modal-footer .btn-primary,
    #editGalleryModal .modal-footer .btn-primary {
        background: linear-gradient(135deg, #667eea, #764ba2) !important;
        color: #fff !important;
        border: none !important;
    }
}
