/* ════════════════════════════════════════════════════════════
   INKSTRIDE — Design System
   Dark creative writing environment with purple accent
   ════════════════════════════════════════════════════════════ */

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Reset & Foundation ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Core Palette */
    --bg-deep:        #0a0a10;
    --bg-dark:        #0f0f16;
    --bg-panel:       #13131c;
    --bg-surface:     #1a1a26;
    --bg-input:       #161620;
    --bg-hover:       #1e1e2c;
    --bg-sidebar:     #0c0c14;

    /* Accent */
    --accent:         #7c6fe0;
    --accent-hover:   #6558c4;
    --accent-dim:     #3d3570;
    --accent-glow:    rgba(124, 111, 224, 0.15);
    --accent-subtle:  rgba(124, 111, 224, 0.08);

    /* Text */
    --text-primary:   #e8e6f0;
    --text-secondary: #9896a8;
    --text-muted:     #5c5a6e;
    --text-dim:       #3e3c4e;

    /* Semantic */
    --success:        #4ade80;
    --success-dim:    rgba(74, 222, 128, 0.12);
    --warning:        #fbbf24;
    --warning-dim:    rgba(251, 191, 36, 0.12);
    --error:          #f87171;
    --error-dim:      rgba(248, 113, 113, 0.12);

    /* Borders */
    --border:         #222233;
    --border-subtle:  #1a1a2a;
    --border-accent:  rgba(124, 111, 224, 0.25);

    /* Dimensions */
    --toolbar-h:      52px;
    --sidebar-w:      220px;
    --panel-header-h: 40px;
    --canvas-footer-h: 52px;
    --companion-input-h: 56px;
    --radius:         8px;
    --radius-sm:      5px;
    --radius-lg:      12px;

    /* Typography */
    --font-ui:        'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-prose:     'Merriweather', 'Georgia', serif;

    /* Animation */
    --ease:           cubic-bezier(0.16, 1, 0.3, 1);
    --duration:       0.2s;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Toolbar ── */
#toolbar {
    height: var(--toolbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    position: relative;
}

#toolbar::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-dim), transparent);
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
    font-style: italic;
    letter-spacing: 0.5px;
}

.toolbar-center {
    display: flex;
    align-items: center;
    gap: 16px;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-selector label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

#model-select {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: border-color var(--duration);
    min-width: 160px;
}

#model-select:focus {
    border-color: var(--accent);
}

.status-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat {
    font-size: 12px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.stat-divider {
    color: var(--text-dim);
    font-size: 10px;
}

/* Save status */
.save-icon {
    display: inline-block;
    margin-right: 4px;
    font-size: 8px;
    vertical-align: middle;
}

.save-idle .save-icon { color: var(--text-dim); }
.save-saving .save-icon { color: var(--warning); animation: pulse-dot 0.8s ease infinite; }
.save-saved .save-icon { color: var(--success); }
.save-nosave .save-icon { color: var(--text-dim); }

/* Connection status */
.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
    transition: background var(--duration);
}

.status-connected .status-dot {
    background: var(--success);
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
}

.status-connecting .status-dot {
    background: var(--warning);
    animation: pulse-dot 1.5s ease infinite;
}

.status-disconnected .status-dot {
    background: var(--error);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration);
}

.toolbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-accent);
}

.toolbar-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.toolbar-btn:disabled:hover {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}

.toolbar-btn.active {
    background: var(--accent-subtle);
    border-color: var(--accent-dim);
    color: var(--accent);
}

/* ══════════════════════════════════════
   APP LAYOUT (sidebar + workspace)
   ══════════════════════════════════════ */

#app-layout {
    display: flex;
    height: calc(100vh - var(--toolbar-h));
    overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: margin-left 0.25s var(--ease), opacity 0.25s var(--ease);
}

#sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-w));
    opacity: 0;
    pointer-events: none;
}

#sidebar::-webkit-scrollbar {
    width: 4px;
}

#sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.sidebar-section {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.project-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
    padding: 6px 8px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration);
    text-align: left;
}

.sidebar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
}

.sidebar-add-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration);
}

.sidebar-add-btn:hover {
    background: var(--accent-subtle);
    border-color: var(--accent-dim);
    color: var(--accent);
    transform: scale(1.1);
}

