/* ==========================================================================
   CSS Custom Properties — light defaults, dark overrides on html.dark
   ========================================================================== */
:root {
    --bg:        #faf9f7;   /* page background */
    --surface:   #ffffff;   /* nav, cards, editor panes, inputs */
    --sb-bg:     #f0ede8;   /* sidebar background */
    --hover:     #f0ede8;   /* gentle hover (buttons, snapshot rows) */
    --active:    #e4e0da;   /* sidebar item hover / active highlight */
    --bd:        #e0dbd4;   /* default border */
    --bd-in:     #d0cac3;   /* input / button border */
    --bd-mu:     #c0bab3;   /* muted border, drag handle, dashed outline */
    --tx:        #1a1a1a;   /* primary text */
    --tx-2:      #4a4744;   /* label text */
    --tx-3:      #6b6563;   /* secondary text */
    --tx-4:      #9b9693;   /* muted text */
    --tx-5:      #b0aaa4;   /* very muted text */
    --tx-6:      #c0bab3;   /* placeholder / ultra-muted */
    --ac:        #2d6a4f;   /* accent green */
    --ac-h:      #245a41;   /* accent hover */
    --ac-bg:     #e8f0ec;   /* tinted accent background */
    --focus:     rgba(45, 106, 79, 0.12);
}

html.dark {
    --bg:        #1c1a18;
    --surface:   #252321;
    --sb-bg:     #1f1d1b;
    --hover:     #2c2a27;
    --active:    #333130;
    --bd:        #38342f;
    --bd-in:     #423e38;
    --bd-mu:     #4e4a44;
    --tx:        #e5e0d9;
    --tx-2:      #b0a89e;
    --tx-3:      #857d75;
    --tx-4:      #605a54;
    --tx-5:      #504a44;
    --tx-6:      #5a5450;
    --ac:        #4ea876;
    --ac-h:      #418f63;
    --ac-bg:     #1c2e22;
    --focus:     rgba(78, 168, 118, 0.22);
}

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

html { height: 100%; }

body {
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--tx);
    font-size: 16px;
    line-height: 1.6;
}

a {
    color: var(--ac);
    text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ==========================================================================
   Navigation
   ========================================================================== */
.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--bd);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 600;
    font-size: 1rem;
    color: var(--tx);
}
.nav-brand:hover { text-decoration: none; }

.nav-version {
    font-size: 0.6875rem;
    color: var(--tx-6);
    margin-left: 6px;
    user-select: none;
}

.nav-left  { display: flex; align-items: center; gap: 0; flex-shrink: 0; }
.nav-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

/* Mobile-only hamburger — hidden on desktop */
.sidebar-toggle-btn {
    display: none;
}

.logout-form { display: inline; }

/* Dark mode toggle */
.dark-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--tx-4);
    padding: 4px 6px;
    line-height: 1;
    font-family: inherit;
    transition: color 0.12s;
}
.dark-toggle-btn:hover { color: var(--tx); }

/* ==========================================================================
   Main wrapper
   ========================================================================== */
.main { min-height: calc(100vh - 52px); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border: 1px solid var(--bd-in);
    border-radius: 6px;
    background: var(--surface);
    color: var(--tx);
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.4;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--hover); text-decoration: none; }

.btn-primary {
    background: var(--ac);
    border-color: var(--ac);
    color: #ffffff;
}
.btn-primary:hover { background: var(--ac-h); border-color: var(--ac-h); }

.btn-danger {
    background: #c0392b;
    border-color: #c0392b;
    color: #ffffff;
}
.btn-danger:hover { background: #a93226; border-color: #a93226; }

.btn-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--tx-3);
    cursor: pointer;
    font-size: 0.875rem;
    font-family: inherit;
}
.btn-link:hover { color: var(--tx); }

.btn-sm { padding: 4px 10px; font-size: 0.8125rem; }

/* ==========================================================================
   Forms
   ========================================================================== */
label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.875rem;
    color: var(--tx-2);
    font-weight: 500;
}

label input,
label textarea,
label select {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid var(--bd-in);
    border-radius: 6px;
    font-size: 0.9375rem;
    font-family: inherit;
    font-weight: 400;
    background: var(--surface);
    color: var(--tx);
    transition: border-color 0.15s, box-shadow 0.15s;
}

label input:focus,
label textarea:focus,
label select:focus {
    outline: none;
    border-color: var(--ac);
    box-shadow: 0 0 0 3px var(--focus);
}

textarea { resize: vertical; }

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--bd);
    border-radius: 10px;
    padding: 20px 24px;
    margin-bottom: 16px;
}
.card h2 { margin-bottom: 16px; font-size: 1rem; }

.hidden { display: none !important; }

/* ==========================================================================
   Flash messages
   ========================================================================== */
