/* Nerve — quiet, engineered dark. Blacks and grays with one bioelectric blue,
   in the spirit of modern power tools: depth from borders and light, not neon. */

:root {
  --bg: #0e0f11;
  --panel: #151619;
  --panel-2: #1b1d21;
  --hover: #202329;
  --text: #e8eaed;
  --muted: #9aa1ab;
  --accent: #5eb1ff;        /* bioelectric blue — actions, citations, synapses */
  --accent-soft: rgba(94, 177, 255, .12);
  --accent-2: #82c4ff;
  --ok: #43c07e;            /* approved, healthy */
  --ok-soft: rgba(67, 192, 126, .12);
  --danger: #f0647a;        /* disputed, needs review */
  --danger-soft: rgba(240, 100, 122, .12);
  --border: #26282d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  height: 100vh; display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
.accent { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
.hidden { display: none !important; }
h2, h3 { letter-spacing: -.015em; }

#login-overlay {
  position: fixed; inset: 0; z-index: 10;
  background:
    radial-gradient(ellipse 60% 45% at 50% -10%, rgba(94, 177, 255, .09), transparent),
    var(--bg);
  display: flex; align-items: center; justify-content: center;
}
#login-form {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  padding: 2.4rem; width: 340px; display: flex; flex-direction: column; gap: .7rem;
}
#login-form h1 { margin: 0; font-size: 1.5rem; letter-spacing: -.02em; }
#login-form .sub { margin: 0 0 .8rem; color: var(--muted); font-size: .9rem; }

header {
  display: flex; align-items: center; gap: 1.2rem;
  padding: .55rem 1.2rem; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.05rem; letter-spacing: -.02em; cursor: pointer; }
nav { display: flex; gap: .15rem; }
.spacer { flex: 1; }
#whoami { color: var(--muted); font-size: .85rem; }