/* Chapter List */
.chapter-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chapter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all var(--duration);
    border: 1px solid transparent;
}

.chapter-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.chapter-item.active {
    background: var(--accent-subtle);
    border-color: var(--accent-dim);
    color: var(--accent);
    font-weight: 600;
}

.chapter-item .chapter-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chapter-item .chapter-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    transition: opacity var(--duration);
}

.chapter-item:hover .chapter-delete {
    opacity: 1;
}

.chapter-item .chapter-delete:hover {
    color: var(--error);
}

.chapter-empty {
    font-size: 11px;
    color: var(--text-dim);
    font-style: italic;
    padding: 8px 10px;
}

/* Lore buttons */
.lore-btn {
    position: relative;
}

.lore-count {
    margin-left: auto;
    background: var(--accent-dim);
    color: var(--accent);
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* ── Workspace (Split Panel) ── */
#workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Canvas Panel (Left) ── */
#canvas-panel {
    flex: 1 1 55%;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    border-right: 1px solid var(--border-subtle);
}

.panel-header {
    height: var(--panel-header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.panel-title svg {
    color: var(--accent);
    opacity: 0.7;
}

.panel-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration);
}

.icon-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

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

#canvas {
    flex: 1;
    background: var(--bg-deep);
    border: none;
    color: var(--text-primary);
    font-family: var(--font-prose);
    font-size: 16px;
    line-height: 1.85;
    padding: 28px 36px;
    resize: none;
    outline: none;
    overflow-y: auto;
    letter-spacing: 0.01em;
}

#canvas::placeholder {
    color: var(--text-dim);
    font-style: italic;
}

#canvas::selection {
    background: var(--accent-dim);
    color: var(--text-primary);
}

#canvas::-webkit-scrollbar {
    width: 6px;
}

#canvas::-webkit-scrollbar-track {
    background: transparent;
}

#canvas::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.canvas-footer {
    height: var(--canvas-footer-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* ── Action Buttons ── */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 16px;
    border-radius: var(--radius);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all var(--duration) var(--ease);
    white-space: nowrap;
}

.action-btn:active { transform: scale(0.97); }
.action-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

.action-btn.primary {
    background: var(--accent);
    color: white;
}

.action-btn.primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 0 20px var(--accent-glow);
}

.action-btn.secondary {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.action-btn.secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-accent);
}

.action-btn.accent {
    background: var(--accent);
    color: white;
    padding: 7px 12px;
}

.action-btn.accent:hover:not(:disabled) {
    background: var(--accent-hover);
}

/* ── Resize Handle ── */
#resize-handle {
    width: 5px;
    cursor: col-resize;
    background: var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--duration);
    position: relative;
    z-index: 10;
}

#resize-handle:hover,
#resize-handle.dragging {
    background: var(--accent-dim);
}

.handle-grip {
    width: 3px;
    height: 30px;
    border-radius: 2px;
    background: var(--text-dim);
    opacity: 0;
    transition: opacity var(--duration);
}

#resize-handle:hover .handle-grip,
#resize-handle.dragging .handle-grip {
    opacity: 1;
}

/* ── Companion Panel (Right) ── */
#companion-panel {
    flex: 1 1 45%;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
}

#companion-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#companion-messages::-webkit-scrollbar {
    width: 5px;
}

#companion-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ── Welcome Message ── */
.welcome-message {
    text-align: center;
    padding: 40px 24px;
    color: var(--text-secondary);
    animation: fadeIn 0.5s var(--ease);
}

.welcome-icon { font-size: 32px; margin-bottom: 12px; }

.welcome-message h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.welcome-message p {
    font-size: 13px;
    line-height: 1.6;
    max-width: 360px;
    margin: 0 auto 16px;
}

.welcome-shortcuts {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    margin-top: 20px;
}

.shortcut {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

kbd {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 6px;
    font-family: var(--font-ui);
    font-size: 10px;
    color: var(--text-secondary);
}

/* ── Chat Messages ── */
.message {
    animation: slideUp 0.3s var(--ease);
}

.message-user {
    background: var(--accent-subtle);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius) var(--radius) var(--radius-sm) var(--radius);
    padding: 10px 14px;
    margin-left: 40px;
    align-self: flex-end;
}

.message-user .message-label { color: var(--accent); }

