/**
 * Inline Editor Styles
 * Mobile-responsive design with <768px breakpoints
 */

/* =====================================================
   Section Container
   ===================================================== */

.section-container {
    margin: 1.5rem 0;
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    transition: all 0.2s ease;
}

.section-container:hover {
    border-color: #bbb;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* =====================================================
   View Mode
   ===================================================== */

.section-view {
    position: relative;
}

.section-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
}

.edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid #3b82f6;
    border-radius: 6px;
    background: #fff;
    color: #3b82f6;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.edit-btn:hover {
    background: #3b82f6;
    color: #fff;
}

.edit-btn:active {
    transform: scale(0.98);
}

.edit-icon {
    font-size: 1rem;
}

.section-content {
    padding: 1rem;
    line-height: 1.6;
    color: #333;
}

/* =====================================================
   Edit Mode
   ===================================================== */

.section-edit {
    background: #f8f9fa;
    border: 2px solid #3b82f6;
    border-radius: 8px;
    padding: 1rem;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    flex-wrap: wrap;
}

.toolbar-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: #f0f0f0;
    border-color: #bbb;
}

.toolbar-btn:active {
    transform: scale(0.96);
}

.toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.save-status {
    margin-left: auto;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 4px;
}

.status-saving {
    color: #1d4ed8;
    background: #eff6ff;
}

.status-saved {
    color: #15803d;
    background: #f0fdf4;
}

.status-error {
    color: #dc2626;
    background: #fef2f2;
}

/* =====================================================
   Editor Container
   ===================================================== */

.editor-container {
    position: relative;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
}

.markdown-editor {
    width: 100%;
    min-height: 300px;
    padding: 1rem;
    border: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #333;
    background: #fff;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
}

.markdown-editor:focus {
    background: #fefefe;
}

.markdown-preview {
    width: 100%;
    min-height: 300px;
    padding: 1rem;
    background: #fafafa;
    border-top: 1px solid #ddd;
    overflow-y: auto;
    max-height: 600px;
}

.markdown-preview pre {
    background: #f4f4f4;
    padding: 0.5rem;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.9rem;
}

/* =====================================================
   Editor Hints
   ===================================================== */

.editor-hints {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #78350f;
}

.editor-hints strong {
    color: #92400e;
    font-weight: 600;
}

/* =====================================================
   Commentary Popup
   ===================================================== */

.commentary-popup {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.5rem;
    padding: 1rem;
    background: #fffbeb;
    border: 2px solid #fbbf24;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.commentary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.commentary-header strong {
    color: #92400e;
    font-size: 0.95rem;
}

.close-btn-small {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #92400e;
    padding: 0;
    line-height: 1;
}

.close-btn-small:hover {
    color: #78350f;
}

.commentary-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d97706;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 0.75rem;
    box-sizing: border-box;
}

.commentary-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.commentary-select {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #d97706;
    border-radius: 4px;
    font-size: 0.9rem;
    background: white;
}

.btn-save-commentary {
    padding: 0.5rem 1.5rem;
    background: #f59e0b;
    color: white;
    border: none;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-save-commentary:hover {
    background: #d97706;
}

/* Commentary display in content */
.editorial-commentary {
    margin: 1rem 0;
    padding: 1rem;
    background: #fffbeb;
    border-left: 4px solid #fbbf24;
    border-radius: 4px;
    font-style: italic;
    color: #92400e;
}

.editorial-commentary::before {
    content: "Jon's Note: ";
    font-weight: 600;
    font-style: normal;
}

/* =====================================================
   Mobile Responsiveness (<768px)
   ===================================================== */

@media (max-width: 768px) {
    .section-container {
        margin: 1rem 0;
        padding: 0.75rem;
    }

    .editor-toolbar {
        gap: 0.4rem;
        padding: 0.5rem;
    }

    .toolbar-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .save-status {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }

    .markdown-editor {
        min-height: 200px;
        font-size: 0.9rem;
        padding: 0.75rem;
    }

    .editor-hints {
        font-size: 0.75rem;
        padding: 0.5rem;
    }

    /* Stack toolbar buttons vertically on very small screens */
    @media (max-width: 480px) {
        .editor-toolbar {
            flex-direction: column;
            align-items: stretch;
        }

        .toolbar-btn {
            width: 100%;
            text-align: center;
        }

        .save-status {
            margin-left: 0;
            margin-top: 0.5rem;
            text-align: center;
        }
    }
}

/* =====================================================
   Mobile Keyboard Handling
   ===================================================== */

/* Ensure save button visible when soft keyboard is open */
@media (max-width: 768px) {
    .section-edit {
        padding-bottom: 60px; /* Extra padding for mobile keyboard */
    }

    /* Sticky toolbar on mobile */
    .editor-toolbar {
        position: sticky;
        top: 0;
        z-index: 10;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
}

/* =====================================================
   Touch-Friendly Interactions (Mobile)
   ===================================================== */

@media (hover: none) and (pointer: coarse) {
    /* Touch devices */

    .edit-btn,
    .toolbar-btn {
        min-height: 44px; /* iOS touch target minimum */
        min-width: 44px;
        padding: 0.6rem 1rem;
    }

    .markdown-editor {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 1rem;
    }
}

/* =====================================================
   Dark Mode Support (Optional Enhancement)
   ===================================================== */

@media (prefers-color-scheme: dark) {
    .section-container {
        background: #1f2937;
        border-color: #374151;
        color: #f3f4f6;
    }

    .section-edit {
        background: #111827;
        border-color: #3b82f6;
    }

    .markdown-editor {
        background: #1f2937;
        color: #f3f4f6;
    }

    .markdown-editor:focus {
        background: #27303f;
    }

    .editor-toolbar {
        background: #1f2937;
        border-color: #374151;
    }

    .toolbar-btn {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }

    .toolbar-btn:hover {
        background: #4b5563;
    }

    .editor-hints {
        background: #422006;
        border-color: #fcd34d;
        color: #fef3c7;
    }
}
