:root {
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --primary: 221.2 83.2% 53.3%;
    --primary-foreground: 210 40% 98%;
    --secondary: 210 40% 96%;
    --secondary-foreground: 222.2 84% 4.9%;
    --muted: 210 40% 96%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96%;
    --accent-foreground: 222.2 84% 4.9%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 221.2 83.2% 53.3%;
}
* { border-color: hsl(var(--border)); }
body { background-color: hsl(var(--background)); color: hsl(var(--foreground)); }

/* Message containers */
.message-container {
    display: flex;
    width: 100%;
    margin-bottom: 1rem;
}
.message-container.user {
    justify-content: flex-end;
}
.message-container.assistant {
    justify-content: flex-start;
}

/* User message bubble */
.message-user {
    background-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    max-width: 80%;
    padding: 0.5rem 1rem;
    border-radius: 1rem;
    border-bottom-right-radius: 0.25rem;
}

/* Assistant message */
.message-assistant { background-color: transparent; }
.message-assistant.prose { max-width: none; }

.typing-indicator span { animation: blink 1.4s infinite both; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0; } 40% { opacity: 1; } }

/* Markdown styling */
.prose p { margin-bottom: 1em; }
.prose ul, .prose ol { margin-left: 1.5em; margin-bottom: 1em; }
.prose li { margin-bottom: 0.25em; }
.prose code { background: hsl(var(--muted)); padding: 0.2em 0.4em; border-radius: 0.25em; font-size: 0.9em; }
.prose pre { background: hsl(var(--muted)); padding: 1em; border-radius: 0.5em; overflow-x: auto; margin-bottom: 1em; white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; color: hsl(var(--foreground)); }
.prose pre code { background: none; padding: 0; white-space: pre-wrap; color: inherit; }
.prose blockquote {
    border-left: 2px solid hsl(var(--primary) / 0.3);
    padding: 0.75em 1em;
    margin: 1em 0;
    background: hsl(var(--muted) / 0.15);
    border-radius: 0 0.5rem 0.5rem 0;
    font-style: normal;
    font-weight: 400;
    color: hsl(var(--foreground) / 0.9);
}
.table-quote {
    display: block;
    font-style: italic;
    color: hsl(var(--foreground) / 0.85);
    border-left: 2px solid hsl(var(--primary) / 0.4);
    padding-left: 0.5em;
    margin-top: 0.25em;
}

/* Timeline thought process styling */
.timeline-container {
    padding: 0.75rem 0;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}
.timeline-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    font-size: 0.85rem;
    padding: 0.25rem 0;
}
.timeline-header:hover { color: hsl(var(--foreground)); }
.timeline-content {
    margin-top: 0.5rem;
    padding-left: 0.25rem;
}
.timeline-step {
    display: flex;
    gap: 0.75rem;
    padding-bottom: 1rem;
    position: relative;
}
.timeline-step:last-child { padding-bottom: 0; }
.timeline-step::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 20px;
    bottom: 0;
    width: 2px;
    background: hsl(var(--border));
}
.timeline-step:last-child::before { display: none; }
.timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: hsl(var(--muted));
    border: 2px solid hsl(var(--border));
    flex-shrink: 0;
    margin-top: 4px;
    z-index: 1;
}
.timeline-dot.active {
    background: hsl(var(--primary));
    border-color: hsl(var(--primary));
}
.timeline-dot.success {
    background: #22c55e;
    border-color: #22c55e;
}
.timeline-dot.spinning {
    animation: pulse 1.5s ease-in-out infinite;
    background: hsl(var(--primary));
    border-color: hsl(var(--primary));
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Thinking indicator styling */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}
.thinking-pulse {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: hsl(var(--primary));
    animation: thinking-pulse 1.5s ease-in-out infinite;
}
@keyframes thinking-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.4;
        transform: scale(0.9);
    }
}
.thinking-text {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    font-style: italic;
}

/* Collapsible thinking/reasoning section */
.thinking-section {
    margin-bottom: 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    background: hsl(var(--muted) / 0.3);
}
.thinking-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    color: hsl(var(--muted-foreground));
    text-align: left;
    transition: background-color 0.15s ease;
}
.thinking-toggle:hover {
    background: hsl(var(--muted) / 0.5);
}
.thinking-chevron {
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
.thinking-label {
    font-weight: 500;
}
.thinking-content {
    padding: 0 0.75rem 0.75rem 0.75rem;
    border-top: 1px solid hsl(var(--border));
}
.thinking-body {
    font-size: 0.85rem;
    color: hsl(var(--muted-foreground));
    line-height: 1.5;
}
.thinking-body p {
    margin: 0.5rem 0;
}
.thinking-body p:first-child {
    margin-top: 0.75rem;
}

/* Progress indicator (between user and assistant messages) */
.progress-indicator {
    transition: opacity 0.3s ease-out;
}
.progress-indicator.fade-out {
    opacity: 0;
}
.progress-steps {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}
.progress-step-line {
    font-size: 0.8rem;
    color: hsl(var(--muted-foreground));
    animation: fade-in 0.2s ease-out;
}
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.step-spinner {
    display: inline-block;
    margin-right: 0.375rem;
    color: hsl(var(--primary));
    animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}
.step-spinner.done {
    animation: none;
    color: #22c55e;
}

.timeline-body { flex: 1; min-width: 0; }
.timeline-title {
    font-weight: 500;
    font-size: 0.8rem;
    color: hsl(var(--foreground));
    margin-bottom: 0.25rem;
}
.timeline-text {
    font-size: 0.8rem;
    color: hsl(var(--muted-foreground));
    line-height: 1.5;
}
.search-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: hsl(var(--muted));
    border-radius: 1rem;
    font-size: 0.75rem;
    margin: 0.25rem 0.25rem 0.25rem 0;
}
.search-chip svg { width: 12px; height: 12px; }

/* Book knowledge items styling */
.knowledge-items {
    margin-top: 0.5rem;
}
.knowledge-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: hsl(var(--muted) / 0.5);
    border-radius: 0.5rem;
    border-left: 3px solid #8b5cf6;
}
.knowledge-badge {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-right: 0.5rem;
}
.knowledge-badge.character { background: #3b82f6; color: white; }
.knowledge-badge.relationship { background: #ec4899; color: white; }
.knowledge-badge.theme { background: #8b5cf6; color: white; }
.knowledge-badge.location { background: #10b981; color: white; }
.knowledge-role {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-left: 0.25rem;
}
.knowledge-desc {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.25rem;
    line-height: 1.4;
}

.source-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    margin-top: 0.5rem;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    font-size: 0.75rem;
}
.source-icon {
    width: 20px;
    height: 20px;
    background: hsl(var(--primary) / 0.1);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.source-icon svg { width: 12px; height: 12px; color: hsl(var(--primary)); }
.source-text { flex: 1; color: hsl(var(--muted-foreground)); line-height: 1.4; }
.source-count {
    font-size: 0.7rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
}
.view-sources-btn {
    font-size: 0.75rem;
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.1);
    border: 1px solid hsl(var(--primary) / 0.2);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    cursor: pointer;
    margin-top: 0.5rem;
    display: inline-block;
}
.view-sources-btn:hover { background: hsl(var(--primary) / 0.2); }
.source-group {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
}
.source-query {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    margin-bottom: 0.5rem;
}
.source-query svg { width: 14px; height: 14px; color: hsl(var(--primary)); flex-shrink: 0; }
.source-query span { flex: 1; }
.source-query .view-btn {
    font-size: 0.7rem;
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.1);
    border: 1px solid hsl(var(--primary) / 0.2);
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    cursor: pointer;
    white-space: nowrap;
}
.source-query .view-btn:hover { background: hsl(var(--primary) / 0.2); }
.source-preview {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    line-height: 1.4;
    margin-bottom: 0.25rem;
}
.source-group .source-count {
    font-size: 0.7rem;
    color: hsl(var(--muted-foreground));
}

/* Response action buttons container */
.response-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-left: 1rem; /* Align with message text (px-4) */
}

/* Copy button (icon only) */
.copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
    border-radius: 50%;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: all 0.15s ease;
}
.copy-btn:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}
.copy-btn.copied {
    background: hsl(142 76% 36%);
    border-color: hsl(142 76% 36%);
    color: white;
}
.copy-btn svg {
    width: 16px;
    height: 16px;
}

