@import url('https://fonts.googleapis.com/css2?family=Fraunces:wght@300;500;700&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

:root {
    color-scheme: only light;
    --bg: #f6efe4;
    --bg-accent: #e6f2ed;
    --ink: #1b1a16;
    --muted: #5d5147;
    --accent: #c64b39;
    --accent-strong: #a63c2d;
    --accent-2: #1f6f5f;
    --panel: #fffaf1;
    --panel-2: #f2f7f5;
    --border: #dfcdbd;
    --shadow: 0 20px 50px rgba(36, 28, 20, 0.15);
    --radius: 18px;
    --toolbar-h: 52px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, #fff2df 0%, transparent 55%),
        radial-gradient(circle at bottom right, #e0f0ea 0%, transparent 45%),
        linear-gradient(120deg, var(--bg) 0%, var(--bg-accent) 100%);
    color: var(--ink);
}

.app-shell {
    min-height: 100vh;
}

/* ── Page: full viewport ── */

.page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Row below the toolbar holds the optional pinned outline sidebar and the main
   document area. When the outline is not pinned (or closed), the sidebar is
   absent and .document-main takes the full width. */
.main-row {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

/* Pinned outline sidebar (in-flow, persistent). Contrast with the auto-hide
   overlay variant which uses .overlay-panel.overlay-left (fixed position). */
.outline-sidebar {
    width: min(320px, 30vw);
    background: var(--panel);
    border-right: 1px solid var(--border);
    box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.25rem;
    overflow-y: auto;
    flex-shrink: 0;
}

/* Pin toggle inside the outline header. */
.pin-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.pin-btn:hover {
    color: var(--ink);
    background: rgba(0, 0, 0, 0.04);
}

.pin-btn.pinned {
    color: var(--accent-strong);
    background: rgba(198, 75, 57, 0.1);
    border-color: var(--accent);
}

/* ── Toolbar ── */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--toolbar-h);
    padding: 0.3rem 1rem 0.2rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(36, 28, 20, 0.08);
    flex-shrink: 0;
    z-index: 100;
    gap: 0.5rem;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-brand {
    font-family: "Fraunces", "Georgia", serif;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--accent-2);
    white-space: nowrap;
}

.toolbar-left-tabs {
    gap: 1rem;
    min-width: 0;
}

.toolbar-branding {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    padding-bottom: 0.35rem;
}

.toolbar-subtitle {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.toolbar-tabs {
    display: flex;
    align-items: flex-end;
    gap: 0.15rem;
    flex-wrap: wrap;
}

.toolbar-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 0.7rem 0.8rem 0.55rem;
    background: transparent;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.12s, border-color 0.12s, background 0.12s;
}

.toolbar-tab:hover {
    color: var(--ink);
    background: rgba(198, 75, 57, 0.06);
}

.toolbar-tab.active {
    color: var(--accent-strong);
    border-color: var(--accent);
    background: linear-gradient(180deg, rgba(198, 75, 57, 0.08), rgba(198, 75, 57, 0.02));
}

.toolbar-analysis-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 0.4rem;
    padding: 0.3rem 0.35rem 0.3rem 0.55rem;
    border-radius: 999px;
    border: 1px solid transparent;
    max-width: min(480px, 42vw);
    min-width: 0;
}

.toolbar-analysis-pill.busy {
    background: #eef6fb;
    border-color: #c7def0;
    color: #1f4d73;
}

.toolbar-analysis-pill.ready {
    background: #ecf7f2;
    border-color: #c9e6d8;
    color: #165c41;
}

.toolbar-analysis-pill svg,
.toolbar-analysis-pill .spinner.small {
    flex-shrink: 0;
}

.toolbar-analysis-pill-body {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.toolbar-analysis-pill-body-button {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    padding: 0;
    text-align: left;
}

.toolbar-analysis-pill-body-button:hover .toolbar-analysis-pill-message,
.toolbar-analysis-pill-body-button:focus-visible .toolbar-analysis-pill-message {
    text-decoration: underline;
}

.toolbar-analysis-pill-message {
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.toolbar-analysis-pill-detail {
    font-size: 0.74rem;
    opacity: 0.92;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toolbar-analysis-pill-close {
    border: none;
    background: transparent;
    color: inherit;
    font-size: 1rem;
    line-height: 1;
    padding: 0 4px;
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
}

.toolbar-analysis-pill-close:hover {
    background: rgba(0, 0, 0, 0.06);
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: var(--ink);
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: rgba(198, 75, 57, 0.08);
}

.toolbar-btn.active {
    background: rgba(198, 75, 57, 0.12);
    border-color: var(--accent);
    color: var(--accent-strong);
}

.toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.toolbar-stats {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.stat-chip {
    background: rgba(31, 111, 95, 0.1);
    color: var(--accent-2);
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.stat-chip.muted {
    background: rgba(93, 81, 71, 0.1);
    color: var(--muted);
}

/* Selected-LLM chips rendered next to the stats chips */

.model-chip-row {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 999px;
    color: var(--muted);
    flex-wrap: wrap;
    max-width: 320px;
}

.model-chip-row.empty {
    cursor: pointer;
    font-size: 0.72rem;
    background: rgba(200, 30, 30, 0.06);
    border-color: rgba(200, 30, 30, 0.3);
    color: #c81e1e;
}

.model-chip-row.empty:hover {
    background: rgba(200, 30, 30, 0.12);
}

.model-chip {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 999px;
    white-space: nowrap;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-chip.local {
    background: rgba(31, 111, 95, 0.14);
    color: var(--accent-2);
}

.model-chip.cloud {
    background: rgba(76, 111, 255, 0.14);
    color: #3955d6;
}

/* Toolbar model-picker dropdown — mirrors .doc-switcher so the toolbar has a
   consistent click-to-open feel for document and model selection. */
.model-switcher {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.model-switcher-btn {
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.model-switcher-btn:hover {
    border-style: solid;
    border-color: var(--accent);
    color: var(--ink);
}

.model-switcher.open .model-switcher-btn {
    border-style: solid;
    border-color: var(--accent);
    background: rgba(198, 75, 57, 0.06);
    color: var(--ink);
}

.model-switcher-menu {
    min-width: 430px;
    max-width: 560px;
    max-height: min(72vh, 680px);
    padding: 4px;
    overflow-y: auto;
    overflow-x: hidden;
}

.toolbar-save {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-save .save-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--muted);
    white-space: nowrap;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel);
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.toolbar-save .save-status.is-saving {
    color: var(--accent-2);
    border-color: rgba(31, 111, 95, 0.4);
    background: rgba(31, 111, 95, 0.08);
}

.toolbar-save .save-status.is-saved {
    /* subtle green-tinted "ok" look once a save lands */
    color: var(--accent-2);
    border-color: rgba(31, 111, 95, 0.25);
}

.save-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
    display: inline-block;
}

.save-dot.saved {
    background: var(--accent-2);
    box-shadow: 0 0 0 0 rgba(31, 111, 95, 0.4);
    animation: save-flash 1.2s ease-out;
}

.save-dot.saving {
    background: var(--accent-2);
    animation: save-pulse 1s ease-in-out infinite;
}

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

@keyframes save-flash {
    0%   { box-shadow: 0 0 0 0 rgba(31, 111, 95, 0.55); transform: scale(1.4); }
    60%  { box-shadow: 0 0 0 8px rgba(31, 111, 95, 0); transform: scale(1); }
    100% { box-shadow: 0 0 0 0 rgba(31, 111, 95, 0); transform: scale(1); }
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--accent-2);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 10px;
    white-space: nowrap;
}

/* ── Document list ── */

.doc-list-panel {
    width: min(380px, 85vw);
}

.user-switch {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.user-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.user-input-row .input {
    flex: 1;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    background: var(--panel);
    color: var(--ink);
    font-family: inherit;
}

.doc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.doc-list-item {
    display: flex;
    align-items: center;
    border-radius: 8px;
    transition: background 0.1s;
}

.doc-list-item:hover {
    background: var(--bg);
}

.doc-list-item.current {
    background: var(--bg-accent);
}

.doc-list-btn {
    flex: 1;
    border: none;
    background: none;
    text-align: left;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.doc-list-title {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-list-meta {
    font-size: 0.72rem;
    color: var(--muted);
}

/* ── Overlay system ── */

.overlay-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(27, 26, 22, 0.3);
    z-index: 200;
    animation: fadeIn 0.15s ease;
}

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

@keyframes slideFromLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

@keyframes slideFromRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.overlay-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 300;
    background: var(--panel);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.25rem;
    overflow-y: auto;
}

.overlay-left {
    left: 0;
    width: min(360px, 85vw);
    animation: slideFromLeft 0.2s ease;
}

.overlay-right {
    right: 0;
    width: min(420px, 90vw);
    animation: slideFromRight 0.2s ease;
}

.overlay-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 300;
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    width: min(780px, 92vw);
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    animation: scaleIn 0.2s ease;
}

.overlay-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.overlay-header h2 {
    margin: 0;
    font-family: "Fraunces", "Georgia", serif;
    font-size: 1.3rem;
    flex: 1;
}

.overlay-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted);
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    line-height: 1;
}

.overlay-close:hover {
    background: rgba(198, 75, 57, 0.1);
    color: var(--accent-strong);
}

/* ── Settings grid inside modal ── */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

/* ── Document editor (maximized) ── */

.document-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--panel-2);
}

.document-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.7rem 1.5rem 0.8rem;
    border-bottom: 1px solid var(--border);
    background:
        linear-gradient(180deg, rgba(255, 252, 247, 0.98), rgba(252, 246, 238, 0.94)),
        rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.ribbon-toolbar {
    box-shadow: inset 0 -1px 0 rgba(223, 205, 189, 0.55);
}

.ribbon-strip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.ribbon-section {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid rgba(223, 205, 189, 0.9);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.72);
    min-width: 0;
}

