:root {
  --bg: #f3efe6;
  --paper: #f7f4ee;
  --field: #e7e2d6;
  --ink: #1c1b18;
  --muted: #6f6b63;
  --faint: #8a857c;
  --line: #d4cec2;
  --line-strong: #1c1b18;
  --accent: #b23a2f;
  --header-h: 58px;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --sans: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; }
a { color: inherit; }
.hidden { display: none !important; }
svg { display: block; }
::selection { background: #edd4cf; color: var(--ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c9c2b4; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #a9a193; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  min-height: var(--header-h);
  padding: 16px clamp(20px, 3vw, 36px) 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.03em;
  line-height: 1;
  text-decoration: none;
  color: var(--ink);
}
.top-status {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0 18px;
}
.chip {
  display: inline;
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 0;
  padding: 0;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  white-space: nowrap;
}
.chip-ready { color: var(--ink); }
.chip-warn { color: var(--accent); }
.chip-error { color: var(--accent); }
.chip-link { text-decoration: none; }
.chip-link:hover { color: var(--ink); }

.index-banner {
  position: sticky;
  top: var(--header-h);
  z-index: 45;
  display: grid;
  grid-template-columns: minmax(180px, 280px) 1fr;
  align-items: center;
  gap: 24px;
  padding: 12px clamp(20px, 3vw, 36px);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.index-banner-error { border-bottom-color: var(--accent); }
.index-banner-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.index-banner-copy strong {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 16px;
  letter-spacing: -0.02em;
}
.index-banner-copy span { color: var(--muted); font-size: 12px; }
.index-banner-bar { height: 1px; background: var(--line); overflow: hidden; }
.index-banner-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .35s ease; }

.page { width: 100%; margin: 0; padding: 0; }

.hero {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-h));
  padding: 22px clamp(20px, 3vw, 36px) 22px;
}
.dropzone {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  min-height: 320px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink));
  background-size:
    18px 1px, 1px 18px,
    18px 1px, 1px 18px,
    18px 1px, 1px 18px,
    18px 1px, 1px 18px;
  background-position:
    22px 22px, 22px 22px,
    right 22px top 22px, right 22px top 22px,
    left 22px bottom 22px, left 22px bottom 22px,
    right 22px bottom 22px, right 22px bottom 22px;
  background-repeat: no-repeat;
  cursor: pointer;
  outline: none;
  transition: border-color .15s ease;
}
.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragover {
  border-color: var(--ink);
}
.dropzone:focus-visible { outline: 1px solid var(--accent); outline-offset: 4px; }
.drop-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  pointer-events: none;
}
.drop-hint {
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.01em;
}
.drop-cross {
  width: 22px;
  height: 22px;
  position: relative;
}
.drop-cross::before,
.drop-cross::after {
  content: "";
  position: absolute;
  background: var(--ink);
}
.drop-cross::before { width: 1px; height: 22px; left: 50%; top: 0; }
.drop-cross::after { height: 1px; width: 22px; top: 50%; left: 0; }
.dropzone:hover .drop-cross::before,
.dropzone:hover .drop-cross::after,
.dropzone.dragover .drop-cross::before,
.dropzone.dragover .drop-cross::after { background: var(--accent); }

.instrument { display: none; margin-top: 18px; }
.instrument:has(#pendingPdf:not(.hidden)) {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 32px 48px;
  align-items: end;
  padding-top: 16px;
  border-top: 1px solid var(--ink);
}