/* Narrate button (icon only, next to copy) */
.narrate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
    border-radius: 50%;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: all 0.15s ease;
}
.narrate-btn:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}
.narrate-btn.playing {
    background: hsl(var(--primary));
    border-color: hsl(var(--primary));
    color: white;
}
.narrate-btn.paused {
    background: hsl(220, 14%, 50%);
    border-color: hsl(220, 14%, 50%);
    color: white;
}
.narrate-btn svg {
    width: 16px;
    height: 16px;
}
/* Default: show speaker icon */
.narrate-btn .pause-icon,
.narrate-btn .play-icon {
    display: none;
}
/* Playing: show pause icon */
.narrate-btn.playing .speaker-icon,
.narrate-btn.playing .play-icon {
    display: none;
}
.narrate-btn.playing .pause-icon {
    display: block;
}
/* Paused: show play icon */
.narrate-btn.paused .speaker-icon,
.narrate-btn.paused .pause-icon {
    display: none;
}
.narrate-btn.paused .play-icon {
    display: block;
}
/* Loading: show spinner animation */
.narrate-btn.loading {
    background: hsl(var(--muted));
    border-color: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    pointer-events: none;
}
.narrate-btn.loading .speaker-icon {
    animation: narrate-pulse 1s ease-in-out infinite;
}
@keyframes narrate-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Sources button at bottom of response */
.sources-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
    border-radius: 2rem;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    cursor: pointer;
    transition: background-color 0.15s ease;
}
.sources-btn:hover {
    background: hsl(var(--accent));
}
.entities-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
    border-radius: 2rem;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    cursor: pointer;
    transition: background-color 0.15s ease;
    text-decoration: none;
}
.entities-btn:hover {
    background: hsl(var(--accent));
}
.entities-btn svg {
    width: 1rem;
    height: 1rem;
}
.sources-btn svg {
    width: 16px;
    height: 16px;
}

/* Sidebar styling */
.sidebar {
    width: 280px;
    min-width: 280px;
    border-right: 1px solid hsl(var(--border));
    background: hsl(var(--background));
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
}
.sidebar.hidden { display: none; }

/* Top section with toggle and new chat - matches collapsed strip positioning */
.sidebar-top-section {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
}

/* App brand wordmark — sits next to the sidebar toggle. */
.sidebar-brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.sidebar-brand {
    font-family: ui-serif, Georgia, 'Times New Roman', serif;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: hsl(var(--foreground));
    text-decoration: none;
    line-height: 1;
    padding-left: 0.25rem;
}
.sidebar-brand:hover { opacity: 0.85; }

/* Admin scope bar — only visible to admins. Hidden by default via .hidden. */
.admin-scope-bar {
    padding: 0.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-bottom: 1px solid hsl(var(--border));
}
.admin-scope-bar.hidden { display: none; }
.admin-scope-toggle {
    display: inline-flex;
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    overflow: hidden;
    width: 100%;
}
.admin-scope-btn {
    flex: 1;
    padding: 0.375rem 0.5rem;
    background: transparent;
    color: hsl(var(--muted-foreground));
    border: none;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.admin-scope-btn:hover { background: hsl(var(--accent)); }
.admin-scope-btn.active {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}
.admin-user-filter {
    padding: 0.375rem 0.5rem;
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 0.75rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.admin-user-filter.hidden { display: none; }

/* Owner badge shown on each conversation row in admin "all users" mode. */
.conv-owner-badge {
    display: inline-block;
    margin-left: 0.375rem;
    padding: 0.1rem 0.35rem;
    font-size: 0.65rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: hsl(var(--muted-foreground));
    background: hsl(var(--muted));
    border-radius: 0.25rem;
    vertical-align: middle;
}

/* Bottom section with logout */
.sidebar-bottom-section {
    padding: 1rem;
    border-top: 1px solid hsl(var(--border));
    margin-top: auto;
}
.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    width: 100%;
    border-radius: 0.375rem;
    color: hsl(var(--muted-foreground));
    text-decoration: none;
    font-size: 0.875rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.logout-btn:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}

/* Collapsed sidebar strip */
.sidebar-collapsed-strip {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 60px;
    background: hsl(var(--background));
    border-right: 1px solid hsl(var(--border));
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0;
    gap: 0.75rem;
    z-index: 40;
}
.sidebar-collapsed-strip.hidden { display: none; }

/* Sidebar icon button */
.sidebar-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    color: hsl(var(--foreground));
    transition: background-color 0.15s ease;
}
.sidebar-icon-btn:hover { background: hsl(var(--accent)); }

/* New chat button with primary color circle (collapsed state) */
.new-chat-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: background-color 0.15s ease;
}
.new-chat-btn:hover { background: hsl(var(--primary) / 0.85); }

/* Unified nav item in the sidebar top section (New conversation, Playgrounds, etc.).
   Same visual weight for every item — Claude-style. */
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    width: 100%;
    border: none;
    background: transparent;
    border-radius: 0.5rem;
    color: hsl(var(--foreground));
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.sidebar-nav-item:hover { background: hsl(var(--accent)); }
.sidebar-nav-item .sidebar-nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: hsl(var(--muted-foreground));
}
.sidebar-nav-item:hover .sidebar-nav-icon { color: hsl(var(--foreground)); }

/* Section header above the recent-conversations list — labels the section
   and exposes a quick link to the full /conversations page. */
.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem 0.25rem;
    margin-top: 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.02em;
}
.sidebar-section-header .sidebar-section-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    color: hsl(var(--muted-foreground));
    border-radius: 0.25rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.sidebar-section-header .sidebar-section-action:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}