.message-forge {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) var(--radius) var(--radius-sm);
    padding: 12px 16px;
    margin-right: 20px;
}

.message-forge .message-label { color: var(--success); }

.message-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.message-body {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-body p { margin-bottom: 8px; }
.message-body p:last-child { margin-bottom: 0; }

/* ── Streaming ── */
.streaming-cursor::after {
    content: '▊';
    animation: blink-cursor 0.8s step-end infinite;
    color: var(--accent);
    margin-left: 2px;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ── Insert to Canvas ── */
.forge-insert-bar {
    display: flex;
    justify-content: flex-end;
    padding: 6px 0 2px;
}

.btn-insert-canvas {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-insert-canvas:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
    background: var(--accent-subtle);
}

.btn-insert-canvas.inserted {
    color: var(--success);
    border-color: var(--success);
    cursor: default;
    pointer-events: none;
    opacity: 0.7;
}

/* ── Suggestion Cards ── */
.suggestion-card {
    background: var(--bg-dark);
    border: 1px solid var(--border-accent);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin: 8px 0;
    animation: slideUp 0.3s var(--ease);
}

.suggestion-card .suggestion-header {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--accent);
    margin-bottom: 10px;
}

.suggestion-old {
    font-family: var(--font-prose);
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: line-through;
    line-height: 1.6;
    margin-bottom: 6px;
    padding: 6px 10px;
    background: var(--error-dim);
    border-radius: var(--radius-sm);
}

.suggestion-new {
    font-family: var(--font-prose);
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.6;
    margin-bottom: 8px;
    padding: 6px 10px;
    background: var(--success-dim);
    border-radius: var(--radius-sm);
}

.suggestion-arrow {
    text-align: center;
    color: var(--text-dim);
    font-size: 11px;
    margin: 2px 0;
}

.suggestion-reason {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    line-height: 1.5;
    margin-bottom: 12px;
}

.suggestion-actions {
    display: flex;
    gap: 8px;
}

.suggestion-actions .btn-apply {
    background: var(--success);
    color: #0a0a10;
    border: none;
    padding: 5px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--duration);
    font-family: var(--font-ui);
}

.suggestion-actions .btn-apply:hover {
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.3);
    transform: translateY(-1px);
}

.suggestion-actions .btn-skip {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 5px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--duration);
    font-family: var(--font-ui);
}

.suggestion-actions .btn-skip:hover {
    color: var(--text-secondary);
    border-color: var(--text-dim);
}

.suggestion-card.applied {
    opacity: 0.4;
    border-left-color: var(--success);
    pointer-events: none;
    transition: opacity 0.4s;
}

.suggestion-card.skipped {
    opacity: 0.2;
    pointer-events: none;
    transition: opacity 0.4s;
}

/* ── Companion Input ── */
.companion-input {
    height: var(--companion-input-h);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#ask-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-family: var(--font-ui);
    font-size: 13px;
    outline: none;
    transition: border-color var(--duration);
}

#ask-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

#ask-input::placeholder {
    color: var(--text-dim);
}

/* ══════════════════════════════════════
   MODALS
   ══════════════════════════════════════ */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 420px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalIn 0.25s var(--ease);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.modal-wide {
    width: 640px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-narrow {
    width: 340px;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-content h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.setting-group {
    margin-bottom: 18px;
}

.setting-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-group label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: none;
    font-weight: 500;
    cursor: pointer;
}

.setting-group input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

.setting-group input[type="text"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 13px;
    outline: none;
}

.setting-group input[type="text"]:focus {
    border-color: var(--accent);
}

.setting-group input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    margin-top: 4px;
}

.setting-group small {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Advanced settings (collapsed by default) */
.advanced-settings {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.advanced-settings summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    padding: 6px 0;
    user-select: none;
    transition: color 0.15s ease;
}

.advanced-settings summary:hover {
    color: var(--text-secondary);
}

.advanced-settings[open] summary {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.advanced-settings .setting-group {
    padding-left: 8px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

/* Lore Editor */
.lore-editor {
    flex: 1;
    min-height: 300px;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.7;
    padding: 16px;
    border-radius: var(--radius-sm);
    resize: none;
    outline: none;
    overflow-y: auto;
}

.lore-editor:focus {
    border-color: var(--accent);
}

/* ── Animations ── */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ── Processing State ── */
.processing .action-btn.primary {
    position: relative;
    color: transparent;
}

.processing .action-btn.primary::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ── Responsive ── */
@media (max-width: 900px) {
    #sidebar { display: none; }

    .toolbar-center .model-selector label { display: none; }
}

@media (max-width: 768px) {
    #workspace {
        flex-direction: column;
    }

    #canvas-panel,
    #companion-panel {
        flex: 1;
        min-width: unset;
    }

    #resize-handle {
        width: 100%;
        height: 5px;
        cursor: row-resize;
    }
}