.ribbon-section-inline {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.ribbon-section-format {
    flex: 1 1 660px;
}

.ribbon-section-hints {
    flex: 1 1 280px;
}

.ribbon-section .chapter-indicator {
    margin-right: 0;
}

.ribbon-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}

.ribbon-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.ribbon-action {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0.45rem 0.7rem;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--ink);
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    white-space: nowrap;
}

.ribbon-action:hover:not(:disabled) {
    background: rgba(31, 111, 95, 0.08);
    border-color: rgba(31, 111, 95, 0.2);
    color: var(--accent-2);
}

.ribbon-action.active {
    background: rgba(198, 75, 57, 0.12);
    border-color: rgba(198, 75, 57, 0.28);
    color: var(--accent-strong);
}

.ribbon-action:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ribbon-field {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
}

.ribbon-divider {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1;
    padding: 0 0.1rem;
    user-select: none;
}

.ribbon-field-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.ribbon-select {
    min-width: 150px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 0.82rem;
}

.ribbon-empty {
    font-size: 0.82rem;
    color: var(--muted);
}

/* Split container: doc + optional result panel */

.editor-split {
    flex: 1;
    display: flex;
    overflow: hidden;
    transition: gap 0.25s ease;
}

.editor-split.has-result {
    gap: 0;
}

.document-body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem clamp(1.5rem, 8vw, 8rem);
    max-width: 100%;
    position: relative;
    min-width: 0;
    transition: flex 0.25s ease;
}

.editor-split.has-result .document-body {
    flex: 1.2;
    padding-right: 1.5rem;
}

/* ── Result gutter (connector line) ── */

.result-gutter {
    width: 24px;
    flex-shrink: 0;
    position: relative;
}

.result-connector {
    position: absolute;
    left: 0;
    width: 24px;
    height: 2px;
    background: var(--accent);
    opacity: 0.4;
}

.result-connector::before {
    content: "";
    position: absolute;
    left: 0;
    top: -4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.6;
}

/* ── Result panel strip (multi-model) ── */

.result-panel-strip {
    flex: 0.8 0 auto;
    flex-shrink: 0;
    min-width: 280px;
    max-width: 440px;
    overflow-y: auto;
    padding: 1rem 1rem 2rem 0;
    display: flex;
    gap: 0.75rem;
    /* Own stacking context so it can't be hidden behind document-body when the
       page-width preset puts the editor on top of a positioned ancestor. */
    position: relative;
    z-index: 2;
    background: var(--panel-2);
    /* Explicit visible base — prevents a stuck animation from hiding the strip
       behind opacity:0 / translateX() when the browser throttles a render tick
       (e.g. the user clicks Rewrite and the panel stayed invisible until the
       window refocused and forced a repaint). */
    opacity: 1;
    transform: none;
}

.result-panel-strip.multi {
    flex: 1.4;
    max-width: none;
}

.result-column {
    flex: 1;
    min-width: 260px;
    display: flex;
    flex-direction: column;
}

/* resultSlideIn keyframes removed — the animation occasionally got stuck at
   its initial opacity:0 state when the browser throttled the render tick,
   hiding the whole result panel until the window was refocused. The panel
   now appears without animation. */

.result-spacer {
    flex-shrink: 0;
}

.result-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 12px 36px rgba(36, 28, 20, 0.12);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.model-pill {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.result-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.result-badge {
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
}

.pill.small {
    font-size: 0.72rem;
    padding: 0.2rem 0.55rem;
}

.overlay-close.small {
    font-size: 1.2rem;
    margin-left: auto;
    padding: 0.15rem 0.4rem;
}

.result-loading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

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

.result-output {
    background: #fef7ef;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--ink);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 50vh;
    overflow-y: auto;
}

.result-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn.small {
    padding: 0.4rem 0.85rem;
    font-size: 0.82rem;
}

.btn.primary.small {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.result-original {
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
}

.result-original summary {
    font-size: 0.8rem;
    color: var(--muted);
    cursor: pointer;
    font-weight: 500;
    user-select: none;
}

.result-original summary:hover {
    color: var(--accent-strong);
}

.result-original-text {
    margin-top: 0.5rem;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--muted);
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    padding: 0.75rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 30vh;
    overflow-y: auto;
}

.welcome {
    text-align: center;
    padding: 4rem 2rem;
}

.welcome h2 {
    font-family: "Fraunces", serif;
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.welcome p {
    font-size: 1.1rem;
    color: var(--muted);
    max-width: 28rem;
    margin: 0 auto;
}

/* ── Shared control styles ── */

.control-block {
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius);
    padding: 1.25rem;
    border: 1px solid var(--border);
    display: grid;
    gap: 0.75rem;
}

.control-label {
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.hint {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0;
}

.paste-area {
    width: 100%;
    min-height: 100px;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 0.75rem;
    background: #fff;
    font-family: "IBM Plex Sans", sans-serif;
}

.input,
.select {
    width: 100%;
    padding: 0.6rem 0.7rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    font-family: "IBM Plex Sans", sans-serif;
}

/* ── Model checklist ── */

.model-group-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
    margin-top: 0.2rem;
}

.model-checklist {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.28rem 0.55rem;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.84rem;
    transition: background 0.12s, border-color 0.12s;
    user-select: none;
}

.model-check span {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-check:hover {
    background: rgba(31, 111, 95, 0.06);
}

.model-check.checked {
    background: rgba(31, 111, 95, 0.1);
    border-color: var(--accent-2);
}

.model-check input[type="checkbox"] {
    accent-color: var(--accent-2);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.hint-inline {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.78rem;
}

/* ── Global error toast ── */

.error-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 640px;
    padding: 10px 14px;
    background: #fdecea;
    border: 1px solid #f5c6c0;
    border-radius: 10px;
    color: #7f1d1d;
    box-shadow: 0 10px 24px rgba(127, 29, 29, 0.18);
    animation: errorToastIn 0.18s ease;
}

@keyframes errorToastIn {
    from { opacity: 0; transform: translate(-50%, -8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

.error-toast svg { flex-shrink: 0; color: #c81e1e; }

.error-toast-text {
    flex: 1;
    font-size: 0.85rem;
    line-height: 1.4;
}

.error-toast .btn.small {
    padding: 3px 8px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.error-toast-close {
    border: none;
    background: transparent;
    color: #7f1d1d;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0 4px;
    cursor: pointer;
    border-radius: 4px;
}

.error-toast-close:hover {
    background: rgba(127, 29, 29, 0.08);
}

.status-toast {
    position: fixed;
    top: 74px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 680px;
    padding: 10px 14px;
    border-radius: 10px;
    animation: errorToastIn 0.18s ease;
    box-shadow: 0 10px 24px rgba(50, 41, 31, 0.14);
}

.status-toast.busy {
    background: #eef6fb;
    border: 1px solid #c7def0;
    color: #1f4d73;
}

.status-toast.ready {
    background: #ecf7f2;
    border: 1px solid #c9e6d8;
    color: #165c41;
}

.status-toast svg,
.status-toast .spinner.small {
    flex-shrink: 0;
}

.status-toast-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.status-toast-body-button {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
    padding: 0;
}

.status-toast-body-button:hover .status-toast-text,
.status-toast-body-button:focus-visible .status-toast-text {
    text-decoration: underline;
}

.status-toast-text {
    font-size: 0.85rem;
    line-height: 1.4;
    font-weight: 600;
}

.status-toast-detail {
    font-size: 0.78rem;
    line-height: 1.35;
    opacity: 0.9;
}

.status-toast .btn.small {
    padding: 3px 8px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.status-toast-close {
    border: none;
    background: transparent;
    color: inherit;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0 4px;
    cursor: pointer;
    border-radius: 4px;
}

.status-toast-close:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* ── Document Analysis overlay ── */

.analysis-modal {
    max-width: 760px;
}

.analysis-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin: 12px 0;
}

.analysis-scope-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.analysis-scope-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 600;
    transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.analysis-scope-option:hover {
    background: var(--panel);
}

.analysis-scope-option.active {
    background: color-mix(in srgb, var(--accent) 12%, var(--panel));
    border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}

.analysis-scope-option input[type="radio"] {
    margin: 0;
    accent-color: var(--accent);
}

.analysis-scope-option span {
    line-height: 1;
}

.analysis-target-field {
    display: inline-flex;
    flex-direction: column;
    gap: 3px;
    min-width: min(320px, 100%);
    max-width: min(420px, 100%);
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: color-mix(in srgb, var(--panel) 92%, white 8%);
}

.analysis-target-label,
.analysis-run-picker-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.analysis-target-value {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.analysis-run-controls {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    max-width: min(100%, 720px);
}

.analysis-run-picker-row {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.analysis-run-actions-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.analysis-run-select {
    display: block;
    width: min(100%, 560px);
    min-width: min(420px, 100%);
    max-width: min(560px, 80vw);
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    padding: 8px 10px;
}

.analysis-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--muted);
}

.analysis-progress-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 10px 0 14px;
    padding: 12px 14px;
    border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--border));
    border-radius: 12px;
    background: color-mix(in srgb, var(--accent) 6%, var(--panel));
}

.analysis-progress-copy {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.analysis-progress-copy strong {
    font-size: 0.92rem;
    color: var(--ink);
}

.analysis-progress-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.analysis-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 10px 0 14px;
}

.analysis-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 14px;
}

.analysis-summary-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.analysis-summary-item {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    padding: 10px 12px;
}

.spinner.small {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

.analysis-character-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.analysis-character {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    padding: 10px 12px;
}

.analysis-character-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.analysis-character-head strong {
    font-size: 1rem;
}

.analysis-field {
    font-size: 0.85rem;
    margin: 2px 0;
    color: var(--ink);
}

.analysis-field em {
    color: var(--muted);
    font-style: normal;
    font-weight: 600;
    margin-right: 4px;
}

/* ── Top-toolbar document switcher dropdown ── */

.doc-switcher {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.doc-switcher-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    max-width: 320px;
}

.doc-switcher-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 260px;
}

.doc-switcher.open .doc-switcher-btn {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.doc-switcher-backdrop {
    position: fixed;
    inset: 0;
    /* Just under .doc-switcher-menu (200) so a click outside the menu still
       closes it, but still over the floating toolbar (150) so the toolbar
       can't intercept the dismissing click. */
    z-index: 199;
}

.doc-switcher-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    /* Sits above the floating-toolbar (z-index: 150) so a selection-anchored
       toolbar can never partially cover the model picker's options when the
       user opens it from the top toolbar. The matching backdrop also gets
       bumped (see .doc-switcher-backdrop) so clicks behave consistently. */
    z-index: 200;
    min-width: 320px;
    max-width: 420px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(36, 28, 20, 0.18), 0 2px 8px rgba(36, 28, 20, 0.08);
    padding: 6px;
    animation: dropdownFloatIn 0.12s ease;
}

.doc-switcher-action {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--ink);
    font-size: 0.85rem;
    cursor: pointer;
    text-align: left;
}

.doc-switcher-action:hover {
    background: var(--surface);
}

.doc-switcher-action input[type="file"] {
    display: none;
}

.doc-switcher-rename {
    display: flex;
    gap: 4px;
    padding: 4px;
    align-items: center;
}

.doc-switcher-rename .input {
    flex: 1;
}

.doc-switcher-divider {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 8px 10px 3px;
}

.doc-switcher-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 280px;
    overflow-y: auto;
}

.doc-switcher-row {
    display: flex;
    align-items: stretch;
    gap: 2px;
}

.doc-switcher-row:hover .doc-switcher-delete {
    opacity: 1;
}

.doc-switcher-delete {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s, color 0.12s;
}

.doc-switcher-delete:hover {
    background: rgba(200, 30, 30, 0.12);
    color: #c81e1e;
    opacity: 1;
}

.doc-switcher-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 7px 10px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    text-align: left;
    min-width: 0;
}

