/* =========================================
   Post Editor Mobile CSS & Responsive
   ========================================= */

/* Default: Mobile header hidden on desktop */
.mobile-header-container,
.mobile-bottom-sheet {
    display: none;
}

/* Responsive Breakpoint: Mobile & Tablet (< 1025px) */
@media (max-width: 1024px) {

    /* 0. Root/Body Reset for Edge-to-Edge */
    html,
    body {
        overflow-x: hidden !important;
        position: relative;
        width: 100%;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 1. Layout Adjustments */
    .post-editor {
        padding: 0;
        min-height: 100vh;
        border-radius: 0;
        box-shadow: none;
        width: 100% !important;
        background-color: #ffffff;
        margin: 0 !important;
    }

    .split-container {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding-top: 54px !important;
        /* Space for fixed mobile header */
        padding-bottom: 0 !important;
        background-color: #ffffff;
        position: static !important;
        /* Avoid transform/positioning issues for fixed children */
        transform: none !important;
        overflow-x: hidden;
    }

    .editor-header {
        display: none !important;
    }

    .main-content {
        padding: 0 !important;
        width: 100% !important;
        margin: 0 !important;
    }

    /* Hide redundant desktop meta fields (Board, Tags) */
    .post-meta {
        display: none !important;
    }

    .title-row {
        display: block !important;
    }

    .title-row #savePost {
        display: none !important;
    }

    /* 2. Global Header Hiding (Force Hide) */
    #header-container {
        display: none !important;
    }

    /* 3. Mobile Custom Header */
    .mobile-header-container {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 3500;
        background: rgba(255, 255, 255, 1);
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }

    .mobile-status-bar-spacer {
        height: env(safe-area-inset-top, 0px);
        background: #fff;
    }

    .mobile-custom-header {
        height: 54px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
    }

    .mobile-header-btn {
        background: none;
        border: none;
        font-size: 1rem;
        color: #555;
        padding: 8px 0;
        cursor: pointer;
        min-width: 44px;
    }

    .mobile-header-btn.primary {
        color: var(--color-primary);
        font-weight: 600;
    }

    .mobile-header-cta {
        background: #f0f4f8;
        border: none;
        border-radius: 20px;
        padding: 6px 14px;
        font-size: 0.95rem;
        color: #333;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 6px;
        cursor: pointer;
    }

    /* 4. Mobile Bottom Sheet Modal */
    .mobile-bottom-sheet {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 5000;
        pointer-events: none;
    }

    .mobile-bottom-sheet-backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: auto;
        visibility: hidden;
        z-index: 1;
    }

    .mobile-bottom-sheet-content {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-radius: 24px 24px 0 0;
        padding: 24px;
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        pointer-events: auto;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
        max-height: 80vh;
        overflow-y: auto;
        z-index: 2;
    }

    .mobile-bottom-sheet.open {
        pointer-events: auto;
    }

    .mobile-bottom-sheet.open .mobile-bottom-sheet-backdrop {
        opacity: 1;
        visibility: visible;
    }

    .mobile-bottom-sheet.open .mobile-bottom-sheet-content {
        transform: translateY(0);
    }

    .mobile-bottom-sheet-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 1.5rem;
    }

    .mobile-bottom-sheet-header h3 {
        margin: 0;
        font-size: 1.2rem;
        color: #333;
        font-weight: 600;
    }

    .close-mobile-sheet {
        background: #f5f5f5;
        border: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        color: #666;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        line-height: 1;
        transition: all 0.2s ease;
    }

    .close-mobile-sheet:hover {
        background: #e0e0e0;
        color: #333;
    }

    .mobile-input,
    .mobile-select {
        width: 100%;
        padding: 14px;
        border: 1px solid #ddd;
        border-radius: 12px;
        font-size: 1rem;
        background: #f9f9f9;
        margin-bottom: 1rem;
        box-sizing: border-box;
    }

    #mobileApplyCategoryBtn {
        display: none !important;
    }

    /* 5. Mobile Sidebar Overrides */
    .classics-list {
        position: fixed;
        right: -100%;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 360px;
        height: 100vh;
        z-index: 4500;
        border-radius: 0;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.1);
        transition: right 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    }

    .classics-list.active {
        display: flex;
        right: 0;
    }

    .close-sidebar-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        background: #f0f2f5;
        border: none;
        border-radius: 50%;
        color: #555;
        font-size: 1.1rem;
        cursor: pointer;
        flex-shrink: 0;
        /* Prevent button from shrinking */
    }

    html[data-theme="dark"] .close-sidebar-btn,
    body[data-theme="dark"] .close-sidebar-btn {
        background: #262d36;
        border: 1px solid #364252;
        color: #d3deeb;
    }

    /* Mobile Sidebar Header Refinements */
    .classics-panel-header {
        padding: 1rem 1rem 0.75rem 1rem !important;
    }

    .classics-panel-header>div {
        display: flex;
        align-items: center;
        /* Vertically center chip and button */
        justify-content: space-between;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .classics-panel-header .classic-chip {
        margin-bottom: 0 !important;
        /* Remove bottom margin on mobile */
        display: inline-flex;
        align-items: center;
    }

    .classics-panel-header p {
        font-size: 0.8rem;
        line-height: 1.5;
        margin: 0;
    }

    #toggleClassicSidebar {
        display: flex !important;
        position: fixed;
        top: auto;
        bottom: 118px;
        right: 20px;
        width: 50px;
        height: 50px;
        z-index: 100 !important;
        background: #fff;
        border: 1px solid #e0e0e0;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border-radius: 50%;
    }

    html[data-theme="dark"] #toggleClassicSidebar,
    body[data-theme="dark"] #toggleClassicSidebar {
        background: #2f5f96 !important;
        border-color: #2f5f96 !important;
        color: #f5f8fc !important;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45) !important;
    }

    html[data-theme="dark"] #toggleClassicSidebar i,
    body[data-theme="dark"] #toggleClassicSidebar i {
        color: #f5f8fc !important;
    }

    /* 6. Mobile Editor Toolbar - Floating Bottom Center */
    #editor-toolbar {
        position: fixed !important;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        width: calc(100vw - 16px) !important;
        max-width: 980px !important;
        z-index: 4000 !important;
        /* Higher than FAB */
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid #e5e7eb;
        border-radius: 14px;
        margin: 0 !important;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)) 8px !important;
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        scrollbar-width: none;
        box-shadow: 0 12px 30px rgba(15, 23, 42, 0.2);
    }

    .toolbar-group {
        flex-shrink: 0;
        margin-right: 8px;
        padding-right: 8px;
        border-right: 1px solid #eee;
    }

    .toolbar-btn span {
        display: none;
    }

    /* 7. Hide Elements */
    #savePost {
        display: none !important;
    }

    /* 8. Mobile Edge-to-Edge Styles */
    .post-title {
        border: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 1.5rem 1rem 0.5rem 1rem !important;
        width: 100% !important;
        box-sizing: border-box;
        background-color: #ffffff;
    }

    .ProseMirror {
        padding: 0.5rem 1rem 140px 1rem !important;
        /* Extra bottom padding for toolbar gap */
        margin: 0 !important;
        width: 100% !important;
        border: none !important;
        box-shadow: none !important;
        outline: none !important;
        min-height: calc(100vh - 120px);
        background-color: #ffffff;
        box-sizing: border-box;
    }

    .editor-content,
    #editor-container {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        background-color: #ffffff;
        width: 100% !important;
    }

    /* 9. Mobile Dark Theme Fix */
    html[data-theme="dark"] .split-container,
    body[data-theme="dark"] .split-container,
    html[data-theme="dark"] .post-editor,
    body[data-theme="dark"] .post-editor,
    html[data-theme="dark"] .main-content,
    body[data-theme="dark"] .main-content,
    html[data-theme="dark"] .editor-content,
    body[data-theme="dark"] .editor-content,
    html[data-theme="dark"] #editor-container,
    body[data-theme="dark"] #editor-container,
    html[data-theme="dark"] .ProseMirror,
    body[data-theme="dark"] .ProseMirror,
    html[data-theme="dark"] .post-title,
    body[data-theme="dark"] .post-title {
        background-color: #10100f !important;
        color: #edf0f3 !important;
        border-color: #2a2a2a !important;
    }

    html[data-theme="dark"] .mobile-header-container,
    body[data-theme="dark"] .mobile-header-container,
    html[data-theme="dark"] .mobile-status-bar-spacer,
    body[data-theme="dark"] .mobile-status-bar-spacer,
    html[data-theme="dark"] .mobile-custom-header,
    body[data-theme="dark"] .mobile-custom-header,
    html[data-theme="dark"] #editor-toolbar,
    body[data-theme="dark"] #editor-toolbar {
        background: rgba(16, 16, 15, 0.96) !important;
        border-color: #2a2a2a !important;
    }

    html[data-theme="dark"] .toolbar-group,
    body[data-theme="dark"] .toolbar-group {
        border-right-color: #2a2a2a !important;
    }
}
