:root {
  color-scheme: dark;
  --bg: #101113;
  --panel: #191b1f;
  --panel-2: #20242a;
  --line: #353b44;
  --text: #f0f2f4;
  --muted: #a6afb9;
  --accent: #62c6a3;
  --accent-2: #e7b85a;
  --danger: #e06f61;
  --chat-dock-width: 360px;
  --chat-mobile-height: 248px;
  --chat-lines: calc(7 * 1.45em);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  min-height: 92px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: #14161a;
}

.eyebrow,
.result-count,
.query-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

h1 {
  margin: 2px 0 0;
  font-size: 30px;
  font-weight: 750;
  letter-spacing: 0;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

.stat {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  color: var(--text);
}

.shell {
  display: grid;
  grid-template-columns: 300px minmax(330px, 0.95fr) minmax(390px, 1.2fr);
  height: calc(100vh - 92px);
}

.filters,
.results-panel,
.detail-panel,
.chat-panel {
  min-height: 0;
  overflow: auto;
}

.filters {
  border-right: 1px solid var(--line);
  padding: 20px;
  background: #15171b;
}

.search-label,
.filter-group span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

input,
select {
  min-width: 0;
  width: 100%;
  color: var(--text);
  background: #0f1114;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 9px 11px;
}

button:hover {
  border-color: #53606d;
}

.filter-group {
  display: block;
  margin-top: 22px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.segmented button.active {
  color: #07110d;
  border-color: var(--accent);
  background: var(--accent);
}

.issues {
  margin-top: 24px;
}

.issues button {
  width: 100%;
}

#issues {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.results-panel {
  border-right: 1px solid var(--line);
  background: var(--bg);
}

.results-head {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 66px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 17, 19, 0.97);
}

.pager {
  display: flex;
  gap: 8px;
}

.pager button:disabled {
  opacity: 0.35;
  cursor: default;
}

.results {
  padding: 12px;
}

