/* ==================== CHAPTER GENERATOR STYLES ==================== */

/* Chapter Generator Button */
#chapter-generator-btn {
    white-space: nowrap;
}

/* Z-index layering for modals */
.chapter-generator-backdrop {
    z-index: 10000;
}

.chapter-generator-backdrop .modal-backdrop {
    z-index: 10001 !important;
}

/* Main Chapter Generator Modal */
.chapter-generator-modal {
    max-width: 900px;
    width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    overflow: hidden;
}

/* Modal Header with System Prompt Button */
.chapter-generator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-medium);
    background: var(--bg-secondary);
}

.chapter-generator-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.chapter-generator-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chapter-generator-header .modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    transition: all var(--transition-fast);
}

.chapter-generator-header .modal-close:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

.system-prompt-btn {
    padding: 8px 16px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.system-prompt-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(107, 124, 255, 0.3);
}

/* Main Content Area */
.chapter-generator-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    background: var(--bg-primary);
}

/* Empty State */
.chapter-generator-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 16px;
}

.chapter-generator-empty::before {
    content: '📖';
    display: block;
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Chapter Panel Card */
.chapter-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    margin-bottom: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
    opacity: 0;
    animation: fadeInUp 300ms ease forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chapter-panel:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-primary);
}

/* Drag Handle */
.chapter-drag-handle {
    cursor: grab;
    color: var(--text-tertiary);
    font-size: 20px;
    user-select: none;
    padding: 4px;
    transition: color var(--transition-fast);
}

.chapter-drag-handle:hover {
    color: var(--accent-primary);
}

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

/* Chapter Content Area */
.chapter-panel-content {
    flex: 1;
    cursor: pointer;
    min-height: 40px;
    display: flex;
    align-items: center;
}

.chapter-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.chapter-title-input {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    outline: none;
    width: 100%;
}

.chapter-preview {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chapter Panel States */
.chapter-panel.empty .chapter-panel-content {
    border: 2px dashed var(--border-medium);
    border-radius: var(--radius-md);
    padding: 12px;
    justify-content: center;
    color: var(--text-tertiary);
}

.chapter-panel.empty .chapter-panel-content:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.chapter-panel.generating {
    /* Ensure panel stays visible while generating */
    opacity: 1;
    border-color: #6B7CFF;
    box-shadow: 0 0 20px rgba(107, 124, 255, 0.4);
    /* Keep the initial fade-in AND add the glow while generating */
    animation: fadeInUp 300ms ease forwards, glow 2s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(107, 124, 255, 0.4);
    }
    50% {
        box-shadow: 0 0 30px rgba(107, 124, 255, 0.6);
    }
}

.chapter-panel.complete {
    border-color: var(--success);
}

/* Progress Bar */
.chapter-progress {
    width: 100%;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.chapter-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6B7CFF, #8B9CFF);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.chapter-status-text {
    font-size: 12px;
    color: var(--accent-primary);
    margin-top: 4px;
    font-weight: 600;
}

/* Completion Badge */
.chapter-completion {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--success);
    font-weight: 600;
}

.chapter-word-count {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Action Buttons */
.chapter-actions {
    display: flex;
    gap: 8px;
}

.chapter-action-btn {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition-fast);
}

.chapter-action-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
    transform: scale(1.1);
}

.chapter-action-btn.read:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.chapter-action-btn.delete:hover {
    border-color: var(--error);
    color: var(--error);
}

/* Drag States */
.chapter-panel.dragging {
    opacity: 0.5;
    transform: scale(1.05) rotate(2deg);
    box-shadow: var(--shadow-xl);
}

.chapter-panel.drag-over {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

/* Footer */
.chapter-generator-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-medium);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.footer-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.progress-text {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 600;
}

.master-progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 20px;
}

.master-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #6ade9c);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.add-chapter-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-md);
}

.add-chapter-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.08);
    box-shadow: var(--shadow-lg);
}

/* Header-specific placement for the add button */
.chapter-generator-header .add-chapter-btn {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    font-size: 20px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(107,124,255,0.18);
}

.chapter-generator-header .add-chapter-btn:hover {
    transform: scale(1.05);
}

.generate-chapters-btn {
    padding: 12px 32px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-normal);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    min-width: fit-content;
}