.doc-switcher-item:hover:not(:disabled) {
    background: var(--surface);
}

.doc-switcher-item.current {
    background: rgba(76, 111, 255, 0.1);
    cursor: default;
}

.doc-switcher-item.current::after {
    content: "• current";
    color: var(--accent);
    font-size: 0.7rem;
    margin-left: 4px;
}

.doc-switcher-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.doc-switcher-item-meta {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 2px;
}

/* ── Prompt Markup ── */

.pm-markup {
    border-radius: 3px;
    padding: 0 2px;
    transition: background 0.12s, color 0.12s;
}

.pm-prompt {
    background: rgba(76, 111, 255, 0.1);
    color: #3955d6;
    font-style: italic;
}

.pm-prompt:hover {
    background: rgba(76, 111, 255, 0.18);
}

.markup-hint {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    font-size: 0.72rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: help;
}

.markup-hint .pm-hint-swatch {
    border-radius: 3px;
    padding: 0 4px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 0.7rem;
}

.markup-hint .pm-hint-swatch.prompt {
    background: rgba(76, 111, 255, 0.15);
    color: #3955d6;
    font-style: italic;
}

.markup-hint .pm-hint-swatch.lock {
    background: var(--panel);
    color: var(--muted);
    border: 1px dashed var(--border);
}

/* ── Floating toolbar (collapsed pill state) ──
   Appears on every text selection. Visible but non-aggressive: a small
   green-tinted pill that clearly reads "Writing tools…", easy to spot
   against the cream document background but small enough to ignore for
   editing-only selections. Hovering it (or clicking) morphs into the
   full .floating-toolbar — the transition is a state swap rather than
   a CSS morph because the two have different content shapes. */
.floating-toolbar-pill {
    position: absolute;
    z-index: 150;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 13px 5px 11px;
    background: var(--panel);
    border: 1px solid rgba(31, 111, 95, 0.55);
    border-radius: 999px;
    color: var(--accent-2);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    /* Soft accent-tinted shadow so the pill reads above the document
       background even when paged-mode's "desk" gradient is behind it. */
    box-shadow:
        0 4px 14px rgba(36, 28, 20, 0.18),
        0 0 0 3px rgba(31, 111, 95, 0.06);
    animation: pillFadeIn 0.18s ease;
    transition: transform 0.15s, color 0.15s, background 0.15s,
                border-color 0.15s, box-shadow 0.15s;
}

.floating-toolbar-pill:hover,
.floating-toolbar-pill:focus-within {
    background: var(--accent-2);
    color: #fff;
    border-color: var(--accent-2);
    transform: translateX(-50%) translateY(-1px);
    box-shadow:
        0 10px 24px rgba(31, 111, 95, 0.38),
        0 0 0 4px rgba(31, 111, 95, 0.14);
}

.floating-toolbar-pill svg {
    flex: none;
}

.floating-toolbar-pill-label {
    font-weight: 600;
    letter-spacing: 0.02em;
}

.floating-toolbar-pill-ellipsis {
    color: inherit;
    opacity: 0.7;
    margin-left: -2px;
}

/* When the selection has no room above for the pill (smart-position dropped
   it below the selection), the host adds .below — reserved hook for
   arrow direction if we ever add one. */
.floating-toolbar-pill.below {
    /* No-op for now. */
}

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

/* ── Floating toolbar (expanded state) ── */

.floating-toolbar {
    position: absolute;
    z-index: 150;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(36, 28, 20, 0.18), 0 2px 6px rgba(36, 28, 20, 0.08);
    animation: floatIn 0.15s ease;
    min-width: 360px;
    max-width: min(640px, 90vw);
}

.floating-btn-row {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
}

.floating-prompt-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.floating-prompt {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--ink);
    font-size: 0.8rem;
    padding: 4px 6px;
    min-width: 0;
}

.floating-prompt::placeholder {
    color: var(--muted);
    font-style: italic;
}

.floating-prompt-clear {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
}

.floating-prompt-clear:hover {
    background: var(--border);
    color: var(--ink);
}

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

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

.floating-toolbar::after {
    content: "";
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 10px;
    height: 10px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

/* When the toolbar sits BELOW the selection (no room above), flip the arrow
   so it points up toward the selected text. */
.floating-toolbar.below::after {
    bottom: auto;
    top: -6px;
    border-right: none;
    border-bottom: none;
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
}

.floating-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--ink);
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
}

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

.floating-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.floating-btn-group {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border-right: 1px solid var(--border);
    margin-right: 2px;
    padding-right: 2px;
}

.floating-btn.sub {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 4px 8px;
    color: var(--muted);
    border-radius: 6px;
}

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

/* ── Floating toolbar: formatting row ── */

