/* Status, tags, relations, images, multi-select, folder tree, structured facts editor, partial apply,
   version comparison and the read-only share view. */

:root {
  --st-idea: #9a86e0;
  --st-draft: #e0a24a;
  --st-review: #5a89b8;
  --st-canon: #6fbf73;
  --st-deprecated: #a24444;
}
html[data-theme="light"] {
  --st-idea: #5a46b3; --st-draft: #9a6a12; --st-review: #2f5f94; --st-canon: #2f7d3a; --st-deprecated: #a02f2f;
}

/* ---------- status + tags ---------- */
.status-chip {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  padding: 2px 7px; border-radius: 10px; margin-left: 6px; vertical-align: 2px;
  border: 1px solid currentColor; background: transparent;
}
.status-idea { color: var(--st-idea); } .status-draft { color: var(--st-draft); }
.status-review { color: var(--st-review); } .status-canon { color: var(--st-canon); } .status-deprecated { color: var(--st-deprecated); }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0 2px; }
.detail-meta .status-chip { margin-left: 0; font-size: 11px; padding: 3px 9px; }
.tag-pill {
  font: inherit; font-size: 12px; color: var(--text-dim); background: var(--bg-raised);
  border: 1px solid var(--border); border-radius: 12px; padding: 2px 10px; cursor: pointer;
}
.tag-pill:hover { color: var(--accent-bright); border-color: var(--accent); }
.status-banner { border-left: 3px solid currentColor; padding: 8px 12px; margin: 10px 0; border-radius: 4px; background: var(--bg-raised); font-size: 13px; }
.breadcrumb { font-size: 12px; color: var(--text-faint); margin: 0 0 4px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.crumb { cursor: pointer; color: var(--link); } .crumb:hover { text-decoration: underline; }
.crumb-sep { color: var(--text-faint); }

/* ---------- wiki links ---------- */
.wiki-link { border-bottom-style: solid; }
.wiki-missing { color: var(--bad); border-bottom: 1px dashed var(--bad); cursor: help; }
.wiki-missing:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); }

/* ---------- images in an article ---------- */
.detail-cover { float: right; margin: 4px 0 14px 20px; max-width: min(300px, 44%); }
.detail-cover img { display: block; width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-raised); }
.detail-cover figcaption, .article-figure figcaption { font-size: 12px; color: var(--text-faint); margin-top: 4px; text-align: center; }
.figure-btn { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; width: 100%; }
.article-figure { margin: 14px auto; max-width: 560px; }
.article-figure img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 8px; border: 1px solid var(--border); }
.detail-gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.gallery-thumb { padding: 0; border: 1px solid var(--border); background: var(--bg-raised); border-radius: 6px; cursor: zoom-in; overflow: hidden; width: 128px; height: 96px; }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-description, .detail-header { clear: none; }
.detail-content::after { content: ""; display: block; clear: both; }

