/* ==========================================================================
   The Age of Assurance - Narrative / Microbooks Styles
   ========================================================================== */

/* ==========================================================================
   Narrative Index Page (book grid)
   ========================================================================== */

.narrative-hero {
    padding: var(--space-md) 0 var(--space-sm);
    text-align: center;
    border-bottom: 2px solid var(--color-border);
    background: linear-gradient(135deg, var(--color-background) 0%, #f5f1eb 100%);
}

.narrative-hero h1 {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.narrative-hero p {
    color: var(--color-text-light);
    font-style: italic;
    font-family: var(--font-primary);
    margin-bottom: var(--space-sm);
}

.add-book-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 2rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
}

.add-book-btn:hover {
    background: var(--color-secondary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(44,62,80,0.15);
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-sm);
    padding: var(--space-md) 0;
}

.book-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: var(--space-sm);
    text-decoration: none;
    color: inherit;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    cursor: pointer;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.08);
    border-color: var(--color-accent);
}

.book-card-spine {
    width: 4px;
    background: linear-gradient(180deg, var(--color-accent), var(--color-secondary));
    border-radius: 2px;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
}

.book-card-inner {
    position: relative;
    padding-left: 1rem;
}

.book-card-wrap {
    position: relative;
    display: flex;
}

.book-title {
    font-family: var(--font-primary);
    font-size: 1.25rem;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.book-description {
    font-size: 0.9rem;
    color: var(--color-text-light);
    line-height: 1.5;
    flex: 1;
    margin-bottom: 1rem;
}

.book-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--color-text-light);
    border-top: 1px solid var(--color-border);
    padding-top: 0.75rem;
    margin-top: auto;
}

.book-meta span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.empty-narrative {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--color-text-light);
    grid-column: 1 / -1;
}

.empty-narrative p {
    font-size: 1.1rem;
    margin-bottom: var(--space-sm);
    font-style: italic;
}

/* Add book modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: var(--color-surface);
    border-radius: 8px;
    padding: var(--space-md);
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-box h2 {
    margin-bottom: var(--space-sm);
    font-size: 1.5rem;
}

.modal-field {
    margin-bottom: 1rem;
}

.modal-field label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    color: var(--color-text-light);
}

.modal-field input,
.modal-field textarea {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
    font-family: var(--font-secondary);
    background: var(--color-background);
    color: var(--color-text);
    transition: border-color 0.2s;
}

.modal-field input:focus,
.modal-field textarea:focus {
    outline: none;
    border-color: var(--color-secondary);
}

.modal-field textarea {
    resize: vertical;
    min-height: 80px;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: var(--space-sm);
}

.btn-cancel {
    padding: 0.6rem 1.5rem;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--color-text-light);
    transition: var(--transition);
}

.btn-cancel:hover { background: var(--color-bg-light); }

.btn-create {
    padding: 0.6rem 1.5rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: var(--transition);
}

.btn-create:hover { background: var(--color-secondary); }

/* ==========================================================================
   Individual Book Page (ebook reader)
   ========================================================================== */

.book-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: calc(100vh - 60px);
    gap: 0;
}

.book-sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: var(--space-sm);
    position: sticky;
    top: 60px;
    height: calc(100vh - 60px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.book-sidebar-title {
    font-family: var(--font-primary);
    font-size: 1rem;
    color: var(--color-primary);
    margin-bottom: var(--space-sm);
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    line-height: 1.3;
}

.chapter-nav {
    list-style: none;
    flex: 1;
}

.chapter-nav li {
    margin-bottom: 0.25rem;
}

.chapter-nav-link {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    text-decoration: none;
    color: var(--color-text-light);
    font-size: 0.875rem;
    transition: var(--transition);
    line-height: 1.3;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.chapter-nav-link:hover {
    background: var(--color-bg-light);
    color: var(--color-primary);
}

.chapter-nav-link.active {
    background: var(--color-bg-light);
    color: var(--color-primary);
    font-weight: 500;
    border-left: 3px solid var(--color-accent);
}

.sidebar-actions {
    margin-top: auto;
    padding-top: var(--space-sm);
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn-add-chapter {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--color-secondary);
    border-radius: 4px;
    color: var(--color-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition);
    text-align: center;
}

.btn-add-chapter:hover {
    background: var(--color-secondary);
    color: white;
}

.btn-save-book {
    padding: 0.5rem 1rem;
    background: var(--color-primary);
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    text-align: center;
}

.btn-save-book:hover {
    background: var(--color-secondary);
    transform: translateY(-1px);
}

.btn-save-book.saving {
    background: #888;
    cursor: wait;
}

.btn-save-book.saved {
    background: #2ecc71;
}

/* Chapter content area */
.book-content {
    padding: var(--space-md);
    max-width: 760px;
}

.chapter-display {
    display: none;
}

.chapter-display.active {
    display: block;
}

.chapter-header {
    margin-bottom: var(--space-sm);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--color-border);
}

.chapter-number {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-accent);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.chapter-title-display {
    font-family: var(--font-primary);
    font-size: clamp(1.5rem, 3vw, 2.25rem);
    color: var(--color-primary);
    font-weight: 400;
    margin-bottom: 0.25rem;
}

.chapter-title-input {
    font-family: var(--font-primary);
    font-size: clamp(1.5rem, 3vw, 2.25rem);
    color: var(--color-primary);
    font-weight: 400;
    border: none;
    border-bottom: 2px dashed var(--color-border);
    width: 100%;
    background: transparent;
    outline: none;
    margin-bottom: 0.25rem;
    padding: 0;
}

.chapter-title-input:focus {
    border-bottom-color: var(--color-accent);
}

.chapter-word-count {
    font-size: 0.8rem;
    color: var(--color-text-light);
}

.chapter-body-display {
    font-family: var(--font-primary);
    font-size: 1.1rem;
    line-height: 1.85;
    color: var(--color-text);
    white-space: pre-wrap;
}

.chapter-body-textarea {
    width: 100%;
    min-height: 60vh;
    padding: var(--space-sm) 0;
    font-family: var(--font-primary);
    font-size: 1.1rem;
    line-height: 1.85;
    color: var(--color-text);
    border: none;
    outline: none;
    resize: vertical;
    background: transparent;
    border-bottom: 1px dashed var(--color-border);
}

.chapter-body-textarea:focus {
    border-bottom-color: var(--color-accent);
}

/* Chapter navigation arrows */
.chapter-nav-arrows {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-md);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--color-border);
}

.btn-prev-chapter,
.btn-next-chapter {
    padding: 0.6rem 1.25rem;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--color-text-light);
    transition: var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-prev-chapter:hover,
.btn-next-chapter:hover {
    border-color: var(--color-secondary);
    color: var(--color-secondary);
}

.btn-prev-chapter:disabled,
.btn-next-chapter:disabled {
    opacity: 0.3;
    cursor: default;
}

/* Save status */
.save-status {
    font-size: 0.8rem;
    text-align: center;
    color: var(--color-text-light);
    min-height: 1.2em;
    margin-top: 0.35rem;
}

.save-status.success { color: #2ecc71; }
.save-status.error { color: #e74c3c; }

/* Delete chapter */
.btn-delete-chapter {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    margin-top: 0.5rem;
    transition: background 0.2s;
}

.btn-delete-chapter:hover { background: #fde8e8; }

/* Responsive */
@media (max-width: 768px) {
    .book-layout {
        grid-template-columns: 1fr;
    }

    .book-sidebar {
        position: relative;
        top: 0;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .book-content {
        padding: var(--space-sm);
    }

    .book-grid {
        grid-template-columns: 1fr;
    }
}