.floating-fmt-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}

.floating-btn.fmt-btn {
    min-width: 28px;
    padding: 4px 8px;
    font-size: 0.85rem;
    justify-content: center;
}

.floating-btn.fmt-btn strong,
.floating-btn.fmt-btn em {
    font-size: 0.9rem;
}

.fmt-field {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--muted);
}

.fmt-label {
    font-weight: 600;
    letter-spacing: 0.02em;
}

.fmt-select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 6px;
    font-size: 0.78rem;
    color: var(--ink);
    cursor: pointer;
}

.fmt-select:focus {
    outline: none;
    border-color: var(--accent);
}

.fmt-select-sm {
    max-width: 80px;
}

.fmt-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 2px;
}

/* ── Page-width presets on .document-body ── */

/* Page-width presets apply to the editor (centered inside document-body) so
   the result panel's flex share is never starved. `width: 100%` + max-width
   means "up to N, but never more than the parent offers" — critical when
   has-result squeezes document-body. */
.document-body.pw-narrow .unified-editor { width: 100%; max-width: 640px; margin: 0 auto; }
.document-body.pw-normal .unified-editor { width: 100%; max-width: 820px; margin: 0 auto; }
.document-body.pw-wide   .unified-editor { width: 100%; max-width: 1040px; margin: 0 auto; }
.document-body.pw-full   .unified-editor { width: 100%; max-width: none; margin: 0; }

/* ── Rewrite sub-buttons in Editing Desk ── */

.rewrite-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-right: 1px solid var(--border);
    padding-right: 8px;
    margin-right: 4px;
}

.btn.primary.sub {
    font-size: 0.75rem;
    padding: 4px 10px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--border);
}

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

/* ── Document content styling ── */

.doc-heading {
    /* Fonts inherit from the editor container so the document-level
       Font dropdown actually takes effect. The heading size is relative
       (em) so it scales with the base Size dropdown. */
    font-size: 1.6em;
    margin-top: 1.5rem;
    cursor: text;
    font-weight: 700;
}

.doc-subheading {
    font-size: 1.25em;
    margin-top: 1.25rem;
    color: var(--accent-2);
    cursor: text;
    font-weight: 600;
}

.doc-paragraph {
    color: var(--ink);
    cursor: text;
}

/* ── Unified editor ── */

.unified-editor {
    min-height: 100%;
    outline: none;
    padding-bottom: 60vh; /* extra scroll space at the bottom */
}

.unified-editor:focus {
    outline: none;
}

.unified-editor .doc-heading,
.unified-editor .doc-subheading,
.unified-editor .doc-paragraph,
.unified-editor p,
.unified-editor h2,
.unified-editor h3 {
    outline: none;
}

/* Paragraphs created by contenteditable on Enter. Inherit font-size,
   font-family, and line-height from the .unified-editor inline style so
   the document-level Font/Size/Line Height controls cascade cleanly. */
.unified-editor p {
    color: var(--ink);
    margin: 0.5em 0;
}

.unified-editor h2 {
    font-size: 1.6em;
    margin-top: 1.5rem;
    font-weight: 700;
}

.unified-editor h3 {
    font-size: 1.25em;
    margin-top: 1.25rem;
    color: var(--accent-2);
    font-weight: 600;
}

.unified-editor div {
    /* Browser sometimes creates <div> instead of <p> when pressing Enter */
    color: var(--ink);
}

/* ── Per-block paragraph alignment (set via data-align on <p>/<h2>/<h3>) ── */

.unified-editor [data-align="left"]    { text-align: left; }
.unified-editor [data-align="center"]  { text-align: center; }
.unified-editor [data-align="right"]   { text-align: right; }
.unified-editor [data-align="justify"] { text-align: justify; }

.edited {
    background: rgba(255, 214, 153, 0.4);
    border-left: 4px solid rgba(198, 75, 57, 0.8);
    padding-left: 0.75rem;
    border-radius: 6px;
}

/* ── Chapter navigation ── */

.chapter-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: auto;
}

.chapter-indicator-button {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0.35rem 0.55rem;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.chapter-indicator-button:hover {
    background: rgba(31, 111, 95, 0.08);
    border-color: rgba(31, 111, 95, 0.18);
}

.chapter-indicator-button:focus-visible {
    outline: 2px solid rgba(31, 111, 95, 0.35);
    outline-offset: 2px;
}

.chapter-label {
    font-family: "Fraunces", serif;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--ink);
}

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

.chapter-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    margin-top: 1rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.chapter-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
    color: var(--ink);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chapter-nav-btn:hover:not(:disabled) {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.chapter-nav-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.chapter-nav-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.chapter-select {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: white;
    font-family: "IBM Plex Sans", sans-serif;
    font-size: 0.85rem;
    color: var(--ink);
    min-width: 200px;
    max-width: 400px;
    cursor: pointer;
}

.chapter-select:focus {
    outline: 2px solid rgba(31, 111, 95, 0.5);
    outline-offset: 1px;
}


/* ── Outline list ── */

.outline-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.5rem;
}

.outline-item {
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    border: 1px solid transparent;
    background: rgba(198, 75, 57, 0.08);
    color: var(--ink);
    font-weight: 500;
    cursor: pointer;
}

.outline-item.level-2 {
    background: rgba(31, 111, 95, 0.08);
    margin-left: 0.5rem;
}

.outline-item:hover {
    border-color: var(--accent);
}

.outline-item.outline-current {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-weight: 600;
}

/* ── Editor desk areas ── */

.editor-area {
    width: 100%;
    min-height: 120px;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 0.75rem;
    background: #fff;
    font-family: "IBM Plex Sans", sans-serif;
}

.editor-area.short {
    min-height: 70px;
}

.editor-area.output {
    min-height: 180px;
    background: #fef7ef;
}

.button-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
}

.panel-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ── Buttons ── */

.btn {
    border: none;
    border-radius: 999px;
    padding: 0.6rem 1rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-size: 0.9rem;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(166, 60, 45, 0.25);
}

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

.btn.ghost {
    background: transparent;
    color: var(--accent-strong);
    border: 1px solid var(--accent-strong);
    box-shadow: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.pill {
    background: rgba(31, 111, 95, 0.12);
    color: var(--accent-2);
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.alert {
    background: rgba(198, 75, 57, 0.12);
    color: var(--accent-strong);
    border-radius: 12px;
    padding: 0.75rem;
    font-size: 0.95rem;
}

.save-path {
    font-size: 0.85rem;
    color: var(--muted);
    word-break: break-all;
}

.placeholder {
    color: var(--muted);
    font-style: italic;
}

#blazor-error-ui {
    background: #b32121;
    color: #fff;
    padding: 0.6rem 1rem;
    position: fixed;
    bottom: 0;
    width: 100%;
    display: none;
    z-index: 999;
}

#blazor-error-ui .reload {
    color: #fff;
    margin-left: 0.5rem;
}

/* ── Responsive ── */

@media (max-width: 900px) {
    .toolbar {
        flex-wrap: wrap;
        height: auto;
        padding: 0.5rem;
    }

    .toolbar-stats {
        display: none;
    }

    .toolbar-left-tabs {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .toolbar-branding {
        padding-bottom: 0;
    }

    .toolbar-tabs {
        width: 100%;
        gap: 0.1rem;
    }

    .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .document-toolbar {
        padding: 0.75rem;
    }

    .analysis-progress-panel {
        flex-direction: column;
        align-items: stretch;
    }

    .analysis-progress-actions {
        justify-content: flex-start;
    }

    .ribbon-section {
        width: 100%;
    }

    .ribbon-section-inline {
        align-items: flex-start;
    }

    .document-body {
        padding: 1.5rem;
    }

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

    .editor-split.has-result {
        flex-direction: column;
    }

    .result-gutter {
        display: none;
    }

    .result-panel-strip {
        max-width: 100%;
        flex: none;
        max-height: 40vh;
        padding: 0.5rem;
        overflow-x: auto;
    }

    .result-panel-strip.multi {
        max-width: 100%;
    }

    .result-column {
        min-width: 240px;
    }

    .result-spacer {
        display: none;
    }
}

/* ── Floating toolbar divider ── */

.floating-divider {
    display: inline-block;
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
    vertical-align: middle;
}

/* ── Attributes modal ── */

.attributes-modal {
    width: min(960px, 95vw);
    max-height: 88vh;
}

.tab-bar {
    display: flex;
    gap: 2px;
    background: var(--bg);
    border-radius: 10px;
    padding: 2px;
}

.tab-btn {
    border: none;
    background: transparent;
    padding: 6px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    color: var(--muted);
    transition: all 0.15s;
}

.tab-btn.active {
    background: var(--panel);
    color: var(--ink);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.tab-btn:hover:not(.active) {
    color: var(--ink);
}

.attr-list-row {
    display: flex;
    gap: 1rem;
    min-height: 300px;
}

.attr-list {
    flex: 0 0 180px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-right: 1px solid var(--border);
    padding-right: 1rem;
    overflow-y: auto;
    max-height: 65vh;
}

.attr-item {
    display: flex;
    align-items: center;
    border-radius: 8px;
    transition: background 0.1s;
}

.attr-item.selected {
    background: var(--bg-accent);
}

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

.attr-item-btn {
    flex: 1;
    border: none;
    background: none;
    text-align: left;
    padding: 6px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attr-delete {
    border: none;
    background: none;
    color: var(--muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.1s;
}

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

.attr-delete:hover {
    color: var(--accent);
    background: rgba(198, 75, 57, 0.1);
}

.add-btn {
    font-size: 0.8rem;
    margin-top: 4px;
}

.attr-form {
    flex: 1;
    overflow-y: auto;
    max-height: 65vh;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-right: 0.25rem;
}

.attr-section h3 {
    margin: 0 0 0.4rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-2);
}

.attr-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
}

.attr-grid.wide {
    grid-template-columns: 1fr;
}

.attr-grid label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 500;
}

.attr-grid .input {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    background: var(--panel);
    color: var(--ink);
    font-family: inherit;
    transition: border-color 0.15s;
}

.attr-grid .input:focus {
    outline: none;
    border-color: var(--accent-2);
}

.attr-grid .input.area {
    min-height: 60px;
    resize: vertical;
}

.attr-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.attr-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-style: italic;
    font-size: 0.9rem;
}