.flash {
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    font-size: 0.9rem;
    border-bottom: 1px solid transparent;
    transition: opacity 0.4s ease;
}
.flash.flash-hiding { opacity: 0; }
.flash-success { background: #d4edda; border-color: #b8dfc5; color: #155724; }
.flash-error   { background: #f8d7da; border-color: #f1aeb5; color: #721c24; }
.flash-warning { background: #fff3cd; border-color: #ffd78c; color: #856404; }

.flash-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: 0.5;
    padding: 0 4px;
}
.flash-close:hover { opacity: 1; }

/* ==========================================================================
   Page header (projects index)
   ========================================================================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 28px 32px 16px;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.page-header-left { display: flex; flex-direction: column; gap: 4px; }

.page-body { padding: 0 32px 40px; }

/* ==========================================================================
   Item list (project cards)
   ========================================================================== */
.item-list {
    list-style: none;
    margin-top: 8px;
}

.item-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 16px;
    background: var(--surface);
    border: 1px solid var(--bd);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: default;
    transition: border-color 0.12s;
}
.item-list-item:hover { border-color: var(--bd-mu); }
.item-list-item.dragging { opacity: 0.35; }

.item-title {
    flex: 1;
    font-weight: 500;
    font-size: 0.9375rem;
    color: var(--tx);
}
.item-title:hover { text-decoration: underline; }

.item-desc {
    color: var(--tx-3);
    font-size: 0.875rem;
    flex: 2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drag-handle {
    color: var(--bd-mu);
    cursor: grab;
    font-size: 1.1rem;
    padding: 2px 4px;
    user-select: none;
    flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }

.empty-state {
    color: var(--tx-4);
    padding: 48px;
    text-align: center;
    font-size: 0.9375rem;
}

/* ==========================================================================
   Trash page
   ========================================================================== */
.trash-section { margin-bottom: 32px; }
.trash-section h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 12px; }
.trash-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.trash-table th, .trash-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.trash-table th { font-weight: 600; color: var(--tx-3); }
.trash-actions { display: flex; gap: 8px; }

/* ==========================================================================
   Split layout (sidebar + content)
   ========================================================================== */
.layout-split {
    display: flex;
    height: calc(100vh - 52px);
    overflow: hidden;
    transition: padding-left 0.22s ease;
}

/* Sidebar */
.sidebar {
    width: 270px;
    min-width: 270px;
    background: var(--sb-bg);
    border-right: 1px solid var(--bd);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: width 0.22s ease, min-width 0.22s ease;
}

/* Desktop: sidebar collapsed — zero width; padding-left on the container
   reserves the 24px strip space so content never slides under the strip */
body.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right-width: 0;
}

body.sidebar-collapsed .layout-split {
    padding-left: 24px;
}

/* ‹ collapse button — pinned to right edge of sidebar header */
.sidebar-collapse-btn {
    flex-shrink: 0;
    align-self: flex-start;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--tx-4);
    padding: 2px 0 2px 4px;
    transition: color 0.12s;
    margin-top: 2px;
}
.sidebar-collapse-btn:hover { color: var(--tx); }

/* Hide collapse btn when collapsed (content is clipped anyway, but be explicit) */
body.sidebar-collapsed .sidebar-collapse-btn { visibility: hidden; }

/* › expand strip — fixed to left edge of viewport, below the nav bar */
.sidebar-expand-strip {
    display: none;
    position: fixed;
    left: 0;
    top: 52px;
    width: 24px;
    height: calc(100vh - 52px);
    background: var(--sb-bg);
    border: none;
    border-right: 1px solid var(--bd);
    cursor: pointer;
    color: var(--tx-4);
    font-size: 1rem;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
    z-index: 100;
}
.sidebar-expand-strip:hover {
    background: var(--active);
    color: var(--tx);
}
body.sidebar-collapsed .sidebar-expand-strip { display: flex; }

.sidebar-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--bd);
}
.sidebar-header-main {
    flex: 1;
    min-width: 0;
}
.sidebar-header h2 {
    font-size: 0.9375rem;
    font-weight: 600;
    word-break: break-word;
    line-height: 1.4;
}
.sidebar-project-wc {
    display: block;
    font-size: 0.7rem;
    color: var(--tx-5);
    margin-top: 2px;
}

.sidebar-breadcrumb {
    padding: 8px 16px;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--bd);
}
.sidebar-breadcrumb a {
    color: var(--tx-3);
}
.sidebar-breadcrumb a:hover { color: var(--ac); }

.sidebar-new-form {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--bd);
}
.sidebar-new-form input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid var(--bd-in);
    border-radius: 6px;
    font-size: 0.8125rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--tx);
}
.sidebar-new-form input[type="text"]:focus {
    outline: none;
    border-color: var(--ac);
}

.sidebar-list {
    list-style: none;
    padding: 6px 0;
    flex: 1;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-size: 0.875rem;
    cursor: default;
    border-radius: 0;
    transition: background 0.1s;
}
.sidebar-item:hover { background: var(--active); }
.sidebar-item.dragging { opacity: 0.35; }