.lightbox {
  position: fixed; inset: 0; z-index: 120; background: rgba(6, 4, 3, .92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px;
}
.lightbox-img { max-width: 94vw; max-height: 80vh; object-fit: contain; border-radius: 6px; box-shadow: 0 10px 50px #000; }
.lightbox-caption { color: #e8e0d0; font-size: 14px; text-align: center; max-width: 80ch; }
.lightbox-count { color: #a89a82; font-size: 12px; }
.lightbox-nav, .lightbox-close {
  position: absolute; background: rgba(0, 0, 0, .45); color: #fff; border: 1px solid #ffffff44; border-radius: 50%;
  width: 44px; height: 44px; font-size: 26px; line-height: 1; cursor: pointer;
}
.lightbox-prev { left: 16px; top: 50%; } .lightbox-next { right: 16px; top: 50%; } .lightbox-close { right: 16px; top: 16px; }
.lightbox-nav:hover, .lightbox-close:hover { background: rgba(255, 255, 255, .18); }

/* ---------- relations, see also, secrets ---------- */
.relation-group { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; margin: 6px 0; }
.relation-label { font-size: 12px; font-weight: 700; color: var(--accent); min-width: 110px; text-transform: uppercase; letter-spacing: .4px; }
.secret-notes { margin: 18px 0; border: 1px dashed var(--st-deprecated); border-radius: 8px; padding: 8px 14px; background: color-mix(in srgb, var(--st-deprecated) 7%, transparent); }
.secret-notes summary { cursor: pointer; font-weight: 700; color: var(--st-deprecated); }
.secret-box { border-color: var(--st-deprecated); }
.see-also[hidden] { display: none; }

/* ---------- list: filters, tree, multi-select ---------- */
.list-tools { flex-wrap: wrap; }
.list-tools select { max-width: 48%; min-width: 0; }
.entity-list.is-tree { padding-bottom: 20px; }
.tree-group { list-style: none; border-bottom: 1px solid var(--border); }
.tree-details > summary { cursor: pointer; padding: 9px 14px; font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 8px; list-style: none; }
.tree-details > summary::-webkit-details-marker { display: none; }
.tree-details > summary::before { content: "▸"; color: var(--text-faint); width: 1em; }
.tree-details[open] > summary::before { content: "▾"; }
.tree-count { margin-left: auto; font-size: 11px; font-weight: 400; color: var(--text-faint); }
.tree-items { list-style: none; margin: 0; padding: 0 0 0 10px; }
.tree-more { padding: 8px 14px; font-size: 12px; color: var(--link); cursor: pointer; list-style: none; }
.entity-item.selecting { cursor: copy; position: relative; padding-left: 34px; }
.entity-check { position: absolute; left: 11px; top: 12px; font-size: 16px; color: var(--text-dim); }
.entity-item.picked { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.entity-item.picked .entity-check { color: var(--accent-bright); }
.bulk-bar {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 9%, var(--bg-panel));
}
.bulk-bar[hidden] { display: none; }
.bulk-count { font-weight: 700; font-size: 13px; margin-right: 4px; }
.bulk-note { flex-basis: 100%; font-size: 11px; }
#selectToggle.active, #viewToggle.active { border-color: var(--accent); color: var(--accent-bright); }
.sidebar-count { display: flex; align-items: baseline; gap: 10px; }

/* ---------- popup menu additions ---------- */
.popup-menu { max-height: min(78vh, 640px); overflow-y: auto; }
.popup-item { display: flex; align-items: center; gap: 12px; }
.popup-item span:first-child { flex: 1; text-align: left; }
.popup-item kbd { font-size: 10px; opacity: .7; }
.picker-overlay { z-index: 130; }
.picker-title { padding: 12px 16px 0; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); font-weight: 700; }

/* ---------- tag input ---------- */
.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 8px; cursor: text;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.tag-input:focus-within { border-color: var(--accent); }
.tag-chips { display: contents; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; }
.tag-x { border: 0; background: none; color: var(--text-faint); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; }
.tag-x:hover { color: var(--bad); }
.tag-input .tag-text { flex: 1; min-width: 110px; border: 0; background: transparent; color: var(--text); font: inherit; outline: none; padding: 4px; }

/* ---------- structured facts editor ---------- */
.attr-editor { display: flex; flex-direction: column; gap: 10px; }
.attr-rows { display: flex; flex-direction: column; gap: 10px; }
.attr-row { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--bg-panel); }
.attr-row-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.attr-key { flex: 1; min-width: 0; font-weight: 600; }
.attr-kind { width: auto; }
.attr-value { width: 100%; resize: vertical; }
.attr-raw { width: 100%; }
.attr-actions { display: flex; gap: 8px; }
.attr-expected { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.attr-expected:empty { display: none; }
.chip.is-required { border-color: var(--warn); color: var(--warn); }
.editor-counter { font-size: 12px; margin-top: 4px; }

/* ---------- images / relations / todos panels ---------- */
.image-drop { border: 2px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center; cursor: pointer; color: var(--text-dim); }
.image-drop:hover, .image-drop.is-over, .image-drop:focus-visible { border-color: var(--accent); color: var(--text); outline: none; }
.image-file { display: none; }
.image-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.image-item { display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--bg-panel); }
.image-thumb { padding: 0; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; width: 120px; height: 90px; flex: none; cursor: zoom-in; background: var(--bg-raised); }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.image-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.relation-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0 10px; }
.relation-form input, .relation-form select { min-width: 0; }
.relation-list { display: flex; flex-direction: column; gap: 6px; }
.relation-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--border); }
.todo-add { display: flex; gap: 8px; }
.todo-add input { flex: 1; }
.todo-list { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.todo-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.todo-row.is-done .check span { text-decoration: line-through; color: var(--text-faint); }
.ai-extra { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 10px; }
.ai-extra h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint); }

/* ---------- partial apply of AI drafts ---------- */
.hunk { border: 1px solid var(--border); border-radius: 8px; margin: 10px 0; padding: 6px 8px 8px; }
.hunk.is-off { opacity: .55; }
.hunk.is-off .diff-block.add { background: transparent; }
.hunk-pick { font-size: 12px; margin-bottom: 4px; }
.hunk-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.hunk-bar .diff-summary { flex: 1; margin: 0; }

/* ---------- version comparison ---------- */
.history-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.history-compare { margin-top: 14px; }
.compare-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.compare-head h4 { margin: 0; }
.version-compare { margin-top: 8px; }
.history-main input[type="checkbox"] { vertical-align: middle; }

/* ---------- read-only share view ---------- */
.share-mode .topbar, .share-mode .category-bar, .share-mode .sidebar, .share-mode .timeline-dock, .share-mode .mobile-back { display: none !important; }
.share-mode #browseView { display: block; }
.share-mode .detail { max-width: 860px; margin: 0 auto; }
.share-mode .wiki-missing { color: inherit; border-bottom: 0; cursor: default; }
.share-mode .entity-link { border-bottom: 0; cursor: default; color: inherit; }
.share-banner { font-size: 12px; color: var(--text-faint); border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 14px; }

@media (max-width: 720px) {
  .detail-cover { float: none; margin: 8px auto 14px; max-width: 100%; }
  .relation-label { min-width: 0; }
  .list-tools select { max-width: 100%; }
  .image-item { flex-direction: column; }
  .image-thumb { width: 100%; height: 160px; }
}

@media print {
  .bulk-bar, .detail-gallery, .see-also, .secret-notes, .detail-meta .tag-pill { display: none !important; }
  .detail-cover { max-width: 240px; }
}

/* ---------- relation graph: typed edges ---------- */
.graph-links line.typed { stroke: var(--accent); stroke-width: 1.8px; stroke-opacity: .9; }
.graph-link-labels text { font-size: 9px; fill: var(--accent-bright); text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: var(--bg-panel); stroke-width: 3px; }
.stat-card.stat-link { cursor: pointer; }
.stat-card.stat-link:hover { border-color: var(--accent); }
