:root {
  --bg: #0c0d10;
  --bg-elev: #14161c;
  --bg-soft: #1a1d26;
  --border: #2a2e3a;
  --text: #e8e9ed;
  --muted: #8b90a0;
  --accent: #6ea8ff;
  --accent-dim: #3d6fbf;
  --clay: #d97757;
  --good: #3ecf8e;
  --warn: #e6b84d;
  --bad: #f07178;
  --user: #1e3a5f;
  --assistant: #161922;
  --radius: 14px;
  --font: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, #10121a 0%, #0c0d10 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px 10px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--clay), #8b4a32);
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-title { font-weight: 600; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 11px; font-family: var(--mono); margin-top: 2px; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 4px;
  background: var(--bg-soft);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 9px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04);
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
  font-family: var(--mono);
}

.conv-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 42vh;
  overflow: auto;
  margin-top: 10px;
}

.conv-list li button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-list li button:hover,
.conv-list li button.active {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--border);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}

.pill {
  font-size: 11px;
  font-family: var(--mono);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  width: fit-content;
}
.pill.ok { color: var(--good); border-color: #1f5c40; background: #0f241a; }
.pill.bad { color: var(--bad); border-color: #5c1f28; background: #241016; }
.pill.muted { color: var(--muted); }

.muted-link {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}
.muted-link:hover { color: var(--accent); }

/* Main */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 70% -10%, rgba(110,168,255,0.07), transparent 60%),
    var(--bg);
}

.panel {
  display: none;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.panel.active { display: flex; }

/* Tools / Learning: body fills remaining height; columns scroll inside */
.panel-browse .panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0 28px 20px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 22px 28px 12px;
  border-bottom: 1px solid transparent;
}

.panel-head h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.muted { color: var(--muted); font-size: 13px; margin-top: 4px; }