.attr-stats {
    font-size: 0.75rem;
    color: var(--muted);
    text-align: right;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
    .attr-list-row {
        flex-direction: column;
    }
    .attr-list {
        flex: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-right: 0;
        padding-bottom: 0.5rem;
        max-height: 120px;
    }
}

/* ── Outline chapter rows: hover-revealed action buttons ── */

.outline-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.outline-row .outline-item {
    flex: 1;
    min-width: 0;
}

.outline-row-actions {
    display: inline-flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.outline-row:hover .outline-row-actions {
    opacity: 1;
}

.outline-action-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 6px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.1s, color 0.1s;
}

.outline-action-btn:hover {
    background: rgba(31, 111, 95, 0.12);
    color: var(--accent-2);
}

.outline-action-btn.danger:hover {
    background: rgba(198, 75, 57, 0.12);
    color: var(--accent);
}

.outline-action-btn.confirm {
    color: var(--accent-2);
}

.outline-rename-input {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--accent-2);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--panel);
    min-width: 0;
}

.outline-footer {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border);
}

.outline-footer .add-btn {
    width: 100%;
}

/* ── Backups (Settings) ── */

.backups-block {
    grid-column: 1 / -1;
}

.backup-create-row {
    display: flex;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.backup-create-row .input {
    flex: 1;
}

.backup-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    display: grid;
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
}

.backup-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    gap: 0.5rem;
}

.backup-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.backup-label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.backup-when {
    font-size: 0.75rem;
    color: var(--muted);
}

.backup-actions {
    display: inline-flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.btn.small {
    font-size: 0.78rem;
    padding: 0.3rem 0.65rem;
}

.btn.danger,
.btn.ghost.danger {
    color: var(--accent);
}

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

.btn.primary.danger:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.hint.muted {
    color: var(--muted);
    font-style: italic;
}

/* ── Confirmation modal ── */

.overlay-modal.confirm-modal {
    max-width: 440px;
    width: 92%;
}

.confirm-message {
    margin: 0.25rem 0 1rem;
    line-height: 1.45;
    color: var(--ink);
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ── Download buttons (Settings) ── */

.download-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.25rem 0 0.25rem;
}

.download-row .btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    border-radius: 8px;
}

/* ── Documents panel: all-users toggle + owner chip ── */

.all-users-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 0.5rem;
    font-size: 0.82rem;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}

.all-users-toggle input[type="checkbox"] {
    accent-color: var(--accent-2);
    cursor: pointer;
}

.doc-list-section {
    margin: 0.75rem 0 0.4rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
    border-top: 1px dashed var(--border);
    padding-top: 0.5rem;
}

.doc-list-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.doc-owner-chip {
    display: inline-flex;
    align-items: center;
    font-size: 0.65rem;
    text-transform: lowercase;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(31, 111, 95, 0.10);
    color: var(--accent-2);
    border: 1px solid rgba(31, 111, 95, 0.25);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.doc-owner-chip.self {
    background: rgba(198, 75, 57, 0.10);
    color: var(--accent);
    border-color: rgba(198, 75, 57, 0.30);
}

/* ── Page View selector (toolbar) ── */

.page-view-picker {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 4px;
    padding: 0 8px;
    border-left: 1px solid var(--border);
    height: 28px;
}

.page-view-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
}

.page-view-select {
    min-width: 140px;
    font-size: 0.85rem;
}

/* ── Insert: source-distinguishing styling ──
   Wraps text the LLM added via "Insert" or batch Chapter/Document edits so
   the user can tell at a glance which prose is new vs. original.
   "Replace" outputs do NOT carry this class; they match destination exactly
   and blend in.

   Two visual signals make the inserted run distinct from any plausible
   body-text setting:
     • A sans-serif family (IBM Plex Sans / Helvetica Neue / Segoe UI) —
       the document body is overwhelmingly serif (Merriweather / Fraunces /
       Georgia / Charter / Lora / etc.), so swapping to sans is a near-
       guaranteed contrast. If the user has chosen a sans body font, the
       size step below still makes the run distinct.
     • Two CSS pixels smaller (`calc(1em - 2px)`) — readable but visibly
       smaller than the surrounding paragraph. Doubled from the previous
       1 px nudge per the user's note that "1 px is hard to spot". */
/* ── LLM insertion marker ──────────────────────────────────────────────
   Wraps EVERY paragraph that came from an LLM — whether it was a batch
   Rewrite/Expand, a single Insert from the floating toolbar, an Append
   from the main toolbar, or anything else. Same prominent treatment
   for all insert paths: a left rule + faint blue tint marks the block
   as LLM-generated; the metadata chip with model + elapsed renders on
   top of that when the wrap function had attribution data (batch ops
   today; single-insert paths join in the next pass). */
