/* 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;
}

/* Refined desktop scale and publishing-studio polish */
html {
    font-size: 12.75px;
}

body {
    background:
        radial-gradient(circle at 8% 4%, rgba(185, 119, 60, .08), transparent 25rem),
        linear-gradient(145deg, #faf8f3 0%, #f1ede5 58%, #edf2ef 100%);
}

.container-fluid {
    max-width: 1600px;
    margin-inline: auto;
    padding-inline: clamp(.8rem, 2vw, 2rem);
}

.studio-hero {
    padding: 1.5rem 1.5rem 1.25rem;
    margin-bottom: 1.25rem;
    border-radius: 0 0 18px 18px;
}

.studio-eyebrow {
    margin-bottom: .35rem;
    font-size: .64rem;
}

.studio-mark {
    width: 36px;
    height: 36px;
    margin-bottom: .25rem;
}

.studio-title {
    font-size: clamp(2.6rem, 5vw, 4rem);
    line-height: .92;
}

.studio-tagline {
    margin-top: .55rem;
    font-size: 1.08rem;
}

.api-connect-button {
    position: absolute;
    top: 1rem;
    left: 1rem;
    display: grid;
    grid-template-columns: auto auto;
    align-items: center;
    gap: .1rem .45rem;
    padding: .55rem .75rem;
    border: 1px solid rgba(41,76,85,.24);
    border-radius: 10px;
    background: rgba(255,253,248,.9);
    color: #294c55;
    box-shadow: 0 7px 20px rgba(45,43,38,.08);
    font-size: .76rem;
    font-weight: 750;
    text-align: left;
}

.api-connect-button small {
    grid-column: 2;
    color: #7a8587;
    font-size: .58rem;
    font-weight: 600;
}

.api-connect-button.is-connected { border-color: rgba(71,118,91,.45); color:#386548; }
.api-connect-button:hover { transform: translateY(-1px); box-shadow:0 9px 24px rgba(45,43,38,.12); }
.api-security-note { display:flex; gap:.75rem; padding:.8rem; border:1px solid #cbdcd1; border-radius:9px; background:#f0f7f2; color:#385345; font-size:.78rem; }

@media (max-width: 700px) {
    .api-connect-button { position: static; display:inline-grid; margin:0 auto .8rem; }
}

.stats-dashboard {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .7rem;
    margin-top: 1.15rem !important;
    margin-bottom: 0;
}

.stat-card {
    padding: .7rem .8rem;
    border: 1px solid rgba(35, 74, 87, .24);
    border-radius: 10px;
    background: rgba(255, 253, 248, .78);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(47, 42, 34, .09);
}

.stat-value {
    font-size: 1.45rem;
}

.stat-label {
    font-size: .68rem;
    letter-spacing: .06em;
}

.studio-layout {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    gap: 1rem;
}

.settings-pane,
.workspace-pane {
    max-height: calc(100vh - 190px);
    min-height: 540px;
}

.card {
    border: 1px solid rgba(48, 59, 61, .11);
    border-radius: 11px;
    box-shadow: 0 8px 24px rgba(50, 42, 31, .07);
    margin-bottom: 1rem;
}

.card:hover {
    transform: none;
    box-shadow: 0 10px 28px rgba(50, 42, 31, .09);
}

.card-header {
    padding: .72rem 1rem;
    background: #294c55 !important;
    color: #fff !important;
    border-radius: 10px 10px 0 0 !important;
}

.card-header h3,
.card-header h4 {
    font-size: 1.03rem;
    font-weight: 650;
    letter-spacing: .01em;
}

.card-body {
    padding: 1rem;
}

.card-footer {
    padding: .8rem 1rem;
    background: #f8f5ee;
    border-top: 1px solid rgba(48, 59, 61, .09);
}

.form-label {
    font-size: .78rem;
    font-weight: 650;
    margin-bottom: .3rem;
}

.form-control,
.form-select {
    min-height: 36px;
    padding: .46rem .68rem;
    border: 1px solid #d8ddd9;
    border-radius: 8px;
    font-size: .86rem;
    background-color: #fffefa;
}

textarea.form-control {
    min-height: auto;
}

.form-text,
.text-muted,
small {
    font-size: .72rem;
}

.btn {
    border-radius: 8px;
    font-size: .78rem;
    font-weight: 650;
    padding: .48rem .72rem;
}

.btn-primary,
.bg-primary {
    background-color: #294c55 !important;
    border-color: #294c55 !important;
}

.btn-warning {
    background-color: #b9773c;
    border-color: #b9773c;
    color: white;
}

.settings-pane .card-body h5 {
    margin-top: .25rem;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.18rem;
    color: #294c55;
}

.settings-pane .mb-3 {
    margin-bottom: .8rem !important;
}

.workspace-status {
    padding: .78rem .9rem;
    border-radius: 11px;
}

.workspace-status-icon {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
}

.workspace-status-label {
    font-size: .86rem;
}

.workspace-status-detail {
    font-size: .74rem;
}

.workspace-jumps {
    padding-top: .5rem;
}

.workspace-jumps a {
    padding: .34rem .6rem;
    font-size: .7rem;
    background: rgba(255, 253, 248, .7);
}

.chapters-container {
    padding: .75rem;
    background: #f4f1ea;
}

.chapter-item {
    margin-bottom: .8rem;
    border-color: rgba(48, 59, 61, .12);
}

.chapter-header {
    padding: .72rem .85rem;
    background: #f6f3ec;
}

.chapter-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.15rem;
}

.modal-content {
    border: 1px solid rgba(48, 59, 61, .12);
    border-radius: 13px;
    box-shadow: 0 24px 70px rgba(28, 33, 34, .22);
}

.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;
}

.studio-layout {
    display: grid;
    grid-template-columns: minmax(330px, 410px) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
    min-height: 620px;
    position: relative;
    transition: grid-template-columns .35s ease;
}

.studio-layout.settings-collapsed {
    grid-template-columns: 0 minmax(0, 1fr);
}

.settings-drawer-toggle {
    position: fixed;
    left: 12px;
    top: calc(50% - 24px);
    z-index: 1060;
    appearance: none;
    width: 48px;
    height: 26px;
    margin: 0;
    border: 2px solid var(--primary-color);
    border-radius: 999px;
    background: #fffdf8;
    box-shadow: 0 6px 18px rgba(30,54,61,.2);
    cursor: pointer;
    transition: background .25s ease;
}
.settings-drawer-toggle::before {
    content: '‹';
    position: absolute;
    display: grid;
    place-items: center;
    width: 18px;
    height: 18px;
    left: 2px;
    top: 2px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    font-weight: 800;
    line-height: 1;
    transition: transform .3s ease;
}
.settings-drawer-toggle:checked { background: var(--primary-color); }
.settings-drawer-toggle:checked::before { content: '›'; background:white; color:var(--primary-color); transform:translateX(20px); }
.settings-drawer-toggle:checked ~ .studio-layout { grid-template-columns: 0 minmax(0, 1fr); }

.settings-pane,
.workspace-pane {
    max-height: calc(100vh - 250px);
    min-height: 620px;
    overflow-y: auto;
    scrollbar-gutter: stable;
    padding: .2rem .4rem 2rem;
}

.settings-pane {
    position: sticky;
    top: 1rem;
    transform: translateX(0);
    opacity: 1;
    transition: transform .35s ease, opacity .25s ease;
}

.settings-collapsed .settings-pane {
    transform: translateX(calc(-100% - 2rem));
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.settings-drawer-toggle:checked ~ .studio-layout .settings-pane {
    transform: translateX(calc(-100% - 2rem));
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.settings-pane .row > [class*="col-md-"] {
    width: 100%;
}

.settings-pane .btn-group {
    display: grid;
    grid-template-columns: 1fr;
}

.settings-pane .btn-group .btn {
    border-radius: 8px !important;
    margin-bottom: .45rem;
}

.settings-pane .card-footer .row > div {
    width: 100%;
}

.pane-label {
    position: sticky;
    top: 0;
    z-index: 5;
    margin-bottom: .65rem;
    padding: .55rem .75rem;
    background: rgba(251, 248, 241, .96);
    color: var(--secondary-color);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

.hide-settings-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    border: 1px solid rgba(35, 74, 87, .22);
    border-radius: 999px;
    padding: .28rem .55rem;
    background: white;
    color: var(--primary-color);
    font-size: .72rem;
    font-weight: 700;
    cursor: pointer;
}

.hide-settings-btn:hover { background: var(--primary-color); color: white; }

.show-settings-tab {
    position: fixed;
    left: 0;
    top: 50%;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    padding: .8rem .42rem;
    border: 0;
    border-radius: 0 10px 10px 0;
    background: var(--primary-color);
    color: white;
    box-shadow: 4px 8px 20px rgba(30, 54, 61, .25);
    transform: translateX(-110%);
    opacity: 0;
    transition: transform .3s ease, opacity .2s ease;
    cursor: pointer;
}

.show-settings-tab span {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.settings-collapsed .show-settings-tab { transform: translateX(0); opacity: 1; }
.settings-drawer-toggle:checked ~ .studio-layout .show-settings-tab { transform: translateX(0); opacity: 1; }
.show-settings-tab:hover { background: var(--accent-color); }

.workspace-status {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: 1rem 1.1rem;
    background: rgba(255, 253, 248, .96);
    border: 1px solid rgba(35, 74, 87, .18);
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(50, 42, 31, .10);
    backdrop-filter: blur(12px);
}

.workspace-status.is-writing {
    border-color: rgba(185, 119, 60, .55);
    box-shadow: 0 10px 30px rgba(185, 119, 60, .16);
}

.workspace-status-icon {
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #e8f0ed;
    color: var(--primary-color);
}

.is-writing .workspace-status-icon { animation: writingPulse 1.2s ease-in-out infinite; background:#f7e9d9; color:var(--accent-color); }
.workspace-status-label { font-weight: 700; color: var(--secondary-color); }
.workspace-status-detail { color: #657074; font-size: .88rem; }
.workspace-status .progress { background: #e4ded2; }
.workspace-status .progress-bar { background: linear-gradient(90deg, var(--primary-color), var(--accent-color)); }

.workspace-jumps {
    display: flex;
    gap: .45rem;
    overflow-x: auto;
    padding: .7rem .1rem .25rem;
}

.workspace-jumps a {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem .7rem;
    border: 1px solid rgba(35, 74, 87, .2);
    border-radius: 999px;
    background: rgba(255, 253, 248, .86);
    color: var(--primary-color);
    font-size: .78rem;
    font-weight: 600;
    text-decoration: none;
}

.workspace-jumps a:hover { background: var(--primary-color); color: white; }

.workspace-content {
    display: flex;
    flex-direction: column;
}

#review-section { order: 80; }
#export-section { order: 90; }
#images-section { order: 100; }

@keyframes writingPulse { 50% { transform: scale(1.12) rotate(-7deg); } }

/* 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: calc(100vh - 340px);
    min-height: 320px;
    overflow-y: auto;
    padding: 1rem;
    background: var(--light-color);
    border-radius: var(--border-radius);
    border: 1px solid #dee2e6;
}

@media (max-width: 991px) {
    .studio-layout { grid-template-columns: 1fr; }
    .settings-pane, .workspace-pane { max-height: none; min-height: auto; overflow: visible; }
    .settings-pane { position: static; }
    .studio-layout.settings-collapsed { grid-template-columns: 1fr; }
    .settings-collapsed .settings-pane { display: none; }
    .workspace-status { top: .5rem; }
    .chapters-container { max-height: 600px; }
}

.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-item.is-writing {
    border: 2px solid var(--accent-color);
    box-shadow: 0 0 0 4px rgba(185, 119, 60, .12), var(--box-shadow);
    animation: chapterWriting 1.4s ease-in-out infinite;
}

@keyframes chapterWriting { 50% { box-shadow: 0 0 0 8px rgba(185, 119, 60, .06), var(--box-shadow); } }

.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; }

/* Final visual layer: compact, consistent, professional */
@media (min-width: 992px) {
    .studio-hero { padding: 1rem 1.4rem .85rem; margin-bottom: .8rem; }
    .studio-title { font-size: clamp(2.25rem, 4.1vw, 3.35rem); line-height: .94; }
    .studio-mark { width: 30px; height: 30px; }
    .studio-tagline { font-size: .96rem; margin-top: .35rem; }
    .stats-dashboard { margin-top: .75rem !important; gap: .55rem; }
    .stat-card { padding: .48rem .65rem; border-width: 1px; }
    .stat-value { font-size: 1.28rem; }
    .studio-layout { grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); gap: .85rem; min-height: 455px; }
    .settings-pane, .workspace-pane { max-height: calc(100vh - 245px); min-height: 455px; }
}

.card { border: 1px solid rgba(48,59,61,.11); border-radius: 11px; box-shadow: 0 8px 24px rgba(50,42,31,.07); margin-bottom: 1rem; }
.card:hover { transform: none; box-shadow: 0 10px 28px rgba(50,42,31,.09); }
.card-header { padding: .72rem 1rem; background: #294c55 !important; color: white !important; border-radius: 10px 10px 0 0 !important; }
.card-header h3, .card-header h4 { font-size: 1.03rem; font-weight: 650; }
.card-body { padding: 1rem; }
.card-footer { padding: .8rem 1rem; background: #f8f5ee; border-top: 1px solid rgba(48,59,61,.09); }
.form-label { font-size: .78rem; font-weight: 650; margin-bottom: .3rem; }
.form-control, .form-select { min-height: 36px; padding: .46rem .68rem; border: 1px solid #d8ddd9; border-radius: 8px; font-size: .86rem; background-color: #fffefa; }
.form-control:focus, .form-select:focus { border-color: #557a80; box-shadow: 0 0 0 .15rem rgba(41,76,85,.12); transform: none; }
.form-control:hover, .form-select:hover { border-color: #9caaa7; }
.btn { border-radius: 8px; border-width: 1px; font-size: .78rem; font-weight: 650; padding: .48rem .72rem; }
.btn:hover { transform: translateY(-1px); }
.settings-pane .card-body h5 { margin-top: .25rem; font-family: 'Cormorant Garamond', Georgia, serif; font-size: 1.18rem; color: #294c55; }
.settings-pane .mb-3 { margin-bottom: .8rem !important; }
.workspace-status { padding: .78rem .9rem; border-radius: 11px; }
.workspace-jumps a { padding: .34rem .6rem; font-size: .7rem; }
.chapters-container { padding: .75rem; background: #f4f1ea; }
.chapter-item { margin-bottom: .8rem; border-color: rgba(48,59,61,.12); }
.chapter-header { padding: .72rem .85rem; background: #f6f3ec; }
.chapter-title { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 1.15rem; }

.site-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    min-height: 58px;
    margin-top: .8rem;
    padding: 1rem;
    color: #667174;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    border-top: 1px solid rgba(41, 76, 85, .14);
}

.footer-separator { color: var(--accent-color); }

@media (max-width: 576px) {
    .site-footer { flex-direction: column; gap: .2rem; text-align: center; }
    .footer-separator { display: none; }
}