.badge {
  font-size: 11px;
  font-family: var(--mono);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge.warn { color: var(--warn); border-color: #5c4a1f; background: #241f0f; }

/* Chat messages */
.messages {
  flex: 1;
  overflow: auto;
  padding: 8px 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  align-items: start;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--mono);
  border: 1px solid var(--border);
}
.msg.user .avatar { background: var(--user); color: #cfe2ff; }
.msg.assistant .avatar { background: var(--assistant); color: var(--clay); }
.msg.system .avatar { background: #222; color: var(--muted); }

.bubble {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  line-height: 1.55;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble {
  background: linear-gradient(180deg, #1a2a42, #152235);
  border-color: #2a4060;
}

.bubble.streaming::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
  color: var(--accent);
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

.tool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
}
.chip.active { color: var(--accent); border-color: var(--accent-dim); }
.chip.done { color: var(--good); border-color: #1f5c40; }

.answer-card, .learn-card {
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #11141b;
  overflow: hidden;
}
.answer-card header, .learn-card header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.mode-pill {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 7px;
  border-radius: 6px;
  background: #2a2110;
  color: var(--warn);
  border: 1px solid #5c4a1f;
}
.mode-pill.trusted { background: #0f241a; color: var(--good); border-color: #1f5c40; }

.answer-card .headline {
  padding: 10px 12px 0;
  font-weight: 600;
  font-size: 14px;
}
.answer-card .headline.takeaway {
  font-size: 15.5px;
  line-height: 1.45;
  padding: 12px 14px 4px;
  font-weight: 650;
  color: var(--text);
}
.answer-card .headline.takeaway strong {
  color: var(--accent);
  font-weight: 700;
}
.answer-highlights {
  margin: 4px 14px 6px;
  padding-left: 18px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}
.answer-highlights li {
  margin: 3px 0;
  color: var(--muted);
}
.answer-meta {
  padding: 6px 12px 10px;
  color: var(--muted);
  font-size: 12px;
}
.answer-meta.scope-line {
  font-family: var(--font);
  font-size: 12.5px;
  padding-top: 2px;
  padding-bottom: 8px;
}
.answer-breakdown,
.answer-tech {
  border-top: 1px solid var(--border);
  padding: 0;
  font-size: 12.5px;
}
.answer-breakdown > summary,
.answer-tech > summary {
  cursor: pointer;
  padding: 9px 12px;
  color: var(--muted);
  list-style: none;
  user-select: none;
}
.answer-breakdown > summary::-webkit-details-marker,
.answer-tech > summary::-webkit-details-marker {
  display: none;
}
.answer-breakdown > summary::before,
.answer-tech > summary::before {
  content: "▸ ";
  color: var(--accent);
  font-size: 11px;
}
.answer-breakdown[open] > summary::before,
.answer-tech[open] > summary::before {
  content: "▾ ";
}
.answer-breakdown > summary:hover,
.answer-tech > summary:hover {
  color: var(--text);
  background: #151821;
}
.answer-tech-body {
  padding: 0 12px 10px;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
}
.table-more {
  padding: 6px 12px 10px;
  margin: 0;
  font-size: 11.5px;
}
.answer-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.answer-card th, .answer-card td {
  border-top: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.answer-card th {
  color: var(--muted);
  font-weight: 600;
  background: #0e1016;
  position: sticky;
  top: 0;
}
.table-wrap { max-height: 280px; overflow: auto; }

.learn-card {
  border-color: #5c3a1f;
  background: linear-gradient(180deg, #1a140f, #12110f);
}
.learn-card .prompt {
  padding: 10px 12px;
  font-size: 14px;
}
.learn-actions {
  display: flex;
  gap: 8px;
  padding: 0 12px 12px;
}
.learn-actions .btn { flex: 0 0 auto; }

/* Composer */
.composer-wrap {
  border-top: 1px solid var(--border);
  padding: 12px 28px 18px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.25));
}
.starters {
  max-width: 820px;
  margin: 0 auto 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.starter {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.starter:hover { color: var(--text); border-color: var(--accent-dim); }

.composer {
  max-width: 820px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.35);
}
.composer textarea {
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  max-height: 160px;
  min-height: 28px;
  width: 100%;
}
.composer-hint {
  max-width: 820px;
  margin: 8px auto 0;
  font-size: 11px;
}

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 11px;
  cursor: pointer;
}
.btn:hover { border-color: #3d4455; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #4d86e0, #3a6fc4);
  border-color: #2f5aa0;
  color: white;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }
.btn.good {
  background: #12402a;
  border-color: #1f5c40;
  color: var(--good);
}
.btn.bad {
  background: #3a1518;
  border-color: #5c1f28;
  color: var(--bad);
}

/* Tools / Learning panels */
.split {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  align-items: stretch;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  min-height: 0;
}
/* Column cards: fill grid cell; list body scrolls inside */
.card-col {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}
.card h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 12px;
  font-family: var(--mono);
  flex: 0 0 auto;
}

.scroll-y {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto !important;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}
.scroll-y::-webkit-scrollbar { width: 10px; }
.scroll-y::-webkit-scrollbar-thumb {
  background: #3a3f4d;
  border-radius: 8px;
  border: 2px solid var(--bg-elev);
}
.scroll-y::-webkit-scrollbar-track { background: transparent; }

.tools-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  padding-bottom: 8px;
}
.tool-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
  flex: 0 0 auto;
}
.tool-item code {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 12.5px;
}
.tool-item p {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 4px;
  line-height: 1.4;
}

.table-scroll {
  padding-right: 2px;
}
#metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
#metrics-table th, #metrics-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 8px;
  text-align: left;
  vertical-align: top;
}
#metrics-table th {
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 1;
}
#metrics-table code { font-family: var(--mono); font-size: 11.5px; color: var(--accent); }

.try-row {
  display: grid;
  grid-template-columns: 220px 1fr auto;
  gap: 10px;
  margin-bottom: 10px;
}
.try-row select, .try-row textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-family: var(--mono);
  font-size: 12.5px;
}
#try-panel {
  flex: 0 0 auto;
  max-height: 42vh;
  overflow: auto;
  margin: 0;
}
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  overflow: auto;
  max-height: 220px;
  color: #c8ccd8;
  white-space: pre-wrap;
}

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  padding-bottom: 8px;
}
.stack-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
}
.stack-item .title { font-weight: 600; font-size: 13.5px; }
.stack-item .meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11.5px;
  font-family: var(--mono);
}
.status-tag {
  display: inline-block;
  font-size: 10px;
  font-family: var(--mono);
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  color: var(--muted);
  margin-right: 6px;
}
.status-tag.open, .status-tag.proposed { color: var(--warn); border-color: #5c4a1f; }
.status-tag.confirmed, .status-tag.active { color: var(--good); border-color: #1f5c40; }

.status-tag.rejected, .status-tag.retired { color: var(--bad); border-color: #5c1f28; }

/* Learning outcome badges */
.stack-item.selected {
  border-color: #3a5a8a;
  box-shadow: inset 0 0 0 1px #2a4060;
  background: linear-gradient(180deg, #141820, var(--bg));
  cursor: pointer;
}
.stack-item[data-session-id] { cursor: pointer; }
.stack-item[data-session-id]:hover { border-color: #3a4558; }

.outcome-inline {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}
.outcome-inline-label {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}
.outcome-inline-write {
  flex: 1 1 100%;
  margin-top: 0 !important;
}

.status-tag.outcome-kind {
  text-transform: none;
  letter-spacing: 0.02em;
  color: var(--accent);
  border-color: #2a4060;
  background: #121820;
}
.status-tag.outcome-glossary {
  color: #8ec8ff;
  border-color: #2a5080;
  background: #101820;
}
.status-tag.outcome-process {
  color: #67e8f9;
  border-color: #0e7490;
  background: #0c1a1f;
}
.status-tag.outcome-metric {
  color: #9fe0b8;
  border-color: #1f5c40;
  background: #0f1a14;
}
.status-tag.outcome-both {
  color: #e0c48a;
  border-color: #5c4a1f;
  background: #1a160f;
}
.status-tag.outcome-repair {
  color: var(--clay, #e0a070);
  border-color: #5c3a1f;
  background: #1a140f;
}
.status-tag.outcome-unclear {
  color: var(--muted);
  border-color: var(--border);
}

.session-outcome {
  flex: 0 0 auto;
  margin-top: 12px;
  padding: 12px 12px 10px;
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  background: linear-gradient(180deg, #12141a, #0e1014);
}
.outcome-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.outcome-badge-label {
  font-size: 11px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.outcome-label-text {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.outcome-will-write {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
}
.outcome-gap-meta {
  margin-top: 4px;
}

.session-next-questions {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.next-q-heading {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}
.next-q-hint {
  font-size: 12px;
  margin-bottom: 8px;
}
.next-q-plain {
  margin: 0;
  padding: 10px 12px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}


.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 4px;
}

@media (max-width: 960px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .panel-browse .panel-body {
    overflow-y: auto;
    padding-left: 14px;
    padding-right: 14px;
  }
  .split {
    grid-template-columns: 1fr;
    /* on small screens, stack and let the page body scroll */
    flex: 0 0 auto;
    min-height: auto;
  }
  .card-col {
    max-height: 50vh;
    height: auto;
  }
  .try-row { grid-template-columns: 1fr; }
  .messages, .composer-wrap, .panel-head { padding-left: 14px; padding-right: 14px; }
  #try-panel { max-height: none; }
}

/* ---- Knowledge tab ---- */
.kn-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.kn-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.kn-view[hidden] { display: none !important; }

/* Create with AI banner */
.kn-ai-banner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  text-align: left;
  width: 100%;
  border: 1px solid #3a2a1a;
  border-radius: 16px;
  padding: 16px 18px;
  cursor: pointer;
  background:
    radial-gradient(600px 120px at 10% 0%, rgba(217,119,87,0.18), transparent 55%),
    linear-gradient(135deg, #1a1410 0%, #12141c 60%, #10121a 100%);
  color: var(--text);
  font: inherit;
  flex: 0 0 auto;
}
.kn-ai-banner:hover {
  border-color: #6b4630;
  filter: brightness(1.05);
}
.kn-ai-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--clay), #8b4a32);
  font-size: 18px;
  color: #fff;
}
.kn-ai-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.kn-ai-copy strong {
  font-size: 15px;
  font-weight: 600;
}
.kn-ai-copy span {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}
.kn-ai-arrow {
  color: var(--clay);
  font-size: 20px;
  font-weight: 600;
}

.kn-summary-row {
  font-size: 12px;
  font-family: var(--mono);
  flex: 0 0 auto;
}

/* 2×2 home cards */
.kn-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
}
.kn-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 16px;
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  min-height: 140px;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.kn-card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-1px);
}
.kn-card-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--accent);
}
.kn-card h3 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.kn-card p {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  flex: 1 1 auto;
}
.kn-card-stat {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  margin-top: 4px;
}

/* Metrics toolbar */
.kn-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  flex: 0 0 auto;
}
.kn-pack-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.kn-pack-pill {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--mono);
}
.kn-pack-pill:hover { color: var(--text); }
.kn-pack-pill.active {
  color: var(--text);
  border-color: var(--accent-dim);
  background: #152238;
  color: var(--accent);
}
.kn-search {
  flex: 1 1 180px;
  min-width: 160px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
}
.kn-search:focus {
  outline: none;
  border-color: var(--accent-dim);
}
.kn-list-card {
  flex: 1 1 auto;
  min-height: 0;
}

