/* AI Book Generator - Modern Styles */
:root {
    --primary-color: #234a57;
    --secondary-color: #27343a;
    --success-color: #47765b;
    --warning-color: #b9773c;
    --danger-color: #e74c3c;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --border-radius: 12px;
    --box-shadow: 0 12px 34px rgba(50, 42, 31, 0.09);
    --transition: all 0.3s ease;
    --bg-gradient: linear-gradient(145deg, #fbf8f1 0%, #f3eee3 52%, #eef3ef 100%);
    --text-color: #27343a;
    --card-bg: rgba(255, 253, 248, 0.96);
    --accent-color: #b9773c;
}

/* Dark Mode */
[data-theme="dark"] {
    --primary-color: #5dade2;
    --secondary-color: #34495e;
    --success-color: #2ecc71;
    --warning-color: #f1c40f;
    --danger-color: #e74c3c;
    --info-color: #3498db;
    --light-color: #2c3e50;
    --dark-color: #ecf0f1;
    --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --text-color: #ecf0f1;
    --card-bg: #2c3e50;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

/* Global Styles */
* {
    box-sizing: border-box;
}

body {
    background: var(--bg-gradient);
    font-family: 'Inter', 'Segoe UI', sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

.card {
    background: var(--card-bg);
    color: var(--text-color);
    transition: var(--transition);
}

/* Dark mode toggle */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: var(--card-bg);
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--box-shadow);
    transition: var(--transition);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

/* Auto-save indicator */
.auto-save-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    background: var(--success-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    opacity: 0;
    transform: translateY(20px);
    transition: var(--transition);
}

.auto-save-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

/* Statistics Dashboard */
.stats-dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--card-bg);
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    text-align: center;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--secondary-color);
    text-transform: uppercase;
    margin-top: 0.25rem;
}