.sidebar-item a {
    flex: 1;
    color: var(--tx);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-item a:hover { color: var(--ac); text-decoration: none; }

.word-count {
    font-size: 0.75rem;
    color: var(--tx-4);
    white-space: nowrap;
    flex-shrink: 0;
}

.chapter-wc {
    font-size: 0.65rem;
    color: var(--tx-5);
    white-space: nowrap;
    flex-shrink: 0;
    margin-right: 2px;
}

.wc-stat {
    margin: -14px 0 16px;
    font-size: 0.875rem;
    color: var(--tx-4);
}

/* Project dashboard actions bar */
.project-actions-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.sidebar-empty {
    padding: 20px 16px;
    color: var(--tx-4);
    font-size: 0.8125rem;
    text-align: center;
}

/* ==========================================================================
   Project tree sidebar (shared across project / chapter / editor pages)
   ========================================================================== */

/* Outer chapter list */
.sidebar-tree {
    list-style: none;
    margin: 0;
    padding: 4px 0 8px;
}

/* Each chapter group: heading + its scene list */
.sidebar-chapter-group {
    list-style: none;
}

/* Chapter heading row */
.sidebar-chapter-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px 3px;
    border-top: 1px solid var(--bd);
    margin-top: 4px;
}
.sidebar-chapter-group:first-child .sidebar-chapter-row {
    border-top: none;
    margin-top: 0;
    padding-top: 6px;
}
.sidebar-chapter-row a {
    flex: 1;
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--tx-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
}
.sidebar-chapter-row a:hover { color: var(--ac); }
.sidebar-chapter-row.active a { color: var(--ac); }
.sidebar-chapter-row .drag-handle {
    font-size: 0.8rem;
    padding: 2px 2px;
    flex-shrink: 0;
}

/* Chapter collapse toggle */
.chapter-collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 1px;
    color: var(--tx-4);
    font-size: 0.5rem;
    line-height: 1;
    flex-shrink: 0;
    transform: rotate(90deg);
    transition: transform 0.15s ease, color 0.1s;
}
.chapter-collapse-btn:hover { color: var(--tx-2); }
.chapter-collapse-btn[aria-expanded="false"] { transform: rotate(0deg); }

/* Scene list nested under its chapter */
.sidebar-scene-list {
    list-style: none;
    padding: 2px 0 4px;
    min-height: 6px; /* keep empty lists droppable */
}
.sidebar-scene-list.collapsed { display: none; }
.sidebar-scene-list .sidebar-item {
    padding-left: 24px;
}

/* Active scene highlight */
.sidebar-scene-list .sidebar-item.active {
    background: var(--active);
}
.sidebar-scene-list .sidebar-item.active a {
    color: var(--ac);
    font-weight: 600;
}

/* Inline rename input (replaces the active sidebar link while editing) */
.sidebar-rename-input {
    flex: 1;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--tx);
    background: var(--surface);
    border: 1px solid var(--ac);
    border-radius: 3px;
    padding: 1px 4px;
    min-width: 0;
    outline: none;
}

/* Project title link in sidebar header */
.sidebar-project-link {
    color: inherit;
    text-decoration: none;
}
.sidebar-project-link:hover { color: var(--ac); text-decoration: none; }

/* Content area */
.content {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}
.content > h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 24px;
}

/* Collapsible details */
.collapsible summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--tx-2);
    list-style: none;
    user-select: none;
}
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible summary::before { content: '▶\00a0'; font-size: 0.65em; }
.collapsible[open] summary::before { content: '▼\00a0'; }
.collapsible > *:not(summary) { margin-top: 18px; }

.danger-zone { border-color: #f1aeb5; }
.danger-zone summary { color: #721c24; }
.danger-zone p {
    color: #721c24;
    font-size: 0.875rem;
    margin-bottom: 12px;
}

/* ==========================================================================
   Login
   ========================================================================== */
.login-wrap {
    max-width: 380px;
    margin: 80px auto;
    padding: 0 16px;
}
.login-wrap h1 {
    text-align: center;
    font-size: 1.75rem;
    margin-bottom: 32px;
    font-weight: 700;
    color: var(--tx);
}
.login-form {
    background: var(--surface);
    border: 1px solid var(--bd);
    border-radius: 12px;
    padding: 28px 28px 24px;
}
.login-form .btn {
    width: 100%;
    justify-content: center;
    padding: 10px;
    font-size: 1rem;
    margin-top: 4px;
}

/* ==========================================================================
   Editor layout
   ========================================================================== */
body.editor-page {
    overflow: hidden;
}
body.editor-page .main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 52px);
    overflow: hidden;
}

/* Sidebar + writing column side-by-side */
.editor-shell {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    transition: padding-left 0.22s ease;
}

body.sidebar-collapsed .editor-shell {
    padding-left: 24px;
}

.editor-layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* Nav breadcrumb — shown on editor pages, sits between nav-left and nav-right */
.nav-breadcrumb {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--tx-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 16px;
    pointer-events: none; /* prevent breadcrumb box from intercepting clicks */
}
.editor-breadcrumb a { color: var(--tx-3); text-decoration: none; pointer-events: auto; }
.editor-breadcrumb a:hover { color: var(--ac); }

/* Secondary doc-level toolbar (between title and Quill) */
.editor-doc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--bd);
    flex-shrink: 0;
    gap: 8px;
}

.editor-doc-toolbar-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.editor-doc-toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8125rem;
    color: var(--tx-4);
    flex-shrink: 0;
}

/* Overflow ••• menu */
.overflow-menu-wrapper {
    position: relative;
}

.overflow-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--bd);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 150;
    min-width: 150px;
    overflow: hidden;
}

.overflow-menu form { margin: 0; }

.overflow-menu-item {
    display: block;
    width: 100%;
    padding: 9px 14px;
    text-align: left;
    background: none;
    border: none;
    font-size: 0.875rem;
    color: var(--tx);
    cursor: pointer;
    text-decoration: none;
    box-sizing: border-box;
}

.overflow-menu-item:hover { background: var(--hover); }