#kn-metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
#kn-metrics-table th,
#kn-metrics-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 8px;
  text-align: left;
  vertical-align: top;
}
#kn-metrics-table th {
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 1;
  font-weight: 600;
}
#kn-metrics-table tbody tr {
  cursor: pointer;
}
#kn-metrics-table tbody tr:hover {
  background: var(--bg-soft);
}
#kn-metrics-table code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
}

/* Metric detail */
.kn-detail-layout {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  align-items: stretch;
}
.kn-detail-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  min-height: 0;
}
.kn-detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.kn-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.kn-detail-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-transform: none;
  color: var(--text);
  font-family: var(--font);
  margin: 0;
}
.kn-detail-id {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  display: block;
  margin-top: 4px;
}
.kn-detail-desc {
  font-size: 13px;
  line-height: 1.45;
  margin: 0;
}
.kn-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin: 4px 0 6px;
}
.kn-meta-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
.kn-meta-item .k {
  display: block;
  font-size: 10px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 3px;
}
.kn-meta-item .v {
  font-size: 12.5px;
  font-family: var(--mono);
  word-break: break-word;
}

.kn-field-label {
  font-size: 11px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 4px;
}
.kn-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
  line-height: 1.45;
}
.kn-textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
}
.kn-textarea.kn-sql,
.kn-textarea.mono {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  min-height: 180px;
  tab-size: 2;
}

