:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, sans-serif;
  color: #18253b;
  background: #f3f5f9;
  --accent: #274eac;
  --muted: #536177;
  --border: #dce2ec;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }

.shell { width: min(920px, calc(100% - 40px)); margin-inline: auto; }
.topbar { border-bottom: 1px solid var(--border); background: #fff; }
.brand { display: flex; align-items: center; gap: 12px; min-height: 64px; font-weight: 700; }
.brand-link { display: flex; align-items: center; gap: 12px; color: #000; text-decoration: none; white-space: nowrap; }
.topbar-nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 16px; margin-inline-start: auto; }
.topbar-link { color: var(--accent); font-size: 0.9rem; }
.brand-mark { flex-shrink: 0; }

main { padding-block: 36px 56px; }
.intro {
  margin-bottom: 36px;
  padding: clamp(24px, 5vw, 44px);
  border: 1px solid #d8e1f2;
  border-radius: 16px;
  background: #eaf0fc;
}
.eyebrow { margin: 0; color: var(--accent); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
h1 { margin: 8px 0 12px; font-size: clamp(2.2rem, 7vw, 3.5rem); line-height: 1.05; letter-spacing: -0.045em; }
.intro > p:not(.eyebrow) { max-width: 54ch; margin: 0; line-height: 1.55; color: var(--muted); }
.search-form { margin-top: 22px; }
.search-form label { display: block; margin-bottom: 7px; font-weight: 650; }
.search-modes { min-width: 0; padding: 0; border: 0; margin: 0 0 14px; }
.search-modes legend { padding: 0; margin-bottom: 7px; font-weight: 650; }
.search-mode-options { display: flex; flex-wrap: wrap; gap: 7px 12px; }
.search-mode-options label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 0.9rem; cursor: pointer; }
.search-mode-options input { margin: 0; accent-color: var(--accent); }
.search-controls { display: flex; gap: 8px; }
.search-controls input { flex: 1; }
.search-controls input, .filter-fields input, .filter-fields select {
  min-width: 0;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #b7c5df;
  border-radius: 8px;
  color: inherit;
  background: #fff;
  font: inherit;
}
#search-submit:not(:disabled), #import-submit:not(:disabled) { background: var(--accent); color: #fff; }
#search-submit:not(:disabled):hover, #import-submit:not(:disabled):hover { background: #1c3d91; }

.results-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-bottom: 14px;
}
h2 { margin: 0; font-size: 1.25rem; scroll-margin-top: 20px; }
#status, #search-status { color: var(--muted); font-size: 0.9rem; }
#status { margin: 0; }
.catalog-filters {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.filter-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 12px; }
.filter-fields label { display: grid; gap: 5px; min-width: 0; font-size: 0.9rem; font-weight: 600; }
.filter-fields input, .filter-fields select { width: 100%; font-weight: normal; }
.filter-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.paper-list { display: grid; gap: 12px; }
.paper { padding: 18px 22px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.paper-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; color: var(--muted); font-size: 0.83rem; }
.paper-id { padding: 3px 7px; border-radius: 5px; background: #eff3fc; color: var(--accent); font-family: ui-monospace, monospace; }
.paper-stage { padding: 3px 8px; border-radius: 999px; background: #edf0f5; color: #3d4c63; font-weight: 600; }
.paper-stage[data-stage="texted"] { background: #e4edff; color: #23458d; }
.paper-stage[data-stage="texting"] { background: #efe8fb; color: #5c397f; }
.paper-summary-status[data-ready="true"] { background: #def5ef; color: #17594e; }
h3 { margin: 9px 0 5px; font-size: 1.08rem; line-height: 1.4; overflow-wrap: anywhere; }
.paper-title { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.paper-title:hover { color: var(--accent); }
.paper-arxiv { margin-inline-start: 6px; color: var(--accent); font-size: 0.85rem; white-space: nowrap; }
.paper-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 12px; }
.paper-download { display: inline-flex; align-items: center; text-decoration: none; }
#paper-title { font-size: clamp(1.6rem, 5vw, 2.6rem); overflow-wrap: anywhere; }
.catalog-back { display: inline-block; margin-bottom: 14px; color: var(--accent); }
.chunk-text { margin: 8px 0 0; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
#paper-summary, #paper-text { margin-bottom: 24px; overflow-wrap: anywhere; }
#summary-status, #text-status { margin: 0; color: var(--muted); font-size: 0.9rem; }
.formatted-text { line-height: 1.6; overflow-x: auto; }
.formatted-text :is(h1, h2, h3, h4, h5, h6) { margin: 1em 0 0.35em; }
.formatted-text h1 { font-size: 1.4rem; }
.formatted-text pre { overflow-x: auto; }
.formatted-text table { border-collapse: collapse; }
.formatted-text :is(th, td) { padding: 4px 8px; border: 1px solid var(--border); }
#text-result { max-height: 65vh; overflow: auto; }
#text-result img { max-width: 100%; height: auto; }
#text-result .katex-display { overflow-x: auto; overflow-y: hidden; padding-block: 0.25em; }
#text-result .katex-display > .katex { width: max-content; min-width: 100%; }
.paper-plain-text { margin: 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
.paper-authors { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
summary { width: fit-content; cursor: pointer; color: var(--accent); font-size: 0.9rem; font-weight: 600; }
.paper-abstract { max-width: 76ch; margin: 10px 0 0; color: #334258; line-height: 1.6; white-space: pre-line; overflow-wrap: anywhere; }
.search-excerpt { margin: 10px 0 0; line-height: 1.6; overflow-wrap: anywhere; }
#rag-points { padding-inline-start: 22px; line-height: 1.6; overflow-wrap: anywhere; }
#rag-points li + li { margin-top: 6px; }
#rag-result a { color: var(--accent); }
#rag-trace { margin-block: 12px; }
#rag-permalink, #rag-trace a { color: var(--accent); }
#rag-trace pre { margin: 0; padding: 10px; background: #f3f5f9; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
#rag-trace-status { margin-block: 10px; color: var(--muted); }
.rag-tool { border: 1px solid var(--border); border-radius: 8px; }
.rag-tool > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 10px; width: 100%; padding: 10px 12px; }
.rag-tool > summary::before { content: "▸"; }
.rag-tool[open] > summary::before { content: "▾"; }
.rag-tool > summary:hover { background: #f3f5f9; border-radius: 8px; }
.rag-tool > summary code { font-weight: 400; overflow-wrap: anywhere; }
.rag-tool-name { color: #18253b; font-weight: 700; }
.rag-tool-badge { padding: 2px 7px; border-radius: 999px; background: #e4edff; color: #23458d; font-size: 0.8rem; }
.rag-tool-badge[data-error="true"] { background: #fbe8eb; color: #962e37; }
.rag-tool-meta { margin: 4px 0 0; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.rag-tool > summary .rag-tool-meta { margin: 0 0 0 auto; }
.rag-tool-body { display: grid; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.rag-tool-body h4 { margin: 0; }
.rag-tool-body details pre { margin-top: 8px; }
.rag-tool-arguments { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 4px 12px; margin: 0; }
.rag-tool-arguments dt { color: var(--muted); overflow-wrap: anywhere; }
.rag-tool-arguments dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.rag-tool-excerpt { padding: 10px 12px; background: #f5f7fb; border: 1px solid var(--border); border-radius: 8px; }
.rag-tool-excerpt > a { font-weight: 650; overflow-wrap: anywhere; }
.rag-tool-error { padding: 8px 10px; border-radius: 6px; background: #fbe8eb; color: #962e37; overflow-wrap: anywhere; }
#paper-chunks .paper:target { border-color: var(--accent); scroll-margin-top: 20px; }

.pagination { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 20px; }
.pagination span { color: var(--muted); font-size: 0.9rem; }
button, .paper-download {
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid #b7c5df;
  border-radius: 8px;
  color: var(--accent);
  background: #fff;
  font: inherit;
  cursor: pointer;
}
button:not(:disabled):hover, .paper-download:hover { background: #eaf0fc; }
button:disabled { color: var(--muted); background: #eef1f6; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#retry { margin-bottom: 12px; }

#import-form { margin-top: 22px; }
#import-feedback { margin: 0; align-self: center; overflow-wrap: anywhere; min-width: 0; }
.imports-table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.imports-table { width: 100%; min-width: 680px; border-collapse: collapse; font-size: 0.9rem; }
.imports-table th, .imports-table td { padding: 12px 14px; text-align: left; vertical-align: top; }
.imports-table th { background: #eaf0fc; }
.imports-table td { border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.imports-table td:first-child { min-width: 170px; }
.imports-table td:nth-child(2) { width: 24%; }
.imports-table td:nth-child(3) { min-width: 135px; }
.imports-table td:last-child { width: 34%; }
.import-meta { margin: 5px 0 0; color: var(--muted); font-size: 0.82rem; }
.import-job-id { display: block; }
.import-action { margin-top: 7px; }
.import-result { white-space: pre-line; }
.paper-stage[data-stage="running"] { background: #e4edff; color: #23458d; }
.paper-stage[data-stage="completed"] { background: #e2f2e8; color: #21603c; }
.paper-stage[data-stage="failed"] { background: #fbe8eb; color: #962e37; }

.worker-name { margin: 0; }
.worker-id { color: var(--muted); font-size: 0.85rem; }
.worker-feedback { align-self: center; margin: 0; color: #962e37; overflow-wrap: anywhere; }

@media (max-width: 480px) {
  .shell { width: calc(100% - 28px); }
  main { padding-top: 22px; }
  .paper { padding: 16px; }
}
