/* AudioBook Organizer - Formatting Styles */

#bookContent {
    position: relative;
}

/* ========================================
   HEADING FORMATS (H1, H2, H3, H4)
   ======================================== */

/* H1 - Main Title (matches HTML h1 standard: 2em, bold) */
[data-formatting-id].fmt-title,
.fmt-title {
    display: block !important;
    font-size: 2em !important;
    font-weight: bold !important;
    margin-block: 0.67em !important;
    line-height: 1.2 !important;
    color: inherit !important;
}

/* H2 - Subtitle (matches HTML h2 standard: 1.5em, bold) */
[data-formatting-id].fmt-subtitle,
.fmt-subtitle {
    display: block !important;
    font-size: 1.5em !important;
    font-weight: bold !important;
    margin-block: 0.83em !important;
    line-height: 1.3 !important;
    color: inherit !important;
}

/* H3 - Section (matches HTML h3 standard: 1.17em, bold) */
[data-formatting-id].fmt-section,
.fmt-section {
    display: block !important;
    font-size: 1.17em !important;
    font-weight: bold !important;
    margin-block: 1em !important;
    line-height: 1.4 !important;
    color: inherit !important;
}

/* H4 - Subsection (matches HTML h4 standard: 1em, bold) */
[data-formatting-id].fmt-subsection,
.fmt-subsection {
    display: block !important;
    font-size: 1em !important;
    font-weight: bold !important;
    margin-block: 1.33em !important;
    line-height: 1.4 !important;
    color: inherit !important;
}

/* ========================================
   COMBINED FORMATTING STYLES
   Support for bold/italic/underline on headings
   ======================================== */

/* Bold formatting - can be combined with headings */
.fmt-bold,
.fmt-title.fmt-bold,
.fmt-subtitle.fmt-bold,
.fmt-section.fmt-bold,
.fmt-subsection.fmt-bold {
    font-weight: bold !important;
}

/* Italic formatting - can be combined with headings */
.fmt-italic,
.fmt-title.fmt-italic,
.fmt-subtitle.fmt-italic,
.fmt-section.fmt-italic,
.fmt-subsection.fmt-italic {
    font-style: italic !important;
}

/* Underline formatting - can be combined with headings */
.fmt-underline,
.fmt-title.fmt-underline,
.fmt-subtitle.fmt-underline,
.fmt-section.fmt-underline,
.fmt-subsection.fmt-underline {
    text-decoration: underline !important;
}

/* ========================================
   FORMATTING TOOLBAR STYLES
   ======================================== */

.formatting-toolbar {
    display: flex;
    gap: 12px;
    padding: 8px 16px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    backdrop-filter: blur(10px);
    user-select: none;
    z-index: 1000;
    
    /* NEW: Sticky positioning above content container */
    position: sticky;
    top: 10px;
    margin: 0 auto 10px auto;
    width: fit-content;
    max-width: 90%;
}

.toolbar-section {
    display: flex;
    gap: 4px;
    align-items: center;
    padding-right: 12px;
    border-right: 1px solid #e8e8e8;
}

.toolbar-section:last-child {
    border-right: none;
    padding-right: 0;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    color: #333;
}

.toolbar-btn:hover {
    background: #f5f5f5;
    border-color: #d0d0d0;
    transform: translateY(-1px);
}

.toolbar-btn:active {
    transform: translateY(0);
}

.toolbar-btn.active {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

.toolbar-btn.active:hover {
    background: #45a049;
    border-color: #45a049;
}

.heading-select {
    padding: 6px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    background: white;
    font-size: 14px;
    cursor: pointer;
    min-width: 120px;
    transition: all 0.2s ease;
}

.heading-select:hover {
    border-color: #4CAF50;
}

.heading-select:focus {
    outline: none;
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

/* File type indicators in toolbar */
.toolbar-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 12px;
    border-right: 1px solid #e8e8e8;
    font-size: 12px;
    font-weight: 500;
}

.file-type-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #666;
    font-size: 12px;
    font-weight: 600;
}

.docx-warning {
    color: #ff9800;
    font-size: 14px;
    cursor: help;
}

.docx-clear-btn {
    background: #fff3e0 !important;
    color: #ff9800 !important;
    border-color: #ffcc80 !important;
}

.docx-clear-btn:hover {
    background: #ffe0b2 !important;
    border-color: #ffb74d !important;
}

/* Edit mode styles for different file types */
.edit-mode-txt {
    border-left: 3px solid #4CAF50;
}

.edit-mode-docx {
    border-left: 3px solid #ff9800;
}

/* ========================================
   DARK THEME SUPPORT FOR FORMATTING TOOLBAR
   ======================================== */

[data-theme="dark"] .formatting-toolbar {
    background: #2d2d2d;
    border-color: #404040;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .toolbar-section {
    border-right-color: #404040;
}

[data-theme="dark"] .toolbar-btn {
    color: #e0e0e0;
}

[data-theme="dark"] .toolbar-btn:hover {
    background: #404040;
    border-color: #555555;
}