/* Live writer enhancements */
.live-writer-header {
    background: var(--info-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.live-writer-content {
    background: var(--card-bg);
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Keyboard shortcut hints */
.kbd {
    display: inline-block;
    padding: 0.2rem 0.4rem;
    font-size: 0.875rem;
    font-family: monospace;
    background: var(--light-color);
    border: 1px solid var(--secondary-color);
    border-radius: 3px;
    box-shadow: 0 2px 0 rgba(0,0,0,0.2);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    text-align: center;
    box-shadow: var(--box-shadow);
    min-width: 300px;
}

.loading-content .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Header Styles */
header {
    background:
        radial-gradient(circle at 14% 20%, rgba(185, 119, 60, .16), transparent 27%),
        radial-gradient(circle at 86% 70%, rgba(35, 74, 87, .10), transparent 31%),
        linear-gradient(135deg, #fffdf8 0%, #f5efe2 100%);
    color: var(--secondary-color);
    margin: -20px -15px 2rem -15px;
    padding: 3.25rem 1.5rem 2rem;
    border-radius: 0 0 24px 24px;
    border-bottom: 1px solid rgba(132, 98, 61, .22);
    box-shadow: 0 18px 44px rgba(67, 55, 39, .10);
}

header h1 {
    margin-bottom: 0.35rem;
}

header .lead {
    color: #5e696d;
}

.studio-eyebrow {
    color: var(--accent-color);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .22em;
    text-transform: uppercase;
    margin-bottom: .8rem;
}

.studio-mark {
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(185, 119, 60, .42);
    border-radius: 50%;
    color: var(--accent-color);
    background: rgba(255, 253, 248, .8);
    box-shadow: 0 8px 22px rgba(94, 68, 40, .10);
    margin-bottom: .55rem;
}

.studio-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: clamp(2.8rem, 7vw, 4.8rem);
    font-weight: 600;
    letter-spacing: -.035em;
    line-height: .95;
    color: #20363d;
}

.studio-title span {
    color: var(--accent-color);
    font-style: italic;
    font-weight: 500;
}

.studio-tagline {
    color: #647074;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.25rem;
    letter-spacing: .025em;
    margin: .8rem 0 0;
}

/* Card Enhancements */
.card {
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    transition: var(--transition);
    margin-bottom: 2rem;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}

.card-header {
    border-radius: var(--border-radius) var(--border-radius) 0 0 !important;
    padding: 1rem 1.5rem;
    border-bottom: none;
}

.card-header h3,
.card-header h4 {
    margin: 0;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

.book-preview-shell {
    background: #e9e1d2;
    border: 0;
    border-radius: 18px;
    overflow: hidden;
}

.book-preview-header {
    background: #f8f2e7;
    border-bottom: 1px solid #d7c9b3;
}

.book-preview-page {
    width: min(100%, 720px);
    min-height: 72vh;
    margin: 0 auto;
    padding: clamp(2rem, 6vw, 5rem);
    background: #fffdf7;
    color: #282622;
    border-radius: 4px 12px 12px 4px;
    box-shadow: -12px 0 0 #d1c1a8, 0 18px 45px rgba(63, 48, 31, .2);
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.2rem;
    line-height: 1.7;
}

.book-preview-page h1,
.book-preview-page h2 { text-align: center; color: #20363d; }
.book-preview-page h1 { font-size: 3rem; margin-top: 18%; }
.book-preview-page p { text-align: justify; }
.book-preview-page .preview-byline { text-align: center; margin-top: 3rem; font-style: italic; }
.book-preview-page .preview-cover { display: block; max-width: 55%; max-height: 48vh; margin: 0 auto 2rem; box-shadow: 0 12px 28px rgba(0,0,0,.2); }
.book-preview-controls { background: #f8f2e7; flex-wrap: nowrap; }
.book-preview-controls .form-select { width: min(340px, 45vw); }

/* Form Enhancements */
.form-label {
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--secondary-color);
}

.form-control,
.form-select {
    border: 2px solid #e9ecef;
    border-radius: var(--border-radius);
    padding: 0.75rem;
    transition: var(--transition);
    font-size: 1rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
    transform: translateY(-1px);
}

.form-control:hover,
.form-select:hover {
    border-color: var(--primary-color);
}

/* Button Styles */
.btn {
    border-radius: var(--border-radius);
    padding: 0.75rem 1.5rem;
    font-weight: 500;
    transition: var(--transition);
    border: 2px solid transparent;
}

.btn:hover {
    transform: translateY(-2px);
}

.btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.btn-outline-dark {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
}

.btn-outline-dark:hover {
    background: var(--secondary-color);
    color: white;
}

.btn-outline-primary {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-outline-primary:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.btn-outline-primary:disabled {
    opacity: 0.6;
    transform: none;
}

.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child {
    border-radius: var(--border-radius) 0 0 var(--border-radius);
}

.btn-group .btn:last-child {
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
}

/* Progress Bar */
.progress {
    height: 8px;
    border-radius: var(--border-radius);
    background-color: rgba(255, 255, 255, 0.3);
}

.progress-bar {
    border-radius: var(--border-radius);
    transition: width 0.3s ease;
}

.form-range::-webkit-slider-thumb {
    background: var(--primary-color);
}
.form-range::-moz-range-thumb {
    background: var(--primary-color);
}
.form-range::-webkit-slider-runnable-track {
    background: rgba(0,0,0,0.08);
}
.form-range::-moz-range-track {
    background: rgba(0,0,0,0.08);
}

#workflow-hint {
    border: 1px solid rgba(0,0,0,0.08);
}
/* Alert Enhancements */
.alert {
    border: none;
    border-radius: var(--border-radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.alert-success {
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    border-left: 4px solid var(--success-color);
}

.alert-danger {
    background: linear-gradient(135deg, #f8d7da, #f5c6cb);
    border-left: 4px solid var(--danger-color);
}

.alert-warning {
    background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    border-left: 4px solid var(--warning-color);
}

.alert-info {
    background: linear-gradient(135deg, #d1ecf1, #bee5eb);
    border-left: 4px solid var(--info-color);
}

/* Chapter Styles */
.chapters-container {
    max-height: 600px;
    overflow-y: auto;
    padding: 1rem;
    background: var(--light-color);
    border-radius: var(--border-radius);
    border: 1px solid #dee2e6;
}

.chapter-item {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.chapter-item:hover {
    box-shadow: var(--box-shadow);
    transform: translateY(-1px);
}

.chapter-header {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 1rem;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    border-bottom: 1px solid #dee2e6;
}

.chapter-title {
    color: var(--secondary-color);
    font-size: 1.25rem;
    font-weight: 600;
}

.chapter-content {
    padding: 1.5rem;
}

.chapter-text {
    line-height: 1.8;
    text-align: justify;
}

.chapter-text p {
    margin-bottom: 1rem;
}

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

.chapter-editor {
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.chapter-actions .btn {
    margin-left: 0.5rem;
    padding: 0.375rem 0.75rem;
}

.chapter-footer {
    padding: 1rem;
    background: var(--light-color);
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    border-top: 1px solid #dee2e6;
}

/* Badge Styles */
.badge {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius);
}

/* Modal Enhancements */
.modal-content {
    border: none;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.modal-header {
    border-bottom: 1px solid #dee2e6;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.modal-footer {
    border-top: 1px solid #dee2e6;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

/* Textarea Enhancements */
textarea.form-control {
    resize: vertical;
    min-height: 120px;
    font-family: 'Georgia', serif;
    line-height: 1.6;
}

textarea.form-control:focus {
    min-height: 200px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: var(--border-radius);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: var(--border-radius);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container-fluid {
        padding: 0.5rem;
    }
    
    header {
        margin: -8px -8px 1rem -8px;
        padding: 1.5rem 1rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .btn-group {
        display: flex;
        flex-direction: column;
    }
    
    .btn-group .btn {
        border-radius: var(--border-radius) !important;
        margin-bottom: 0.5rem;
    }
    
    .chapters-container {
        max-height: 400px;
    }
    
    .chapter-actions {
        margin-top: 1rem;
    }
    
    .chapter-actions .btn {
        margin: 0.25rem;
    }
}

@media (max-width: 576px) {
    header h1 {
        font-size: 1.75rem;
    }
    
    .loading-content {
        margin: 1rem;
        min-width: auto;
        width: calc(100% - 2rem);
    }
    
    .modal-dialog {
        margin: 1rem;
    }
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

.slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Utility Classes */
.text-gradient {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.shadow-hover {
    transition: var(--transition);
}

.shadow-hover:hover {
    box-shadow: var(--box-shadow);
}


/* Print Styles */
@media print {
    body {
        background: white !important;
    }
    
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
    
    .btn,
    .loading-overlay,
    .modal {
        display: none !important;
    }
    
    .chapter-item {
        page-break-inside: avoid;
        margin-bottom: 2rem;
    }
}

/* ---- Agent Mode Panel ---- */
.agent-panel .card-header {
    border-bottom: none;
}

.agent-log {
    max-height: 280px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    background: var(--light-color, #f8f9fa);
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 0.75rem 1rem;
}

.agent-log-entry {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.15rem 0;
    line-height: 1.4;
}

.agent-log-icon {
    flex-shrink: 0;
    font-size: 0.9rem;
}

.agent-log-success { color: #198754; }
.agent-log-warning  { color: #ffc107; }
.agent-log-error    { color: #dc3545; }
.agent-log-running  { color: #0d6efd; }
.agent-log-info     { color: #6c757d; }

[data-theme="dark"] .agent-log {
    background: #1a1a2e;
    border-color: #333;
    color: #ccc;
}

[data-theme="dark"] .agent-log-success { color: #50fa7b; }
[data-theme="dark"] .agent-log-running { color: #8be9fd; }
[data-theme="dark"] .agent-log-warning { color: #ffb86c; }
[data-theme="dark"] .agent-log-error   { color: #ff5555; }