button {
  background: var(--accent); color: #0b1420; border: 0; border-radius: 8px;
  padding: .5rem .95rem; font-weight: 600; cursor: pointer; font-size: .9rem;
  transition: filter .12s ease, background .12s ease, color .12s ease;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.ghost:hover { background: var(--hover); color: var(--text); filter: none; }
button.tab { background: transparent; color: var(--muted); font-weight: 500; border-radius: 8px; padding: .4rem .85rem; }
button.tab:hover { color: var(--text); background: var(--hover); filter: none; }
button.tab.active { background: var(--panel-2); color: var(--text); }

input {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: .55rem .8rem; font-size: .95rem;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: #6b7280; }

main { flex: 1; overflow: hidden; display: flex; }
.panel { display: none; flex: 1; flex-direction: column; padding: 1.2rem; overflow-y: auto; }
.panel.active { display: flex; }

/* ------------------------------------------------------------------ home */
.home-wrap { max-width: 1060px; margin: 0 auto; width: 100%; padding-top: 1.5rem; }
.home-head { display: flex; align-items: baseline; gap: 1.2rem; margin-bottom: .9rem; }
.home-head h2 { margin: 0; font-size: 1.25rem; }
#home-search { flex: 0 1 320px; margin-left: auto; }

.carousel-wrap { position: relative; }
.carousel {
  display: flex; gap: .9rem; overflow-x: auto; scroll-snap-type: x proximity;
  padding: .3rem .1rem .8rem; scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.wcard {
  flex: 0 0 250px; scroll-snap-align: start; cursor: pointer;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; transition: border-color .12s ease, transform .12s ease;
}
.wcard:hover { border-color: var(--accent); transform: translateY(-2px); }
.wcard .thumb { width: 100%; height: 140px; object-fit: cover; display: block; background: var(--panel-2); }
.wcard .thumb.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; font-weight: 700; color: rgba(94, 177, 255, .4);
  background:
    radial-gradient(ellipse 80% 90% at 70% -20%, rgba(94, 177, 255, .12), transparent),
    var(--panel-2);
}
.wcard-body { padding: .6rem .75rem .7rem; }
.wcard-title {
  font-size: .88rem; font-weight: 600; line-height: 1.35; margin-bottom: .45rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.4em;
}
.wcard-meta { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip {
  font-size: .68rem; font-weight: 600; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: .08rem .55rem;
}
.chip.ok-chip { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip.review-chip { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

.car-arrow {
  position: absolute; top: 40%; z-index: 2; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 50%; padding: 0;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  font-size: 1.2rem; line-height: 1; box-shadow: var(--shadow);
}
.car-arrow:hover { background: var(--hover); filter: none; }
#car-left { left: -14px; }
#car-right { right: -14px; }

#threads-section { margin-top: 2.2rem; }
.thread-row {
  display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: .55rem .8rem; margin-bottom: .45rem; font-size: .9rem;
}
.thread-title { font-weight: 600; }
.thread-meta { margin-left: auto; font-size: .8rem; }

.home-ask { margin-top: 3.2rem; text-align: center; }
.home-ask h2 { margin: 0 0 .2rem; font-size: 1.25rem; }
.home-ask p { margin: 0 0 1rem; }
#home-ask-form { display: flex; gap: .6rem; max-width: 640px; margin: 0 auto; }
#home-ask-form input { flex: 1; padding: .7rem 1rem; border-radius: 10px; }

/* ------------------------------------------------------------------ chat */
#tab-chat { max-width: 860px; margin: 0 auto; width: 100%; }
#chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; padding-bottom: 1rem; }
.msg { border-radius: 12px; padding: .85rem 1.1rem; }
.msg.q {
  background: var(--accent-soft); border: 1px solid rgba(94, 177, 255, .25);
  align-self: flex-end; max-width: 75%; white-space: pre-wrap; border-bottom-right-radius: 4px;
}
.msg.a { background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow); }

.msg.a > :first-child { margin-top: 0; }
.msg.a > :last-child { margin-bottom: 0; }
.msg.a p, .msg.a ul, .msg.a ol { margin: .55rem 0; }
.msg.a li { margin: .25rem 0; }
.msg.a h1, .msg.a h2, .msg.a h3 { font-size: 1rem; margin: 1rem 0 .35rem; }
.msg.a hr { border: 0; border-top: 1px solid var(--border); margin: .8rem 0; }
.msg.a blockquote { margin: .55rem 0; padding: .1rem .9rem; border-left: 3px solid var(--border); color: var(--muted); }

.cite {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  font-size: .72rem; font-weight: 600; line-height: 1.4;
  border-radius: 999px; padding: 0 .45rem; margin: 0 .1rem;
  vertical-align: text-top; cursor: default;
}

details.citations { margin-top: .8rem; border-top: 1px solid var(--border); padding-top: .55rem; font-size: .84rem; }
details.citations summary { cursor: pointer; color: var(--muted); font-weight: 500; user-select: none; list-style-position: inside; }
details.citations summary:hover { color: var(--accent); }
details.citations[open] summary { margin-bottom: .45rem; }
.citation-row { display: flex; gap: .5rem; align-items: baseline; color: var(--muted); margin-bottom: .35rem; }
.citation-row b { color: var(--text); font-weight: 600; }

#ask-form { display: flex; gap: .6rem; padding-top: .8rem; }
#ask-form input { flex: 1; }

/* -------------------------------------------------------- lists & detail */
.split { display: flex; gap: 1rem; flex: 1; min-height: 0; }
.list-col { width: 320px; display: flex; flex-direction: column; gap: .5rem; min-height: 0; }
.list-col .list { width: auto; flex: 1; }
.list { width: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; }
.list .item {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: .55rem .75rem; cursor: pointer; font-size: .88rem;
  transition: border-color .12s ease;
}
.list .item:hover { border-color: var(--accent); }
.list .item .type { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.detail {
  flex: 1; overflow-y: auto; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.1rem 1.3rem;
}
.claim { border-left: 3px solid var(--accent); padding: .45rem .85rem; margin: .6rem 0; background: var(--panel-2); border-radius: 0 8px 8px 0; }
.claim.disputed { border-left-color: var(--danger); background: var(--danger-soft); }
.claim .quote { color: var(--muted); font-size: .82rem; font-style: italic; }

.area-group { margin-bottom: 1.15rem; }
.area-head {
  font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); padding-bottom: .3rem; margin-bottom: .45rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; justify-content: space-between; align-items: baseline;
  transition: color .12s ease;
}
.area-head:hover { color: var(--accent); border-bottom-color: var(--accent); }
.hub-hint {
  font-size: .68rem; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-radius: 999px; padding: .05rem .5rem;
  opacity: .75; transition: opacity .12s ease;
}
.area-head:hover .hub-hint { opacity: 1; }

.nav-badge {
  display: inline-block; margin-left: .4rem; min-width: 1.3em;
  background: var(--danger-soft); color: var(--danger);
  border-radius: 999px; padding: .02rem .4rem;
  font-size: .7rem; font-weight: 700; text-align: center;
}
.review-head {
  color: var(--danger); border-bottom-color: var(--danger);
  cursor: default;
}
.review-head:hover { color: var(--danger); border-bottom-color: var(--danger); }

.hub-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .8rem; margin: .6rem 0 1rem;
}
.hub-cards .wcard { flex: none; width: auto; }
.activity-row {
  display: flex; gap: .6rem; align-items: baseline; padding: .35rem 0;
  border-bottom: 1px solid var(--border); font-size: .88rem;
}
.activity-row .muted { margin-left: auto; white-space: nowrap; }
.review-chip { background: var(--danger-soft); color: var(--danger); border-radius: 999px; padding: .05rem .5rem; font-weight: 600; }

/* ------------------------------------------------- wiki-how step cards */
.step-card {
  display: flex; gap: 1rem; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: .8rem .95rem; margin: .65rem 0;
}
.step-text { flex: 1; min-width: 0; }
.step-head { margin-bottom: .25rem; }
.step-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: .78rem; font-weight: 700; margin-right: .3rem;
}
.step-shot {
  flex: 0 0 260px; max-width: 40%; border-radius: 8px; border: 1px solid var(--border);
  cursor: zoom-in; display: block;
}
@media (max-width: 900px) { .step-card { flex-direction: column; } .step-shot { max-width: 100%; flex-basis: auto; } }

/* --------------------------------------------------- knowledge graph */
#dropzone {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  border: 1.5px dashed var(--border); border-radius: 10px;
  padding: .6rem 1rem; margin-bottom: .8rem; cursor: pointer;
  color: var(--muted); font-size: .88rem;
  transition: border-color .12s ease, background .12s ease;
}
#dropzone:hover, #dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
#upload-status { white-space: nowrap; }

#graph-panel {
  position: relative; height: 46vh; min-height: 280px; margin-bottom: 1rem;
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background:
    radial-gradient(ellipse 70% 60% at 50% 0%, rgba(94, 177, 255, .05), transparent),
    #0b0c0e;
}
#graph { position: absolute; inset: 0; }
#graph-legend {
  position: absolute; left: .8rem; bottom: .6rem; display: flex; flex-direction: column; gap: .3rem;
  font-size: .74rem; color: var(--muted); max-width: 85%;
}
.legend-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: .3rem; }
.legend-item .dot { width: .55rem; height: .55rem; border-radius: 50%; display: inline-block; }
.legend-item.toggle {
  cursor: pointer; background: rgba(21, 22, 25, .8); border: 1px solid var(--border);
  border-radius: 999px; padding: .06rem .55rem; user-select: none;
  transition: opacity .12s ease, border-color .12s ease;
}
.legend-item.toggle:hover { border-color: var(--accent); color: var(--text); }
.legend-item.toggle.off { opacity: .35; text-decoration: line-through; }
.legend-item.focus-chip {
  cursor: pointer; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: .06rem .55rem; font-weight: 600;
}
.legend-item.hint { opacity: .7; }