.kn-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  flex: 0 0 auto;
}
.kn-status-msg {
  font-size: 12px;
  font-family: var(--mono);
  flex: 1 1 160px;
}
.kn-status-msg.err { color: var(--bad); }
.kn-status-msg.ok { color: var(--good); }

.kn-preview-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.kn-preview-scroll {
  flex: 1 1 auto;
  min-height: 120px;
}
.kn-preview-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.kn-preview-card th,
.kn-preview-card td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.kn-preview-card th {
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 1;
}

.kn-instructions-body {
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.55;
}
.kn-instructions-body ul {
  margin: 10px 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kn-instructions-body code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

/* status badge variants used on knowledge */
.status-tag.builtin { color: var(--accent); border-color: #2a4060; }
.status-tag.exploratory { color: var(--warn); border-color: #5c4a1f; }
.status-tag.override { color: var(--clay); border-color: #5c3a1f; }

/* Glossary list + editor */
.kn-glossary-layout {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  align-items: stretch;
}
.kn-glossary-detail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  min-height: 0;
}
#kn-glossary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
#kn-glossary-table th,
#kn-glossary-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 8px;
  text-align: left;
  vertical-align: top;
}
#kn-glossary-table th {
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 1;
  font-weight: 600;
}
#kn-glossary-table tbody tr {
  cursor: pointer;
}
#kn-glossary-table tbody tr:hover {
  background: var(--bg-soft);
}
#kn-glossary-table tbody tr.selected {
  background: linear-gradient(180deg, #141820, var(--bg-soft));
  box-shadow: inset 0 0 0 1px #2a4060;
}
#kn-glossary-table code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
}
.kn-input,
.kn-select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 13px;
}
.kn-select {
  font-family: var(--mono);
  font-size: 12.5px;
  cursor: pointer;
  appearance: auto;
}
.kn-input:focus,
.kn-select:focus {
  outline: none;
  border-color: var(--accent-dim);
}