.overflow-menu-item-danger { color: #c0392b; }
html.dark .overflow-menu-item-danger { color: #e08080; }

/* Save status */
#save-status {
    min-width: 90px;
    text-align: right;
    transition: color 0.2s;
    font-size: 0.8125rem;
}
.status-idle    { color: transparent; }
.status-saving  { color: var(--tx-4); }
.status-saved   { color: var(--ac); font-weight: 500; }
.status-error   { color: #c0392b; font-weight: 500; }

/* Scene title input */
.editor-title-row {
    padding: 16px 24px 4px;
    background: var(--surface);
    flex-shrink: 0;
}

.scene-title-input {
    width: 100%;
    font-size: 1.625rem;
    font-weight: 700;
    border: none;
    outline: none;
    background: transparent;
    color: var(--tx);
    font-family: Georgia, 'Times New Roman', serif;
    padding: 0 0 10px;
    border-bottom: 2px solid transparent;
    transition: border-color 0.15s;
}
.scene-title-input:focus { border-bottom-color: var(--ac); }
.scene-title-input::placeholder { color: var(--tx-6); }

/* Quill editor container (left and right panes) */
#quill-editor,
#quill-editor-right {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--surface);
}

/* Override Quill snow theme */
.ql-toolbar.ql-snow {
    border: none !important;
    border-bottom: 1px solid var(--bd) !important;
    padding: 6px 16px;
    flex-shrink: 0;
    background: var(--bg);
}

.ql-container.ql-snow {
    border: none !important;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.0625rem;
    line-height: 1.85;
}

.ql-editor {
    /* Override Quill's height:100% which causes a zero-height loop in flex layouts.
       height:auto sizes to content; min-height:100% ensures it fills the container
       when content is short. The container's overflow-y:auto handles scrolling.
       width:100% overrides any Quill 2.x flex-context shrink-to-content behaviour
       that would otherwise reduce the editor to its padding width (~30px), making
       it appear full-width via the absolute ::before placeholder while being
       unclickable. max-width + margin:auto then re-apply the centred column.
       position:relative is required so that the ::before placeholder (position:absolute)
       anchors to this element rather than to .ql-container, which would misplace it
       in the left margin when the editor is narrower than its container. */
    height: auto !important;
    min-height: 100%;
    width: 100% !important;
    padding: 28px 24px 60px;
    max-width: 720px;
    margin: 0 auto;
    position: relative;
    caret-color: var(--ac);
}

.ql-editor p { margin-bottom: 0.6em; }

.ql-editor.ql-blank::before {
    color: var(--tx-6);
    font-style: italic;
    left: 24px;
}

/* ==========================================================================
   Sidebar quick-create buttons
   ========================================================================== */

/* Inline form wrapping the "+" scene button — transparent to flex layout */
.quick-create-form {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* "+" button that appears on chapter-row hover */
.quick-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 4px;
    color: var(--tx-4);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.1s, color 0.1s, background 0.1s;
}
.sidebar-chapter-row:hover .quick-add-btn,
.sidebar-chapter-row:focus-within .quick-add-btn {
    opacity: 1;
}
.quick-add-btn:hover {
    color: var(--ac);
    background: var(--bd);
}

/* "+" Chapter footer area */
.sidebar-quick-chapter {
    padding: 8px 12px 4px;
    border-top: 1px solid var(--bd);
    flex-shrink: 0;
}
.sidebar-trash-row {
    padding: 4px 12px 12px;
    flex-shrink: 0;
}
.sidebar-trash-link {
    font-size: 0.8125rem;
    color: var(--tx-4);
    text-decoration: none;
}
.sidebar-trash-link:hover { color: var(--ac); }

.quick-add-chapter-btn {
    display: block;
    width: 100%;
    padding: 6px 10px;
    background: none;
    border: 1px dashed var(--bd-mu);
    border-radius: 6px;
    color: var(--tx-3);
    font-size: 0.8125rem;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.quick-add-chapter-btn:hover {
    border-color: var(--ac);
    color: var(--ac);
    background: var(--ac-bg);
}

/* Snapshots panel — toggled via Snapshots button in secondary toolbar */
.snapshots-panel {
    flex-shrink: 0;
    border-top: 1px solid var(--bd);
    background: var(--bg);
}
.snapshots-list {
    max-height: 172px;
    overflow-y: auto;
    padding: 2px 0;
}
.snapshot-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 16px;
    font-size: 0.8rem;
}
.snapshot-row:hover { background: var(--hover); }
.snapshot-meta {
    flex: 1;
    color: var(--tx-3);
    display: flex;
    align-items: baseline;
    gap: 0;
    min-width: 0;
    overflow: hidden;
}
.snapshot-stamp {
    white-space: nowrap;
    flex-shrink: 0;
}
.snapshot-name {
    cursor: pointer;
    border-radius: 2px;
    padding: 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.snapshot-name:hover { background: var(--hover); text-decoration: underline; }
.snapshot-name--empty { color: var(--tx-4); font-style: italic; }
.snapshot-name-input {
    font-size: 0.8rem;
    font-family: inherit;
    border: 1px solid var(--bd);
    border-radius: 3px;
    padding: 1px 5px;
    background: var(--bg);
    color: var(--tx);
    width: 130px;
    outline: none;
    flex-shrink: 0;
}
.snapshots-empty {
    padding: 6px 16px;
    font-size: 0.8rem;
    color: var(--tx-4);
}

/* ==========================================================================
   Project Dashboard
   ========================================================================== */

.dashboard-content { max-width: 900px; }

/* Editable header */
.dash-header { margin-bottom: 28px; }

.dash-title {
    display: inline-block;
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 6px;
    margin-left: -4px;
    padding: 2px 6px;
    border-radius: 5px;
    cursor: pointer;
    line-height: 1.25;
}
.dash-title:hover { background: var(--hover); }

.dash-title-input {
    display: block;
    width: 100%;
    font-size: 1.75rem;
    font-weight: 700;
    font-family: inherit;
    line-height: 1.25;
    padding: 2px 6px;
    margin-bottom: 6px;
    border: 2px solid var(--ac);
    border-radius: 5px;
    background: var(--surface);
    color: var(--tx);
    outline: none;
    box-shadow: 0 0 0 3px var(--focus);
}

.dash-description {
    display: block;
    font-size: 0.9375rem;
    color: var(--tx-3);
    cursor: pointer;
    padding: 3px 6px;
    margin-left: -6px;
    border-radius: 5px;
    max-width: 680px;
}
.dash-description:hover { background: var(--hover); }
.dash-description--empty { color: var(--tx-5); font-style: italic; }

.dash-description-input {
    display: block;
    width: 100%;
    max-width: 680px;
    font-size: 0.9375rem;
    font-family: inherit;
    padding: 6px 10px;
    border: 1px solid var(--ac);
    border-radius: 6px;
    background: var(--surface);
    color: var(--tx);
    outline: none;
    resize: vertical;
    box-shadow: 0 0 0 3px var(--focus);
}

/* Goal card */
.dash-goal-card { margin-bottom: 24px; }
.dash-goal-card h2 { margin-bottom: 14px; }

.goal-progress-bar {
    height: 8px;
    background: var(--hover);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}
.goal-progress-fill {
    height: 100%;
    background: var(--ac);
    border-radius: 4px;
    transition: width 0.4s ease;
    min-width: 2px;
}
.goal-progress-text {
    font-size: 0.875rem;
    color: var(--tx-3);
    margin-bottom: 14px;
}
.goal-pct { color: var(--tx-4); }

.goal-empty-hint {
    font-size: 0.875rem;
    color: var(--tx-4);
    margin-bottom: 14px;
}
.goal-input-row { display: flex; align-items: center; gap: 8px; }
.goal-input {
    width: 140px;
    padding: 6px 10px;
    border: 1px solid var(--bd-in);
    border-radius: 6px;
    font-size: 0.9375rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--tx);
}
.goal-input:focus { outline: none; border-color: var(--ac); box-shadow: 0 0 0 3px var(--focus); }

/* Stats grid */
.dash-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.stat-tile {
    background: var(--surface);
    border: 1px solid var(--bd);
    border-radius: 8px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.stat-tile-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--tx-4);
}
.stat-tile-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--tx);
    line-height: 1.2;
}
.stat-tile-date { font-size: 1rem; }
.stat-tile-unit { font-size: 0.8125rem; font-weight: 400; color: var(--tx-4); margin-left: 1px; }
.stat-tile-detail {
    font-size: 0.75rem;
    color: var(--tx-4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* Recently edited */
.dash-recent { margin-bottom: 24px; }
.dash-recent h2 { margin-bottom: 4px; }
.recent-list { list-style: none; }

.recent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--bd);
}
.recent-item:first-child { padding-top: 12px; }
.recent-item:last-child  { border-bottom: none; padding-bottom: 0; }