/* ── Toast Notifications ── */
.inkstride-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.inkstride-toast.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.toast-success { border-color: var(--success); }
.toast-success .toast-icon { color: var(--success); }

.toast-error { border-color: var(--error); }
.toast-error .toast-icon { color: var(--error); }

.toast-warning { border-color: var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }

.toast-info { border-color: var(--accent); }
.toast-info .toast-icon { color: var(--accent); }

/* ── Disabled sidebar add button ── */
.sidebar-add-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Project Guide Modal ── */
.project-guide-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.project-guide-overlay.guide-visible {
    opacity: 1;
}

.project-guide-modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    padding: 32px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.project-guide-modal h2 {
    font-family: 'Inter', sans-serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.guide-body {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.guide-body p {
    margin-bottom: 12px;
}

.guide-body ul {
    margin: 8px 0 12px 20px;
    padding: 0;
}

.guide-body li {
    margin-bottom: 6px;
}

.guide-body strong {
    color: var(--text-primary);
}

.guide-body code {
    background: var(--bg-surface);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--accent);
}

.guide-note {
    background: var(--accent-subtle);
    border-left: 3px solid var(--accent);
    padding: 8px 12px;
    border-radius: 0 6px 6px 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.guide-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

/* ══════════════════════════════════════════════════════════
   ONBOARDING WIZARD
   Full-screen first-run experience. 5 steps with fade transitions.
   ══════════════════════════════════════════════════════════ */

.onboarding-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5, 5, 8, 0.92);
    backdrop-filter: blur(20px);
    opacity: 0;
    transition: opacity 0.5s ease;
}

.onboarding-overlay.visible {
    opacity: 1;
}

.onboarding-card {
    position: relative;
    width: 580px;
    max-width: 92vw;
    max-height: 88vh;
    overflow-y: auto;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 44px 40px 36px;
    box-shadow:
        0 0 0 1px rgba(124, 111, 224, 0.06),
        0 24px 80px rgba(0, 0, 0, 0.6),
        0 0 120px rgba(124, 111, 224, 0.04);
}

.onboarding-card::-webkit-scrollbar {
    width: 4px;
}

.onboarding-card::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ── Step Content ── */
.wizard-step {
    display: none;
    animation: wizardFadeIn 0.4s var(--ease);
}

.wizard-step.active {
    display: block;
}

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

/* ── Typography ── */
.wizard-step h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.wizard-step h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.wizard-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 28px;
}

.wizard-text {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 16px;
}

.wizard-text strong {
    color: var(--text-primary);
    font-weight: 600;
}

.wizard-text em {
    color: var(--accent);
    font-style: normal;
    font-weight: 500;
}

/* ── Accent Badge (step icon) ── */
.wizard-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent-dim), rgba(124, 111, 224, 0.08));
    border: 1px solid var(--border-accent);
    font-size: 22px;
    margin-bottom: 20px;
}

/* ── Welcome Step: Philosophy Points ── */
.philosophy-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 24px 0 32px;
}

.philosophy-point {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.3s ease;
}

.philosophy-point:hover {
    border-color: var(--border-accent);
}

.philosophy-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--accent-dim);
    font-size: 15px;
}

.philosophy-content {
    flex: 1;
}