@media (max-width: 960px) {
  .kn-cards { grid-template-columns: 1fr; }
  .kn-detail-layout { grid-template-columns: 1fr; }
  .kn-glossary-layout { grid-template-columns: 1fr; }
  .tabs { grid-template-columns: 1fr 1fr; }
}

/* ===== Map (replaces Chat) ===== */
.sidebar-hint {
  font-size: 11.5px;
  line-height: 1.4;
  margin: 0 0 8px;
}
.map-tool-filters {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: calc(100vh - 320px);
  padding-right: 2px;
}
.map-filter-family {
  margin-top: 10px;
  margin-bottom: 2px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-family: var(--mono);
}
.map-tool-chip {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.map-tool-chip:hover {
  border-color: var(--accent-dim);
}
.map-tool-chip.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, #152036, var(--bg-soft));
  color: var(--accent);
  box-shadow: inset 0 0 0 1px #2a4a7a;
}

.panel-map {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-map .panel-head {
  flex: 0 0 auto;
}
.map-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 0 22px 10px;
  flex: 0 0 auto;
}
.map-stat {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}
.map-stat em {
  font-style: normal;
  color: var(--text);
  font-weight: 600;
  margin-right: 4px;
}
.map-stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 360px;
  margin: 0 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(110, 168, 255, 0.06), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(217, 119, 87, 0.05), transparent 45%),
    var(--bg-elev);
  overflow: auto;
}
.map-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 1;
}
.map-svg {
  display: block;
  min-width: 900px;
  min-height: 400px;
}
.map-layer-title {
  fill: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.map-edge {
  fill: none;
  stroke: #3a4154;
  stroke-width: 1.25;
  opacity: 0.75;
}
.map-edge-provides { stroke: #6ea8ff; opacity: 0.45; }
.map-edge-feeds_metric { stroke: #3ecf8e; opacity: 0.5; }
.map-edge-owns_metric { stroke: #8b90a0; opacity: 0.35; }
.map-edge-exposed_by,
.map-edge-used_by_tool { stroke: #d97757; opacity: 0.55; }
.map-edge-answers_via { stroke: #6ea8ff; opacity: 0.25; stroke-dasharray: 4 4; }
.map-edge-overview,
.map-edge-summarized_by { stroke: #8b90a0; opacity: 0.3; stroke-dasharray: 3 3; }

.map-node-rect {
  stroke: var(--border);
  stroke-width: 1;
}
.map-node-project .map-node-rect { fill: #1a2233; stroke: #3d6fbf; }
.map-node-table .map-node-rect { fill: #14241c; stroke: #2f8f62; }
.map-node-metric .map-node-rect { fill: #241c14; stroke: #a86b4a; }
.map-node-tool .map-node-rect { fill: #1c1828; stroke: #7a6bb0; }
.map-node.selected .map-node-rect {
  stroke-width: 2;
  filter: drop-shadow(0 0 6px rgba(110, 168, 255, 0.35));
}
.map-node-label {
  fill: var(--text);
  font-size: 11px;
  font-family: var(--mono);
  pointer-events: none;
}
.map-footer {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: start;
  padding: 12px 22px 18px;
  flex: 0 0 auto;
}
.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.lg {
  font-size: 11px;
  font-family: var(--mono);
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.lg-project { border-color: #3d6fbf; color: #9ec0ff; }
.lg-table { border-color: #2f8f62; color: #7ddeb0; }
.lg-metric { border-color: #a86b4a; color: #e0b39a; }
.lg-tool { border-color: #7a6bb0; color: #c4b6ef; }
.map-detail {
  font-size: 12.5px;
  line-height: 1.45;
  min-height: 2.5em;
}
.map-detail code,
.map-detail .mono {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
}
.kn-info-banner {
  cursor: default;
}
.request-detail {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