.sidebar-content { flex: 1; overflow-y: auto; padding: 0.5rem; }
.session-item {
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    margin-bottom: 0.25rem;
    transition: background-color 0.15s;
}
.session-item:hover { background: hsl(var(--accent)); }
.session-item.active {
    background: hsl(var(--primary) / 0.1);
    border: 1px solid hsl(var(--primary) / 0.3);
}
.session-preview {
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.session-book {
    font-size: 0.7rem;
    color: hsl(var(--primary));
    margin-top: 0.125rem;
}
.session-date {
    font-size: 0.7rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.125rem;
}
.session-delete { opacity: 0; transition: opacity 0.15s; }
.session-item:hover .session-delete { opacity: 1; }

/* Main content area */
.main-content {
    margin-left: 280px;
    transition: margin-left 0.2s ease;
    position: relative;
}
.main-content.sidebar-collapsed { margin-left: 60px; }

/* Side-by-side EPUB reader pane (docked left of the chat column).
   Uses .epub-reader-open (NOT .reader-open — that class is already owned by
   the long-form #readerPanel below, which sets margin-right:700px and was
   shrinking #mainContent here). Hidden until opened; when #mainContent has
   .epub-reader-open the pane takes half the width and chat takes the rest. */
.epub-reader-pane {
    width: 0;
    flex: 0 0 0;
    overflow: hidden;
    transition: flex-basis 0.2s ease, width 0.2s ease;
}
.main-content.epub-reader-open .epub-reader-pane {
    flex: 0 0 50% !important;
    width: 50% !important;
    max-width: 50% !important;
    overflow: visible;
}
/* Chat column takes the other half and its children fill it. */
.main-content.epub-reader-open #chatColumn {
    flex: 1 1 50% !important;
    width: 50% !important;
    min-width: 0;
}

/* Independent scroll for reader vs chat: pin #mainContent and both columns
   to the viewport height with overflow hidden, so the only scroll regions
   are the reader viewer and the chat's #messagesContainer. */
.main-content.epub-reader-open {
    height: 100vh;
    overflow: hidden;
}
.main-content.epub-reader-open #chatColumn {
    height: 100vh;
    overflow: hidden;
    min-height: 0;
}
.main-content.epub-reader-open #epubReaderPane {
    height: 100vh;
    min-height: 0;
}
.main-content.epub-reader-open #epubReaderViewer {
    overflow: auto;
}
/* Drop the max-w-4xl cap + centering on chat content so it fills the column. */
.main-content.epub-reader-open #messagesContainer,
.main-content.epub-reader-open #chatColumn [class*="max-w-"] {
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
}
/* On narrow screens the reader overlays the whole content area instead of
   splitting, so chat isn't squeezed to nothing. */
@media (max-width: 900px) {
    .main-content.epub-reader-open .epub-reader-pane {
        position: absolute;
        inset: 0;
        width: 100%;
        flex-basis: 100%;
        z-index: 25;
    }
}

/* Floating action menu shown over a text selection in the reader (Highlight /
   Ask AI). Positioned absolutely within the viewer, which is the offset
   parent. */
