*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #222;
  background: #fff;
  margin: 0;
}

nav {
  background: #1a1a2e;
  padding: 0.5rem 1.5rem;
  display: flex;
  gap: 1.5rem;
  align-items: center;
}
nav a { color: #ddd; text-decoration: none; font-weight: 500; }
nav a:hover { color: #fff; text-decoration: underline; }

main { padding: 1rem 1.5rem; max-width: 1400px; margin: 0 auto; }

h1 { font-size: 1.4rem; margin: 0.75rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; border-bottom: 1px solid #e8e8e8; padding-bottom: 0.2rem; color: #333; }

/* ── Filters form ─────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
  align-items: center;
}
.filters input, .filters select {
  padding: 0.3rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 13px;
}
.filters button {
  padding: 0.3rem 0.9rem;
  background: #1a1a2e;
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
}
.filters button:hover { background: #2d2d5e; }
.filters a { color: #666; font-size: 0.85em; text-decoration: none; }
.filters a:hover { text-decoration: underline; }

/* ── Table ────────────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 1rem;
}
th {
  background: #f2f2f2;
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 2px solid #ddd;
  white-space: nowrap;
  font-weight: 600;
}
td {
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
tr:hover td { background: #fafafa; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badges { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.badges a {
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  background: #e6f4ea;
  color: #1e7e34;
  border-radius: 2px;
  text-decoration: none;
  font-weight: 500;
}
.badges a:hover { background: #c8e6c9; }
.badge-llm {
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  background: #e8f0fe;
  color: #1a56db;
  border-radius: 2px;
  font-weight: 500;
}
.badge-llm-outdated {
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  background: #fff3cd;
  color: #7c5800;
  border-radius: 2px;
  font-weight: 500;
}
.dim { font-size: 0.72rem; padding: 0.1rem 0.35rem; color: #bbb; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 1rem; align-items: center; margin: 0.75rem 0 1.5rem; }
.pagination a { color: #1a56db; text-decoration: none; }
.pagination a:hover { text-decoration: underline; }
.pagination span { color: #555; font-size: 0.9em; }

/* ── Detail metadata table ────────────────────────────────────────────────── */
.metadata { width: auto; max-width: 800px; margin-bottom: 1rem; }
.metadata th {
  font-weight: 600;
  white-space: nowrap;
  color: #555;
  width: 200px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f8f8f8;
}
.metadata td { font-family: ui-monospace, monospace; font-size: 13px; }
.provenance { float: right; white-space: nowrap; margin-left: 1.5em; color: #888; font-size: 0.85em; }
.field-history { display: block; clear: both; }

/* ── Pre / code ───────────────────────────────────────────────────────────── */
pre {
  background: #f5f5f5;
  padding: 0.9rem 1rem;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid #e8e8e8;
}

/* ── Detail sections ──────────────────────────────────────────────────────── */
section { margin-bottom: 2rem; }
.md-body { max-width: 820px; line-height: 1.7; }
.md-body p { margin: 0.5rem 0; }
.md-body h1, .md-body h2, .md-body h3 { margin: 1rem 0 0.3rem; }

/* ── Messages ─────────────────────────────────────────────────────────────── */
.error { color: #c0392b; font-weight: 600; }
.warning {
  background: #fffbec;
  border: 1px solid #f0c040;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  color: #7a5c00;
}

/* ── Search excerpts ──────────────────────────────────────────────────────── */
.excerpt-row td {
  background: #fffdf0;
  font-style: italic;
  color: #555;
  padding-top: 0;
}
.excerpt-row mark { background: #ffe580; font-style: normal; }

/* ── iframe ───────────────────────────────────────────────────────────────── */
iframe { border: 1px solid #ccc; border-radius: 4px; display: block; }

/* ── Audio speaker button ─────────────────────────────────────────────────── */
.btn-audio {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.15rem;
  line-height: 1;
  opacity: 0.55;
  transition: opacity 0.1s;
}
.btn-audio:hover { opacity: 1; }
.btn-audio-active { opacity: 1; }

/* ── Floating audio player ────────────────────────────────────────────────── */
#audio-player {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  background: #1a1a2e;
  color: #eee;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  gap: 0.7rem;
  z-index: 1000;
  max-width: 480px;
}
#audio-player[hidden] { display: none; }
#audio-label { font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
#audio-el { height: 32px; }
#audio-close {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}
#audio-close:hover { color: #fff; }

/* Extraction span highlighting */
mark.ext { border-radius: 2px; opacity: 0.85; }
mark.ext-case_wallet    { background: #bfdbfe; } /* blue-200 */
mark.ext-order_annotation { background: #bbf7d0; } /* green-200 */
mark.ext-wallet_address { background: #fde68a; } /* amber-200 */
mark.ext-amount         { background: #fecaca; } /* red-200 */
mark.ext-other          { background: #e9d5ff; } /* purple-200 */
mark.ext-crypto_mention { background: #fed7aa; } /* orange-200 — legacy */
mark.ext-crypto_high    { background: #fb923c; } /* orange-400 — confidence 8-10 */
mark.ext-crypto_mid     { background: #fed7aa; } /* orange-200 — confidence 5-7 */
mark.ext-crypto_low     { background: #ffedd5; } /* orange-100 — confidence 2-4 */
mark.ext-crypto_min     { background: #e5e7eb; } /* gray-200   — confidence 0-1 */
mark.ext-unverified     { background: #fef9c3; border-bottom: 2px dashed #d97706; } /* yellow-100 + amber dashed */
.quote-link             { cursor: pointer; }
.conf-badge             { display:inline-block; min-width:1.6em; text-align:center; padding:1px 5px; border-radius:3px; font-size:0.78em; font-weight:700; }
.conf-badge.conf-high   { background:#fb923c; color:#431407; }
.conf-badge.conf-mid    { background:#fed7aa; color:#92400e; }
.conf-badge.conf-low    { background:#ffedd5; color:#92400e; }
.conf-badge.conf-min    { background:#e5e7eb; color:#6b7280; }
@keyframes mark-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(217,119,6,0.7); }
  60%  { box-shadow: 0 0 0 7px rgba(217,119,6,0);   }
  100% { box-shadow: 0 0 0 0   rgba(217,119,6,0);   }
}
.mark-target { animation: mark-pulse 0.7s ease-out 2; }

.unverified-panel { border-left: 3px solid #f59e0b; padding-left: 1rem; }
.unverified-panel h2 { color: #92400e; }
.warning-panel { border-left: 3px solid #f59e0b; padding: 0.5rem 1rem; background: #fffbeb; color: #78350f; margin-bottom: 1rem; }
.unverified-span-link { cursor: pointer; border-radius: 3px; padding: 1px 2px; }
.unverified-span-link:hover { background: #fef3c7; }

/* ── Small action buttons / links ─────────────────────────────────────────── */
.btn-small, button.btn-small {
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #f5f5f5;
  color: #333;
  text-decoration: none;
  cursor: pointer;
  display: inline-block;
}
.btn-small:hover, button.btn-small:hover { background: #e8e8e8; }

/* ── Collapsible sections ─────────────────────────────────────────────────── */
.section-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85em;
  padding: 0 4px;
  color: #888;
  vertical-align: middle;
  line-height: 1;
}
.section-toggle:hover { color: #333; }

/* ── Inline annotation edit ───────────────────────────────────────────────── */
.btn-inline-edit {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85em;
  opacity: 0.35;
  padding: 0 2px;
  vertical-align: middle;
  line-height: 1;
}
.btn-inline-edit:hover { opacity: 1; }
.field-edit-form { display: inline-flex; gap: 0.3rem; align-items: center; flex-wrap: wrap; }
.field-edit-form input,
.field-edit-form select,
.field-edit-form textarea {
  font-size: 13px;
  padding: 0.15rem 0.35rem;
  border: 1px solid #aaa;
  border-radius: 3px;
}
.field-edit-form textarea { width: 24rem; height: 3.5rem; resize: vertical; }
.field-edit-form button {
  padding: 0.1rem 0.45rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #f0f0f0;
  cursor: pointer;
  font-size: 13px;
}
.field-edit-form button:hover { background: #e0e0e0; }
.field-edit-form button:disabled { opacity: 0.5; cursor: default; }

/* ── Retry LLM panel ──────────────────────────────────────────────────────── */
.retry-llm-panel {
  margin: 0.75rem 0;
  padding: 0.75rem 1rem;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 4px;
}
.retry-llm-panel select { font-size: 13px; padding: 0.2rem 0.4rem; margin-right: 0.5rem; }
.retry-llm-panel textarea {
  display: block;
  width: 100%;
  max-width: 600px;
  height: 4rem;
  margin: 0.5rem 0;
  font-size: 13px;
  padding: 0.3rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  resize: vertical;
}
.retry-llm-panel .llm-status { font-style: italic; color: #666; margin-left: 0.5rem; }
.btn-edit {
  font-size: 0.8rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #f5f5f5;
  color: #333;
  text-decoration: none;
  cursor: pointer;
  margin-left: 0.5rem;
  display: inline-block;
}
.btn-edit:hover { background: #e8e8e8; text-decoration: none; }

/* ── Crypto mention selection toolbar ─────────────────────────────────────── */
#cm-toolbar {
  position: fixed;
  z-index: 1010;
  background: #1a1a2e;
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  display: none;
}
#cm-toolbar button {
  background: none;
  border: none;
  color: #eee;
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  padding: 0;
}
#cm-toolbar button:hover { color: #fff; text-decoration: underline; }

/* ── Crypto mention add panel (fixed bottom) ──────────────────────────────── */
#cm-add-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1009;
  background: #1a1a2e;
  color: #eee;
  padding: 0.75rem 1.5rem 1rem;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.35);
  display: none;
}
#cm-add-panel label { font-size: 0.82rem; color: #aaa; margin-right: 0.3rem; }
#cm-add-quote-preview {
  font-style: italic;
  font-size: 0.85rem;
  color: #aaa;
  margin-bottom: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#cm-add-error { color: #f87171; font-size: 0.85rem; margin: 0.3rem 0; display: none; }
#cm-add-panel .field-edit-form { margin: 0.4rem 0; align-items: flex-start; }
#cm-add-panel .field-edit-form select,
#cm-add-panel .field-edit-form input,
#cm-add-panel .field-edit-form textarea {
  background: #2d2d5e; color: #eee; border-color: #555;
}
#cm-add-panel .field-edit-form button {
  background: #2d2d5e; color: #eee; border-color: #555;
}
#cm-add-panel .field-edit-form button:hover { background: #3d3d7e; }

/* ── Fix-mode message bar (fixed top) ────────────────────────────────────── */
#cm-fix-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1010;
  background: #7c3aed;
  color: #fff;
  padding: 0.4rem 1.5rem;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  display: none;
}
#cm-fix-bar button {
  background: none;
  border: 1px solid rgba(255,255,255,0.5);
  color: #fff;
  border-radius: 3px;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
  font-size: 0.85em;
}
#cm-fix-bar button:hover { background: rgba(255,255,255,0.15); }

/* ── Per-row action column ───────────────────────────────────────────────── */
.cm-actions { white-space: nowrap; vertical-align: middle; }