.record-card {
  width: 100%;
  display: block;
  text-align: left;
  margin: 0 0 10px;
  padding: 13px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.record-card.active {
  border-color: var(--accent);
}

.record-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.record-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kind {
  color: #07110d;
  background: var(--accent);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 800;
}

.kind.video {
  background: var(--accent-2);
}

.kind.image {
  background: #8db7ef;
}

.new-flag {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border: 1px solid #7d6640;
  border-radius: 4px;
  background: #2a2418;
  color: #f1cd6d;
  font-size: 11px;
  font-weight: 800;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.record-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
}

.snippet,
.blurb {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

mark {
  color: #0f1114;
  background: var(--accent-2);
  padding: 0 2px;
}

.detail-panel {
  background: #121417;
}

.chat-panel {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: var(--chat-dock-width);
  max-height: calc(100vh - 92px);
  display: grid;
  grid-template-rows: auto auto auto;
  background: #15171b;
  border-left: 1px solid var(--line);
  box-shadow: -14px 0 28px rgba(0, 0, 0, 0.28);
}

.chat-head {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-head h2 {
  margin: 2px 0 0;
  font-size: 16px;
  letter-spacing: 0;
}

.chat-status {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 5px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.chat-status.ready {
  color: #07110d;
  border-color: var(--accent);
  background: var(--accent);
}

.chat-status.missing {
  color: #190b07;
  border-color: var(--danger);
  background: var(--danger);
}

.chat-collapse {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  color: #07110d;
  border-color: var(--accent);
  background: var(--accent);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0;
}

.chat-panel.collapsed {
  width: 68px;
  height: 68px;
  min-height: 68px;
  max-height: 68px;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.chat-panel.collapsed .chat-head {
  width: 68px;
  height: 68px;
  min-height: 68px;
  padding: 0;
  border: 0;
  background: transparent;
}

.chat-panel.collapsed .chat-head > div:first-child,
.chat-panel.collapsed .chat-status,
.chat-panel.collapsed .chat-messages,
.chat-panel.collapsed .chat-form {
  display: none;
}

.chat-panel.collapsed .chat-head-actions {
  width: 100%;
  height: 100%;
}

.chat-panel.collapsed .chat-collapse {
  width: 58px;
  height: 58px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
}

.chat-messages {
  min-height: 0;
  max-height: calc(var(--chat-lines) + 28px);
  overflow: auto;
  padding: 10px;
  overscroll-behavior: contain;
}

.chat-message {
  margin: 0 0 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel);
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-message.user {
  margin-left: 16px;
  border-color: #405063;
  background: #1b222b;
}

.chat-message.assistant {
  margin-right: 16px;
}

.chat-message.error {
  color: #ffd7d2;
  border-color: var(--danger);
}

.chat-sources {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.chat-sources a {
  color: var(--accent);
  text-decoration: none;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.chat-form textarea {
  width: 100%;
  min-width: 0;
  resize: vertical;
  height: 54px;
  max-height: 92px;
  color: var(--text);
  background: #0f1114;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  outline: none;
}

.chat-form textarea:focus {
  border-color: var(--accent);
}

.chat-form button {
  align-self: end;
  min-width: 72px;
  min-height: 44px;
}

.empty-detail {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.detail {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto minmax(280px, 48vh) auto;
}

.detail-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.detail-header h2 {
  margin: 8px 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.detail-actions a,
.detail-actions button {
  display: inline-block;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 6px;
  padding: 9px 11px;
}

.detail-actions button {
  min-height: 0;
}

.detail-actions button:first-of-type {
  color: #07110d;
  border-color: var(--accent);
  background: var(--accent);
}

.viewer {
  min-height: 280px;
  border-bottom: 1px solid var(--line);
  background: #090a0c;
}

.viewer iframe,
.viewer video,
.viewer img {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  object-fit: contain;
}

.detail-text {
  padding: 18px 20px 28px;
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-wrap;
}

.detail-text h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 15px;
}

.content-summary {
  padding: 18px 20px 32px;
  border-top: 1px solid var(--line);
  background: #15171b;
}

.summary-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 14px;
}

.summary-head h3 {
  margin: 3px 0 0;
  font-size: 20px;
  letter-spacing: 0;
}

.summary-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.summary-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 16px;
}

.summary-meta div {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  padding: 9px 10px;
}

.summary-meta dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.summary-meta dd {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.summary-block {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  padding: 14px;
}

.summary-block h4 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 14px;
}

.summary-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.summary-search-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.ocr-block {
  padding: 0;
  overflow: hidden;
}

.ocr-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #1b1e23;
}

.ocr-head h4 {
  margin: 0;
}

.ocr-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.ocr-block .summary-search-note {
  padding: 10px 14px 0;
}

.ocr-text {
  max-height: 72vh;
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: #d7dee6;
  background: #0d0f12;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}

.ocr-text mark {
  color: #0f1114;
  background: #f1cd6d;
  border-radius: 3px;
  padding: 0 2px;
}

.ocr-text .ocr-hit {
  outline: 2px solid var(--accent);
}

.error {
  margin: 14px;
  color: var(--danger);
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 280px 1fr;
    height: auto;
  }

  .detail-panel {
    grid-column: 1 / -1;
    min-height: 70vh;
    border-top: 1px solid var(--line);
  }

  .chat-panel {
    max-height: calc(100vh - 92px);
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    padding: 14px;
  }

  h1 {
    font-size: 24px;
  }

  .stats {
    justify-content: start;
  }

  .stat {
    padding: 6px 8px;
  }

  .shell {
    display: block;
    padding-right: 0;
    padding-bottom: 18px;
    height: auto;
  }

  .filters,
  .results-panel,
  .detail-panel {
    max-height: none;
    border-right: 0;
  }

  .filters {
    padding: 14px;
  }

  .results-head {
    min-height: 58px;
    padding: 10px 12px;
  }

  .results {
    padding: 10px;
  }

  .record-card {
    padding: 12px;
  }

  button,
  input,
  select {
    min-height: 44px;
  }

  .detail {
    grid-template-rows: auto minmax(220px, 42vh) auto;
  }

  .detail-header,
  .detail-text,
  .content-summary {
    padding: 14px;
  }

  .detail-header h2 {
    font-size: 19px;
  }

  .summary-head {
    display: block;
  }

  .summary-head span {
    display: block;
    margin-top: 6px;
    white-space: normal;
  }

  .summary-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ocr-head {
    display: block;
  }

  .ocr-head span {
    display: block;
    margin-top: 5px;
    white-space: normal;
  }

  .ocr-text {
    max-height: 58vh;
    font-size: 12px;
  }

  .chat-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: calc(var(--chat-mobile-height) + env(safe-area-inset-bottom));
    max-height: calc(56vh + env(safe-area-inset-bottom));
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -14px 28px rgba(0, 0, 0, 0.34);
  }

  .chat-panel.collapsed {
    left: auto;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: 64px;
    height: 64px;
    min-height: 64px;
    max-height: 64px;
    padding-bottom: 0;
  }

  body:has(.chat-panel.collapsed) {
    padding-bottom: 0;
  }

  .chat-head {
    min-height: 44px;
    padding: 7px 10px;
  }

  .chat-panel.collapsed .chat-head {
    width: 64px;
    height: 64px;
    min-height: 64px;
  }

  .chat-panel.collapsed .chat-collapse {
    width: 56px;
    height: 56px;
  }

  .chat-head .eyebrow {
    display: none;
  }

  .chat-head h2 {
    margin: 0;
    font-size: 15px;
  }

  .chat-status {
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-messages {
    max-height: calc(7 * 1.35em + 20px);
    padding: 8px 10px;
    font-size: 14px;
  }

  .chat-message {
    padding: 8px 9px;
    line-height: 1.35;
  }

  .chat-message.user,
  .chat-message.assistant {
    margin-left: 0;
    margin-right: 0;
  }

  .chat-form {
    padding: 8px 10px;
  }

  .chat-form textarea {
    height: 48px;
    padding: 8px 9px;
    resize: none;
  }
}