#epubReaderViewer {
    position: relative;
}
.epub-selection-menu {
    position: absolute;
    z-index: 30;
    display: flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid hsl(var(--input, 0 0% 80%));
    border-radius: 6px;
    background: hsl(var(--background, 0 0% 100%));
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.epub-selection-menu.hidden {
    display: none;
}
.epub-selection-menu button {
    font-size: 12px;
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
}
.epub-selection-menu button:hover {
    background: hsl(var(--muted, 0 0% 94%));
}
.epub-selection-menu button.epub-selection-destructive {
    color: #c0392b;
}

/* Highlights list dropdown in the reader toolbar. Anchored below the header;
   each row jumps to that highlight. */
.epub-highlights-list {
    position: absolute;
    top: 44px;
    right: 8px;
    z-index: 28;
    width: 320px;
    max-width: calc(100% - 16px);
    max-height: 50vh;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid hsl(var(--input, 0 0% 80%));
    border-radius: 8px;
    background: hsl(var(--background, 0 0% 100%));
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.epub-highlights-list.hidden {
    display: none;
}
.epub-highlights-empty {
    padding: 12px;
    font-size: 13px;
    color: hsl(var(--muted-foreground, 0 0% 45%));
    text-align: center;
}
.epub-highlight-row {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    border-radius: 6px;
}
.epub-highlight-row:hover {
    background: hsl(var(--muted, 0 0% 94%));
}
.epub-highlight-row-text {
    flex: 1;
    text-align: left;
    font-size: 13px;
    line-height: 1.4;
    padding: 8px 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.epub-highlight-row-delete {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: hsl(var(--muted-foreground, 0 0% 45%));
    font-size: 14px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}
.epub-highlight-row:hover .epub-highlight-row-delete {
    opacity: 1;
}
.epub-highlight-row-delete:hover {
    color: #c0392b;
    background: hsl(var(--muted, 0 0% 92%));
}


/* Highlight chat empty state: canned starter prompts. */
.highlight-empty-state {
    padding: 16px;
    max-width: 640px;
    margin: 0 auto;
}
.highlight-quote-card {
    border-left: 4px solid #ffdb54;
    padding: 6px 0 6px 12px;
    margin: 0 0 8px 0;
    margin-left: auto;
    max-width: 80%;
    font-style: italic;
    color: hsl(var(--foreground, 0 0% 12%));
}
.highlight-empty-intro {
    font-size: 14px;
    margin-bottom: 12px;
    color: hsl(var(--foreground, 0 0% 12%));
}
.highlight-suggestion {
    display: block;
    width: 100%;
    text-align: left;
    font-size: 14px;
    padding: 12px 14px;
    margin-bottom: 8px;
    border: 1px solid hsl(var(--input, 0 0% 80%));
    border-radius: 10px;
    background: hsl(var(--muted, 0 0% 97%));
    cursor: pointer;
}
.highlight-suggestion:hover {
    background: hsl(var(--muted, 0 0% 92%));
}

/* Book selection cards */
.book-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}
.book-card {
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    text-align: left;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: hsl(var(--card));
}
.book-card:hover {
    border-color: hsl(var(--primary) / 0.5);
    box-shadow: 0 6px 20px -8px hsl(var(--primary) / 0.25);
    transform: translateY(-1px);
}
.book-card.selected {
    border-color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.05);
}

.book-card-cover {
    position: relative;
    aspect-ratio: 2 / 3;
    background: hsl(var(--muted));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.book-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.book-card-cover-placeholder {
    color: hsl(var(--muted-foreground));
    opacity: 0.5;
}

.book-card-body {
    padding: 0.625rem 0.75rem 0.75rem;
}
.book-card-title {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.book-card-author {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.book-card.reimagined {
    border-color: hsl(var(--primary) / 0.3);
}
.book-card-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.book-section {
    margin-bottom: 2.5rem;
}
.book-section:last-child {
    margin-bottom: 0;
}
.book-section-title {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: hsl(var(--muted-foreground));
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid hsl(var(--border));
}
@media (max-width: 900px) {
    .book-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
@media (max-width: 640px) {
    .book-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Scroll to bottom button */
.scroll-to-bottom-btn {
    position: fixed;
    bottom: 100px;
    left: calc(280px + (100% - 280px) / 2);
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: hsl(var(--muted-foreground));
    transition: opacity 0.2s ease, left 0.2s ease;
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
}
.scroll-to-bottom-btn.sidebar-collapsed {
    left: calc(60px + (100% - 60px) / 2);
}
.scroll-to-bottom-btn:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}
.scroll-to-bottom-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Voice state indicator - centered in chat window */
.voice-state-indicator {
    position: fixed;
    bottom: 100px;
    left: calc(280px + (100% - 280px) / 2);
    transform: translateX(-50%);
    background: #22c55e;
    color: white;
    border-radius: 9999px;
    padding: 0.5rem 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: left 0.2s ease;
}
.voice-state-indicator.hidden { display: none; }
.voice-state-indicator.sidebar-collapsed {
    left: calc(60px + (100% - 60px) / 2);
}
.voice-state-indicator.listening { background: #ef4444; }
.voice-state-indicator.processing { background: #f59e0b; }
.voice-state-indicator.speaking { background: #22c55e; }

/* Voice transcript - centered in chat window */
.voice-transcript {
    position: fixed;
    bottom: 140px;
    left: calc(280px + (100% - 280px) / 2);
    transform: translateX(-50%);
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    text-align: center;
    font-style: italic;
    max-width: 300px;
    background: hsl(var(--background) / 0.9);
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 50;
    transition: left 0.2s ease;
}
.voice-transcript.hidden { display: none; }
.voice-transcript.sidebar-collapsed {
    left: calc(60px + (100% - 60px) / 2);
}

/* Agent transcript - streaming response text */
.agent-transcript {
    position: fixed;
    bottom: 160px;
    left: calc(280px + (100% - 280px) / 2);
    transform: translateX(-50%);
    font-size: 0.9rem;
    color: hsl(var(--foreground));
    text-align: center;
    max-width: 500px;
    background: hsl(var(--background));
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid hsl(var(--primary) / 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 50;
    transition: left 0.2s ease;
    line-height: 1.5;
}
.agent-transcript.hidden { display: none; }
.agent-transcript.sidebar-collapsed {
    left: calc(60px + (100% - 60px) / 2);
}

/* Voice selector dropdown */
.voice-selector {
    position: relative;
    margin-right: 0.5rem;
}
.voice-selector-btn {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.5rem;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    font-size: 0.7rem;
    color: hsl(var(--foreground));
    cursor: pointer;
    transition: all 0.15s ease;
}
.voice-selector-btn:hover {
    background: hsl(var(--accent));
}
.voice-selector-btn svg {
    width: 12px;
    height: 12px;
}
.voice-selector-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 0.25rem;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 120px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
}
.voice-selector-dropdown.hidden {
    display: none;
}
.voice-selector-header {
    padding: 0.5rem 0.75rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground));
    background: hsl(var(--muted));
    border-bottom: 1px solid hsl(var(--border));
}
.voice-option {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.voice-option:hover {
    background: hsl(var(--accent));
}
.voice-option.active {
    background: hsl(var(--primary) / 0.1);
    color: hsl(var(--primary));
}
.voice-option .checkmark {
    width: 14px;
    height: 14px;
    opacity: 0;
}
.voice-option.active .checkmark {
    opacity: 1;
}
.voice-option-content {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}
.voice-name {
    font-weight: 500;
}
.voice-desc {
    font-size: 0.65rem;
    color: hsl(var(--muted-foreground));
}
.voice-option.active .voice-desc {
    color: hsl(var(--primary) / 0.7);
}

/* Model selector dropdown - shadcn style */
#modelSelectorContainer .voice-selector-dropdown {
    min-width: 280px;
    max-height: 480px;
    right: 0;
    left: auto;
}
.model-option {
    position: relative;
    padding: 0.5rem 0.5rem 0.5rem 2rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 0.25rem;
    margin: 0.125rem 0.25rem;
    outline: none;
}
.model-option:hover {
    background: hsl(var(--accent));
}
.model-option:focus {
    background: hsl(var(--accent));
}
.model-option.active {
    background: transparent;
}
.model-option .checkmark {
    position: absolute;
    left: 0.5rem;
    width: 16px;
    height: 16px;
    opacity: 0;
    color: hsl(var(--foreground));
}
.model-option.active .checkmark {
    opacity: 1;
}
.model-option-content {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    flex: 1;
}
.model-name {
    font-weight: 400;
    color: hsl(var(--foreground));
}
.model-desc {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}
.model-group-header {
    padding: 0.5rem 0.5rem 0.375rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: hsl(var(--foreground));
}
.model-group-separator {
    height: 1px;
    background: hsl(var(--border));
    margin: 0.25rem 0.5rem;
}

.selected-book-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: hsl(var(--primary) / 0.1);
    border: 1px solid hsl(var(--primary) / 0.3);
    border-radius: 2rem;
    font-size: 0.875rem;
    color: hsl(var(--primary));
    margin-bottom: 1rem;
}

/* Reader Panel - for long-form content (like Claude Artifacts) */
.reader-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 50%;
    max-width: 700px;
    min-width: 400px;
    height: 100vh;
    background: hsl(var(--background));
    border-left: 1px solid hsl(var(--border));
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
    z-index: 50;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}
.reader-panel.open {
    transform: translateX(0);
}
.reader-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid hsl(var(--border));
    background: hsl(var(--muted) / 0.3);
}
.reader-panel-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: hsl(var(--foreground));
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.reader-panel-title svg {
    width: 18px;
    height: 18px;
    color: hsl(var(--primary));
}
.reader-panel-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.reader-control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: all 0.15s ease;
}
.reader-control-btn:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
    border-color: hsl(var(--foreground) / 0.2);
}
.reader-control-btn.copied {
    background: #22c55e;
    border-color: #22c55e;
    color: white;
}
.reader-control-btn svg {
    width: 16px;
    height: 16px;
}
.reader-panel-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid hsl(var(--border));
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}
.reader-panel-meta span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Chapter navigation */
.reader-chapter-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid hsl(var(--border));
    background: hsl(var(--muted) / 0.2);
}
.reader-chapter-nav.loading {
    opacity: 0.6;
    pointer-events: none;
}
.chapter-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    color: hsl(var(--foreground));
    cursor: pointer;
    transition: all 0.15s ease;
}
.chapter-nav-btn:hover:not(:disabled) {
    background: hsl(var(--accent));
    border-color: hsl(var(--primary) / 0.3);
}
.chapter-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.chapter-nav-btn svg {
    width: 16px;
    height: 16px;
}
.chapter-indicator {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    min-width: 120px;
    text-align: center;
}
.reader-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    color: hsl(var(--foreground));
    cursor: pointer;
    transition: all 0.15s ease;
}
.reader-nav-btn:hover:not(:disabled) {
    background: hsl(var(--accent));
    border-color: hsl(var(--primary) / 0.3);
}
.reader-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.reader-nav-btn svg {
    width: 16px;
    height: 16px;
}
.reader-chapter-indicator {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    min-width: 140px;
    text-align: center;
}
.reader-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: hsl(var(--muted-foreground));
    font-style: italic;
}
.reader-error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: hsl(var(--destructive));
}

.reader-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}
.reader-panel-content .prose {
    max-width: none;
    line-height: 1.8;
}
.reader-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.2);
    z-index: 49;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.reader-panel-overlay.visible {
    opacity: 1;
    visibility: visible;
}
/* When reader panel is open, shrink main content on larger screens */
@media (min-width: 1200px) {
    .main-content.reader-open {
        margin-right: min(50%, 700px);
        transition: margin-right 0.3s ease;
    }
}
/* Reader link message in chat */
.reader-link-message {
    padding: 1rem;
    background: hsl(var(--primary) / 0.05);
    border: 1px solid hsl(var(--primary) / 0.2);
    border-radius: 0.75rem;
}