.philosophy-content strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.philosophy-content span {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ── Folder Tree Visualization ── */
.folder-tree {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin: 16px 0;
    font-family: 'Consolas', 'Menlo', monospace;
    font-size: 12px;
    line-height: 1.9;
    color: var(--text-secondary);
    animation: wizardFadeIn 0.4s var(--ease);
}

.folder-tree .tree-root {
    color: var(--accent);
    font-weight: 600;
}

.folder-tree .tree-dir {
    color: var(--warning);
}

.folder-tree .tree-file {
    color: var(--text-muted);
}

.folder-tree .tree-desc {
    color: var(--text-dim);
    font-style: italic;
    margin-left: 8px;
}

/* ── Project path callout ── */
.project-path-callout {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--success-dim);
    border: 1px solid rgba(74, 222, 128, 0.2);
    border-radius: var(--radius);
    margin: 16px 0 24px;
    animation: wizardFadeIn 0.4s var(--ease);
}

.project-path-callout .path-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.project-path-callout .path-details {
    flex: 1;
    min-width: 0;
}

.project-path-callout .path-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--success);
    margin-bottom: 2px;
}

.project-path-callout .path-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
    font-family: 'Consolas', 'Menlo', monospace;
}

/* ── Workspace Callout List ── */
.callout-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 20px 0;
}

.callout-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.callout-number {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    font-size: 11px;
    font-weight: 700;
    margin-top: 1px;
}

.callout-body {
    flex: 1;
}

.callout-body strong {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.callout-body span {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 2px;
}

/* ── Shortcut Table ── */
.shortcut-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 16px 0;
}

.shortcut-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
}

.shortcut-row kbd {
    min-width: 130px;
    text-align: center;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 10px;
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.3px;
}

.shortcut-row span {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ── Section Divider ── */
.wizard-divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

.wizard-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ── Buttons ── */
.wizard-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 28px;
}

.wizard-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border-radius: var(--radius);
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.25s var(--ease);
    letter-spacing: -0.1px;
}

.wizard-btn:active { transform: scale(0.97); }
.wizard-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

.wizard-btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 16px rgba(124, 111, 224, 0.25);
}

.wizard-btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 6px 24px rgba(124, 111, 224, 0.35);
    transform: translateY(-1px);
}

.wizard-btn-secondary {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.wizard-btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-accent);
}

/* Large CTA button variant */
.wizard-btn-cta {
    width: 100%;
    justify-content: center;
    padding: 14px 28px;
    font-size: 15px;
    border-radius: 10px;
}

/* ── Progress Dots ── */
.wizard-progress {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.wizard-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: all 0.3s var(--ease);
}

.wizard-dot.active {
    background: var(--accent);
    box-shadow: 0 0 8px rgba(124, 111, 224, 0.5);
    transform: scale(1.25);
}

.wizard-dot.completed {
    background: var(--success);
}

/* ── Loading spinner for project creation ── */
.wizard-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

/* ── Summary card for final step ── */
.summary-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin: 20px 0;
}

.summary-card p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 8px;
}

.summary-card p:last-child {
    margin-bottom: 0;
}

.summary-card strong {
    color: var(--text-primary);
}

.summary-card code {
    background: var(--bg-deep);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--accent);
}

/* ════════════════════════════════════════════════════════════
   STAGE 3: Kill List + Voice + Deep Audit
   ════════════════════════════════════════════════════════════ */

/* ── Kill List Scan Bar ── */
.scan-bar {
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    padding: 0;
    font-size: 12px;
    transition: all 0.25s ease;
}

.scan-bar.hidden {
    display: none;
}

.scan-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-subtle);
}

.scan-count {
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.scan-count .kill { color: var(--error); }
.scan-count .warn { color: var(--warning); }
.scan-count .info { color: #57a5ff; }

.scan-position {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 40px;
    text-align: center;
}

.scan-nav-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 4px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.15s ease;
}

.scan-nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-dim);
}

.scan-close {
    font-size: 16px;
    margin-left: 4px;
}

.scan-detail {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-height: 120px;
    overflow-y: auto;
}

.scan-detail .scan-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
    line-height: 1.5;
}

.scan-detail .scan-item:hover {
    background: var(--bg-hover);
}

.scan-detail .scan-item.active {
    background: var(--accent-subtle);
    border-left: 2px solid var(--accent);
}

.scan-detail .scan-item .severity-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 5px;
}

