/**
 * Memorial Book Editor - Professional Book-Like Design
 * Matches the preview page design for consistent UX
 */

/* ============================================
   VARIABLES (Match Preview)
   ============================================ */

:root {
    /* Memorial-appropriate colors */
    --memorial-charcoal: #1F2937;
    --memorial-gray: #6B7280;
    --memorial-light-gray: #9CA3AF;
    --memorial-off-white: #FEFEFE;
    --memorial-cream: #FFF9F0;
    --memorial-brown: #8B7355;
    --memorial-slate: #4A5568;
    --memorial-border: #E5E5E5;
    
    /* Book dimensions */
    --page-width-desktop: 600px;
    --page-height-desktop: auto;
    --page-min-height: 800px;
    --page-padding-desktop: 48px;
    --page-padding-mobile: 24px;
    
    /* Typography */
    --font-serif: 'Crimson Text', 'Georgia', 'Garamond', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ============================================
   GLOBAL EDITOR CONTAINER
   ============================================ */

.memorial-editor-container {
    width: 100%;
    min-height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    display: flex;
    flex-direction: column;
}

/* ============================================
   EDITOR HEADER (Match Preview Header)
   ============================================ */

.editor-header {
    background: var(--memorial-charcoal);
    color: var(--memorial-off-white);
    padding: 20px 32px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

.editor-header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-title {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.editor-title h1 {
    font-family: var(--font-sans);
    font-size: 24px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.editor-logo {
    max-height: 60px;
    max-width: 300px;
    height: auto;
    width: auto;
    object-fit: contain;
}

.editor-subtitle {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--memorial-light-gray);
    display: flex;
    align-items: center;
    gap: 8px;
}

.save-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.editor-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.editor-action-btn {
    background-color: black;
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--memorial-off-white);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-sans);
    font-weight: 500;
}

.editor-action-btn:hover {
    background: #c9a76a;
    border-color: rgba(255,255,255,0.3);
}

.editor-action-btn.btn-primary {
    background: #10B981;
    border-color: #10B981;
}

.editor-action-btn.btn-primary:hover {
    background: #059669;
    border-color: #059669;
}

.editor-action-btn i {
    font-size: 16px;
}

/* ============================================
   EDITOR LAYOUT (3 Columns)
   ============================================ */

.editor-workspace {
    display: flex;
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Left Sidebar - Navigation */
.editor-sidebar-left {
    width: 280px;
    background: white;
    border-right: 1px solid var(--memorial-border);
    overflow-y: auto;
    padding: 20px;
}

.sidebar-section {
    margin-bottom: 32px;
}

.sidebar-section-title {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--memorial-charcoal);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.page-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.page-list-item {
    padding: 10px 12px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    color: var(--memorial-gray);
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-list-item:hover {
    background: var(--memorial-off-white);
}

.page-list-item.active {
    background: #DBEAFE;
    color: #1E40AF;
    font-weight: 600;
}

.page-list-item i {
    font-size: 14px;
    width: 16px;
}

/* Chapter drag and drop styles */
.chapter-item {
    position: relative;
    cursor: move;
    transition: all 0.2s ease;
}

.chapter-item:hover {
    background: #F3F4F6;
    transform: translateX(2px);
}

.chapter-item.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
    z-index: 1000;
}

.chapter-item.drag-over {
    border-top: 2px solid #3B82F6;
    background: #EFF6FF;
}

.drag-handle {
    cursor: grab;
    color: var(--memorial-light-gray);
    margin-right: 8px;
    transition: color 0.2s ease;
}

.drag-handle:hover {
    color: var(--memorial-gray);
}

.drag-handle:active {
    cursor: grabbing;
}

.chapter-title {
    flex: 1;
    margin-right: 8px;
}

.delete-chapter-btn {
    background: none;
    border: none;
    color: var(--memorial-light-gray);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0;
    margin-left: auto;
}

.chapter-item:hover .delete-chapter-btn {
    opacity: 1;
}

.delete-chapter-btn:hover {
    background: #FEE2E2;
    color: #DC2626;
}

.btn-add-chapter {
    width: 100%;
    padding: 10px 16px;
    background: white;
    border: 2px dashed var(--memorial-border);
    border-radius: 6px;
    color: var(--memorial-gray);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 500;
}

.btn-add-chapter:hover {
    border-color: #3B82F6;
    color: #3B82F6;
    background: #EFF6FF;
}

/* Main Editor Area */
.editor-main {
    flex: 1;
    padding: 40px 20px;
    overflow-y: auto;
    display: flex;
    justify-content: center;
}

.editor-canvas-wrapper {
    width: 100%;
    max-width: var(--page-width-desktop);
}

.editor-canvas {
    background: var(--memorial-off-white);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    min-height: var(--page-min-height);
    position: relative;
}

/* Right Sidebar - Properties */
.editor-sidebar-right {
    width: 320px;
    background: white;
    border-left: 1px solid var(--memorial-border);
    overflow-y: auto;
    padding: 20px;
}

.properties-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--memorial-border);
}