/* Modal styling */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal-content {
    background: hsl(var(--background));
    border-radius: 0.75rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
}
.modal-header h3 { font-weight: 600; font-size: 1.1rem; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}
.modal-close:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.modal-subheader {
    padding: 0.75rem 1.5rem;
    background: hsl(var(--muted));
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    border-bottom: 1px solid hsl(var(--border));
}
.modal-body { flex: 1; overflow-y: auto; padding: 1.5rem; }
.modal-passage {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
}
.modal-passage:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.modal-passage-header { font-weight: 500; font-size: 0.875rem; color: hsl(var(--primary)); margin-bottom: 0.5rem; }
.modal-passage-content {
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    background: hsl(var(--muted));
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* Two-panel modal */
.modal-two-panel {
    max-width: 1000px;
    width: 95%;
    height: 80vh;
}
.modal-panels {
    display: flex;
    flex: 1;
    overflow: hidden;
}
.modal-left-panel {
    width: 280px;
    min-width: 280px;
    border-right: 1px solid hsl(var(--border));
    overflow-y: auto;
    background: hsl(var(--muted) / 0.3);
}
.modal-right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-query-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid hsl(var(--border));
    transition: background-color 0.15s ease;
}
.modal-query-item:hover {
    background: hsl(var(--accent));
}
.modal-query-item.active {
    background: hsl(var(--primary) / 0.1);
    border-left: 3px solid hsl(var(--primary));
}
.modal-query-text {
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.modal-query-count {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.25rem;
}
.modal-snippets-header {
    padding: 0.75rem 1rem;
    background: hsl(var(--muted));
    border-bottom: 1px solid hsl(var(--border));
    font-size: 0.875rem;
    font-weight: 500;
}
.modal-snippets-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}
.modal-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
}

@media (max-width: 768px) {
    .sidebar { display: none; }
    .sidebar.mobile-open { display: flex; }
    .sidebar-collapsed-strip { display: none; }
    .sidebar-collapsed-strip.mobile-show { display: flex; }
    .main-content { margin-left: 0; }
    .main-content.sidebar-collapsed { margin-left: 0; }
}

/* Toast notification styles */
.toast {
    animation: slide-in 0.2s ease-out;
}
@keyframes slide-in {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}
.toast.animate-slide-out {
    animation: slide-out 0.2s ease-out forwards;
}
@keyframes slide-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Feedback dialog styles */
.feedback-dialog-overlay {
    backdrop-filter: blur(2px);
}
.feedback-dialog {
    animation: dialog-appear 0.2s ease-out;
}
@keyframes dialog-appear {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Review action buttons in reader panel */
.reader-actions {
    display: flex;
    gap: 0.75rem;
    padding-top: 1rem;
    margin-top: 1.5rem;
    border-top: 1px solid hsl(var(--border));
}
.reader-actions .btn-primary {
    flex: 1;
    padding: 0.625rem 1rem;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border-radius: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background 0.15s;
}
.reader-actions .btn-primary:hover {
    background: hsl(var(--primary) / 0.9);
}
.reader-actions .btn-secondary {
    flex: 1;
    padding: 0.625rem 1rem;
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background 0.15s;
}
.reader-actions .btn-secondary:hover {
    background: hsl(var(--muted));
}

/* Task Progress Container */
.task-progress-container {
    position: fixed;
    bottom: 100px;
    left: calc(280px + (100% - 280px) / 2);
    transform: translateX(-50%);
    z-index: 40;
    transition: left 0.2s ease;
}
.task-progress-container.hidden {
    display: none;
}
.task-progress-container.sidebar-collapsed {
    left: calc(60px + (100% - 60px) / 2);
}
.task-progress-card {
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    min-width: 340px;
    max-width: 420px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
}
.task-progress-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid hsl(var(--border));
    margin-bottom: 0.75rem;
}
.task-spinner-ring {
    width: 22px;
    height: 22px;
}
.task-spinner-ring svg {
    width: 100%;
    height: 100%;
    animation: spin 1.2s linear infinite;
}
.task-progress-title {
    font-weight: 500;
    font-size: 0.9375rem;
    color: hsl(var(--foreground));
}
.task-progress-percent {
    font-weight: 600;
    font-size: 0.9375rem;
    color: hsl(var(--muted-foreground));
}
/* Steps timeline */
.task-progress-steps {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    max-height: 200px;
    overflow-y: auto;
}
.task-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    position: relative;
}
.task-step:not(:last-child)::after {
    content: '';
    position: absolute;
    left: 5px;
    top: calc(50% + 10px);
    width: 2px;
    height: calc(100% - 8px);
    background: hsl(var(--border));
}
.task-step-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}
.task-step-dot.completed {
    background: hsl(142 76% 36%);
}
.task-step-dot.active {
    background: hsl(var(--primary));
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.2);
    animation: pulse-dot 1.5s ease-in-out infinite;
}
.task-step-dot.pending {
    background: transparent;
    border: 2px solid hsl(var(--muted-foreground) / 0.4);
}
@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 3px hsl(var(--primary) / 0.2); }
    50% { box-shadow: 0 0 0 5px hsl(var(--primary) / 0.1); }
}
.task-step-content {
    flex: 1;
    min-width: 0;
}
.task-step-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    line-height: 1.3;
}
.task-step.completed .task-step-label {
    color: hsl(var(--muted-foreground));
}
.task-step-detail {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.125rem;
}
.task-step-percent {
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    flex-shrink: 0;
}

/* Toast slide-up animation */
@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.animate-slide-up {
    animation: slide-up 0.3s ease-out;
}

/* Card background for toasts */
.bg-card {
    background: hsl(var(--background));
}

/* Task Recovery Banner - shown when returning to a book with an active task */
.task-recovery-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(90deg, hsl(var(--primary) / 0.1), hsl(var(--primary) / 0.05));
    border: 1px solid hsl(var(--primary) / 0.2);
    border-radius: 0.5rem;
    margin: 0.5rem 1rem;
    gap: 1rem;
}
.task-recovery-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}
.task-recovery-title {
    font-weight: 500;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
}
.task-recovery-description {
    font-size: 0.8rem;
    color: hsl(var(--muted-foreground));
}
.task-recovery-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}
.recovery-action-btn {
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}
.recovery-action-btn.primary {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
}
.recovery-action-btn.primary:hover {
    background: hsl(var(--primary) / 0.9);
}
.recovery-action-btn.secondary {
    background: transparent;
    color: hsl(var(--primary));
    border: 1px solid hsl(var(--primary) / 0.3);
}
.recovery-action-btn.secondary:hover {
    background: hsl(var(--primary) / 0.1);
}
.task-recovery-banner .spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid hsl(var(--primary) / 0.2);
    border-top-color: hsl(var(--primary));
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Recovery banner variants */
.task-recovery-banner.sample-ready {
    background: linear-gradient(90deg, hsl(142 76% 36% / 0.1), hsl(142 76% 36% / 0.05));
    border-color: hsl(142 76% 36% / 0.3);
}
.task-recovery-banner.running {
    background: linear-gradient(90deg, hsl(var(--primary) / 0.1), hsl(var(--primary) / 0.05));
}
.task-recovery-banner.paused {
    background: linear-gradient(90deg, hsl(38 92% 50% / 0.1), hsl(38 92% 50% / 0.05));
    border-color: hsl(38 92% 50% / 0.3);
}