.page-picker { min-width: 0; padding: 0; border: 0; background: none; border-radius: 0; }
.page-picker-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.page-picker-head strong {
  color: var(--ink);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.08em;
}
.page-picker-head span { color: var(--ink); text-align: right; letter-spacing: 0; text-transform: none; font-size: 13px; }
.page-mode-control {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}
.page-mode-control select,
.page-fields input,
.page-indicator input,
.category-control select,
.query-category select {
  appearance: none;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 4px 0;
  outline: none;
}
.page-mode-control select { width: 148px; flex: none; font-size: 14px; }
.page-mode-control select:focus,
.page-fields input:focus,
.category-control select:focus,
.query-category select:focus { border-bottom-color: var(--accent); }
.page-fields { display: flex; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.page-fields.page-fields-column { flex-direction: column; gap: 8px; }
.page-fields label { display: flex; align-items: baseline; gap: 8px; color: var(--muted); font-size: 13px; }
.page-fields input { width: 72px; font-size: 14px; }
.page-fields input::placeholder { color: var(--faint); }
.page-fields label.page-field-wide { flex-direction: column; align-items: stretch; gap: 4px; }
.page-field-wide input { width: 100%; }
.page-picker-hint { display: block; margin-top: 8px; color: var(--faint); font-size: 12px; }

.pending-pdf {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 20px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
}
.pending-pdf-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pending-pdf-copy span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.pending-pdf-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.pending-pdf .btn { flex: 0 0 auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:not(:disabled):hover { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:not(:disabled):hover { border-color: var(--ink); }
.btn-sm { padding: 8px 12px; }

.workspace { padding: 28px clamp(20px, 3vw, 36px) 0; scroll-margin-top: 74px; }
.workspace-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--ink);
}
.file-meta { display: flex; align-items: center; gap: 14px; min-width: 0; }
.file-badge {
  display: inline;
  width: auto;
  height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
}
.file-meta strong {
  display: block;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.03em;
  max-width: 62vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-meta span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.workspace-grid {
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
.pages-panel {
  position: sticky;
  top: 78px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0 16px 0 0;
  max-height: calc(100vh - 108px);
  display: flex;
  flex-direction: column;
}
.panel-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--line);
}
.pages-list { display: flex; flex-direction: column; gap: 2px; overflow: auto; padding: 8px 0 0; }
.page-thumb {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 0;
  border-radius: 0;
  padding: 6px 0;
  cursor: pointer;
  background: transparent;
  text-align: left;
  border-bottom: 1px solid transparent;
}
.page-thumb:hover { border-bottom-color: var(--line); }
.page-thumb.active { border-bottom-color: var(--accent); }
.page-thumb img {
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: 0;
  background: #fff;
  border: 1px solid var(--line);
}
.page-thumb-copy { min-width: 0; }
.page-thumb-copy strong { display: block; font-size: 13px; font-weight: 500; }
.page-thumb-copy span { display: block; color: var(--faint); font-size: 11px; margin-top: 1px; }
.page-thumb .count { color: var(--accent); }

.viewer-panel { border: 0; background: transparent; border-radius: 0; overflow: visible; min-width: 0; }
.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 20px;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--line);
  background: transparent;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 0;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--ink); }
