/* --- Theme tokens --- */
:root {
    --bg: #f5f5f7;
    --surface: #fff;
    --surface-soft: #fafbfc;
    --surface-hover: #f0f4f8;
    --text: #222;
    --text-muted: #6a737d;
    --text-faded: #98a1aa;
    --accent: #2a6;
    --accent-strong: #185fa5;
    --accent-soft: #e6f1fb;
    --warning-bg: #fff8e1;
    --warning-text: #8a5a00;
    --error: #c83030;
    --border: #e5e5e7;
    --border-strong: #c8ccd0;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.06);
    --highlight-bg: #fff3a8;
    color-scheme: light;
}

/* Dark theme: same token names, different values. Toggled by setting
   `data-theme="dark"` on <html> from the settings popover. Only the
   token values change here — every component that already reads from
   var(--surface), var(--text), etc. flips automatically. */
:root[data-theme="dark"] {
    --bg: #1a1c1f;
    --surface: #24272b;
    --surface-soft: #2b2f33;
    --surface-hover: #303439;
    --text: #e6e7ea;
    --text-muted: #a0a6ae;
    --text-faded: #6e7680;
    --accent: #3e9;
    --accent-strong: #6cb6ff;
    --accent-soft: #1e3a52;
    --warning-bg: #3a3015;
    --warning-text: #f3c66b;
    --error: #ff7e7e;
    --border: #383c41;
    --border-strong: #4a4f56;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    --highlight-bg: #6e5a17;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

/* --- Topbar --- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .brand {
    font-size: 20px;
    font-weight: 600;
    color: var(--accent-strong);
    letter-spacing: .5px;
    margin-bottom: 8px;
}
.search-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.search-row input[type=text] {
    flex: 1;
    min-width: 220px;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}
.search-row input[type=text]:focus {
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 3px rgba(24, 95, 165, .15);
}
.search-row button {
    padding: 9px 16px;
    background: var(--accent-strong);
    color: #fff;
    border: 1px solid var(--accent-strong);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}
.search-row button:hover { filter: brightness(1.06); }
.search-row button.secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}
.search-row button.secondary:hover { background: var(--surface-hover); }

.count-pill {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
}

/* --- Sources panel --- */
.sources-panel {
    margin-top: 10px;
    padding: 12px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.sources-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.sources-actions button {
    padding: 4px 10px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
.sources-actions button:hover { background: var(--surface-hover); }
.sources-actions .muted { font-size: 12px; color: var(--text-muted); margin-left: auto; }
.sources-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 4px 12px;
}
.source-item label {
    display: flex;
    gap: 6px;
    align-items: center;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
}
.source-item label:hover { background: var(--surface-hover); }
.source-label { flex: 1; }
.source-kind {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--text-muted);
}
.source-kind.kind-thesaurus { background: #e6f1fb; color: #185fa5; }
.source-kind.kind-citations { background: #f3eefb; color: #533ab7; }
.source-kind.kind-list      { background: #e1f5ee; color: #0f6e56; }
.source-count { font-size: 11px; }

/* --- Content area --- */
.content {
    flex: 1;
    display: flex;
    gap: 16px;
    padding: 16px;
    align-items: flex-start;
}
.results-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.content-resize-handle {
    /* Vertical splitter sitting between the results and detail columns.
       JS owns whether it's hidden — visible whenever the detail panel
       is open. */
    flex: 0 0 6px;
    align-self: stretch;
    cursor: col-resize;
    background: transparent;
    position: relative;
    transition: background 80ms;
}
.content-resize-handle::before {
    /* Three short bars to read as a grip handle, rotated for vertical. */
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 28px;
    transform: translate(-50%, -50%);
    background:
        linear-gradient(var(--border-strong), var(--border-strong)) top    / 2px 8px no-repeat,
        linear-gradient(var(--border-strong), var(--border-strong)) center / 2px 8px no-repeat,
        linear-gradient(var(--border-strong), var(--border-strong)) bottom / 2px 8px no-repeat;
}
.content-resize-handle:hover,
.content-resize-handle:focus,
.content-resize-handle.dragging {
    background: var(--accent-soft);
    outline: none;
}
.content-resize-handle:hover::before,
.content-resize-handle.dragging::before {
    background:
        linear-gradient(var(--accent-strong), var(--accent-strong)) top    / 2px 8px no-repeat,
        linear-gradient(var(--accent-strong), var(--accent-strong)) center / 2px 8px no-repeat,
        linear-gradient(var(--accent-strong), var(--accent-strong)) bottom / 2px 8px no-repeat;
}
.detail-col {
    width: 360px;
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 110px;
    max-height: calc(100vh - 130px);
    overflow-y: auto;
}
/* Both action buttons sit in the top-right of the detail panel side
   by side: heart (toggle into selection) on the left, close (×) on
   the right. Absolute positioning anchored to the sticky detail-col
   keeps them stable regardless of the title's wrapping. */
.detail-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    color: var(--text-muted);
}
.detail-close:hover { background: var(--surface-hover); color: var(--text); }
/* Dubbele class so this rule beats the generic `.heart-btn` selector
   that lives further down in the file — both have single-class
   specificity and source order would otherwise let the search-result
   one win and park the heart on top of the close button. */
.heart-btn.detail-heart {
    position: absolute;
    top: 6px;
    right: 50px;          /* close ~32px wide + 8px gap to its left edge */
    z-index: 2;
    margin: 0;
    width: 32px;
    height: 32px;
    font-size: 20px;
    line-height: 1;
}
.detail-title {
    margin: 0 0 8px;
    font-size: 17px;
    font-weight: 500;
    line-height: 1.3;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    /* room for both buttons (heart + close) parked top-right. */
    padding-right: 96px;
}
.detail-body-text {
    margin: 0 0 12px;
    line-height: 1.55;
}
.detail-citations {
    list-style: none;
    margin: 4px 0 12px;
    padding: 0;
    font-size: 13px;
}
.detail-citations li {
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}
.detail-citations li:last-child { border-bottom: 0; }
.detail-relations {
    margin: 4px 0 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.relation-group { font-size: 13px; }
.relation-group-title {
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.relation-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.relation-list li { padding: 3px 0; }
.relation-list li:not(:last-child) { border-bottom: 1px dotted var(--border); }
.related-term { color: var(--accent); text-decoration: none; }
.related-term:hover { text-decoration: underline; }
.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.detail-table th, .detail-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.detail-table th {
    width: 35%;
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Source result blocks --- */
.source-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.source-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    background: var(--surface-soft);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.source-title { font-weight: 500; }
.source-badge {
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 11px;
}
.source-block.kind-thesaurus .source-badge { background: #e6f1fb; color: #185fa5; }
.source-block.kind-citations .source-badge { background: #f3eefb; color: #533ab7; }
.source-block.kind-list      .source-badge { background: #e1f5ee; color: #0f6e56; }
.source-cap-hint {
    margin-left: auto;
    font-size: 11px;
}
.block-toggle {
    margin-left: auto;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1;
    padding: 2px 7px;
}
.block-toggle:hover { background: var(--accent-soft); border-color: var(--border-strong); color: var(--accent-strong); }
/* When the cap-hint is present, push the toggle past it instead of
   stacking both at margin-left: auto. */
.source-cap-hint + .block-toggle { margin-left: 8px; }
.source-block.collapsed { /* header-only height; result-list and handle are hidden inline */ }
.source-block.collapsed .source-header {
    /* No bottom border when there's nothing under the header. */
    border-bottom: 0;
}

.result-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    /* max-height comes from inline style — JS owns the value so it can
       persist a per-block override across reloads. */
}
.result-list::-webkit-scrollbar { width: 8px; }
.result-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}
.result-list::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.block-resize-handle {
    height: 10px;
    cursor: ns-resize;
    border-top: 1px solid var(--border);
    background: var(--surface-soft);
    position: relative;
    transition: background 80ms;
}
.block-resize-handle::before {
    /* Three short bars to read as a grip handle. */
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 2px;
    transform: translate(-50%, -50%);
    background:
        linear-gradient(var(--border-strong), var(--border-strong)) left  / 8px 2px no-repeat,
        linear-gradient(var(--border-strong), var(--border-strong)) center/ 8px 2px no-repeat,
        linear-gradient(var(--border-strong), var(--border-strong)) right / 8px 2px no-repeat;
}
.block-resize-handle:hover,
.block-resize-handle:focus,
.block-resize-handle.dragging {
    background: var(--accent-soft);
    outline: none;
}
.block-resize-handle.dragging::before,
.block-resize-handle:hover::before {
    background:
        linear-gradient(var(--accent-strong), var(--accent-strong)) left  / 8px 2px no-repeat,
        linear-gradient(var(--accent-strong), var(--accent-strong)) center/ 8px 2px no-repeat,
        linear-gradient(var(--accent-strong), var(--accent-strong)) right / 8px 2px no-repeat;
}
.result-item {
    border-bottom: 1px solid var(--border);
}
.result-item:last-child { border-bottom: 0; }
.result-link {
    display: block;
    padding: 9px 14px;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}
.result-link:hover { background: var(--surface-hover); }
.result-title {
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.result-subtitle {
    font-size: 12.5px;
    color: var(--text);
    line-height: 1.4;
    margin-bottom: 2px;
}
.result-snippet {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}
.result-snippet mark {
    background: var(--highlight-bg);
    color: var(--text);
    padding: 0 1px;
    border-radius: 2px;
}
.lang-tag {
    font-size: 10px;
    text-transform: uppercase;
    background: var(--surface-soft);
    color: var(--text-muted);
    padding: 1px 6px;
    border-radius: 999px;
}

/* --- Rich-content rendering --- */
.rich-content { line-height: 1.55; }
.rich-content p:first-child { margin-top: 0; }
.rich-content p:last-child { margin-bottom: 0; }
.rich-content ul, .rich-content ol { margin: 6px 0 8px 22px; padding: 0; }
.rich-content li { margin: 2px 0; }
.rich-content blockquote {
    margin: 6px 0;
    padding: 4px 12px;
    border-left: 3px solid var(--border-strong);
    color: var(--text-muted);
}
.rich-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 6px 0;
}
.rich-content a { color: var(--accent-strong); }
.rich-content cite.cite-link {
    cursor: help;
    color: var(--accent-strong);
    text-decoration: underline dotted;
    text-underline-offset: 2px;
    font-style: normal;
}
.rich-content cite.cite-orphan {
    color: var(--text-muted);
    text-decoration: line-through;
    font-style: normal;
}
.cite-tooltip {
    position: absolute;
    z-index: 100;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 8px 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    font-size: 13px;
    pointer-events: none;
}
.cite-tooltip[hidden] { display: none; }
.cite-tooltip-title { font-weight: 600; margin-bottom: 4px; }
.cite-tooltip-body { color: var(--text-muted); }
@media (prefers-reduced-motion: no-preference) {
    .cite-tooltip { transition: opacity 80ms; }
}

/* --- Tabs bar (search tabs + collections tab) --- */
.tabs-bar {
    display: flex;
    align-items: stretch;
    gap: 0;
    padding: 0 14px;
    background: var(--surface-soft, #fafafa);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
}
.tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
    background: transparent;
    border-top: 0;
    border-left: 0;
    border-right: 0;
    margin: 0;
}
.tab.active {
    color: var(--accent-strong);
    border-bottom-color: var(--accent-strong);
    background: var(--surface);
}
.tab .close-tab {
    margin-left: 4px;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 3px;
}
.tab .close-tab:hover { color: #d04a4a; background: rgba(0,0,0,0.04); }
.tab-newtab {
    color: var(--accent-strong);
    font-weight: 500;
}
.tab-collections {
    margin-left: auto;
    border-left: 1px solid var(--border);
}
.tab-collections .heart-icon { font-size: 14px; color: #d04a4a; }
.tab-collections .count-pill {
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 11px;
    margin-left: 2px;
}

/* --- Collections view (full-width, with sub-tabs per collection) --- */
.coll-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft, #fafafa);
    overflow-x: auto;
    margin: 0 0 12px;
    border-radius: 8px 8px 0 0;
    flex-shrink: 0;
}
.coll-tab {
    padding: 8px 14px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border-top: 0;
    border-left: 0;
    border-right: 0;
}
.coll-tab.active {
    color: var(--accent-strong);
    border-bottom-color: var(--accent-strong);
    background: var(--surface);
}
.coll-tab:hover { background: rgba(0,0,0,0.03); }
.coll-tab .coll-close {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1;
}
.coll-tab .coll-close:hover { color: #d04a4a; }
.coll-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}
.coll-actions button {
    padding: 4px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface);
    cursor: pointer;
    font-size: 12px;
}
.coll-actions button:hover { background: var(--accent-soft); }
.coll-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--text-muted);
}
.coll-empty .icon { font-size: 36px; opacity: 0.3; margin-bottom: 8px; }

/* Collection-level metadata: rich-text description shown above the
   action row. */
.coll-meta { margin-bottom: 10px; }

/* Generic rich-text editor (used by collection description + per-item
   notes). Toolbar above a contenteditable area; minimal toolbar with
   inline formatting + lists only. */
.rt-editor {
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    overflow: hidden;
}
.rt-editor:focus-within {
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 2px var(--accent-soft);
}
.rt-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 3px 6px;
    background: var(--surface-soft, #fafafa);
    border-bottom: 1px solid var(--border);
}
.rt-toolbar button {
    padding: 1px 7px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}
.rt-toolbar button:hover {
    background: var(--accent-soft);
    border-color: var(--border-strong);
    color: var(--accent-strong);
}
.rt-sep {
    display: inline-block;
    width: 1px;
    background: var(--border-strong);
    margin: 2px 4px;
}
.rt-area {
    min-height: 2.6em;
    padding: 6px 10px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    outline: none;
}
.rt-area p:first-child { margin-top: 0; }
.rt-area p:last-child  { margin-bottom: 0; }
.rt-area ul, .rt-area ol { margin: 4px 0 4px 22px; padding: 0; }
.rt-area li { margin: 2px 0; }
/* Placeholder via data-attribute, only when the editor is empty. */
.rt-area:empty::before,
.rt-area > p:only-child:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    font-style: italic;
    pointer-events: none;
}
/* Compact variant for inline notes — shorter min-height, smaller font. */
.rt-editor.rt-compact .rt-area {
    min-height: 1.6em;
    font-size: 12px;
    padding: 4px 8px;
}
.rt-editor.rt-compact .rt-toolbar { padding: 2px 4px; }
.rt-editor.rt-compact .rt-toolbar button { font-size: 11px; padding: 0 5px; }

.coll-export-group {
    margin-left: auto;
    display: inline-flex;
    gap: 6px;
}
.coll-export-group button {
    padding: 4px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface);
    cursor: pointer;
    font-size: 12px;
}
.coll-export-group button:hover { background: var(--accent-soft); color: var(--accent-strong); }

/* Drag-grip + drag-drop visual feedback for collection items. */
.coll-item {
    position: relative;
}
.coll-item .drag-grip {
    position: absolute;
    top: 8px;
    left: 4px;
    width: 18px;
    text-align: center;
    color: var(--text-muted);
    cursor: grab;
    user-select: none;
    line-height: 1;
    letter-spacing: -2px;
    font-size: 14px;
}
.coll-item .drag-grip:hover { color: var(--accent-strong); }
.coll-item.dragging { opacity: 0.45; }
.coll-item.drop-target {
    box-shadow: inset 0 2px 0 var(--accent-strong);
}
.coll-item .result-link { padding-left: 26px; padding-right: 40px; }

/* Note editor sits below the title; uses the rich-text widget but with
   a dashed border so it's visibly secondary to the description. */
.result-item .coll-note {
    margin: 0 14px 8px 26px;
    border-style: dashed;
}
.result-item .coll-note:focus-within {
    border-style: solid;
}

/* "+ add note / + add description" placeholder buttons — shown when
   the corresponding field is empty. Click swaps the button for a live
   editor with focus. */
.add-note-btn,
.add-desc-btn {
    display: inline-block;
    background: transparent;
    border: 1px dashed transparent;
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 10px;
    margin: 0;
    text-align: left;
}
.add-note-btn:hover,
.add-desc-btn:hover {
    color: var(--accent-strong);
    border-color: var(--border-strong);
    background: var(--accent-soft);
}
.add-note-btn { margin: 0 14px 8px 26px; }
.add-desc-btn { font-style: italic; }

/* --- Heart button + selection bar + collections --- */
.result-item { position: relative; }
.heart-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
}
.heart-btn:hover { background: var(--accent-soft); border-color: var(--border-strong); color: var(--accent-strong); }
.heart-btn.active { color: #d04a4a; }
.heart-btn.active:hover { color: #d04a4a; background: #fde7e7; border-color: #f5b5b5; }
.result-item .result-link { padding-right: 40px; display: block; }

.selection-bar {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.12);
    z-index: 90;
    font-size: 13px;
}
.selection-bar .selection-count { font-weight: 600; }
.selection-bar button {
    padding: 6px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface);
    cursor: pointer;
    font-size: 13px;
}
.selection-bar button.primary {
    background: var(--accent-strong);
    color: #fff;
    border-color: var(--accent-strong);
}
.selection-bar button:hover { filter: brightness(0.97); }

.save-collection-dialog {
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 0;
    max-width: 420px;
    width: 90vw;
}
.save-collection-dialog::backdrop { background: rgba(0,0,0,0.4); }
.save-collection-dialog .dialog-form { padding: 16px 18px; }
.save-collection-dialog h3 { margin: 0 0 10px; font-size: 15px; }
.save-collection-dialog input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    font-size: 14px;
}
.dialog-existing { list-style: none; margin: 0 0 6px; padding: 0; max-height: 160px; overflow-y: auto; }
.dialog-existing li { margin: 0; }
.dialog-existing button {
    width: 100%;
    text-align: left;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
.dialog-existing button:hover { background: var(--accent-soft); border-color: var(--border-strong); }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.dialog-buttons button {
    padding: 6px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface);
    cursor: pointer;
    font-size: 13px;
}
.dialog-buttons button.primary { background: var(--accent-strong); color: #fff; border-color: var(--accent-strong); }
.dialog-buttons button:hover { filter: brightness(0.97); }

.collections-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 360px;
    max-width: 95vw;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border-strong);
    box-shadow: -8px 0 24px rgba(0,0,0,0.08);
    z-index: 95;
    display: flex;
    flex-direction: column;
}
.collections-panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.collections-panel-header h3 { margin: 0; font-size: 15px; }
.collections-panel-header button {
    background: transparent;
    border: 0;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
}
.collections-panel-body { padding: 12px 16px; overflow-y: auto; flex: 1; }
.collection-section { margin-bottom: 18px; }
.collection-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.collection-name { margin: 0; font-size: 13px; font-weight: 600; }
.collection-actions button {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
}
.collection-actions button:hover { background: var(--accent-soft); border-color: var(--border-strong); }
.collection-items { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.collection-items li {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    border-bottom: 1px dotted var(--border);
}
.collection-items li:last-child { border-bottom: 0; }
.collection-items a { flex: 1; color: var(--accent-strong); text-decoration: none; }
.collection-items a:hover { text-decoration: underline; }
.collection-items .remove-item {
    background: transparent;
    border: 0;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
    font-size: 14px;
}
.collection-items .remove-item:hover { color: #d04a4a; }

/* --- Result-list score bar + query-highlight --- */
.score-bar {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    vertical-align: middle;
    cursor: help;
}
.score-track {
    display: inline-block;
    width: 60px;
    height: 8px;
    background: #e5e5e5;
    border-radius: 4px;
    overflow: hidden;
}
.score-fill {
    display: block;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(90deg, #93c5fd, var(--accent-strong));
}
mark {
    background: var(--highlight-bg);
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}
.result-extract {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px dotted var(--border);
}

/* --- Help overlay --- */
.help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.help-reader {
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 760px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.help-reader-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.help-reader-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
}
.help-reader-header .detail-close {
    position: static;       /* override the absolute placement used in the side panel */
    top: auto;
    right: auto;
}
.help-reader-body {
    overflow-y: auto;
    padding: 18px 24px;
    font-size: 13.5px;
    line-height: 1.65;
    color: var(--text);
}
.help-reader-body h2 {
    font-size: 15px;
    margin: 18px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
    color: var(--accent-strong);
}
.help-reader-body h2:first-child { margin-top: 0; }
.help-reader-body h3 {
    font-size: 13px;
    margin: 12px 0 4px;
    color: var(--text);
}
.help-reader-body p { margin: 0 0 8px; }
.help-reader-body ul { margin: 0 0 10px 20px; padding: 0; }
.help-reader-body li { margin: 0 0 4px; }
.help-reader-body code {
    background: var(--surface-soft);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}
.help-reader-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 6px 0 12px;
}
.help-reader-body th {
    text-align: left;
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px 10px;
    border-bottom: 2px solid var(--border);
}
.help-reader-body td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: top;
}
.help-reader-body .kbd {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border-strong);
    border-radius: 3px;
    background: var(--surface-soft);
    font-size: 11px;
    font-family: monospace;
}