/* ============================================
   Message Flow (V2 inline cards)
   ============================================ */

.message-flow {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ============================================
   Inline Tool Cards
   ============================================ */

.inline-cards-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.inline-cards-container:empty {
    display: none;
}

/* ============================================
   Suggestion Chips
   ============================================ */

.suggestion-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0;
    margin-top: 0.25rem;
    width: 100%;
    flex-basis: 100%;
}

/* Placeholder shown while live conversation starters are being generated. */
.conversation-starters-loading {
    padding: 0.5rem 0;
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    opacity: 0.7;
}

.suggestion-chip {
    display: inline-block;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: hsl(var(--foreground));
    background: hsl(var(--muted) / 0.3);
    border: 1px solid hsl(var(--border));
    border-radius: 1.5rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    text-align: left;
    max-width: 100%;
    word-break: break-word;
}

.suggestion-chip:hover {
    background: hsl(var(--muted) / 0.6);
    border-color: hsl(var(--primary) / 0.5);
}

.suggestion-chip:active {
    background: hsl(var(--primary) / 0.15);
    border-color: hsl(var(--primary));
}

.suggestion-chip-history {
    cursor: default;
    opacity: 0.6;
}

.suggestion-chip-history:hover {
    background: hsl(var(--muted) / 0.3);
    border-color: hsl(var(--border));
}

/* === Inline citation chips ===
   <sup class="citation-chip"> overlaid on the assistant response at the
   character-offset ranges the backend gave us.  Labeled (Ch. VI /
   forbes.com) rather than numeric, with a `+N` form for sentences
   backed by multiple sources. */
.citation-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.15em;
    margin: 0 0.15em;
    padding: 0.05em 0.4em;
    font-size: 0.72em;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    vertical-align: super;
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.08);
    border: 1px solid hsl(var(--primary) / 0.28);
    border-radius: 999px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.citation-chip:hover {
    background: hsl(var(--primary) / 0.18);
    border-color: hsl(var(--primary) / 0.55);
}

.citation-chip:focus-visible {
    outline: 2px solid hsl(var(--primary));
    outline-offset: 1px;
}

.citation-chip--passage {
    border-left-width: 2px;
}

.citation-chip--web {
    color: hsl(220, 70%, 35%);
    background: hsl(220, 70%, 55% / 0.08);
    border-color: hsl(220, 70%, 55% / 0.32);
}

.citation-chip--web:hover {
    background: hsl(220, 70%, 55% / 0.18);
    border-color: hsl(220, 70%, 55%);
}

.citation-chip--multi {
    /* Multi-source chips slightly darker so the +N reads as "more". */
    background: hsl(var(--primary) / 0.14);
    border-color: hsl(var(--primary) / 0.45);
}

/* === Source-strip chips (beneath the bubble) ===
   The skim-reader / accessibility view: every citation gets its own
   labeled pill in a horizontal row right under the response. */
.citation-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.35rem 0 0.25rem 0;
    margin-top: 0.25rem;
    width: 100%;
    flex-basis: 100%;
}

.citation-strip-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.65rem;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.2;
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.08);
    border: 1px solid hsl(var(--primary) / 0.28);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.citation-strip-chip:hover {
    background: hsl(var(--primary) / 0.18);
    border-color: hsl(var(--primary) / 0.55);
}

.citation-strip-chip--web {
    color: hsl(220, 70%, 35%);
    background: hsl(220, 70%, 55% / 0.08);
    border-color: hsl(220, 70%, 55% / 0.32);
}

.citation-strip-chip--web:hover {
    background: hsl(220, 70%, 55% / 0.18);
    border-color: hsl(220, 70%, 55%);
}

/* "+N others" chip — neutral muted styling so the first source still
   reads as the primary citation; this is just a "more" affordance. */
.citation-strip-chip--more {
    color: hsl(var(--muted-foreground));
    background: hsl(var(--muted) / 0.4);
    border-color: hsl(var(--border));
}

.citation-strip-chip--more:hover {
    background: hsl(var(--muted) / 0.7);
    border-color: hsl(var(--foreground) / 0.3);
}

/* === Multi-source popover ===
   Shown when the user clicks a chip with `+N` collapse.  Lists each
   contributing source in a vertical menu. */
.citation-popover {
    z-index: 1000;
    min-width: 16rem;
    max-width: 22rem;
    padding: 0.4rem;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.citation-popover-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    padding: 0.4rem 0.55rem;
    border: none;
    background: transparent;
    border-radius: 0.4rem;
    cursor: pointer;
    text-align: left;
}

.citation-popover-row:hover,
.citation-popover-row:focus-visible {
    background: hsl(var(--muted) / 0.5);
    outline: none;
}

.citation-popover-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.citation-popover-sub {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    line-height: 1.3;
}

/* Single-source preview card — title + snippet + open CTA. */
.citation-popover--preview {
    padding: 0;
}

.citation-preview {
    display: flex;
    flex-direction: column;
    padding: 0.65rem 0.8rem;
}

.citation-preview-header {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-bottom: 0.45rem;
}

.citation-preview-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    line-height: 1.25;
}

.citation-preview-domain {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.citation-preview-body {
    font-size: 0.82rem;
    color: hsl(var(--foreground) / 0.85);
    line-height: 1.4;
    margin-bottom: 0.55rem;
    /* Italics for passages reads as quoted material; reset for web. */
    font-style: italic;
}

.citation-preview--web .citation-preview-body {
    font-style: normal;
}

.citation-preview-footer {
    display: flex;
    justify-content: flex-end;
}

.citation-preview-cta {
    padding: 0.3rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.08);
    border: 1px solid hsl(var(--primary) / 0.28);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.citation-preview-cta:hover {
    background: hsl(var(--primary) / 0.18);
    border-color: hsl(var(--primary) / 0.55);
}

/* ============================================
   Clarification Card
   ============================================ */

.clarification-card {
    background: hsl(var(--muted) / 0.15);
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    overflow: hidden;
    width: 100%;
    margin-top: 0.5rem;
}

.clarification-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
}

.clarification-card-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.clarification-nav-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    padding: 0.25rem;
}

.clarification-nav-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.clarification-page-indicator {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.clarification-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: hsl(var(--muted-foreground));
    padding: 0.25rem;
}

.clarification-close-btn:hover {
    color: hsl(var(--foreground));
}

.clarification-card-body {
    padding: 0.75rem;
}

.clarification-question-text {
    font-size: 0.9375rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: hsl(var(--foreground));
}

.clarification-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.clarification-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
    color: hsl(var(--foreground));
}

.clarification-option:hover {
    border-color: hsl(var(--primary) / 0.5);
    background: hsl(var(--primary) / 0.05);
}

.clarification-option.selected {
    border-color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.1);
}