.page-indicator { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.page-indicator input {
  width: 42px;
  text-align: center;
  font-size: 13px;
  padding: 3px 0;
}
.page-indicator input::-webkit-outer-spin-button,
.page-indicator input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.mode-switch { padding: 0; border: 0; border-radius: 0; background: none; gap: 16px; }
.tool-btn {
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 0;
  padding: 2px 0 3px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.tool-btn:hover { color: var(--ink); }
.tool-btn.active {
  background: none;
  color: var(--ink);
  box-shadow: none;
  border-bottom-color: var(--accent);
}
.zoom-group { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; }
.zoom-group span { min-width: 40px; text-align: center; }
.viewer-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
}
.threshold-control { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.threshold-control input { width: 120px; accent-color: var(--accent); }
.threshold-control b { color: var(--ink); font-weight: 500; font-size: 12px; min-width: 32px; font-variant-numeric: tabular-nums; }
.category-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.category-control select,
.query-category select { max-width: 220px; font-size: 13px; cursor: pointer; }
.query-category {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 8px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
}
.query-category select { max-width: 240px; color: var(--ink); }
.viewer-filters { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.site-filter { position: relative; display: inline-block; }
.site-filter summary {
  list-style: none;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  max-width: 260px;
  padding: 0 0 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.site-filter summary::-webkit-details-marker { display: none; }
.site-filter summary:hover,
.site-filter[open] summary { border-bottom-color: var(--ink); }
.site-filter summary b {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
}
.site-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  width: 260px;
  max-width: min(260px, calc(100vw - 40px));
  max-height: 320px;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  box-shadow: none;
}
.viewer-subbar .site-menu { left: auto; right: 0; }
.site-menu-head {
  padding: 0 0 8px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.site-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-radius: 0;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}
.site-option:hover { color: var(--accent); }
.site-option input { margin: 0; accent-color: var(--accent); }
.site-option span { flex: 1; min-width: 0; }
.site-option small { color: var(--faint); font-size: 11px; }
.site-menu-actions {
  position: sticky;
  bottom: -10px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.site-menu-actions button {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.site-menu-actions button:hover { color: var(--ink); }
.site-menu-actions .site-apply { color: var(--accent); }
.site-empty { padding: 6px 0; color: var(--faint); font-size: 12px; }
.query-filters { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; margin: 4px 0 16px; }
.query-filters .query-category { margin-top: 0; }
.selection-actions { display: flex; gap: 8px; align-items: center; }
.auto-status {
  margin-left: auto;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.35;
  text-align: right;
}
.auto-status.success { color: var(--ink); }
.auto-status.error { color: var(--accent); }
.auto-status.loading { color: var(--accent); }
.auto-status.loading::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 7px;
  background: currentColor;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.viewer-hint {
  padding: 10px 0 12px;
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  letter-spacing: -0.01em;
  background: none;
  border-bottom: 0;
}
.viewer-hint strong { color: var(--ink); font-style: normal; font-weight: 500; }

.viewport {
  position: relative;
  overflow: auto;
  max-height: min(74vh, 960px);
  min-height: 440px;
  background: var(--field);
  padding: 28px;
  border: 1px solid var(--line);
}
.stage {
  position: relative;
  width: 100%;
  margin: 0 auto;
  line-height: 0;
  box-shadow: none;
  background: #fff;
  border-radius: 0;
  transition: width .18s ease;
}
.stage img { display: block; width: 100%; height: auto; border-radius: 0; user-select: none; }
.overlay, .draw-layer { position: absolute; inset: 0; }
.overlay { pointer-events: none; z-index: 5; }
.draw-layer { pointer-events: none; z-index: 4; }
.draw-layer.active { pointer-events: auto; cursor: crosshair; }
.draw-preview {
  position: absolute;
  border: 1px dashed var(--accent);
  background: rgba(178, 58, 47, .08);
  pointer-events: none;
}

.det-box {
  position: absolute;
  border: 1px solid var(--ink);
  background: transparent;
  border-radius: 0;
  pointer-events: auto;
  cursor: pointer;
}
.det-box:hover { background: rgba(28, 27, 24, .06); }
.det-box.selected,
.det-box.matched { border-color: var(--accent); background: rgba(178, 58, 47, .08); }
.det-box.matched:hover,
.det-box.selected:hover { background: rgba(178, 58, 47, .14); }
.det-box.unmatched { border-style: dashed; opacity: .4; }
.det-box.unmatched:hover { opacity: .8; }
.det-box.searchable { border-style: dashed; opacity: .85; }
.det-box.searchable:hover { opacity: 1; background: rgba(28, 27, 24, .06); }
.det-box.searching { border-color: var(--accent); background: rgba(178, 58, 47, .12); opacity: 1; cursor: wait; }
.det-box.low { opacity: .45; }
.det-box.searchable.low { opacity: .65; }
.det-box.manual { border: 1px dashed var(--accent); background: rgba(178, 58, 47, .06); pointer-events: auto; }
.det-box.manual.selected { border-color: var(--accent); }
.det-label {
  position: absolute;
  left: -1px;
  top: -20px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 230px;
  padding: 2px 5px;
  border-radius: 0;
  background: var(--ink);
  color: var(--bg);
  border: 0;
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.det-box.selected .det-label,
.det-box.matched .det-label { background: var(--accent); color: #fff; }
.det-label input { width: 11px; height: 11px; margin: 0; accent-color: var(--bg); cursor: pointer; }
.det-label .score { color: rgba(243, 239, 230, .7); }
.det-delete {
  position: absolute;
  right: -8px;
  top: -22px;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}
.det-delete:hover { background: var(--accent); color: #fff; }

.page-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(243, 239, 230, .72);
  z-index: 6;
}
.page-loader span,
.progress-spinner span {
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 0;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results-section { margin-top: 64px; padding: 0 clamp(20px, 3vw, 36px) 72px; }
.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ink);
}
.results-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(32px, 4vw, 48px);
  letter-spacing: -0.035em;
  line-height: 1;
}
.results-head h2 span {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-left: 10px;
}
.results-list { display: flex; flex-direction: column; gap: 36px; }
.query-card {
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  border-radius: 0;
  overflow: visible;
  padding-top: 18px;
}
.query-card.query-highlight { border-top-color: var(--accent); }
.query-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 0 0 14px;
  border-bottom: 0;
  border-radius: 0;
  background: none;
}
.query-crop {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border-radius: 0;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
}
.query-meta { min-width: 0; flex: 1; }
.query-meta strong {
  display: block;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.query-meta .query-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.query-meta .query-desc {
  color: var(--faint);
  font-size: 13px;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70vw;
}
.query-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip-tag {
  display: inline-flex;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: none;
}
.chip-tag + .chip-tag::before { content: "·"; margin-right: 8px; color: var(--line); text-transform: none; }
.query-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.query-time { color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 22px 18px;
  padding: 8px 0 0;
}
.product-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: visible;
  min-width: 0;
}
.product-card:hover { transform: none; border-color: transparent; box-shadow: none; }
.product-img-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #fff;
  overflow: hidden;
  border: 1px solid var(--line);
}
.product-img-wrap img { width: 100%; height: 100%; object-fit: contain; padding: 12px; }
.product-card:hover .product-img-wrap { border-color: var(--ink); }
.rank-badge {
  position: absolute;
  left: 8px;
  top: 6px;
  z-index: 2;
  display: block;
  width: auto;
  height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 500;
}
.product-body { display: flex; flex-direction: column; gap: 4px; padding: 10px 0 0; flex: 1; }
.product-title {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  min-height: 0;
}
.product-cat { color: var(--muted); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }
.product-dim { color: var(--faint); font-size: 12px; }
.product-reasons { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.reason {
  color: var(--muted);
  font-size: 11px;
  border: 0;
  background: none;
  border-radius: 0;
  padding: 0;
}
.reason + .reason::before { content: "· "; color: var(--faint); }
.product-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  border-top: 0;
  padding-top: 8px;
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0.02em;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  align-self: flex-start;
}
.product-link:hover { border-bottom-color: var(--accent); color: var(--accent); }
.product-link.disabled { color: var(--faint); pointer-events: none; border: 0; }

.empty-results { padding: 18px 0; color: var(--muted); font-size: 14px; }
.results-note {
  border: 0;
  border-left: 1px solid var(--accent);
  border-radius: 0;
  padding: 4px 0 4px 12px;
  color: var(--muted);
  background: none;
  font-size: 14px;
}
.results-note.loading { color: var(--ink); }
.query-pending { border-top-color: var(--accent); }
.query-crop-pending {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.live-spin {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 1px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
  flex: 0 0 auto;
}
.search-live {
  height: 2px;
  margin: 0 0 16px;
  background: var(--line);
  overflow: hidden;
}
.search-live span {
  display: block;
  width: 32%;
  height: 100%;
  background: var(--accent);
  animation: search-slide 1.15s ease-in-out infinite;
}
@keyframes search-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(340%); }
}
.results-note.error { color: var(--accent); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(243, 239, 230, .9);
}
.progress-card {
  width: min(380px, 100%);
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  box-shadow: none;
  padding: 28px 28px 24px;
  text-align: left;
}
.progress-spinner {
  width: auto;
  height: auto;
  margin: 0 0 18px;
  display: flex;
  border: 0;
  border-radius: 0;
  background: none;
}
.progress-card strong {
  display: block;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: -0.03em;
}
.progress-card p { color: var(--muted); font-size: 13px; margin: 8px 0 20px; min-height: 18px; }
.progress-bar { height: 1px; background: var(--line); overflow: hidden; }
.progress-bar span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .3s ease; }
.progress-card small {
  display: block;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.06em;
  margin-top: 8px;
}

.back-to-pdf {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 110;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border: 0;
  border-radius: 0;
  background: var(--ink);
  color: var(--bg);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: none;
}
.back-to-pdf:hover { background: var(--accent); color: #fff; }
.back-to-pdf span { font-size: 13px; line-height: 1; }

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  border-radius: 0;
  padding: 12px 14px;
  font-size: 13px;
  box-shadow: none;
}
.toast-error { border-color: var(--accent); color: var(--accent); }
.toast-success { border-color: var(--ink); }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: var(--bg);
}
.login-card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-kicker {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: -0.03em;
}
.login-card h1 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 42px;
  letter-spacing: -0.04em;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.login-field input {
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  padding: 8px 0 10px;
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
}
.login-field input:focus { outline: none; border-bottom-color: var(--accent); }
.login-submit { align-self: flex-start; margin-top: 8px; }
.login-error { min-height: 1.2em; margin: 0; color: var(--accent); font-size: 13px; letter-spacing: 0; text-transform: none; }

.shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  align-items: start;
  min-height: calc(100vh - var(--header-h));
}
.shell-main { min-width: 0; }
.history-rail {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  padding: 18px 16px 16px 22px;
  border-right: 1px solid var(--line);
  background: var(--bg);
}
.new-search {
  flex: 0 0 auto;
  width: 100%;
  padding: 0 0 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.03em;
  cursor: pointer;
}
.new-search:hover { color: var(--accent); }
.history-list {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 12px;
  padding-right: 4px;
}
.history-empty { color: var(--faint); font-size: 12px; padding: 12px 0; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  gap: 6px;
  align-items: center;
  border-bottom: 1px solid transparent;
}
.history-item.active { border-bottom-color: var(--line); }
.history-open {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 8px 0;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.history-item img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
}
.history-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.history-copy strong {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-copy span { color: var(--faint); font-size: 11px; }
.history-delete {
  border: 0;
  color: var(--faint);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
}
.history-delete:hover { color: var(--accent); }

.admin-page { padding: 28px clamp(20px, 3vw, 48px) 64px; }
.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 28px;
}
.admin-head h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 40px;
  letter-spacing: -0.04em;
}
.admin-grid {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}
.admin-form, .user-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.user-table { width: 100%; border-collapse: collapse; }
.user-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding: 0 8px 10px 0;
  border-bottom: 1px solid var(--line);
}
.user-table td {
  padding: 12px 12px 12px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.user-actions { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.user-actions button { color: var(--muted); cursor: pointer; }
.user-actions button:hover { color: var(--accent); }
.role-user { color: var(--muted); }
.role-off { color: var(--accent); }

@media (max-width: 920px) {
  .instrument:has(#pendingPdf:not(.hidden)) { grid-template-columns: 1fr; gap: 18px; }
  .pending-pdf { justify-content: space-between; }
  .workspace-grid { grid-template-columns: 1fr; gap: 18px; }
  .pages-panel { position: static; max-height: none; padding: 0; border-bottom: 1px solid var(--line); }
  .pages-list { flex-direction: row; overflow-x: auto; }
  .page-thumb { flex: 0 0 148px; grid-template-columns: 44px 1fr; border-bottom: 0; }
  .page-thumb img { width: 44px; height: 32px; }
  .file-meta strong { max-width: 58vw; font-size: 18px; }
  .index-banner { grid-template-columns: 1fr; gap: 8px; }
}
@media (max-width: 680px) {
  #datasetChip { display: none; }
  .topbar { align-items: center; }
  .hero { padding: 14px 14px 16px; }
  .dropzone { min-height: 64vh; }
  .pending-pdf { align-items: stretch; flex-direction: column; }
  .pending-pdf .btn { width: 100%; }
  .back-to-pdf { right: 14px; bottom: 14px; }
  .viewer-toolbar, .viewer-subbar { align-items: flex-start; }
  .results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
  .query-head { align-items: flex-start; }
  .query-crop { width: 56px; height: 56px; }
  .query-meta .query-desc { max-width: 58vw; }
  .query-time { display: none; }
  .viewer-subbar .site-menu { left: 0; right: auto; }
  .query-card .site-menu { left: auto; right: 0; }
  .results-head { align-items: baseline; }
  .results-section { margin-top: 40px; }
  .threshold-control input { width: 88px; }
  .selection-actions { width: 100%; justify-content: space-between; }
  .shell { grid-template-columns: 1fr; }
  .history-rail {
    position: relative;
    top: 0;
    height: auto;
    max-height: 280px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px;
  }
  .admin-grid { grid-template-columns: 1fr; }
  .workspace, .results-section { padding-left: 14px; padding-right: 14px; }
  .workspace { padding-top: 18px; }
}