.diff-panel {
  margin: .5rem 0 .8rem; border: 1px solid var(--border); border-radius: 10px;
  padding: .5rem .8rem; background: var(--panel-2); font-size: .88rem;
}
.diff-panel summary { cursor: pointer; color: var(--muted); font-weight: 500; user-select: none; }
.diff-panel summary:hover { color: var(--accent); }
.diff-panel[open] summary { margin-bottom: .4rem; }
.diff-row { padding: .12rem 0; }
.diff-row.added { color: var(--ok); }
.diff-row.removed { color: var(--danger); }
.diff-row.changed { color: var(--accent); }

#policy-editor { max-width: 640px; margin-bottom: 1rem; }
#policy-editor select {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: .45rem .7rem; margin-bottom: .4rem; font-size: .9rem;
}
#policy-editor textarea { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
#policy-status { margin-left: .6rem; font-size: .85rem; }
.card-warn { border-color: var(--red, #e5534b); }
.card-warn .n { color: var(--red, #e5534b); }
#feedback-pop {
  position: fixed; top: 3.4rem; right: 1rem; z-index: 50; width: 320px;
  background: var(--panel, #1b1f27); border: 1px solid var(--border, #2a2f3a);
  border-radius: 10px; padding: .8rem; box-shadow: 0 8px 30px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: .5rem;
}
#feedback-pop.hidden { display: none; }
#feedback-pop textarea { width: 100%; font: inherit; font-size: .9rem; }
#feedback-status { margin-left: .5rem; font-size: .85rem; }
#policy-test { display: flex; gap: .4rem; align-items: center; margin: .4rem 0 .6rem; flex-wrap: wrap; }
#policy-test input { flex: 1; min-width: 140px; }
#policy-test-result { font-size: .85rem; font-weight: 600; }
#policy-test-result.test-blocked { color: var(--red, #e5534b); }
#policy-test-result.test-watched { color: var(--accent, #5eb1ff); }

/* ------------------------------------------------------------- status */
.cards { display: flex; gap: 1rem; margin-bottom: 1rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1.4rem; }
.card .n { font-size: 1.6rem; font-weight: 700; color: var(--accent); letter-spacing: -.02em; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
td, th { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }
.branch { margin: .3rem 0 .3rem 1rem; padding-left: .6rem; border-left: 2px dashed var(--accent); font-size: .88rem; }
.version { padding: .45rem .4rem; border-bottom: 1px solid var(--border); font-size: .88rem; cursor: pointer; }
.version:hover { background: var(--panel-2); }
.version.viewing { background: var(--accent-soft); border-left: 3px solid var(--accent); }
textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: .5rem .7rem; font: inherit; margin: .2rem 0 .5rem;
}
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.edit-step input.step-title { width: 100%; margin-bottom: .3rem; font-weight: 600; }
.del-step { margin-top: .2rem; font-size: .75rem; }
.edit-shot-row { display: flex; align-items: center; gap: .5rem; margin-top: .3rem; flex-wrap: wrap; }
.edit-shot { height: 64px; border-radius: 6px; border: 1px solid var(--border); }
.pick-shot, .clear-shot { font-size: .75rem; }
.frame-picker { margin-top: .5rem; }
.frame-preview img {
  width: 100%; max-height: 360px; object-fit: contain; display: block;
  background: #0b0c0e; border: 1px solid var(--border); border-radius: 8px;
}
.frame-preview > span { display: block; font-size: .74rem; margin: .25rem 0 .1rem; }
.frame-strip {
  display: flex; gap: .5rem; overflow-x: auto; padding: .5rem 0 .7rem; margin-top: .2rem;
  scrollbar-width: auto; scrollbar-color: var(--muted) var(--panel-2);
}
.frame-strip::-webkit-scrollbar { height: 10px; }
.frame-strip::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
.frame-strip::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.frame-thumb {
  flex: 0 0 200px; cursor: pointer; text-align: center;
  border: 2px solid transparent; border-radius: 8px; padding: 2px;
  transition: border-color .12s ease;
}
.frame-thumb:hover { border-color: var(--accent); }
.frame-thumb.selected { border-color: var(--accent); background: var(--accent-soft); }
.frame-thumb img { width: 100%; border-radius: 6px; display: block; }
.frame-thumb span { font-size: .68rem; color: var(--muted); }
.version .approve { margin-left: .6rem; padding: .15rem .6rem; font-size: .78rem; }
.ok { color: var(--ok); font-weight: 600; }
code { background: var(--panel-2); border: 1px solid var(--border); padding: .08rem .35rem; border-radius: 5px; font-size: .85em; }
.status-done { color: var(--ok); }
.status-error, .status-dead { color: var(--danger); }
.status-running, .status-queued { color: var(--accent); }