.unified-editor span.gw-inserted,
.doc-paragraph .gw-inserted,
.doc-heading .gw-inserted,
.doc-subheading .gw-inserted {
    /* Block context so the left rule + chip attach correctly even
       across multiple wrapped lines. Inline rendering would have left
       the border clipped on every line break. */
    display: block;
    position: relative;
    margin: 6px 0;
    padding: 6px 10px 6px 12px;
    border-left: 3px solid var(--accent, #2563eb);
    background: linear-gradient(
        to right,
        rgba(37, 99, 235, 0.06),
        rgba(37, 99, 235, 0) 60%
    );
    border-radius: 0 4px 4px 0;
    /* Visual differentiation from author prose — sans-serif vs. the
       book's serif body; one step smaller. Doubles as a fallback when
       the border itself isn't enough (e.g. inside a serif page that
       already uses tinted backgrounds). */
    font-size: calc(1em - 2px);
    font-family: "IBM Plex Sans", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
    color: inherit;
    line-height: inherit;
    box-shadow: none;
}

/* Per-insertion remove button (×). Rendered inline as a real <button>
   inside the wrapper span so it's keyboard-accessible and doesn't
   need pseudo-element click hacks. Sits at the top-right corner; the
   chip below shifts left to make room. */
.gw-inserted-remove {
    position: absolute;
    top: -10px;
    right: 8px;
    width: 20px;
    height: 20px;
    line-height: 18px;
    text-align: center;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 50%;
    background: var(--surface, #fff);
    color: var(--text-muted, #6b7280);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    z-index: 2;
    user-select: none;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.gw-inserted-remove:hover {
    background: #fee2e2;
    color: #b91c1c;
    border-color: rgba(220, 38, 38, 0.45);
}

/* Metadata chip — top-right pill with `model · elapsed`. Built from
   data attributes so the C# wrap function just emits the span +
   dataset; CSS composes the visible content. Hidden when the
   data-model attribute is absent or empty so single-insert paths
   that don't carry attribution don't render an empty pill. The chip
   is shifted left by ~30px to clear the remove button overhead. */
.gw-inserted[data-model]:not([data-model=""])::before {
    content: attr(data-model) " · " attr(data-elapsed);
    position: absolute;
    top: -8px;
    right: 36px;
    font-size: 10px;
    font-family: "JetBrains Mono", "Menlo", "SFMono-Regular", monospace;
    font-weight: 600;
    color: #fff;
    background: var(--accent, #2563eb);
    padding: 1px 8px;
    border-radius: 8px;
    line-height: 1.4;
    letter-spacing: 0.02em;
    user-select: none;
    pointer-events: none;
    white-space: nowrap;
}

/* Op + chunk chip on hover — secondary info for users tracking which
   slice of the chapter produced what. Same gated-on-data-op rule. */
.gw-inserted[data-op]:not([data-op=""])::after {
    content: attr(data-op) " · #" attr(data-chunk);
    position: absolute;
    bottom: -7px;
    right: 8px;
    font-size: 9.5px;
    font-family: "JetBrains Mono", "Menlo", "SFMono-Regular", monospace;
    color: var(--text-muted, #6b7280);
    background: var(--surface, #fff);
    padding: 0 6px;
    border: 1px solid rgba(37, 99, 235, 0.25);
    border-radius: 6px;
    line-height: 1.3;
    user-select: none;
    pointer-events: none;
    opacity: 0;
    transition: opacity 120ms ease-out;
}
.gw-inserted[data-op]:not([data-op=""]):hover::after { opacity: 1; }

/* ── Icon-only toolbar buttons (Undo / Redo / Find) ── */

.btn.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 7px;
    min-width: 30px;
    height: 28px;
    border-radius: 6px;
    color: var(--ink);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
}

.btn.icon-btn:hover:not(:disabled) {
    background: rgba(31, 111, 95, 0.10);
    border-color: rgba(31, 111, 95, 0.25);
    color: var(--accent-2);
}

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

.btn.icon-btn.active {
    background: rgba(198, 75, 57, 0.12);
    border-color: rgba(198, 75, 57, 0.30);
    color: var(--accent);
}

/* ── Find & Replace floating panel ── */

.find-replace-panel {
    position: fixed;
    top: calc(var(--toolbar-h) + 12px);
    right: 18px;
    width: min(380px, calc(100vw - 36px));
    z-index: 1100;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 14px 36px rgba(36, 28, 20, 0.20),
                0 4px 10px rgba(36, 28, 20, 0.08);
    overflow: hidden;
    animation: floatIn 0.15s ease;
}

.find-replace-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: linear-gradient(180deg, rgba(31, 111, 95, 0.08) 0%, transparent 100%);
    border-bottom: 1px solid var(--border);
}

.find-replace-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--accent-2);
}

.find-replace-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.find-replace-row {
    display: grid;
    grid-template-columns: 64px 1fr;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
}

.find-replace-row .input {
    padding: 6px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 0.88rem;
    font-family: inherit;
    background: #fff;
    color: var(--ink);
    width: 100%;
}

.find-replace-row .input:focus {
    outline: none;
    border-color: var(--accent-2);
    box-shadow: 0 0 0 2px rgba(31, 111, 95, 0.15);
}

.find-replace-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 0.78rem;
    color: var(--muted);
    padding: 2px 0;
}

.find-replace-options label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
}

.find-replace-options input[type="checkbox"] {
    accent-color: var(--accent-2);
    cursor: pointer;
}

.find-replace-count {
    margin-left: auto;
    font-style: italic;
    color: var(--muted);
}

.find-replace-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
    margin-top: 4px;
}

.find-replace-actions .btn {
    flex: 0 0 auto;
}

.find-replace-status {
    font-size: 0.78rem;
    color: var(--muted);
    font-style: italic;
    padding-top: 2px;
}

/* ── Page View modes ──
   "web" is the default continuous flow — no rules below override the existing
   editor styling. The print-style modes (paperback / hardcover / journal)
   convert the editor into a horizontally-scrolling strip of fixed-size pages
   using CSS multi-column. Each column visually represents one physical page;
   the surrounding .document-body uses a darker "desk" background so the
   white page cards stand out, and column-rule fills the gap with a hairline
   so adjacent pages read as separate sheets.

   Trim sizes (96 CSS px = 1in):
     • Paperback   — 5in × 8in   (trade paperback)
     • Hard Cover  — 6in × 9in   (typical hardback novel)
     • Journal     — 5.5in × 8.5in with a faint horizontal-rule background

   Editing inside a multi-column contenteditable works in modern Chromium /
   Firefox / Safari; the caret may briefly snap when crossing a column
   boundary, which is acceptable for a presentation mode. Switching back to
   Web is fully lossless — only the wrapping changes. */

/* Paged view ── single EditorControl with internal pages
   ────────────────────────────────────────────────────────
   The actual layout is driven by FxControlKit's EditorControl: when its
   Pages parameter is non-null, JS adds .fx-paged to the editor and wraps
   each slice's blocks in <div class="fx-page">. The library's own CSS
   (Editor/EditorControl.razor.css) lays them out as a CSS Grid of cards
   that wrap to new rows as the viewport runs out of horizontal room. The
   editor itself is still ONE contenteditable surface — cursor, selection,
   find/replace, format toolbar, undo, and LLM operations all keep working
   without per-page bookkeeping.

   Below we just set the per-format CSS custom properties the library
   consumes (--fx-page-w, --fx-page-h, --fx-page-pad, --fx-page-bg) and
   give the document-body a desk-coloured backdrop. The per-format class
   (paged-paperback / paged-hardcover / paged-journal) is added by JS at
   init time from EditorControl's PagedCssClass parameter. */

.document-body.page-view-paperback,
.document-body.page-view-hardcover,
.document-body.page-view-journal {
    overflow-x: hidden;
    overflow-y: auto;
    background: linear-gradient(180deg, #d8cdb9 0%, #cfc3ad 100%);
}

/* Per-format trim sizes + book-typeset metrics ────────────────────────────
   The library reads --fx-page-* from the editor element itself, so we set
   them on .unified-editor (which IS the editor root) when the matching
   paged-* class is present.

   Per-format font-size + line-height are applied to the .fx-page CARD
   (not the editor) so children of the card inherit "book metrics" while
   the editor's user-chosen font size stays in effect for Web view. The
   paginator's measurement probe is itself a .fx-page inside the editor,
   so it sees the same metrics the user sees — 5in × 8in × 13.5 px font
   × 1.5 line-height yields ~33 lines × ~10 words ≈ 330 words per page,
   matching the "real paperback" feel. Hardcover and Journal calibrated
   similarly. */

.unified-editor.paged-paperback {
    --fx-page-w:   5in;
    --fx-page-h:   8in;
    --fx-page-pad: 0.65in 0.6in;
    --fx-page-bg:  #fdfaf3;
    font-family: "Merriweather", "Georgia", serif;
}
.unified-editor.paged-paperback .fx-page {
    font-size: 13.5px;
    line-height: 1.5;
}

.unified-editor.paged-hardcover {
    --fx-page-w:   6in;
    --fx-page-h:   9in;
    --fx-page-pad: 0.85in 0.75in;
    --fx-page-bg:  #fcf7e9;
    font-family: "Merriweather", "Georgia", serif;
}
.unified-editor.paged-hardcover .fx-page {
    font-size: 14.5px;
    line-height: 1.55;
}

.unified-editor.paged-journal {
    --fx-page-w:   5.5in;
    --fx-page-h:   8.5in;
    --fx-page-pad: 0.75in 0.6in;
    /* Lined-paper background — drawn via a layered repeating gradient on the
       page-bg variable so the rules line up with each card's inside padding. */
    --fx-page-bg:
        repeating-linear-gradient(
            to bottom,
            transparent 0,
            transparent 27px,
            rgba(70, 110, 160, 0.18) 27px,
            rgba(70, 110, 160, 0.18) 28px
        ),
        #fdfdfb;
    font-family: "Merriweather", "Georgia", serif;
}
.unified-editor.paged-journal .fx-page {
    /* Journal lines are 28 px apart (see the gradient above) — match
       line-height to that pitch so prose lands on the rules. */
    font-size: 15px;
    line-height: 28px;
}

/* Mobile / very narrow viewports: trim widths are absolute inches, so a
   phone only has room for one card. The grid still works (1 col) — just
   tighten the document-body padding so the card isn't squeezed by the
   surrounding gutters. */
@media (max-width: 540px) {
    .document-body.page-view-paperback,
    .document-body.page-view-hardcover,
    .document-body.page-view-journal {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* ── Prompt editor (Editing Desk → "Edit default prompts") ── */
.prompt-editor {
    margin-top: 1.25rem;
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.prompt-editor-toggle {
    align-self: flex-start;
}

.prompt-op {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.4rem 0;
    border-bottom: 1px dashed var(--border);
}

.prompt-op:last-child { border-bottom: 0; }

.prompt-op-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.prompt-op-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--ink);
}

.prompt-op-badge {
    background: rgba(198, 75, 57, 0.12);
    color: var(--accent-strong);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 1px 6px;
    border-radius: 999px;
}

.prompt-op-text {
    font-size: 0.82rem;
    line-height: 1.45;
}

/* ── LLM log overlay ── */
.llm-log-modal {
    width: min(920px, 96vw);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow: hidden;
}

.llm-log-modal .overlay-header {
    flex-wrap: wrap;
    gap: 0.5rem;
}

.llm-log-summary {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.llm-log-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0.65rem;
}

.llm-log-summary-card,
.llm-log-breakdown {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.8rem 0.9rem;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
}

.llm-log-summary-card {
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
}

.llm-log-summary-label,
.llm-log-breakdown-sub,
.llm-log-usage-label {
    color: var(--muted);
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.llm-log-summary-value {
    color: var(--ink);
    font-size: 1.1rem;
    font-weight: 700;
}

.llm-log-summary-note {
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.35;
}

.llm-log-breakdowns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 0.7rem;
}

.llm-log-breakdown {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-height: 0;
}

.llm-log-breakdown-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
}

.llm-log-breakdown-head h3 {
    margin: 0;
    font-size: 0.95rem;
}

.llm-log-breakdown-head span {
    color: var(--muted);
    font-size: 0.78rem;
}

.llm-log-breakdown-table-wrap {
    overflow: auto;
}

.llm-log-breakdown-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 520px;
    font-size: 0.8rem;
}