[data-theme="dark"] .toolbar-btn.active {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

[data-theme="dark"] .toolbar-btn.active:hover {
    background: #45a049;
    border-color: #45a049;
}

[data-theme="dark"] .heading-select {
    background: #404040;
    border-color: #555555;
    color: #e0e0e0;
}

[data-theme="dark"] .heading-select:hover {
    border-color: #4CAF50;
}

[data-theme="dark"] .heading-select:focus {
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

[data-theme="dark"] .heading-select option {
    background: #404040;
    color: #e0e0e0;
}

/* Dark theme for file type indicators */
[data-theme="dark"] .toolbar-info {
    border-right-color: #404040;
}

[data-theme="dark"] .file-type-indicator {
    color: #b0b0b0;
}

[data-theme="dark"] .docx-warning {
    color: #ffb74d;
}

[data-theme="dark"] .docx-clear-btn {
    background: #3e2723 !important;
    color: #ffb74d !important;
    border-color: #5d4037 !important;
}

[data-theme="dark"] .docx-clear-btn:hover {
    background: #4e342e !important;
    border-color: #6d4c41 !important;
}

/* Dark theme for quote formatting */
[data-theme="dark"] .fmt-quote {
    background: #2d2d2d !important;
    color: #e0e0e0 !important;
    border-left-color: #4CAF50 !important;
}

[data-theme="dark"] .fmt-quote::before {
    color: #4CAF50 !important;
}

/* Dark theme for comment system */
[data-theme="dark"] .comment-popup {
    background: #2d2d2d;
    border-color: #404040;
    color: #e0e0e0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .comment-dialog {
    background: rgba(0, 0, 0, 0.8);
}

[data-theme="dark"] .comment-dialog-content {
    background: #2d2d2d;
    border-color: #404040;
    color: #e0e0e0;
}

[data-theme="dark"] .comment-dialog-content textarea {
    background: #404040;
    border-color: #555555;
    color: #e0e0e0;
}

[data-theme="dark"] .comment-dialog-content textarea:focus {
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

/* ========================================
   TEXT FORMATTING STYLES
   ======================================== */

/* Text Formatting Styles */
[data-formatting-id].fmt-bold,
.fmt-bold {
    font-weight: bold !important;
}

[data-formatting-id].fmt-italic,
.fmt-italic {
    font-style: italic !important;
}

[data-formatting-id].fmt-underline,
.fmt-underline {
    text-decoration: underline !important;
}

/* Quote formatting */
[data-formatting-id].fmt-quote,
.fmt-quote {
    display: block !important;
    margin: 1em 2em !important;
    padding: 1em 1.5em !important;
    background: #f9f9f9 !important;
    border-left: 4px solid #4CAF50 !important;
    font-style: italic !important;
    color: #555 !important;
    position: relative !important;
    border-radius: 5px !important;
}

.fmt-quote::before {
    content: '"' !important;
    font-size: 4em !important;
    color: #4CAF50 !important;
    position: absolute !important;
    top: -0.2em !important;
    left: 0.2em !important;
    opacity: 0.3 !important;
}

/* ========================================
   COMMENT SYSTEM STYLES
   ======================================== */

.comment-indicator {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: #FF9800;
    color: white;
    text-align: center;
    font-size: 10px;
    line-height: 16px;
    border-radius: 50%;
    cursor: pointer;
    margin: 0 2px;
    vertical-align: baseline;
    position: relative;
    animation: commentPulse 3s infinite;
    transition: all 0.2s ease;
}

@keyframes commentPulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.7);
    }
    50% { 
        transform: scale(1.05);
        box-shadow: 0 0 0 4px rgba(255, 152, 0, 0);
    }
}

.comment-indicator:hover {
    background: #F57C00;
    transform: scale(1.2);
    animation: none;
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.4);
}

/* Comment Popup */
.comment-popup {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    max-width: 300px;
    z-index: 1001;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    animation: commentPopupSlide 0.2s ease-out;
}

@keyframes commentPopupSlide {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.comment-popup::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid white;
}

.comment-popup .comment-text {
    margin-bottom: 8px;
    line-height: 1.4;
    color: #333;
}

.comment-popup .comment-meta {
    font-size: 12px;
    color: #666;
    border-top: 1px solid #eee;
    padding-top: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.resolve-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.resolve-btn:hover {
    background: #45a049;
}

/* Comment Dialog */
.comment-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1002;
    backdrop-filter: blur(4px);
}

.comment-dialog-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    min-width: 400px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: commentDialogSlide 0.3s ease-out;
}