.recent-item-main {
    display: flex;
    align-items: baseline;
    gap: 7px;
    min-width: 0;
    flex: 1;
}
.recent-item-type {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--tx-5);
    flex-shrink: 0;
}
.recent-item-name {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--tx);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.recent-item-name:hover { color: var(--ac); text-decoration: none; }
.recent-item-chapter {
    font-size: 0.8125rem;
    color: var(--tx-4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}
.recent-item-meta { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.recent-item-wc   { font-size: 0.8125rem; color: var(--tx-4); white-space: nowrap; }
.recent-item-date { font-size: 0.8125rem; color: var(--tx-5); white-space: nowrap; }

/* Actions section */
.dash-actions-section { margin-bottom: 32px; }
.dash-section-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--tx-4);
    margin-bottom: 10px;
}

/* ==========================================================================
   Split screen
   ========================================================================== */

/* Panes row: single column by default, row in split mode */
.editor-panes-row {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    flex-direction: column;
}

body.split-active .editor-panes-row {
    flex-direction: row;
}

/* Each pane is a flex column */
.editor-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

/* Right pane: hidden until split is active */
#pane-right {
    display: none;
    border-left: 1px solid var(--bd);
}

body.split-active #pane-right {
    display: flex;
}

/* Right pane header: title input + meta (word count / status) */
.pane-right-header {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 16px 24px 0;
    background: var(--surface);
    border-bottom: 1px solid var(--bd);
    flex-shrink: 0;
}

.pane-right-header .scene-title-input {
    flex: 1;
    min-width: 0;
}

.pane-right-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8125rem;
    color: var(--tx-4);
    flex-shrink: 0;
    padding-bottom: 10px;
    white-space: nowrap;
}

/* Right pane Quill container — same as #quill-editor */
#quill-editor-right {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--surface);
}