.scan-detail .scan-item .severity-dot.kill { background: var(--error); }
.scan-detail .scan-item .severity-dot.warn { background: var(--warning); }
.scan-detail .scan-item .severity-dot.info { background: #57a5ff; }

.scan-detail .scan-item .scan-text {
    font-family: 'Merriweather', serif;
    color: var(--text-primary);
    font-size: 12px;
}

.scan-detail .scan-item .scan-reason {
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 2px;
}

.scan-detail .scan-item .scan-fix {
    color: var(--accent);
    font-size: 11px;
    opacity: 0.8;
}

/* ── Scan button active state ── */
#btn-scan.scanning {
    color: var(--error);
    animation: pulse-scan 1.5s ease infinite;
}

#btn-scan.clean {
    color: var(--success);
}

@keyframes pulse-scan {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Deep Audit Button ── */
.action-btn.tertiary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 8px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.action-btn.tertiary:hover {
    border-color: var(--accent-dim);
    color: var(--accent);
    background: var(--accent-subtle);
}

.action-btn.tertiary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Voice Dictation ── */
#btn-voice.voice-active {
    color: var(--error) !important;
    background: var(--error-dim) !important;
    border-color: var(--error) !important;
    animation: pulse-mic 1s ease infinite;
}

@keyframes pulse-mic {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
}

/* ── Voice status toast ── */
.voice-indicator {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--error);
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 9999;
    box-shadow: 0 4px 20px rgba(248, 113, 113, 0.3);
    animation: slideUp 0.3s ease;
}

.voice-indicator .mic-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    animation: pulse-mic-dot 1s ease infinite;
}

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

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

/* ── Canvas highlight overlays for Kill List ── */
.canvas-highlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    overflow: hidden;
}

/* ════════════════════════════════════════════════════════════
   FIND & REPLACE BAR
   ════════════════════════════════════════════════════════════ */

.find-replace-bar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 6px 10px;
    flex-shrink: 0;
    animation: fr-slide-down 0.2s ease;
}

.find-replace-bar.hidden {
    display: none;
}

@keyframes fr-slide-down {
    from { opacity: 0; transform: translateY(-100%); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Rows ── */
.fr-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.fr-replace-row {
    margin-top: 5px;
}

.fr-replace-row.hidden {
    display: none;
}

/* ── Toggle expand button (chevron) ── */
.fr-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 22px;
    height: 22px;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.fr-toggle-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.fr-toggle-btn.expanded {
    color: var(--accent);
}

.fr-toggle-btn.expanded svg {
    transform: rotate(0deg);
}

.fr-toggle-btn svg {
    transform: rotate(-90deg);
    transition: transform 0.15s ease;
}

/* ── Input wrapper ── */
.fr-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    max-width: 320px;
}

.fr-input-wrap input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 12px;
    padding: 5px 80px 5px 10px;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.15s ease;
}

.fr-input-wrap input:focus {
    border-color: var(--accent-dim);
}

.fr-input-wrap input::placeholder {
    color: var(--text-dim);
}

/* ── Match count badge ── */
.fr-count {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    pointer-events: none;
    white-space: nowrap;
}

.fr-count.has-matches {
    color: var(--text-secondary);
}

.fr-count.no-matches {
    color: var(--error);
}

/* ── Option toggle buttons (Aa, Ab|) ── */
.fr-option-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 7px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    line-height: 1;
}

.fr-option-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-dim);
}

.fr-option-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

/* ── Nav buttons (▲ ▼ ×) ── */
.fr-nav-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 4px;
    width: 32px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.fr-nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-dim);
}

.fr-close {
    font-size: 18px;
    margin-left: 4px;
    width: 32px;
}

/* ── Replace action buttons ── */
.fr-action-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    white-space: nowrap;
}

.fr-action-btn:hover {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

.fr-action-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ── Spacer to align replace row with find input ── */
.fr-spacer {
    width: 22px;
    flex-shrink: 0;
}

/* ── Replace row input (no match count, so full width padding) ── */
.fr-replace-row .fr-input-wrap input {
    padding-right: 10px;
}

/* ── Replace toast notification ── */
.fr-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    z-index: 9999;
    box-shadow: 0 4px 20px rgba(124, 111, 224, 0.3);
    animation: fr-toast-in 0.3s ease;
    pointer-events: none;
}

@keyframes fr-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ═══════════════════════════════════════
   COMPILE BOOK BUTTON
   ═══════════════════════════════════════ */

.compile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    background: linear-gradient(135deg, rgba(124, 111, 224, 0.08), rgba(124, 111, 224, 0.15));
    border: 1px solid rgba(124, 111, 224, 0.2);
    transition: all 0.2s;
}