/* --- Settings popover (gear icon) --- */
.icon-btn {
    width: 36px;
    padding: 6px 0;
    text-align: center;
    font-size: 16px;
    line-height: 1;
}
.settings-panel {
    position: absolute;
    top: calc(100% + 4px);
    right: 16px;
    z-index: 70;
    min-width: 240px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
    padding: 10px 12px;
    color: var(--text);
}
.settings-panel[hidden] { display: none; }
.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 2px;
    border-bottom: 1px dotted var(--border);
}
.settings-row:last-child { border-bottom: 0; }
.settings-label {
    flex: 1;
    font-size: 13px;
    color: var(--text);
}
.settings-row select {
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
}
.settings-row input[type="checkbox"] { transform: scale(1.1); }

/* --- Thesaurus cross-source highlighter --- */
.thesaurus-hit {
    color: var(--accent-strong);
    background: var(--accent-soft);
    padding: 0 2px;
    border-radius: 3px;
    text-decoration: none;
    cursor: pointer;
    border-bottom: 1px dotted var(--accent-strong);
}
.thesaurus-hit:hover { background: var(--accent-soft); filter: brightness(0.97); }
.thesaurus-popup {
    position: absolute;
    z-index: 110;
    max-width: 320px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 10px 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.14);
    font-size: 13px;
}
.thesaurus-popup[hidden] { display: none; }
.thesaurus-popup-title {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.thesaurus-popup-desc { color: var(--text-muted); margin-bottom: 6px; }
.thesaurus-popup-hint { color: var(--text-muted); font-size: 11px; font-style: italic; }
.thesaurus-popup-loading { color: var(--text-muted); font-size: 12px; }

/* --- Generic helpers --- */
.muted { color: var(--text-muted); }
.empty { color: var(--text-muted); padding: 12px 16px; }
.loading { color: var(--text-muted); padding: 12px 16px; }
.error { color: var(--error); padding: 12px 16px; }

@media (max-width: 720px) {
    .content { flex-direction: column; }
    .detail-col { position: static; width: 100%; max-height: none; }
}