/* Empty state shown when no document loaded in right pane */
.split-empty-state {
    display: none;
    flex: 1;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--tx-4);
    font-size: 0.9375rem;
    padding: 48px;
}

#pane-right.pane-empty .split-empty-state {
    display: flex;
}

#pane-right.pane-empty #quill-editor-right {
    display: none;
}

/* Split toggle button: highlighted when active */
.split-toggle-btn.split-on {
    background: var(--ac-bg);
    border-color: var(--ac);
    color: var(--ac);
}

/* Swap button: hidden when split is off */
.split-swap-btn {
    display: none;
}

body.split-active .split-swap-btn {
    display: inline-flex;
}

/* ==========================================================================
   Mobile — sidebar as a slide-in overlay drawer
   ========================================================================== */
@media (max-width: 768px) {
    /* Sidebar leaves the document flow and becomes a fixed overlay.
       JS adds sidebar-collapsed on page load so it starts hidden.
       Toggling that class slides it in/out via transform. */
    .sidebar {
        position: fixed;
        top: 52px;
        left: 0;
        height: calc(100vh - 52px);
        width: 270px;
        min-width: 270px;
        z-index: 200;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.14);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        /* Override the desktop width-based collapse */
        overflow-y: auto;
        border-right-width: 1px;
    }

    /* Shown: class absent means open on mobile */
    body:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
    }

    /* Desktop collapsed-width rules don't apply on mobile */
    body.sidebar-collapsed .sidebar {
        width: 270px;
        min-width: 270px;
        overflow-y: auto;
        border-right-width: 1px;
    }

    /* Expand strip and padding offset don't apply on mobile */
    .sidebar-expand-strip,
    body.sidebar-collapsed .sidebar-expand-strip { display: none; }

    body.sidebar-collapsed .layout-split,
    body.sidebar-collapsed .editor-shell { padding-left: 0; }

    /* Show the nav hamburger on mobile */
    .sidebar-toggle-btn {
        display: block;
        background: none;
        border: none;
        cursor: pointer;
        font-size: 1.125rem;
        color: var(--tx-4);
        padding: 4px 10px 4px 0;
        line-height: 1;
        flex-shrink: 0;
        transition: color 0.12s;
    }
    .sidebar-toggle-btn:hover { color: var(--tx); }

    /* Tap-outside backdrop */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 52px 0 0 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 199;
        cursor: pointer;
    }

    body:not(.sidebar-collapsed) .sidebar-backdrop {
        display: block;
    }

    /* Tighten secondary toolbar on small screens */
    .editor-doc-toolbar {
        flex-wrap: wrap;
        gap: 4px;
    }

    .nav-breadcrumb {
        display: none; /* too cramped on mobile — sidebar provides nav context */
    }

    /* Split screen unavailable on mobile */
    .split-toggle-btn,
    .split-swap-btn {
        display: none !important;
    }
}

/* ==========================================================================
   Dark mode — flash messages
   ========================================================================== */