.clarification-option-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    flex-shrink: 0;
}

.clarification-custom {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
}

.clarification-custom-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
}

.clarification-custom-input::placeholder {
    color: hsl(var(--muted-foreground) / 0.5);
}

.clarification-card-footer {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid hsl(var(--border) / 0.5);
    display: flex;
    justify-content: flex-end;
}

.clarification-submit-btn {
    padding: 0.5rem 1.25rem;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}

.clarification-submit-btn:hover {
    opacity: 0.9;
}

/* History clarification card (non-interactive) */
.clarification-history-card {
    background: hsl(var(--muted) / 0.15);
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    width: 100%;
}

.clarification-history-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.clarification-history-body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.clarification-history-question {
    display: flex;
    gap: 0.375rem;
}

.inline-tool-card {
    display: flex;
    flex-direction: column;
    background: hsl(var(--muted) / 0.3);
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    overflow: hidden;
}

.tool-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.tool-card-header:hover {
    background: hsl(var(--muted) / 0.5);
}

.tool-card-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: hsl(var(--muted-foreground));
}

.tool-card-icon svg {
    width: 16px;
    height: 16px;
}

.tool-card-query {
    flex: 1;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-card-result {
    font-size: 0.8rem;
    color: hsl(var(--muted-foreground));
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.tool-card-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid hsl(var(--border));
    border-top-color: hsl(var(--primary));
    border-radius: 50%;
    animation: inline-spin 0.8s linear infinite;
}

@keyframes inline-spin {
    to { transform: rotate(360deg); }
}

.inline-tool-card[data-status="complete"] .tool-card-spinner {
    display: none;
}

.tool-card-count {
    display: none;
}

.inline-tool-card[data-status="complete"] .tool-card-count {
    display: inline;
}

.tool-card-chevron {
    width: 16px;
    height: 16px;
    color: hsl(var(--muted-foreground));
    transition: transform 0.2s ease;
}

.inline-tool-card.expanded .tool-card-chevron {
    transform: rotate(180deg);
}

.tool-card-content {
    display: none;
    border-top: 1px solid hsl(var(--border));
    padding: 0.75rem;
    background: hsl(var(--background));
    max-height: 250px;
    overflow-y: auto;
}

.inline-tool-card.expanded .tool-card-content {
    display: block;
}

.tool-card-preview-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    font-size: 0.8rem;
}

.tool-card-preview-item:last-child {
    border-bottom: none;
}

.tool-card-preview-query,
.tool-card-preview-header {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    margin-bottom: 0.25rem;
}

.tool-card-preview-text {
    color: hsl(var(--foreground));
    line-height: 1.4;
}

.tool-card-preview-link {
    color: hsl(var(--primary));
    text-decoration: none;
    cursor: pointer;
}

.tool-card-preview-link:hover {
    text-decoration: underline;
}

/* ============================================
   Inline Progress Card (for Transformation)
   ============================================ */

.inline-progress-card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    overflow: hidden;
    margin: 0.5rem 0;
}

.inline-progress-card.complete {
    border-color: #22c55e40;
    background: #22c55e08;
}

.inline-progress-card.failed {
    border-color: hsl(var(--destructive) / 0.4);
    background: hsl(var(--destructive) / 0.05);
}

.inline-progress-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--muted) / 0.3);
}

.inline-progress-title {
    font-weight: 500;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
}

.inline-progress-percent {
    font-size: 0.875rem;
    font-weight: 600;
    color: hsl(var(--primary));
}

.inline-progress-steps {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
    max-height: 300px;
    overflow-y: auto;
}

.inline-progress-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.375rem 0;
    position: relative;
}

/* Vertical line connecting steps */
.inline-progress-step:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 24px;
    bottom: -8px;
    width: 2px;
    background: hsl(var(--border));
}

.inline-progress-step.completed:not(:last-child)::before {
    background: #22c55e;
}

.inline-progress-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

/* Pending state - outline only */
.inline-progress-step.pending .inline-progress-dot {
    background: transparent;
    border: 2px solid hsl(var(--border));
}

/* Active state - pulsing blue */
.inline-progress-step.active .inline-progress-dot {
    background: hsl(var(--primary));
    animation: progress-pulse 1.5s ease-in-out infinite;
}

/* Completed state - solid green */
.inline-progress-step.completed .inline-progress-dot {
    background: #22c55e;
}

/* Failed state - red */
.inline-progress-step.failed .inline-progress-dot {
    background: hsl(var(--destructive));
}

@keyframes progress-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

.inline-progress-label {
    font-size: 0.8125rem;
    color: hsl(var(--foreground));
}

.inline-progress-step.pending .inline-progress-label {
    color: hsl(var(--muted-foreground));
}

.inline-progress-step.active .inline-progress-label {
    font-weight: 500;
}

.inline-progress-actions {
    padding: 0.75rem 1rem;
    border-top: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--muted) / 0.2);
}

.inline-progress-view-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}

.inline-progress-view-btn:hover {
    background: hsl(var(--primary) / 0.9);
}

.inline-progress-cancel-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.inline-progress-cancel-btn:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
    border-color: hsl(var(--foreground) / 0.2);
}

.inline-progress-error {
    padding: 0.5rem 1rem;
    color: hsl(var(--destructive));
    font-size: 0.8125rem;
}

/* ============================================
   Inline Document Card (for write_document)
   ============================================ */

.inline-document-card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    overflow: hidden;
    margin: 0.5rem 0;
    cursor: pointer;
    transition: all 0.15s ease;
}

.inline-document-card:hover {
    border-color: hsl(var(--primary) / 0.5);
    background: hsl(var(--primary) / 0.03);
}

.document-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
}

.document-card-icon {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: hsl(var(--primary) / 0.1);
    border-radius: 0.5rem;
    color: hsl(var(--primary));
}

.document-card-icon svg {
    width: 1.125rem;
    height: 1.125rem;
}

.document-card-info {
    flex: 1;
    min-width: 0;
}

