:root {
  color-scheme: dark;
  --bg: #0d0e0f;
  --panel: #151719;
  --panel-2: #1b1d1f;
  --panel-3: #202326;
  --line: #34373a;
  --line-soft: #272a2d;
  --text: #f1eee7;
  --muted: #aaa79f;
  --quiet: #7d7f80;
  --yellow: #f2d21d;
  --yellow-soft: #3b3518;
  --green: #5bd6a0;
  --red: #f47575;
  --blue: #7db1e8;
  --focus: #fff4a6;
  --max: 1600px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
button, input, select, textarea { font: inherit; }
button, select { color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; z-index: 100; left: 1rem; top: -5rem; background: var(--yellow); color: #111; padding: .7rem 1rem; font-weight: 800; }
.skip-link:focus { top: 1rem; }

.site-header { position: sticky; z-index: 20; top: 0; min-height: 70px; border-bottom: 1px solid var(--line-soft); background: rgba(13,14,15,.96); backdrop-filter: blur(12px); display: flex; align-items: center; justify-content: space-between; gap: 2rem; padding: .8rem max(1.2rem, calc((100vw - var(--max)) / 2)); }
.brand { display: flex; align-items: center; gap: .85rem; }
.brand img { width: 44px; height: 44px; object-fit: contain; border: 1px solid var(--line); background: #070707; }
.brand strong, .brand span { display: block; }
.brand strong { font: 700 18px/1.2 var(--serif); }
.brand span { color: var(--muted); font-size: 12px; margin-top: 2px; }
.header-status { display: flex; align-items: center; gap: .9rem; }
.status-dot { color: var(--muted); font-size: 12px; }
.status-dot::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .5rem; background: var(--yellow); box-shadow: 0 0 0 4px rgba(242,210,29,.08); }
.status-dot.live::before { background: var(--green); box-shadow: 0 0 0 4px rgba(91,214,160,.08); }
.status-dot.error::before { background: var(--red); box-shadow: 0 0 0 4px rgba(244,117,117,.08); }

.app-shell { max-width: var(--max); margin: 0 auto; padding: 0 1.2rem 4rem; }
.search-workbench { padding-top: 2.4rem; border-bottom: 1px solid var(--line); }
.workbench-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 3rem; }
.eyebrow { margin: 0 0 .4rem; color: var(--yellow); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; }
h1 { margin: 0; max-width: 800px; font: 700 clamp(32px,4.2vw,58px)/1.02 var(--serif); letter-spacing: -.03em; }
.workbench-heading p:last-child { max-width: 780px; margin: .8rem 0 0; color: var(--muted); font-size: 16px; }
.archive-summary { min-width: 180px; padding: 0 0 .3rem 1.4rem; border-left: 2px solid var(--yellow); }
.archive-summary strong, .archive-summary span, .archive-summary small { display: block; }
.archive-summary strong { font: 700 34px/1 var(--serif); }
.archive-summary span { margin-top: .25rem; }
.archive-summary small { margin-top: .65rem; color: var(--muted); }

.search-form { max-width: 1180px; margin-top: 2rem; }
.search-form > label { display: block; margin-bottom: .5rem; font-weight: 750; }
.search-line { display: grid; grid-template-columns: minmax(0,1fr) auto; }
.search-line input { width: 100%; min-height: 54px; border: 1px solid #56595b; border-right: 0; border-radius: 3px 0 0 3px; background: #f3f0e8; color: #111; padding: .8rem 1rem; font-size: 16px; }
.search-line input::placeholder { color: #686867; }
.primary-button { border: 1px solid var(--yellow); border-radius: 0 3px 3px 0; background: var(--yellow); color: #111; min-height: 40px; padding: .65rem 1.2rem; font-weight: 800; }
.primary-button:hover { background: #ffe438; }
.quiet-button, .filter-button, .icon-button { border: 1px solid var(--line); border-radius: 3px; background: var(--panel-2); padding: .55rem .8rem; }
.quiet-button:hover, .filter-button:hover, .icon-button:hover { border-color: #666; background: var(--panel-3); }
.text-button { padding: .35rem 0; border: 0; background: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { color: var(--text); }
.search-tools { display: flex; flex-wrap: wrap; gap: 1.2rem; margin-top: .65rem; }
.syntax-help { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0 0; color: var(--muted); }
.syntax-help span { border: 1px solid var(--line-soft); background: var(--panel); padding: .35rem .5rem; }
.syntax-help code { color: var(--text); }

.section-tabs { display: flex; gap: 1.6rem; margin-top: 2.2rem; overflow-x: auto; }
.section-tab { flex: 0 0 auto; border: 0; border-bottom: 3px solid transparent; background: none; padding: .8rem 0 .75rem; font-weight: 750; color: var(--muted); }
.section-tab:hover { color: var(--text); }
.section-tab.active { color: var(--text); border-bottom-color: var(--yellow); }

.workspace { display: grid; grid-template-columns: 270px minmax(0,1fr); align-items: start; gap: 1.5rem; padding-top: 1.5rem; }
.filters { position: sticky; top: 92px; max-height: calc(100vh - 110px); overflow: auto; border: 1px solid var(--line); background: var(--panel); }
.filter-heading { display: flex; justify-content: space-between; align-items: center; padding: .85rem 1rem; border-bottom: 1px solid var(--line); }
.filter-heading h2 { margin: 0; font: 700 17px/1.2 var(--serif); }
#close-filters, #open-filters { display: none; }
fieldset { border: 0; margin: 0; }
.date-filter, .facet { padding: 1rem; border-bottom: 1px solid var(--line-soft); }
.date-filter legend, .facet h3 { width: 100%; margin: 0 0 .7rem; padding: 0; color: var(--text); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.date-fields { display: grid; gap: .6rem; }
.date-fields label { display: grid; grid-template-columns: 38px minmax(0,1fr); align-items: center; gap: .4rem; color: var(--muted); font-size: 12px; }
input[type="date"], select { min-width: 0; border: 1px solid var(--line); border-radius: 3px; background: var(--panel-2); padding: .5rem; }
.facet-list { display: grid; gap: .15rem; }
.facet-option { display: grid; grid-template-columns: 18px minmax(0,1fr) auto; gap: .45rem; align-items: start; padding: .25rem 0; color: var(--muted); }
.facet-option:hover { color: var(--text); }
.facet-option input { margin: .2rem 0 0; accent-color: var(--yellow); }
.facet-option small { color: var(--quiet); font-variant-numeric: tabular-nums; }
.facet-more { margin-top: .5rem; border: 0; background: none; color: var(--muted); padding: 0; text-decoration: underline; }

.results { min-width: 0; }
.results-toolbar { min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); padding: 0 0 .8rem; }
.results-toolbar > div { display: flex; align-items: center; gap: .55rem; }
#result-count { font: 700 18px/1.2 var(--serif); }
#result-context { color: var(--muted); font-size: 12px; }
.toolbar-actions label { color: var(--muted); font-size: 12px; }
.toolbar-actions select { min-width: 150px; }
.active-filters { display: flex; flex-wrap: wrap; gap: .45rem; padding: .75rem 0; min-height: 12px; }
.filter-chip { border: 1px solid #5c583a; background: var(--yellow-soft); color: var(--text); border-radius: 999px; padding: .28rem .6rem; font-size: 12px; }
.filter-chip::after { content: " ×"; color: var(--yellow); }

.result-list { border: 1px solid var(--line); }
.dossier-summary { padding: 1.2rem; border-bottom: 1px solid var(--line); background: linear-gradient(90deg, #252315, var(--panel)); }
.dossier-summary h2 { margin: .2rem 0 .35rem; font: 700 28px/1.15 var(--serif); }
.dossier-summary p { max-width: 900px; margin: 0 0 .7rem; color: #cbc7ba; }
.result-row { position: relative; display: grid; grid-template-columns: minmax(0,1fr) 180px; gap: 1.2rem; padding: 1rem 1.1rem; background: var(--panel); border-bottom: 1px solid var(--line-soft); }
.result-row:nth-child(even) { background: #181a1c; }
.result-row:last-child { border-bottom: 0; }
.result-row:hover { background: #1d1f20; }
.result-title { margin: 0; font: 700 20px/1.25 var(--serif); }
.result-title button { text-align: left; color: var(--text); border: 0; padding: 0; background: none; }
.result-title button:hover { color: var(--yellow); text-decoration: underline; text-underline-offset: 3px; }
.result-excerpt { margin: .45rem 0 .65rem; color: #c4c1b9; max-width: 980px; }
.result-excerpt mark { background: #5e5313; color: #fff; }
.result-taxonomy { display: flex; flex-wrap: wrap; gap: .35rem; }
.taxonomy-button { border: 1px solid var(--line); border-radius: 2px; background: transparent; color: var(--muted); padding: .2rem .42rem; font-size: 11px; }
.taxonomy-button:hover { color: var(--text); border-color: #666; }
.result-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: .8rem; }
.result-side time { font-size: 12px; color: var(--muted); }
.result-metrics { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .65rem; color: var(--muted); font-size: 11px; }
.result-actions { display: flex; gap: .45rem; }
.row-action { border: 1px solid var(--line); background: transparent; border-radius: 2px; padding: .35rem .5rem; font-size: 11px; }
.row-action.saved { border-color: var(--yellow); color: var(--yellow); }
.empty-state { padding: 4rem 1rem; text-align: center; background: var(--panel); color: var(--muted); }
.empty-state h2 { color: var(--text); font: 700 24px/1.2 var(--serif); }

.pagination { display: flex; justify-content: center; align-items: center; gap: .35rem; padding: 1.2rem 0; }
.pagination button { min-width: 36px; border: 1px solid var(--line); background: var(--panel); padding: .5rem; }
.pagination button.active { background: var(--yellow); color: #111; border-color: var(--yellow); font-weight: 800; }
.pagination button:disabled { opacity: .4; cursor: default; }

.thread-grid, .document-list, .saved-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; }
.thread-card, .document-card, .saved-card { border: 1px solid var(--line); background: var(--panel); padding: 1rem; }
.thread-card h3, .document-card h3, .saved-card h3 { margin: 0; font: 700 18px/1.25 var(--serif); }
.thread-card p, .document-card p, .saved-card p { color: var(--muted); }
.thread-card button, .document-card button, .saved-card button { border: 0; padding: 0; background: none; color: var(--yellow); text-decoration: underline; }
.thread-meta { display: flex; gap: 1rem; color: var(--muted); font-size: 12px; }
.document-card a { color: var(--yellow); }
.document-record-meta { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin: .7rem 0; color: var(--muted); font-size: 12px; }
.record-label { display: inline-block; margin-bottom: .6rem; border: 1px solid #5c583a; background: var(--yellow-soft); padding: .2rem .45rem; color: var(--yellow); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }

.detail-dialog { width: min(760px,100vw); max-width: none; height: 100vh; max-height: none; margin: 0 0 0 auto; border: 0; border-left: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 0; }
.detail-dialog::backdrop, .save-dialog::backdrop { background: rgba(0,0,0,.72); }
.dialog-header { position: sticky; z-index: 2; top: 0; display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); background: var(--panel); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 800; }
.dialog-content { padding: 1.4rem; }
.dialog-content h2 { margin: 0; font: 700 32px/1.1 var(--serif); }
.dialog-deck { color: #cac7c0; font-size: 15px; }
.record-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); margin: 1.2rem 0; border: 1px solid var(--line); }
.record-grid div { padding: .75rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.record-grid div:nth-child(even) { border-right: 0; }
.record-grid strong, .record-grid span { display: block; }
.record-grid strong { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.record-grid span { margin-top: .2rem; }
.detail-section { margin-top: 1.5rem; }
.detail-section h3 { border-bottom: 1px solid var(--line); padding-bottom: .4rem; font: 700 18px/1.2 var(--serif); }
.detail-link-list { padding-left: 1.2rem; }
.detail-link-list a { color: var(--yellow); }
.note-area { width: 100%; min-height: 120px; resize: vertical; border: 1px solid var(--line); background: #101112; color: var(--text); padding: .7rem; }
.visit-link { display: inline-block; margin-top: 1rem; background: var(--yellow); color: #111; padding: .65rem .9rem; text-decoration: none; font-weight: 800; }

.save-dialog { width: min(440px,calc(100vw - 2rem)); border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 1.2rem; }
.save-dialog h2 { margin-top: 0; font-family: var(--serif); }
.save-dialog label, .save-dialog input { display: block; width: 100%; }
.save-dialog input { margin-top: .35rem; border: 1px solid var(--line); background: #101112; color: var(--text); padding: .65rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
.dialog-actions .primary-button { border-radius: 3px; }

.toast { position: fixed; z-index: 80; right: 1rem; bottom: 1rem; max-width: 360px; border-left: 3px solid var(--yellow); background: #282a2c; color: var(--text); padding: .75rem 1rem; box-shadow: 0 8px 24px rgba(0,0,0,.4); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 920px) {
  .workbench-heading { align-items: flex-start; }
  .archive-summary { display: none; }
  .workspace { display: block; }
  .filters { position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(330px,90vw); max-height: none; transform: translateX(-102%); transition: transform .2s ease; box-shadow: 20px 0 50px rgba(0,0,0,.45); }
  .filters.open { transform: translateX(0); }
  #close-filters, #open-filters { display: inline-block; }
  .thread-grid, .document-list, .saved-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .site-header { min-height: 62px; padding: .6rem .8rem; }
  .brand img { width: 38px; height: 38px; }
  .brand span, .status-dot { display: none; }
  .app-shell { padding-inline: .8rem; }
  .search-workbench { padding-top: 1.5rem; }
  .search-line { grid-template-columns: 1fr; gap: .45rem; }
  .search-line input, .primary-button { border: 1px solid var(--yellow); border-radius: 3px; }
  .search-line input { border-color: #56595b; }
  .section-tabs { gap: 1rem; }
  .results-toolbar { align-items: flex-start; }
  .results-toolbar, .results-toolbar > div { flex-wrap: wrap; }
  .toolbar-actions { justify-content: flex-start; }
  .result-row { grid-template-columns: 1fr; }
  .result-side { text-align: left; align-items: flex-start; }
  .result-metrics { justify-content: flex-start; }
  .detail-dialog { width: 100%; }
  .record-grid { grid-template-columns: 1fr; }
  .record-grid div { border-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