.compile-btn:hover {
    background: linear-gradient(135deg, rgba(124, 111, 224, 0.15), rgba(124, 111, 224, 0.25));
    color: var(--accent);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.compile-btn svg {
    flex-shrink: 0;
}

/* ═══════════════════════════════════════
   BOOK PREVIEW MODAL
   ═══════════════════════════════════════ */

.book-preview-content {
    width: 90vw;
    max-width: 800px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
}

.book-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.book-preview-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.book-preview-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.book-preview-stats {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 10px;
    background: rgba(124, 111, 224, 0.1);
    border-radius: 12px;
}

.book-preview-body {
    flex: 1;
    overflow-y: auto;
    padding: 40px 60px;
    background: var(--bg);
    font-family: 'EB Garamond', Georgia, 'Times New Roman', serif;
    font-size: 16px;
    line-height: 1.8;
    color: var(--text-primary);
}

.book-preview-body .book-chapter {
    margin-bottom: 3em;
    padding-bottom: 2em;
    border-bottom: 1px solid var(--border);
}

.book-preview-body .book-chapter:last-child {
    border-bottom: none;
}

.book-preview-body h1.chapter-title {
    font-family: 'Outfit', sans-serif;
    font-size: 28px;
    font-weight: 600;
    color: var(--accent);
    text-align: center;
    margin: 0.5em 0 1em 0;
    letter-spacing: 0.02em;
}

.book-preview-body h2.section-title {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 1.5em 0 0.5em 0;
}

.book-preview-body h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 1em 0 0.5em 0;
}

.book-preview-body p {
    text-indent: 1.5em;
    margin-bottom: 0.4em;
    text-align: justify;
}

.book-preview-body p:first-of-type {
    text-indent: 0;
}

.book-preview-body strong { font-weight: 600; }
.book-preview-body em { font-style: italic; }

/* ════════════════════════════════════════════════════════════
   AUTH SECTION — Toolbar sign-in button, user menu, dropdown
   ════════════════════════════════════════════════════════════ */

#auth-section {
    display: flex;
    align-items: center;
    margin-left: 4px;
}

.auth-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px !important;
    border-radius: 6px;
    background: var(--accent-dim);
    border: 1px solid var(--border-accent);
    transition: all 0.2s ease;
}

.auth-btn:hover {
    background: var(--accent);
    color: #fff;
}