.properties-section:last-child {
    border-bottom: none;
}

.properties-section-title {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--memorial-charcoal);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.property-group {
    margin-bottom: 16px;
}

.property-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--memorial-gray);
    margin-bottom: 6px;
    display: block;
}

.property-control {
    display: flex;
    gap: 8px;
    align-items: center;
}

.property-input,
.property-select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--memorial-border);
    border-radius: 6px;
    font-size: 14px;
    font-family: var(--font-sans);
    transition: all 0.2s;
}

.property-input:focus,
.property-select:focus {
    outline: none;
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.property-btn-group {
    display: flex;
    gap: 4px;
}

.property-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--memorial-border);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--memorial-gray);
}

.property-btn:hover {
    background: #F3F4F6;
    border-color: #3B82F6;
    color: #1F2937;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.property-btn.active {
    background: #3B82F6;
    border-color: #3B82F6;
    color: white;
}

.color-picker-btn {
    width: 40px;
    height: 36px;
    border: 1px solid var(--memorial-border);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.color-picker-btn input[type="color"] {
    position: absolute;
    top: -5px;
    left: -5px;
    width: 50px;
    height: 50px;
    border: none;
    cursor: pointer;
}

/* ============================================
   EDITABLE BOOK PAGE CONTENT
   ============================================ */

.book-page-editor {
    padding: var(--page-padding-desktop);
    font-family: var(--font-serif);
    min-height: var(--page-min-height);
}

.book-page-editor .page-header {
    font-size: 32px;
    font-weight: 600;
    color: var(--memorial-charcoal);
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--memorial-border);
    outline: none;
}

.book-page-editor .page-header:focus {
    background: #FFFBEB;
}

.book-page-editor .page-content {
    font-size: 16px;
    line-height: 1.8;
    color: var(--memorial-charcoal);
    outline: none;
}

.book-page-editor .page-content:focus {
    background: #FFFBEB;
}

.book-page-editor .page-content p {
    margin-bottom: 16px;
    text-align: justify;
    hyphens: auto;
}

.book-page-editor .page-content h2 {
    font-size: 24px;
    font-weight: 600;
    margin: 24px 0 16px;
    color: var(--memorial-charcoal);
}

.book-page-editor .page-content h3 {
    font-size: 20px;
    font-weight: 600;
    margin: 20px 0 12px;
    color: var(--memorial-gray);
}

/* Editable elements */
[contenteditable="true"] {
    cursor: text;
    position: relative;
}

[contenteditable="true"]:hover {
    background: rgba(59, 130, 246, 0.05);
}

[contenteditable="true"]:focus {
    background: #FFFBEB;
    outline: 2px solid #FCD34D;
    outline-offset: 2px;
}

/* Cover Page Specific */
.book-cover-editor {
    padding: var(--page-padding-desktop);
    min-height: var(--page-min-height);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: var(--memorial-cream);
}

.book-cover-editor .book-title {
    font-size: 48px;
    font-weight: 700;
    color: var(--memorial-charcoal);
    margin-bottom: 16px;
    line-height: 1.2;
    outline: none;
}

.book-cover-editor .book-subtitle {
    font-size: 18px;
    color: var(--memorial-gray);
    margin-bottom: 32px;
    outline: none;
}

.book-cover-editor .memorial-name {
    font-size: 24px;
    font-weight: 600;
    color: var(--memorial-charcoal);
    margin-bottom: 12px;
    outline: none;
}

.book-cover-editor .created-for {
    font-size: 16px;
    color: var(--memorial-gray);
    outline: none;
}