.document-card-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.document-card-meta {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.125rem;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.document-card-sep {
    color: hsl(var(--muted-foreground) / 0.5);
}

.document-card-action {
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: hsl(var(--muted-foreground));
    transition: color 0.15s ease;
}

.inline-document-card:hover .document-card-action {
    color: hsl(var(--primary));
}

.document-card-action svg {
    width: 1rem;
    height: 1rem;
}

/* Streaming document card state */
.inline-document-card.streaming {
    border-color: hsl(var(--primary) / 0.3);
}

.document-card-streaming {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: hsl(var(--primary));
}

.streaming-dot-small {
    width: 6px;
    height: 6px;
    background: hsl(var(--primary));
    border-radius: 50%;
    animation: streaming-pulse 1.2s ease-in-out infinite;
}

/* Incomplete document card (interrupted generation) */
.inline-document-card.incomplete {
    border-color: hsl(45 93% 47% / 0.4);
    background: hsl(45 93% 47% / 0.05);
}

.document-card-incomplete-icon {
    color: hsl(45 93% 47%);
    font-size: 0.75rem;
}

/* ============================================
   Document Streaming Mode
   ============================================ */

.streaming-document {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Outline sidebar */
.document-outline {
    background: hsl(var(--muted) / 0.3);
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.outline-header {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: hsl(var(--muted-foreground));
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
}

.outline-sections {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.outline-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    color: hsl(var(--muted-foreground));
    transition: all 0.15s ease;
}

.outline-section.active {
    background: hsl(var(--primary) / 0.1);
    color: hsl(var(--foreground));
}

.outline-section.complete {
    color: hsl(var(--muted-foreground));
}

.outline-status {
    width: 1rem;
    height: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.outline-status.pending {
    color: hsl(var(--muted-foreground) / 0.5);
}

.outline-status.complete {
    color: #22c55e;
}

.outline-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Streaming content area */
.streaming-content {
    min-height: 200px;
}

.streaming-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
    padding: 1rem;
}

.streaming-dot {
    width: 8px;
    height: 8px;
    background: hsl(var(--primary));
    border-radius: 50%;
    animation: streaming-pulse 1.2s ease-in-out infinite;
}

@keyframes streaming-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* Document completion indicator */
.document-complete-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding: 0.75rem 1rem;
    background: hsl(142 76% 36% / 0.1);
    border: 1px solid hsl(142 76% 36% / 0.2);
    border-radius: 0.5rem;
    color: #22c55e;
    font-size: 0.875rem;
    font-weight: 500;
}

.complete-icon {
    font-size: 1rem;
}

/* ============================================
   Characters Home (/characters)
   ============================================ */
.characters-home {
    max-width: 72rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
}
.characters-home-header {
    margin-bottom: 1.5rem;
    padding: 0 0.25rem;
}
.characters-home-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: hsl(var(--foreground));
    letter-spacing: -0.01em;
}
.characters-home-subtitle {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.25rem;
}

.character-row {
    margin-bottom: 2rem;
}

.character-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
    padding: 0 0.25rem;
}
.character-row-book {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}
.character-row-cover {
    width: 36px;
    height: 54px;
    flex-shrink: 0;
    border-radius: 0.25rem;
    overflow: hidden;
    background: hsl(var(--muted));
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.character-row-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.character-row-cover-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, hsl(var(--muted)) 0%, hsl(var(--accent)) 100%);
}
.character-row-meta {
    min-width: 0;
}
.character-row-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.character-row-author {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.character-row-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.character-row-roundtable-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: 9999px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.character-row-roundtable-btn:hover {
    color: hsl(var(--primary));
    border-color: hsl(var(--primary) / 0.5);
    background: hsl(var(--primary) / 0.05);
}
.character-row-show-all {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    text-decoration: none;
    border-radius: 0.375rem;
    transition: color 0.15s, background-color 0.15s;
}
.character-row-show-all:hover {
    color: hsl(var(--foreground));
    background: hsl(var(--accent));
}

.character-row-carousel {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding: 0.25rem 0.25rem 0.75rem;
    scrollbar-width: thin;
}
.character-row-carousel::-webkit-scrollbar {
    height: 6px;
}
.character-row-carousel::-webkit-scrollbar-track {
    background: transparent;
}
.character-row-carousel::-webkit-scrollbar-thumb {
    background: hsl(var(--border));
    border-radius: 3px;
}
.character-row-carousel::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.5);
}

.character-row-card {
    flex-shrink: 0;
    width: 180px;
    text-align: left;
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    padding: 0.75rem;
    cursor: pointer;
    scroll-snap-align: start;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.character-row-card:hover {
    border-color: hsl(var(--primary) / 0.5);
    box-shadow: 0 6px 18px -10px hsl(var(--primary) / 0.3);
    transform: translateY(-1px);
}
.character-row-card-portrait {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 0.5rem;
    overflow: hidden;
    background: hsl(var(--muted));
    display: flex;
    align-items: center;
    justify-content: center;
}
.character-row-card-voice {
    position: absolute;
    top: 0.375rem;
    right: 0.375rem;
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    background: hsl(142 71% 45%);
    border-radius: 9999px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.character-row-card-voice svg {
    width: 0.75rem;
    height: 0.75rem;
}
.character-row-card-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.character-row-card-initials {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    font-weight: 700;
}
.character-row-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}
.character-row-card-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.character-row-card-role {
    display: inline-block;
    align-self: flex-start;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
}
.character-row-card-role-protagonist {
    background: hsl(217 91% 60% / 0.15);
    color: hsl(217 91% 50%);
}
.character-row-card-role-antagonist {
    background: hsl(0 84% 60% / 0.15);
    color: hsl(0 84% 50%);
}
.character-row-card-role-supporting {
    background: hsl(220 9% 46% / 0.15);
    color: hsl(220 9% 35%);
}
.character-row-card-desc {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.character-row-skeleton {
    flex-shrink: 0;
    width: 180px;
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.character-row-skeleton-avatar {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 0.5rem;
    background: hsl(var(--muted));
    animation: character-row-skeleton-pulse 1.4s ease-in-out infinite;
}
.character-row-skeleton-line {
    height: 0.625rem;
    border-radius: 0.25rem;
    background: hsl(var(--muted));
    animation: character-row-skeleton-pulse 1.4s ease-in-out infinite;
}
.character-row-skeleton-line-name {
    width: 70%;
}
.character-row-skeleton-line-desc {
    width: 90%;
}
@keyframes character-row-skeleton-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.85; }
}

.character-row-empty {
    flex-shrink: 0;
    padding: 1.25rem 1rem;
    font-size: 0.8125rem;
    color: hsl(var(--muted-foreground));
    border: 1px dashed hsl(var(--border));
    border-radius: 0.5rem;
    background: hsl(var(--muted) / 0.3);
}

@media (max-width: 640px) {
    .character-row-card,
    .character-row-skeleton {
        width: 150px;
    }
    .character-row-cover {
        width: 32px;
        height: 48px;
    }
}

/* Illustration card — shown inline in chat while an illustrate_highlight task
   runs. The shimmer hints "we're making something visual" without committing
   to a fake skeleton of the final image. */
.illustration-card .illustration-shimmer-bg {
    background: linear-gradient(
        110deg,
        hsl(var(--muted) / 0.6) 8%,
        hsl(var(--muted) / 0.3) 18%,
        hsl(var(--muted) / 0.6) 33%
    );
    background-size: 220% 100%;
    animation: illustration-shimmer 1.6s linear infinite;
}
@keyframes illustration-shimmer {
    0%   { background-position: 220% 0; }
    100% { background-position: -20% 0; }
}
.illustration-image {
    background: hsl(var(--muted) / 0.4);
}

/* Animation card — shown inline in chat while an animate_highlight task
   runs. Same shimmer treatment as illustration; switches to a <video>
   element when the kling clip lands. */
.animation-card .animation-shimmer-bg {
    background: linear-gradient(
        110deg,
        hsl(var(--muted) / 0.6) 8%,
        hsl(var(--muted) / 0.3) 18%,
        hsl(var(--muted) / 0.6) 33%
    );
    background-size: 220% 100%;
    animation: animation-shimmer 1.6s linear infinite;
}
@keyframes animation-shimmer {
    0%   { background-position: 220% 0; }
    100% { background-position: -20% 0; }
}
.animation-video {
    background: hsl(var(--muted) / 0.4);
    max-height: 70vh;
}