.llm-log-breakdown-table th,
.llm-log-breakdown-table td {
    padding: 0.48rem 0.35rem;
    border-top: 1px solid var(--border);
    vertical-align: top;
    text-align: left;
}

.llm-log-breakdown-table thead th {
    border-top: 0;
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    position: sticky;
    top: 0;
    background: var(--panel);
}

.llm-log-breakdown-table tbody th {
    font-weight: 600;
    color: var(--ink);
}

.llm-log-breakdown-label {
    line-height: 1.35;
}

.llm-log-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 200px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
}

.llm-log-row {
    border-bottom: 1px solid var(--border);
}

.llm-log-row:last-child { border-bottom: 0; }

.llm-log-row.expanded { background: rgba(198, 75, 57, 0.04); }

.llm-log-row.error .llm-log-head { color: #7f1d1d; }

.llm-log-head {
    display: flex !important;
    align-items: center !important;
    gap: 0.6rem !important;
    width: 100% !important;
    padding: 0.45rem 0.75rem !important;
    text-align: left !important;
    font-size: 0.82rem !important;
    justify-content: flex-start !important;
}

.llm-log-head:hover { background: rgba(0, 0, 0, 0.03); }

.llm-log-time {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    min-width: 145px;
}

.llm-log-badge {
    background: var(--accent);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.llm-log-model {
    color: var(--ink);
    font-weight: 600;
}

.llm-log-meta {
    color: var(--muted);
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.llm-log-error-chip {
    background: #fdecea;
    color: #7f1d1d;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 999px;
    text-transform: uppercase;
}

.llm-log-detail {
    padding: 0.5rem 0.9rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.llm-log-usage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.55rem;
}

.llm-log-usage-cell {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.55rem 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.18rem;
}

.llm-log-usage-cell strong {
    color: var(--ink);
    font-size: 0.9rem;
    line-height: 1.3;
    word-break: break-word;
}

.llm-log-section label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.llm-log-pre {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    margin: 0;
    font-family: "SF Mono", "Menlo", "Consolas", monospace;
    font-size: 0.78rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 260px;
    overflow-y: auto;
    color: var(--ink);
}

.llm-log-pre.alert {
    background: #fdecea;
    color: #7f1d1d;
    border-color: #f5c6c0;
}

.btn.small.danger {
    color: #b91c1c;
    border-color: rgba(185, 28, 28, 0.35);
}

.btn.small.danger:hover {
    background: rgba(185, 28, 28, 0.08);
}

/* Pending LLM log row — request logged, response not back yet. */
.llm-log-row.pending .llm-log-head { color: var(--accent-2); }
.llm-log-row.pending { background: rgba(31, 111, 95, 0.04); }

.llm-log-pending-chip {
    background: rgba(31, 111, 95, 0.14);
    color: var(--accent-2);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.llm-log-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(31, 111, 95, 0.25);
    border-top-color: var(--accent-2);
    border-radius: 50%;
    animation: llm-log-spin 0.7s linear infinite;
    vertical-align: -2px;
    margin-right: 4px;
}

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

.llm-log-pre--pending {
    color: var(--accent-2);
    font-style: italic;
}

@media (max-width: 840px) {
    .llm-log-modal {
        width: min(96vw, 96vw);
    }

    .llm-log-head {
        flex-wrap: wrap !important;
    }

    .llm-log-time {
        min-width: 0;
    }

    .llm-log-meta {
        width: 100%;
        margin-left: 0;
    }
}

/* Instructions (default-prompt editor) overlay — admin-only. */
.instructions-modal {
    width: min(860px, 96vw);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow: hidden;
}

.instructions-modal .overlay-header { flex-wrap: wrap; gap: 0.5rem; }

.instructions-list {
    overflow-y: auto;
    flex: 1 1 auto;
    padding-right: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

/* ── History overlay ── */
.history-modal {
    width: min(820px, 96vw);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow: hidden;
}

.history-modal .overlay-header { flex-wrap: wrap; gap: 0.5rem; }

.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 200px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
}

.history-row {
    border-bottom: 1px solid var(--border);
}

.history-row:last-child { border-bottom: 0; }

.history-row.expanded { background: rgba(198, 75, 57, 0.04); }

.history-head {
    display: flex !important;
    align-items: center !important;
    gap: 0.6rem !important;
    width: 100% !important;
    padding: 0.5rem 0.75rem !important;
    text-align: left !important;
    font-size: 0.85rem !important;
    justify-content: flex-start !important;
}

.history-head:hover { background: rgba(0, 0, 0, 0.03); }

.history-time {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    min-width: 130px;
}

.history-badge {
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.history-model {
    color: var(--ink);
    font-weight: 600;
}

.history-meta {
    color: var(--muted);
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
}

.history-detail {
    padding: 0.5rem 0.9rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.history-section label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.history-pre {
    background: #fef7ef;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    margin: 0;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 240px;
    overflow-y: auto;
    color: var(--ink);
}

.history-pre--orig {
    background: var(--panel-2);
    font-style: italic;
    color: var(--muted);
}

.history-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    padding-top: 0.25rem;
}

/* ── Writing Tools scope picker (Review tab ribbon) ──
   Three-state segmented control sitting at the left of the Writing Tools
   action row. Selection scope is the default; Chapter / Document switch
   the seven editor buttons over to the batch-edit code path, which walks
   the chapter (or every chapter) in model-capacity-aware chunks and
   appends each chunk's output after its source. The active pill reads as
   the green accent, mirroring how .doc-switcher uses --accent-2 for the
   "current" chip elsewhere in the ribbon. */
/* Legacy ".scope-picker" / ".scope-pill" classes kept for any in-flight
   render of an older Writing-Tools layout — the new top-row scope picker
   is `.scope-row` + `.scope-radio-group` below. */
.scope-picker {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--panel);
    margin-right: 4px;
}

.scope-pill {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
}

.scope-pill + .scope-pill {
    border-left: 1px solid var(--border);
}

.scope-pill:hover {
    background: rgba(31, 111, 95, 0.06);
    color: var(--ink);
}

.scope-pill.active {
    background: var(--accent-2);
    color: #fff;
}

.scope-pill.active:hover {
    background: var(--accent-2);
}

/* ── Writing-Tools scope bar ────────────────────────────────────────────
   Compact icon-only segmented control + small Remove-All trash button,
   all on a single inline row that sits beside the action buttons inside
   the Writing Tools ribbon section. No labels — pure icons with
   tooltips so the bar stays narrow. */
.scope-bar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 6px;
}

.scope-radio-group {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 999px;
    overflow: hidden;
    background: var(--panel, #fff);
}

.scope-radio {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 24px;
    color: var(--muted, #6b7280);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    user-select: none;
    position: relative;
}

.scope-radio + .scope-radio {
    border-left: 1px solid var(--border, #d1d5db);
}

.scope-radio:hover {
    background: rgba(31, 111, 95, 0.06);
    color: var(--ink, #111);
}

.scope-radio.active {
    background: var(--accent-2, #2563eb);
    color: #fff;
}

.scope-radio.active:hover {
    background: var(--accent-2, #2563eb);
}

/* Hide the underlying input — the label IS the visible affordance.
   Keep it a real <input> so accessibility tooling and keyboard nav
   still work (Tab to focus, Space to activate). */
.scope-radio input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Remove-All sits right next to the scope radios. Icon-only, same
   height as the radios, red tint to mark it as a destructive action. */
.scope-remove-all {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 24px;
    border: 1px solid rgba(220, 38, 38, 0.45);
    background: transparent;
    color: #b91c1c;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    padding: 0;
}

.scope-remove-all:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.08);
    color: #991b1b;
}

.scope-remove-all:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Batch-edit progress strip ──
   Shown in the Writing Tools action row while a Chapter / Document batch
   run is in flight. A thin spinner + "X/Y chunks" label + Cancel button.
   The Writing Tools action buttons disable themselves via
   `Disabled="@(IsBatchEditing)"` so the user can't kick off a second
   batch on top of the first. */
.batch-progress {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    padding: 3px 9px;
    background: rgba(31, 111, 95, 0.08);
    border: 1px solid rgba(31, 111, 95, 0.30);
    border-radius: 999px;
    font-size: 0.74rem;
    color: var(--accent-2);
    font-weight: 600;
}

.batch-progress-spinner {
    display: inline-block;
    width: 11px;
    height: 11px;
    border: 2px solid rgba(31, 111, 95, 0.25);
    border-top-color: var(--accent-2);
    border-radius: 50%;
    animation: spin 0.85s linear infinite;
    flex: none;
}

.batch-progress-text {
    /* Numerals sit cleanly when monospaced — keeps "12/47" stable as it
       counts up. */
    font-variant-numeric: tabular-nums;
}

.batch-progress-cancel {
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 0.74rem;
    font-weight: 700;
    padding: 0 4px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.batch-progress-cancel:hover {
    color: var(--accent-strong);
    text-decoration: underline;
}

/* ── Server-side spell-checker overlay ─────────────────────────────────
   The overlay is a sibling of the editor sized to its bounding box,
   pointer-events:none so it never intercepts editor input. Each
   .gw-spell-mark is an absolute-positioned 3px-tall element drawn just
   below a misspelled word; a wavy red SVG background gives the familiar
   squiggle. Marks are positioned relative to #document-panel. */
.gw-spell-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}
.gw-spell-overlay > .gw-spell-mark {
    position: absolute;
    height: 3px;
    pointer-events: auto;            /* enable native title tooltip on hover */
    cursor: help;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 6 3' preserveAspectRatio='none'><path d='M0 2 Q 1.5 0 3 2 T 6 2' fill='none' stroke='%23dc2626' stroke-width='1'/></svg>");
    background-repeat: repeat-x;
    background-size: 6px 3px;
}
/* Establish positioning context for the absolute spell overlay. */
#document-panel { position: relative; }


/* ── Spell-correction pill ─────────────────────────────────────────────
   Floats below a misspelled word when the caret enters it. Lives inside
   .gw-spell-overlay so it inherits the same positioning context as the
   underline marks. pointer-events: auto overrides the overlay's none so
   the buttons are clickable. */
.gw-spell-overlay > .gw-spell-pill {
    position: absolute;
    pointer-events: auto;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    background: var(--surface, #fff);
    color: var(--text, #111);
    border: 1px solid var(--border, #d1d5db);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    font-size: 13px;
    user-select: none;
    max-width: 480px;
    flex-wrap: wrap;
}
.gw-spell-pill-btn {
    background: var(--surface-muted, #f3f4f6);
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 2px 10px;
    cursor: pointer;
    color: inherit;
    font: inherit;
}
.gw-spell-pill-btn:hover {
    background: var(--accent-soft, #dbeafe);
    border-color: var(--accent, #2563eb);
}
.gw-spell-pill-sep {
    width: 1px;
    align-self: stretch;
    background: var(--border, #e5e7eb);
    margin: 2px 4px;
}
.gw-spell-pill-ignore {
    background: none;
    border: none;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    padding: 2px 6px;
    font: inherit;
}
.gw-spell-pill-ignore:hover { color: var(--text, #111); }
.gw-spell-pill-none {
    color: var(--text-muted, #6b7280);
    font-style: italic;
    padding: 2px 8px;
}

/* ── Thesaurus / Define popover ────────────────────────────────────────
   Centered fixed-position dialog. Backdrop dims and captures outside-
   clicks for dismiss. Used by RunThesaurusAsync / RunDefineAsync. */
.lookup-popover-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 1100;
}
/* ── New (Ghost Write) wizard ──────────────────────────────────────────
   Reuses the lookup-popover header/backdrop styling so the chrome is
   consistent with the Thesaurus / Define popovers. The body has a
   stack of labelled rows (Title / Genre / Synopsis / Outline) plus a
   sticky action footer at the bottom. */
.ghostwrite-wizard {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1101;
    width: min(640px, 92vw);
    max-height: min(86vh, 800px);
    background: var(--surface, #fff);
    color: var(--text, #111);
    border: 1px solid var(--border, #d1d5db);
    border-radius: 10px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-size: 14px;
}
.ghostwrite-wizard-body {
    padding: 14px 16px;
    overflow-y: auto;
    flex: 1;
}
.ghostwrite-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}
.ghostwrite-row-inline {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.ghostwrite-row-inline .ghostwrite-label { margin-right: 4px; }
.ghostwrite-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted, #6b7280);
    letter-spacing: 0.02em;
}
.ghostwrite-hint {
    font-weight: 400;
    color: var(--text-muted, #9ca3af);
}
.ghostwrite-input,
.ghostwrite-textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 6px;
    padding: 6px 9px;
    font: inherit;
    color: inherit;
    background: var(--surface, #fff);
    resize: vertical;
}
.ghostwrite-input:focus,
.ghostwrite-textarea:focus {
    outline: none;
    border-color: var(--accent, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.ghostwrite-input-narrow { width: 80px; flex: 0 0 80px; }
.ghostwrite-outline {
    font-family: "JetBrains Mono", "Menlo", monospace;
    font-size: 13px;
    line-height: 1.5;
}
.ghostwrite-generate {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 6px;
    background: var(--accent-soft, #dbeafe);
    color: var(--accent, #2563eb);
    border: 1px solid var(--accent, #2563eb);
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
    margin-left: auto;
}
.ghostwrite-generate:hover:not(:disabled) {
    background: var(--accent, #2563eb);
    color: #fff;
}
.ghostwrite-generate:disabled { opacity: 0.5; cursor: not-allowed; }
.ghostwrite-status {
    margin-top: 6px;
    padding: 6px 10px;
    background: rgba(37, 99, 235, 0.08);
    border-left: 3px solid var(--accent, #2563eb);
    font-size: 12.5px;
    color: var(--text, #111);
    border-radius: 0 4px 4px 0;
}
.ghostwrite-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border, #e5e7eb);
    background: var(--surface-muted, #f9fafb);
}
.ghostwrite-cancel,
.ghostwrite-create {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    border: 1px solid var(--border, #d1d5db);
    background: var(--surface, #fff);
    color: inherit;
}
.ghostwrite-cancel:hover:not(:disabled) { background: var(--surface-muted, #f3f4f6); }
.ghostwrite-create {
    background: var(--accent, #2563eb);
    color: #fff;
    border-color: var(--accent, #2563eb);
}
.ghostwrite-create:hover:not(:disabled) { filter: brightness(0.95); }
.ghostwrite-cancel:disabled,
.ghostwrite-create:disabled { opacity: 0.55; cursor: not-allowed; }

.lookup-popover {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1101;
    width: min(440px, 92vw);
    max-height: min(70vh, 600px);
    background: var(--surface, #fff);
    color: var(--text, #111);
    border: 1px solid var(--border, #d1d5db);
    border-radius: 10px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-size: 14px;
}
.lookup-popover-header {
    display: flex;
    align-items: baseline;
    gap: 0.6em;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    background: var(--surface-muted, #f9fafb);
}
.lookup-popover-kind {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted, #6b7280);
}
.lookup-popover-word {
    font-weight: 600;
    font-size: 16px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.lookup-popover-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted, #6b7280);
    padding: 0 6px;
}
.lookup-popover-close:hover { color: var(--text, #111); }
.lookup-popover-body {
    padding: 12px 14px;
    overflow-y: auto;
    flex: 1;
}
.lookup-popover-loading {
    display: flex;
    align-items: center;
    gap: 0.6em;
    color: var(--text-muted, #6b7280);
    padding: 12px 0;
}
.lookup-popover-error {
    color: #b91c1c;
    padding: 6px 0;
}
.lookup-synonyms {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.lookup-synonym {
    background: var(--surface-muted, #f3f4f6);
    border: 1px solid var(--border, #d1d5db);
    border-radius: 999px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 13px;
    color: inherit;
}
.lookup-synonym:hover {
    background: var(--accent-soft, #dbeafe);
    border-color: var(--accent, #2563eb);
}
.lookup-popover-hint {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-muted, #6b7280);
}
.lookup-definitions {
    margin: 0;
    padding-left: 22px;
}
.lookup-definitions li { margin-bottom: 12px; line-height: 1.45; }
.lookup-definitions li:last-child { margin-bottom: 0; }
.lookup-pos {
    display: inline-block;
    font-style: italic;
    color: var(--text-muted, #6b7280);
    margin-right: 0.5em;
    font-size: 12.5px;
}
.lookup-example {
    margin-top: 4px;
    font-size: 12.5px;
    color: var(--text-muted, #6b7280);
    font-style: italic;
}
