:root {
  --bg: #0b0d12;
  --panel: #141821;
  --panel-2: #1b212d;
  --line: #262d3a;
  --text: #e8ecf3;
  --muted: #8b95a7;
  --accent: #ffcf5c;      /* projector amber */
  --accent-2: #5cc8ff;    /* cool cyan */
  --good: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 70% -10%, #171c27 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  background: rgba(11,13,18,.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 30px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.partner { color: var(--accent); font-weight: 600; }

.ingest { display: flex; gap: 8px; flex-wrap: wrap; }
.ingest input { min-width: 200px; }

main {
  max-width: 1080px; margin: 0 auto; padding: 28px;
  display: flex; flex-direction: column; gap: 22px;
}

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px;
}
.card.hero { background: linear-gradient(180deg, var(--panel-2), var(--panel)); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card h2 { margin: 0 0 4px; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0 14px; }

input, button, textarea { font: inherit; }
input[type=text] {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 10px; outline: none;
}
input[type=text]:focus { border-color: var(--accent-2); }

button {
  background: var(--accent); color: #1a1400; border: none; font-weight: 600;
  padding: 10px 16px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.small { padding: 6px 10px; font-size: 13px; }
button.danger { background: var(--danger); color: #2a0000; }

.search { display: flex; gap: 8px; }
.search input { flex: 1; }

.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 14px; }
.stat {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; min-width: 96px;
}
.stat .k { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .sub { font-size: 11px; color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px;
}
.chip.active { border-color: var(--accent); color: var(--accent); }

.results-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px; margin-top: 8px;
}
.asset {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
  cursor: pointer; text-align: left; color: inherit;
  transition: border-color .15s, transform .15s;
}
.asset:hover, .asset:focus-visible {
  border-color: var(--accent-2); transform: translateY(-1px);
  outline: none;
}
.asset .icon { font-size: 22px; }
.asset .thumb {
  width: 100%; height: 110px; object-fit: cover; border-radius: 8px;
  background: #0e121a; border: 1px solid var(--line);
}
.asset .thumb.placeholder, .asset .thumb.audio-thumb {
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 6px; font-size: 28px;
}
.asset .play-hint {
  font-size: 11px; font-weight: 700; letter-spacing: .4px;
  color: var(--accent-2); text-transform: uppercase;
}
.asset .name { font-weight: 600; font-size: 14px; word-break: break-word; }
.asset .cap { color: var(--muted); font-size: 12.5px; }
.asset .tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { background: #222a38; color: #b9c4d6; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.asset .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge.reusable { background: rgba(74,222,128,.15); color: var(--good); }
.badge.stale { background: rgba(251,191,36,.15); color: var(--warn); }
.score { font-weight: 700; color: var(--accent-2); }

.dup {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); margin-bottom: 10px;
}
.dup.clickable { cursor: pointer; }
.dup.clickable:hover { border-color: var(--accent-2); }
.dup .pair { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; min-width: 0; flex: 1; }
.dup .dist { color: var(--muted); font-size: 12px; }
.dup .actions { display: flex; gap: 8px; flex-shrink: 0; }
.dup .thumbs { display: flex; gap: 8px; flex-shrink: 0; }
.dup .thumbs img, .dup .thumbs .ph {
  width: 64px; height: 48px; object-fit: cover; border-radius: 6px;
  background: #0e121a; border: 1px solid var(--line);
}
.dup .thumbs .ph {
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.review-h { margin: 18px 0 8px; font-size: 14px; }

.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 18px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.4);
  z-index: 50; max-width: 90vw;
}
.spin { color: var(--muted); font-size: 13px; }

/* --- Live multi-agent reasoning console --- */
.card.reasoning { background: linear-gradient(180deg, #12161f, var(--panel)); }

.crew { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 16px; }
.crew .member {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px 6px 10px;
  opacity: .5; transition: opacity .25s, border-color .25s, box-shadow .25s;
}
.crew .member .ava { font-size: 18px; }
.crew .member .nm { font-size: 13px; font-weight: 600; }
.crew .member .tick { font-size: 12px; color: var(--muted); margin-left: 2px; }
.crew .member.active {
  opacity: 1; border-color: var(--accent-2);
  box-shadow: 0 0 0 1px var(--accent-2), 0 0 18px rgba(92,200,255,.25);
}
.crew .member.done { opacity: 1; border-color: var(--good); }
.crew .member.done .tick { color: var(--good); }

.reasoning-log {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 420px; overflow-y: auto; padding-right: 4px;
}
.rstep {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--line);
  border-left: 3px solid var(--line); border-radius: 10px;
  padding: 10px 14px; animation: rstep-in .28s ease;
}
@keyframes rstep-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.rstep .ricon { font-size: 18px; line-height: 1.4; }
.rstep .rbody { flex: 1; min-width: 0; }
.rstep .rhead { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rstep .ragent { font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--accent-2); }
.rstep .rtitle { font-size: 14px; font-weight: 600; }
.rstep .rdetail { color: var(--muted); font-size: 12.5px; margin-top: 2px; word-break: break-word; }
.rstep .rdot {
  width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex-shrink: 0;
  background: var(--muted);
}
.rstep.working { border-left-color: var(--accent-2); }
.rstep.working .rdot { background: var(--accent-2); animation: pulse 1s ease-in-out infinite; }
.rstep.done { border-left-color: var(--good); }
.rstep.done .rdot { background: var(--good); }
.rstep.info .rdot { background: var(--warn); }
.rstep.error { border-left-color: var(--danger); }
.rstep.error .rdot { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }

.rstep.summary { border-left-color: var(--accent); background: rgba(255,207,92,.06); }
.rstep.summary .rtitle { color: var(--accent); }

/* --- Reusability-ranked library --- */
.head-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sort-toggle {
  display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.sort-toggle .seg {
  background: var(--panel-2); color: var(--muted); border: none; border-radius: 0;
  padding: 6px 14px; font-size: 12.5px; font-weight: 600;
}
.sort-toggle .seg.active { background: var(--accent); color: #1a1400; }
.sort-toggle .seg:hover { filter: none; color: var(--text); }
.sort-toggle .seg.active:hover { color: #1a1400; }

/* Full-width band label that breaks the grid flow between reusability tiers. */
.band-label {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px;
  margin: 6px 0 2px; color: var(--muted); font-size: 12px; font-weight: 600;
  letter-spacing: .3px; text-transform: uppercase;
}
.band-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.band-label.reuse { color: var(--good); }
.band-label.unique { color: var(--warn); }

.asset .reuse-meter { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.asset .reuse-meter .track {
  flex: 1; height: 6px; border-radius: 999px; background: #222a38; overflow: hidden;
}
.asset .reuse-meter .fill { height: 100%; border-radius: 999px; }
.asset .reuse-meter .fill.hi { background: var(--good); }
.asset .reuse-meter .fill.lo { background: var(--warn); }
.asset .reuse-meter .rs { font-size: 11px; color: var(--muted); min-width: 58px; text-align: right; }
.asset .subtype { font-size: 11px; color: var(--muted); text-transform: capitalize; }

/* --- Storage Scout --- */
.storage-meter { margin: 4px 0 10px; }
.storage-meter .bar {
  height: 12px; border-radius: 999px; background: #222a38; overflow: hidden; margin-bottom: 6px;
}
.storage-meter .bar .fill { height: 100%; border-radius: 999px; background: var(--accent-2); transition: width .4s; }
.storage-meter .bar .fill.warn { background: var(--warn); }
.storage-meter .lbl { font-size: 12.5px; color: var(--muted); }
.storage-meter .lbl b { color: var(--text); }
.storage-meter .lbl .alert { color: var(--warn); font-weight: 600; }

.provider {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 6px;
}
.provider .pname { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.provider .gb { color: var(--good); font-weight: 700; }
.provider .pnote { color: var(--muted); font-size: 12.5px; }
.provider .psrc { font-size: 10px; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .3px; }
.provider .psrc.web { background: rgba(92,200,255,.15); color: var(--accent-2); }
.provider .psrc.fallback { background: rgba(139,149,167,.15); color: var(--muted); }
.provider a { color: var(--accent); font-size: 12.5px; text-decoration: none; word-break: break-all; }
.provider a:hover { text-decoration: underline; }
.provider.top { border-color: var(--good); box-shadow: 0 0 0 1px rgba(74,222,128,.25); }
.cloud-form { margin: 8px 0 12px; flex-wrap: wrap; }
.cloud-form select {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 10px;
}
.provider .connect-vendor { margin-top: 8px; align-self: flex-start; }

/* Scout's concrete offload plan — ties the web result to the ClickHouse footprint. */
.offload-plan {
  background: rgba(255,207,92,.07); border: 1px solid rgba(255,207,92,.35);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 4px;
  display: flex; flex-direction: column; gap: 8px;
}
.offload-plan .plan-head {
  font-size: 11px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; color: var(--accent);
}
.offload-plan .plan-body { color: var(--text); font-size: 14px; line-height: 1.5; }
.offload-plan button { align-self: flex-start; }
.dup .actions [data-rec] { white-space: nowrap; }

/* --- Librarian chat --- */
.chat-log {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 420px; overflow-y: auto; margin: 10px 0 12px;
  min-height: 72px;
}
.chat-row { display: flex; }
.chat-row.from-user { justify-content: flex-end; }
.bubble {
  max-width: 86%; padding: 10px 14px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  white-space: pre-wrap; font-size: 14px; line-height: 1.45;
}
.bubble.user { background: #1d2838; border-color: var(--accent-2); }
.bubble.agent { background: rgba(255,207,92,.08); border-color: var(--accent); }
.bubble.sys, .bubble.err { color: var(--muted); font-size: 13px; }
.bubble.err { color: var(--danger); }

/* Rendered Markdown for the Librarian's final answer */
.bubble.md { white-space: normal; }
.bubble.md > :first-child { margin-top: 0; }
.bubble.md > :last-child { margin-bottom: 0; }
.bubble.md h1, .bubble.md h2, .bubble.md h3,
.bubble.md h4, .bubble.md h5, .bubble.md h6 {
  margin: 12px 0 6px; line-height: 1.25; font-weight: 700;
}
.bubble.md h1 { font-size: 17px; }
.bubble.md h2 { font-size: 16px; }
.bubble.md h3 { font-size: 14.5px; color: var(--accent); }
.bubble.md h4, .bubble.md h5, .bubble.md h6 { font-size: 13.5px; color: var(--muted); }
.bubble.md p { margin: 6px 0; }
.bubble.md ul, .bubble.md ol { margin: 6px 0; padding-left: 20px; }
.bubble.md li { margin: 2px 0; }
.bubble.md hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.bubble.md code {
  background: rgba(92,200,255,.10); padding: 1px 5px; border-radius: 5px;
}
.bubble.md table {
  border-collapse: collapse; width: 100%; margin: 8px 0;
  font-size: 13px; display: block; overflow-x: auto;
}
.bubble.md th, .bubble.md td {
  border: 1px solid var(--line); padding: 5px 9px; text-align: left;
}
.bubble.md th { background: rgba(255,255,255,.04); font-weight: 700; }
.chat-form { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-form input { flex: 1; }
button.golden {
  margin-top: 10px; border-color: var(--accent); color: var(--accent);
}
.tool {
  width: 100%; background: #10141c; border: 1px dashed var(--line);
  border-radius: 10px; padding: 8px 12px;
}
.tool.mcp { border-color: var(--accent-2); background: rgba(92,200,255,.06); }
.tool .tname {
  font-size: 11px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; color: var(--accent-2);
}
.tool pre {
  margin: 6px 0 0; white-space: pre-wrap; word-break: break-word;
  font: 11.5px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted); max-height: 140px; overflow: auto;
}
#mcp-badge { font-size: 12px; font-weight: 600; }
#mcp-badge.ok { color: var(--good); }
#mcp-badge.bad { color: var(--danger); }

/* --- Multi-agent trace: agent badges + delegation --- */
.agent-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .3px;
  padding: 1px 8px; border-radius: 999px; margin-right: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
  text-transform: none;
}
.agent-badge.analyst   { border-color: var(--accent-2); color: var(--accent-2); }
.agent-badge.archivist { border-color: var(--muted); color: var(--text); }
.agent-badge.scout     { border-color: var(--good); color: var(--good); }
.agent-badge.curator   { border-color: var(--accent); color: var(--accent); }
.agent-badge.editor    { border-color: var(--accent); color: var(--accent); }
.agent-badge.librarian { border-color: var(--line); color: var(--text); }

.bubble.agent .agent-badge { margin-bottom: 8px; }
.bubble.md .md-body { display: block; }
.bubble.md .md-body > :first-child { margin-top: 0; }
.bubble.md .md-body > :last-child { margin-bottom: 0; }

.delegate {
  width: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: rgba(255,207,92,.06); border: 1px dashed var(--accent);
  border-radius: 10px; padding: 8px 12px; font-size: 12.5px;
}
.delegate .arrow { color: var(--muted); font-size: 12px; }

/* --- Assemble a cut: storyboard/timeline --- */
.card.assemble { background: linear-gradient(180deg, #16121f, var(--panel)); }
#assemble-trace:empty { display: none; }
#assemble-trace { margin: 10px 0; }
#search-trace:empty { display: none; }
#search-trace { margin: 10px 0; max-height: 280px; }
#search-crew:empty { display: none; }
.storyboard:empty { display: none; }
.seq-head { margin: 8px 0 12px; }
.seq-title { font-size: 18px; font-weight: 800; color: var(--accent); }
.seq-log { color: var(--text); font-size: 13.5px; margin-top: 2px; }
.seq-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.timeline {
  display: flex; align-items: stretch; gap: 6px; overflow-x: auto;
  padding: 6px 2px 12px; scroll-snap-type: x proximity;
}
.timeline .shot {
  flex: 0 0 190px; scroll-snap-align: start;
  background: #0e121a; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; display: flex; flex-direction: column; gap: 6px;
}
.timeline .shot .beat {
  align-self: flex-start; font-size: 10.5px; font-weight: 800; letter-spacing: .5px;
  text-transform: uppercase; color: #1a1400; background: var(--accent);
  padding: 2px 8px; border-radius: 999px;
}
.timeline .shot .thumb {
  width: 100%; height: 96px; object-fit: cover; border-radius: 8px; background: #0b0d12;
}
.timeline .shot .icon {
  width: 100%; height: 96px; display: flex; align-items: center; justify-content: center;
  font-size: 34px; background: var(--panel-2); border-radius: 8px;
}
.timeline .shot .shot-top { display: flex; justify-content: space-between; align-items: center; }
.timeline .shot .dur { font-size: 12px; font-weight: 700; color: var(--accent-2); }
.timeline .shot .action { font-size: 13px; font-weight: 600; }
.timeline .shot .why { font-size: 12px; color: var(--muted); }
.timeline .shot .fname { font-size: 10.5px; color: var(--muted); word-break: break-all; margin-top: auto; }
.timeline .cut { align-self: center; color: var(--muted); font-size: 14px; flex: 0 0 auto; }
.music {
  margin: 6px 0; padding: 8px 12px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px;
}
.gaps { margin-top: 10px; }
.gaps-h { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
  color: var(--warn); margin-bottom: 6px; }
.gaps .gap {
  font-size: 12.5px; color: var(--text); padding: 6px 10px; margin-bottom: 6px;
  background: rgba(251,191,36,.06); border: 1px dashed rgba(251,191,36,.35); border-radius: 8px;
}
.gaps .gap b { color: var(--warn); }
code { font-size: 12px; color: var(--accent-2); }

/* --- Pagination --- */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-top: 14px;
}
.pager:empty { display: none; }
.pg-info { color: var(--muted); font-size: 12.5px; }
.pg-btns { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.pager .pg {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  min-width: 36px;
}
.pager .pg[aria-current="page"] {
  background: var(--accent); color: #1a1400; border-color: var(--accent);
}
.pager .pg:disabled { opacity: .45; cursor: default; }
.pg-ellipsis { color: var(--muted); padding: 0 4px; }

/* --- Lightbox / asset inspector --- */
.lightbox {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.lightbox[hidden] { display: none; }
.lb-backdrop {
  position: absolute; inset: 0; background: rgba(5, 7, 12, .78);
  backdrop-filter: blur(6px);
}
.lb-panel {
  position: relative; z-index: 1;
  width: min(860px, 96vw); max-height: 92vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 18px 22px; box-shadow: 0 24px 80px rgba(0,0,0,.5);
}
.lb-close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 36px; height: 36px; border-radius: 999px; padding: 0;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  font-size: 22px; line-height: 1;
}
.lb-media {
  background: #0b0d12; border-radius: 12px; overflow: hidden;
  min-height: 160px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.lb-media img, .lb-media video {
  display: block; width: 100%; max-height: 52vh; object-fit: contain; background: #000;
}
.lb-media audio { width: 90%; margin: 28px 0; }
.lb-media .lb-empty {
  color: var(--muted); text-align: center; padding: 36px 16px; font-size: 14px;
}
.lb-media .lb-empty .icon { font-size: 42px; display: block; margin-bottom: 8px; }
.lb-meta .name { font-size: 18px; font-weight: 800; word-break: break-word; margin-right: 40px; }
.lb-meta .cap { color: var(--muted); font-size: 13.5px; margin: 6px 0 10px; }
.lb-kv {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px 14px; font-size: 12.5px;
}
.lb-kv .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; }
.lb-kv .v { font-weight: 600; }
@media (max-width: 640px) {
  .lb-panel { padding: 14px; }
  .dup { flex-wrap: wrap; }
  .dup .actions { width: 100%; justify-content: flex-end; }
}