html.dark .flash-success { background: #1a3020; border-color: #2a5038; color: #6dbd8e; }
html.dark .flash-error   { background: #2d1a1a; border-color: #5a2828; color: #e08080; }
html.dark .flash-warning { background: #2d2510; border-color: #5a4820; color: #d4a830; }

/* ==========================================================================
   Dark mode — danger zone
   ========================================================================== */
html.dark .danger-zone             { border-color: #5a2828; }
html.dark .danger-zone summary     { color: #e08080; }
html.dark .danger-zone p           { color: #e08080; }

/* ==========================================================================
   Dark mode — save status error
   ========================================================================== */
html.dark .status-error            { color: #e08080; }
html.dark .btn-danger              { background: #a93226; border-color: #a93226; }
html.dark .btn-danger:hover        { background: #8e2a20; border-color: #8e2a20; }

/* ==========================================================================
   Dark mode — Quill editor toolbar icons
   ========================================================================== */
html.dark .ql-toolbar.ql-snow .ql-stroke                            { stroke: var(--tx-3); }
html.dark .ql-toolbar.ql-snow .ql-fill                              { fill:   var(--tx-3); }
html.dark .ql-toolbar.ql-snow .ql-picker-label                      { color:  var(--tx-3); }

html.dark .ql-toolbar.ql-snow button:hover .ql-stroke,
html.dark .ql-toolbar.ql-snow button.ql-active .ql-stroke           { stroke: var(--ac); }
html.dark .ql-toolbar.ql-snow button:hover .ql-fill,
html.dark .ql-toolbar.ql-snow button.ql-active .ql-fill             { fill:   var(--ac); }
html.dark .ql-toolbar.ql-snow .ql-picker-label:hover,
html.dark .ql-toolbar.ql-snow .ql-picker-label.ql-active            { color:  var(--ac); }

html.dark .ql-toolbar.ql-snow .ql-picker-options {
    background:   var(--surface);
    border-color: var(--bd);
}
html.dark .ql-toolbar.ql-snow .ql-picker-options .ql-picker-item         { color: var(--tx); }
html.dark .ql-toolbar.ql-snow .ql-picker-options .ql-picker-item:hover,
html.dark .ql-toolbar.ql-snow .ql-picker-options .ql-picker-item.ql-selected { color: var(--ac); }

html.dark .ql-editor { color: var(--tx); }

/* ==========================================================================
   Project type badge
   ========================================================================== */
.project-type-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 10px;
    border: 1px solid var(--bd);
    color: var(--tx-3);
    background: var(--surface);
    vertical-align: middle;
    line-height: 1.6;
}

.wiki-badge {
    color: #2a8a8a;
    background: #e6f7f7;
    border-color: #b2e0e0;
}

html.dark .wiki-badge {
    color: #5ecfcf;
    background: #0d2828;
    border-color: #1a4a4a;
}

/* ==========================================================================
   Wiki tree — sidebar nodes
   ========================================================================== */
.wiki-tree {
    list-style: none;
    padding: 0;
    margin: 0;
}

.wiki-node {
    list-style: none;
}

.wiki-node-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 4px;
    min-height: 30px;
    position: relative;
}

.wiki-node-row:hover {
    background: var(--sb-hover, rgba(0,0,0,0.05));
}

.wiki-node-row.active {
    background: var(--ac-soft, rgba(45,106,79,0.12));
}

html.dark .wiki-node-row:hover     { background: rgba(255,255,255,0.06); }
html.dark .wiki-node-row.active    { background: rgba(78,168,118,0.15); }

.wiki-node-title {
    flex: 1;
    font-size: 0.875rem;
    color: var(--tx-2);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.wiki-node-title:hover { color: var(--tx); }
.wiki-node-row.active .wiki-node-title { color: var(--ac); font-weight: 500; }

.wiki-node-children {
    list-style: none;
    padding-left: 1rem;
    margin: 0;
}

/* Collapse button */
.wiki-collapse-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--tx-4, #aaa);
    font-size: 0.6rem;
    padding: 0 2px;
    line-height: 1;
    transition: transform 0.15s;
    width: 14px;
    text-align: center;
}

.wiki-collapse-btn[hidden] { visibility: hidden; }

.wiki-collapsed > .wiki-node-row > .wiki-collapse-btn {
    transform: rotate(-90deg);
}

/* Add-child and delete buttons — hidden until row hovered */
.wiki-add-child-btn,
.wiki-delete-btn {
    flex-shrink: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    color: var(--tx-4, #aaa);
    font-size: 0.85rem;
    padding: 0 4px;
    line-height: 1.4;
    opacity: 0;
    transition: opacity 0.1s, color 0.1s;
}

.wiki-node-row:hover .wiki-add-child-btn,
.wiki-node-row:hover .wiki-delete-btn {
    opacity: 1;
}

.wiki-add-child-btn:hover { color: var(--ac); }
.wiki-delete-btn:hover    { color: #c0392b; }

/* Inline rename input */
.wiki-rename-input {
    font-size: 0.875rem;
    width: 100%;
    border: 1px solid var(--ac);
    border-radius: 3px;
    padding: 1px 4px;
    background: var(--surface);
    color: var(--tx);
    outline: none;
}

/* ==========================================================================
   Wiki hub — root page cards
   ========================================================================== */
.wiki-root-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 1rem;
}

.wiki-root-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--tx);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.wiki-root-card:hover {
    border-color: var(--ac);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.wiki-root-card-title {
    font-weight: 500;
    font-size: 0.95rem;
}

.wiki-root-card-meta {
    font-size: 0.78rem;
    color: var(--tx-3);
}

/* ==========================================================================
   Wiki tree — drag-and-drop
   ========================================================================== */

/* Grip handle — shown on row hover */
.wiki-drag-handle {
    flex-shrink: 0;
    cursor: grab;
    color: var(--tx-4, #aaa);
    font-size: 0.8rem;
    line-height: 1;
    padding: 0 1px;
    opacity: 0;
    transition: opacity 0.1s;
    user-select: none;
    /* Keep handle in layout so the row doesn't reflow on hover */
    width: 12px;
    text-align: center;
}

.wiki-node-row:hover .wiki-drag-handle {
    opacity: 1;
}

.wiki-drag-handle:active {
    cursor: grabbing;
}

/* The node being dragged: semi-transparent so the ghost stands apart */
.wiki-node-dragging {
    opacity: 0.35;
}

/* Drop indicator: horizontal coloured line that appears between siblings */
.wiki-drop-indicator {
    list-style: none;
    height: 2px;
    margin: 0 8px;
    background: var(--ac);
    border-radius: 2px;
    pointer-events: none;
    position: relative;
}

/* Small circle at the left end — matches common tree-editor convention */
.wiki-drop-indicator::before {
    content: '';
    position: absolute;
    left: -4px;
    top: -3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ac);
}

/* Nest-target highlight: teal outline + tinted background on the row */
.wiki-node-row.drop-target-nest {
    background: rgba(45, 106, 79, 0.18) !important;
    outline: 2px solid var(--ac);
    outline-offset: -2px;
    border-radius: 4px;
}

html.dark .wiki-node-row.drop-target-nest {
    background: rgba(78, 168, 118, 0.2) !important;
}

/* ==========================================================================
   Wiki page linking — toolbar button
   ========================================================================== */
button.ql-wiki-link {
    width: auto !important;
    padding: 2px 6px !important;
    font-size: 10px !important;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--tx-2);
    line-height: 1.5;
}

button.ql-wiki-link:hover { color: var(--ac); }

html.dark button.ql-wiki-link { color: var(--tx-3); }
html.dark button.ql-wiki-link:hover { color: var(--ac); }

/* Wiki links inside the editor get a distinct visual treatment */
.ql-editor a[href*="/wiki-pages/"] {
    color: var(--ac);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
    cursor: pointer;
}

.ql-editor a[href*="/wiki-pages/"]:hover {
    text-decoration-style: solid;
}

/* ==========================================================================
   Wiki page linking — page picker modal
   ========================================================================== */
.wiki-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 14vh;
}

.wiki-picker-overlay.hidden { display: none; }

.wiki-picker-modal {
    background: var(--surface);
    border: 1px solid var(--bd);
    border-radius: 10px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.22);
    width: 420px;
    max-width: calc(100vw - 32px);
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.wiki-picker-search {
    padding: 12px 14px;
    border-bottom: 1px solid var(--bd);
    flex-shrink: 0;
}

.wiki-picker-input {
    width: 100%;
    border: 1px solid var(--bd-in);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--tx);
    outline: none;
    transition: border-color 0.15s;
}

.wiki-picker-input:focus { border-color: var(--ac); }

.wiki-picker-list {
    overflow-y: auto;
    flex: 1;
    padding: 6px;
    margin: 0;
    list-style: none;
}

.wiki-picker-item {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--tx-2);
    transition: background 0.1s, color 0.1s;
}

.wiki-picker-item:hover {
    background: var(--hover);
    color: var(--tx);
}

.wiki-picker-item.active {
    background: var(--ac-bg);
    color: var(--ac);
}

.wiki-picker-empty {
    padding: 16px;
    text-align: center;
    color: var(--tx-4);
    font-size: 0.875rem;
}

/* ==========================================================================
   Wiki page linking — @mention dropdown
   ========================================================================== */
.wiki-mention-dropdown {
    position: fixed;
    z-index: 1010;
    background: var(--surface);
    border: 1px solid var(--bd);
    border-radius: 8px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
    width: 280px;
    max-height: 240px;
    overflow-y: auto;
    padding: 4px;
}

.wiki-mention-dropdown.hidden { display: none; }

.wiki-mention-item {
    padding: 7px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--tx-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.1s, color 0.1s;
}

.wiki-mention-item:hover {
    background: var(--hover);
    color: var(--tx);
}

.wiki-mention-item.active {
    background: var(--ac-bg);
    color: var(--ac);
}

/* ==========================================================================
   Wiki page linking — hover preview card
   ========================================================================== */
.wiki-link-preview {
    position: fixed;
    z-index: 1020;
    background: var(--surface);
    border: 1px solid var(--bd);
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.16);
    padding: 12px 14px;
    width: 280px;
    pointer-events: auto;
    line-height: 1.5;
}

.wiki-link-preview.hidden { display: none; }

.wiki-preview-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--tx);
    margin-bottom: 5px;
}

.wiki-preview-excerpt {
    color: var(--tx-3);
    font-size: 0.8125rem;
    margin-bottom: 10px;
    /* Clamp to 3 lines */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.wiki-preview-goto {
    display: inline-block;
    color: var(--ac);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
}

.wiki-preview-goto:hover { text-decoration: underline; }

.wiki-preview-loading {
    color: var(--tx-4);
    font-style: italic;
    font-size: 0.875rem;
}

/* ==========================================================================
   Nav badge (new changelog indicator)
   ========================================================================== */
.changelog-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.nav-badge {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ac);
    flex-shrink: 0;
}

/* ==========================================================================
   Changelog page
   ========================================================================== */
.changelog-list {
    max-width: 680px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.changelog-entry {
    padding: 18px 0;
    border-bottom: 1px solid var(--bd);
}

.changelog-entry:last-child { border-bottom: none; }

.changelog-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.changelog-date {
    font-size: 0.8125rem;
    color: var(--tx-4);
    flex-shrink: 0;
}

.changelog-version {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--tx-3);
    flex-shrink: 0;
}

.changelog-cat {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.changelog-cat-feature     { background: var(--ac-bg);  color: var(--ac); }
.changelog-cat-fix         { background: #fde8e8;        color: #c0392b;   }
.changelog-cat-improvement { background: #e8f0ff;        color: #2563eb;   }

html.dark .changelog-cat-fix         { background: #2d1a1a; color: #e08080; }
html.dark .changelog-cat-improvement { background: #1a2040; color: #7aa2f7; }

.changelog-desc {
    font-size: 0.9375rem;
    color: var(--tx-2);
    line-height: 1.6;
    margin: 0;
}

/* ============================================================
   Admin panel
   ============================================================ */

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.admin-table th,
.admin-table td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--br);
    white-space: nowrap;
}
.admin-table th {
    font-weight: 600;
    color: var(--tx-2);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--bg-2); }

.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-yes   { background: #d4edda; color: #155724; }
.badge-no    { background: #f8d7da; color: #721c24; }
.badge-admin { background: var(--ac-bg); color: var(--ac); }

html.dark .badge-yes   { background: #1a3a22; color: #6fcf97; }
html.dark .badge-no    { background: #3a1a1a; color: #e08080; }
html.dark .badge-admin { background: var(--ac-bg); color: var(--ac); }

.admin-dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 16px;
    margin: 0;
}
.admin-dl dt {
    font-weight: 600;
    color: var(--tx-2);
    font-size: 0.85rem;
}
.admin-dl dd { margin: 0; }

.card-danger {
    border-color: #c0392b;
}
html.dark .card-danger { border-color: #a93226; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
}
.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}