.auth-label {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

/* User avatar button */
.user-avatar-btn {
    padding: 2px !important;
    border-radius: 50%;
    overflow: hidden;
    width: 32px;
    height: 32px;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

/* User dropdown menu */
.user-dropdown {
    position: absolute;
    top: calc(var(--toolbar-h) - 4px);
    right: 12px;
    width: 260px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 0;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    z-index: 1000;
    animation: dropdownSlide 0.15s ease;
}

@keyframes dropdownSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.user-dropdown-header {
    padding: 4px 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-dropdown-header span:first-child {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

.user-email-text {
    font-size: 12px;
    color: var(--text-muted);
}

.user-dropdown-tier {
    padding: 6px 16px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-usage-text {
    font-size: 12px;
    color: var(--text-secondary);
}

.user-dropdown-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

.user-dropdown-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
}

.user-dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Tier badges */
.tier-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tier-badge-free     { background: var(--bg-hover); color: var(--text-muted); }
.tier-badge-byok     { background: rgba(56,152,236,0.15); color: #3898ec; }
.tier-badge-writer   { background: var(--success-dim); color: var(--success); }
.tier-badge-author   { background: var(--accent-glow); color: var(--accent); }
.tier-badge-apex     { background: rgba(251,191,36,0.15); color: #fbbf24; }

/* ════════════════════════════════════════════════════════════
   SIGN-IN PROMPT MODAL
   ════════════════════════════════════════════════════════════ */

.signin-modal-content {
    text-align: center;
    max-width: 420px;
}

.signin-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

.signin-modal-content h2 {
    font-size: 24px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.signin-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 20px;
}

.signin-features {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
    text-align: left;
}

.signin-feature {
    padding: 8px 14px;
    background: var(--accent-subtle);
    border: 1px solid var(--border-accent);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary);
}

.signin-google-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px 20px !important;
    font-size: 15px;
    font-weight: 600;
    border-radius: 8px;
    background: #fff !important;
    color: #333 !important;
    border: none;
    transition: all 0.2s ease;
}

.signin-google-btn:hover {
    background: #f0f0f0 !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateY(-1px);
}

.signin-note {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 12px;
    font-style: italic;
}

/* ════════════════════════════════════════════════════════════
   PAYWALL MODAL — Tier selection with glassmorphism cards
   ════════════════════════════════════════════════════════════ */

.paywall-modal-content {
    max-width: 900px;
    text-align: center;
}

.paywall-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.paywall-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 28px;
}

.tier-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.tier-card {
    position: relative;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px 18px 20px;
    text-align: left;
    transition: all 0.25s ease;
    display: flex;
    flex-direction: column;
}

.tier-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0,0,0,0.3);
}

/* Tier-specific border glows */
.tier-byok:hover  { border-color: #3898ec; box-shadow: 0 12px 32px rgba(56,152,236,0.15); }
.tier-writer:hover { border-color: var(--success); box-shadow: 0 12px 32px rgba(74,222,128,0.1); }
.tier-author:hover { border-color: var(--accent); box-shadow: 0 12px 32px rgba(124,111,224,0.15); }
.tier-apex:hover   { border-color: #fbbf24; box-shadow: 0 12px 32px rgba(251,191,36,0.15); }

.tier-badge-ribbon {
    position: absolute;
    top: -1px;
    right: 16px;
    padding: 3px 12px 5px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 0 0 6px 6px;
}

.tier-author .tier-badge-ribbon {
    background: var(--accent);
    color: #fff;
}

.tier-apex .tier-badge-ribbon {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1a1a26;
}

.tier-header {
    margin-bottom: 16px;
}

.tier-name {
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.tier-price {
    font-size: 36px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.tier-period {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-muted);
}

.tier-features {
    list-style: none;
    padding: 0;
    margin: 0 0 auto 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 20px;
}

.tier-features li {
    font-size: 13px;
    color: var(--text-secondary);
    padding-left: 18px;
    position: relative;
    line-height: 1.4;
}

.tier-features li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: 700;
}

.tier-features li strong {
    color: var(--text-primary);
    font-weight: 600;
}

.tier-cta {
    width: 100%;
    text-align: center;
    padding: 10px 16px !important;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    margin-top: auto;
}

/* Tier-specific CTA colors */
.tier-byok .tier-cta {
    background: rgba(56,152,236,0.15);
    color: #3898ec;
    border: 1px solid rgba(56,152,236,0.3);
}
.tier-byok .tier-cta:hover { background: #3898ec; color: #fff; }

.tier-writer .tier-cta {
    background: var(--success-dim);
    color: var(--success);
    border: 1px solid rgba(74,222,128,0.3);
}
.tier-writer .tier-cta:hover { background: var(--success); color: #0a0a10; }

.tier-author .tier-cta {
    background: var(--accent-glow);
    color: var(--accent);
    border: 1px solid var(--border-accent);
}
.tier-author .tier-cta:hover { background: var(--accent); color: #fff; }

.tier-apex .tier-cta {
    background: rgba(251,191,36,0.1);
    color: #fbbf24;
    border: 1px solid rgba(251,191,36,0.3);
}
.tier-apex .tier-cta:hover { background: #fbbf24; color: #1a1a26; }

.paywall-note {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

/* Responsive: stack tier cards on narrow screens */
@media (max-width: 800px) {
    .tier-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 500px) {
    .tier-grid {
        grid-template-columns: 1fr;
    }
}

/* ════════════════════════════════════════════════════════════
   USAGE BADGE — Toolbar call counter
   ════════════════════════════════════════════════════════════ */

.usage-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: default;
    transition: all 0.2s ease;
}

.usage-badge.usage-green  { border-color: rgba(74,222,128,0.3); color: var(--success); }
.usage-badge.usage-amber  { border-color: rgba(251,191,36,0.3); color: var(--warning); }
.usage-badge.usage-red    { border-color: rgba(248,113,113,0.3); color: var(--error); }

.usage-ring {
    width: 14px;
    height: 14px;
}

.usage-ring-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 2.5;
}

.usage-ring-fill {
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dashoffset 0.4s ease;
}