.generate-chapters-btn:hover:not(:disabled) {
    background: #3cc96a;
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(74, 222, 128, 0.4);
}

.generate-chapters-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    cursor: not-allowed;
}

.generate-chapters-btn.generating {
    background: var(--error);
}

.generate-chapters-btn.complete {
    background: var(--accent-primary);
}

/* Export Options */
.export-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.export-btn {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all var(--transition-fast);
    white-space: nowrap;
    min-width: fit-content;
}

.export-btn:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(107, 124, 255, 0.3);
}

/* Chapter Editor Modal */
.chapter-editor-modal {
    max-width: 800px;
    width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.chapter-editor-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.editor-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.editor-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.editor-textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    resize: vertical;
    transition: all var(--transition-fast);
}

.editor-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(107, 124, 255, 0.1);
}

.editor-textarea.monospace {
    font-family: var(--font-mono);
    line-height: 1.6;
}

.editor-textarea::placeholder {
    color: var(--text-hint);
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    padding: var(--space-lg);
    border-top: 1px solid var(--border-medium);
    background: var(--bg-secondary);
}

.editor-btn {
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.editor-btn.cancel {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.editor-btn.cancel:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.editor-btn.save {
    background: var(--success);
    color: white;
}

.editor-btn.save:hover {
    background: #3cc96a;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(74, 222, 128, 0.3);
}

/* System Prompt Modal */
.system-prompt-modal {
    max-width: 700px;
    width: 95vw;
}

.system-prompt-content {
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.system-prompt-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.system-prompt-textarea {
    width: 100%;
    height: 400px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    resize: vertical;
    line-height: 1.6;
}

.system-prompt-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(107, 124, 255, 0.1);
}

.system-prompt-footer {
    display: flex;
    justify-content: space-between;
    padding: var(--space-lg);
    border-top: 1px solid var(--border-medium);
    background: var(--bg-secondary);
}

/* Delete Confirmation Modal */
.delete-confirmation-content {
    padding: var(--space-lg);
}

.delete-confirmation-text {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.delete-confirmation-preview {
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
}

.delete-confirmation-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.delete-btn {
    padding: 10px 24px;
    background: var(--error);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.delete-btn:hover {
    background: #dc2626;
    transform: scale(1.05);
}

/* Statistics Display */
.chapter-stats {
    display: flex;
    gap: 20px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Success Toast Animation */
.success-confetti {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 100px;
    animation: confetti 1s ease-out;
    pointer-events: none;
    z-index: 10000;
}

@keyframes confetti {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.5) rotate(360deg);
        opacity: 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .chapter-generator-modal {
        max-width: 100%;
        width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }

    .chapter-generator-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .chapter-panel {
        flex-direction: column;
        align-items: flex-start;
    }

    .chapter-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .footer-top {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .footer-bottom {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .master-progress-bar {
        margin: 0;
    }

    .export-options {
        flex-direction: column;
    }

    .chapter-stats {
        flex-direction: column;
        gap: 8px;
    }

    .chapter-drag-handle {
        font-size: 24px;
        padding: 8px;
    }
}

/* Saved Indicator Toast */
.saved-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 8px 16px;
    background: var(--success);
    color: white;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.3s ease, fadeOut 0.3s ease 2.7s;
    z-index: 10000;
}

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

@keyframes fadeOut {
    to {
        opacity: 0;
    }
}

/* ==================== CHAPTER READER MODAL ==================== */

.chapter-reader-modal {
    max-width: 800px;
}

.chapter-reader-content {
    padding: var(--space-lg);
    max-height: 600px;
    overflow-y: auto;
}

.chapter-reader-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-medium);
    font-size: 14px;
    color: var(--text-secondary);
}

.reader-word-count {
    font-weight: 600;
}

.reader-separator {
    color: var(--text-tertiary);
}

.reader-reading-time {
    font-style: italic;
}

.chapter-reader-text {
    line-height: 1.8;
    font-size: 16px;
    color: var(--text-primary);
}

.chapter-reader-text p {
    margin-bottom: 16px;
}

.chapter-reader-text p:last-child {
    margin-bottom: 0;
}

/* Make reader content scrollable with custom scrollbar */
.chapter-reader-content::-webkit-scrollbar {
    width: 8px;
}

.chapter-reader-content::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

.chapter-reader-content::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 4px;
}

.chapter-reader-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}