.book-cover-editor .book-decoration {
    font-size: 48px;
    color: var(--memorial-brown);
    margin: 32px 0;
}

/* ============================================
   FLOATING TOOLBAR
   ============================================ */

.formatting-toolbar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 8px;
    display: flex;
    gap: 4px;
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.formatting-toolbar.visible {
    opacity: 1;
    pointer-events: all;
}

.toolbar-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--memorial-gray);
    font-size: 16px;
}

.toolbar-btn:hover {
    background: #F3F4F6;
    color: #1F2937;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.toolbar-btn.active {
    background: #3B82F6;
    color: white;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: var(--memorial-border);
    margin: 4px 4px;
}

.toolbar-select {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--memorial-border);
    border-radius: 6px;
    background: white;
    color: var(--memorial-charcoal);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
}

.toolbar-select:hover {
    background: var(--memorial-off-white);
    border-color: #3B82F6;
}

.toolbar-select:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.toolbar-color {
    width: 36px;
    height: 36px;
    border: 1px solid var(--memorial-border);
    border-radius: 6px;
    cursor: pointer;
    padding: 2px;
    background: white;
    transition: all 0.2s;
}

.toolbar-color:hover {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.toolbar-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.toolbar-color::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.toolbar-color::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablet */
@media (max-width: 1280px) {
    .editor-sidebar-right {
        width: 280px;
    }
}

@media (max-width: 1024px) {
    .editor-workspace {
        flex-direction: column;
    }
    
    .editor-sidebar-left,
    .editor-sidebar-right {
        width: 100%;
        border: none;
        border-top: 1px solid var(--memorial-border);
    }
    
    .editor-sidebar-left {
        order: 2;
    }
    
    .editor-main {
        order: 1;
    }
    
    .editor-sidebar-right {
        order: 3;
    }
}

/* Mobile */
@media (max-width: 639px) {
    .editor-header {
        padding: 16px 20px;
    }
    
    .editor-title h1 {
        font-size: 18px;
    }
    
    .editor-subtitle {
        font-size: 12px;
    }
    
    .editor-action-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .editor-action-btn span {
        display: none;
    }
    
    .editor-main {
        padding: 20px 16px;
    }
    
    .book-page-editor {
        padding: var(--page-padding-mobile);
    }
    
    .book-page-editor .page-header {
        font-size: 24px;
    }
    
    .book-page-editor .page-content {
        font-size: 14px;
    }
    
    .book-cover-editor .book-title {
        font-size: 32px;
    }
    
    .formatting-toolbar {
        width: calc(100% - 32px);
        left: 16px;
        right: 16px;
        transform: none;
        bottom: 16px;
    }
}

/* ============================================
   LOADING & EMPTY STATES
   ============================================ */

.editor-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    padding: 60px 20px;
}

.editor-loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #E5E7EB;
    border-top-color: #3B82F6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.editor-loading p {
    margin-top: 24px;
    font-size: 18px;
    font-weight: 600;
    color: #1F2937;
}

.editor-empty-state {
    text-align: center;
    padding: 60px 20px;
}

.editor-empty-state i {
    font-size: 64px;
    color: #D1D5DB;
    margin-bottom: 16px;
}

.editor-empty-state h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--memorial-charcoal);
    margin-bottom: 8px;
}

.editor-empty-state p {
    font-size: 14px;
    color: var(--memorial-gray);
}

/* ============================================
   NOTIFICATIONS & IMAGES
   ============================================ */

.editor-notification {
    position: fixed;
    top: 80px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 9999;
    animation: slideInRight 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 14px;
    max-width: 300px;
}

.editor-notification-success {
    background: #10B981;
    color: white;
}

.editor-notification-error {
    background: #EF4444;
    color: white;
}

.editor-notification-info {
    background: #3B82F6;
    color: white;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Inserted images */
.inserted-image {
    max-width: 100% !important;
    height: auto !important;
    margin: 15px 0 !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    transition: transform 0.2s ease !important;
}

.inserted-image:hover {
    transform: scale(1.02) !important;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .editor-header,
    .editor-sidebar-left,
    .editor-sidebar-right,
    .formatting-toolbar,
    .editor-actions {
        display: none;
    }
    
    .editor-canvas {
        box-shadow: none;
    }
    
    [contenteditable="true"]:focus {
        outline: none;
        background: transparent;
    }
}