@keyframes commentDialogSlide {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.comment-dialog-content h4 {
    margin: 0 0 16px 0;
    color: #333;
    font-size: 18px;
}

.comment-dialog-content textarea {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 16px;
}

.comment-dialog-content textarea:focus {
    outline: none;
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.comment-dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.comment-dialog-actions .btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.comment-dialog-actions .btn-primary {
    background: #4CAF50;
    color: white;
}

.comment-dialog-actions .btn-primary:hover {
    background: #45a049;
    transform: translateY(-1px);
}

.comment-dialog-actions .btn-secondary {
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
}

.comment-dialog-actions .btn-secondary:hover {
    background: #e8e8e8;
    transform: translateY(-1px);
}

/* ========================================
   EDIT MODE ENHANCEMENTS
   ======================================== */

.book-content.edit-mode {
    caret-color: #4CAF50;
    position: relative;
}

.book-content.edit-mode [data-formatting-id] {
    position: relative;
}

.book-content.edit-mode .fmt-title,
.book-content.edit-mode .fmt-subtitle,
.book-content.edit-mode .fmt-section,
.book-content.edit-mode .fmt-subsection {
    /* Clean edit mode - no visual indicators */
    transition: all 0.2s ease;
}

.book-content.edit-mode .fmt-title:hover,
.book-content.edit-mode .fmt-subtitle:hover,
.book-content.edit-mode .fmt-section:hover,
.book-content.edit-mode .fmt-subsection:hover {
    /* Subtle hover effect - just cursor change */
    cursor: text;
}

.book-content.edit-mode .fmt-quote {
    transition: all 0.2s ease;
}

.book-content.edit-mode .fmt-quote:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Selection highlighting */
.book-content.edit-mode ::selection {
    background: rgba(76, 175, 80, 0.3);
}

.book-content.edit-mode ::-moz-selection {
    background: rgba(76, 175, 80, 0.3);
}

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

@media (max-width: 768px) {
    .formatting-toolbar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 6px 12px;
        max-width: calc(100vw - 20px);
    }
    
    .toolbar-section {
        padding-right: 8px;
        margin-bottom: 4px;
        border-right: none;
        border-bottom: 1px solid #e8e8e8;
        padding-bottom: 4px;
    }
    
    .toolbar-section:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    
    .heading-select {
        min-width: 100px;
        font-size: 13px;
    }
    
    .toolbar-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .fmt-title {
        font-size: 2em;
        margin: 1em 0 0.8em 0;
    }
    
    .fmt-subtitle {
        font-size: 1.6em;
        margin: 0.8em 0 0.6em 0;
    }
    
    .fmt-section {
        font-size: 1.3em;
        margin: 0.8em 0 0.5em 0;
    }
    
    .fmt-quote {
        margin: 1em 1em;
        padding: 1em 1.2em;
    }
    
    .fmt-quote::before {
        font-size: 3em;
    }
    
    .comment-popup {
        max-width: 250px;
        font-size: 13px;
    }
    
    .comment-dialog-content {
        min-width: 300px;
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .formatting-toolbar {
        position: sticky !important;
        top: 10px !important;
        left: 10px !important;
        right: 10px !important;
        width: calc(100% - 20px) !important;
    }
    
    .fmt-quote {
        margin: 1em 0.5em;
        padding: 0.8em 1em;
    }
    
    .comment-dialog-content {
        min-width: 280px;
        padding: 16px;
    }
}

/* ========================================
   ACCESSIBILITY ENHANCEMENTS
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .comment-indicator {
        animation: none;
    }
    
    .comment-popup,
    .comment-dialog-content {
        animation: none;
    }
    
    .toolbar-btn:hover {
        transform: none;
    }
    
    .fmt-quote:hover {
        transform: none;
    }
}

/* High contrast support */
@media (prefers-contrast: high) {
    .formatting-toolbar {
        border: 2px solid #333;
        background: #fff;
    }
    
    .toolbar-btn {
        border: 1px solid #333;
    }
    
    .toolbar-btn.active {
        background: #000;
        color: #fff;
        border-color: #000;
    }
    
    .fmt-title,
    .fmt-subtitle,
    .fmt-section,
    span[data-formatting-id].fmt-title,
    span[data-formatting-id].fmt-subtitle,
    span[data-formatting-id].fmt-section {
        border-bottom-color: #000;
    }
    
    .fmt-quote {
        border-left-color: #000;
        background: #f0f0f0;
    }
    
    .comment-indicator {
        background: #000;
        color: #fff;
    }
}

/* Focus indicators for keyboard navigation */
.toolbar-btn:focus,
.heading-select:focus,
.resolve-btn:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .formatting-toolbar {
        display: none !important;
    }
    
    .comment-indicator {
        display: none !important;
    }
    
    .fmt-title,
    .fmt-subtitle,
    .fmt-section,
    .fmt-subsection,
    span[data-formatting-id].fmt-title,
    span[data-formatting-id].fmt-subtitle,
    span[data-formatting-id].fmt-section,
    span[data-formatting-id].fmt-subsection {
        break-after: avoid;
        color: #000 !important; /* Only for print - doesn't affect screen display */
    }
    
    .fmt-quote {
        break-inside: avoid;
        background: #f9f9f9 !important; /* Only for print */
        border-left: 4px solid #333 !important; /* Only for print */
    }
}

/* Duplicate styles removed - consolidated above */ 