:root {
  --paper: #f4f0e8;
  --ink: #20201d;
  --muted: #706a5f;
  --line: #d8d0c0;
  --panel: #fffaf0;
  --entity: #a94438;
  --concept: #28685b;
  --missing: #7a6a87;
  --accent: #b88b2d;
  --shadow: 0 16px 44px rgba(43, 35, 22, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Aptos", "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 24px;
  background: #ebe4d7;
  max-height: 100vh;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.mark {
  width: 38px;
  height: 38px;
  border: 2px solid var(--ink);
  display: inline-block;
  position: relative;
}

.mark::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 2px solid var(--accent);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: Georgia, serif;
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.topbar p,
.details p {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

select,
input[type="search"],
input[type="number"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
}

input[type="range"] {
  accent-color: var(--accent);
}

.split {
  display: grid;
  grid-template-columns: 1fr 48px;
  align-items: end;
  gap: 12px;
}

output {
  color: var(--muted);
  padding-bottom: 19px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.toggles {
  display: grid;
  gap: 10px;
  margin: 20px 0;
  color: var(--muted);
}

.legend {
  display: grid;
  gap: 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend i {
  width: 12px;
  height: 12px;
  display: inline-block;
  border-radius: 50%;
}

.legend .entity {
  background: var(--entity);
}

.legend .concept {
  background: var(--concept);
}

.legend .claim {
  background: var(--accent);
}

.legend .missing {
  background: var(--missing);
}

.stage {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 22px 28px 16px;
}

h2 {
  font-family: Georgia, serif;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.05;
}

.actions {
  display: flex;
  gap: 10px;
}

button,
.buttonLink {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.buttonLink:hover {
  border-color: var(--accent);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric {
  background: #f8f3e9;
  padding: 13px 16px;
  min-width: 0;
}

.metric strong {
  display: block;
  font-size: 23px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  overflow: hidden;
}

#graphCanvas {
  width: 100%;
  height: 100%;
  min-height: 420px;
  display: block;
  background:
    linear-gradient(rgba(32, 32, 29, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 32, 29, 0.035) 1px, transparent 1px),
    #f6efe2;
  background-size: 32px 32px;
  cursor: grab;
}

#graphCanvas:active {
  cursor: grabbing;
}

.rightPanel {
  min-width: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: #ebe4d7;
}

.tab {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
  background: var(--panel);
}

.tabPanel {
  display: none;
  min-height: 0;
  overflow: auto;
}

.tabPanel.is-active {
  display: block;
}

.viewToggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  margin-right: 8px;
}

.viewToggle-btn {
  border: 0;
  border-radius: 0;
  background: var(--panel);
  color: var(--muted);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  min-height: 38px;
}

.viewToggle-btn:hover {
  color: var(--ink);
}

.viewToggle-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.details {
  min-width: 0;
  padding: 22px;
}

.synthesis,
.lens,
.worksList {
  padding: 22px;
}

.cloud {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.cloudControls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: #f8f3e9;
}

.cloudControl {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.cloudKind {
  border: 0;
  background: var(--panel);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cloudKind:hover {
  color: var(--ink);
}

.cloudKind.is-active {
  background: var(--accent);
  color: #fff;
}

.cloudField {
  display: grid;
  gap: 4px;
}

.cloudField span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cloudField select {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
}

.cloudWords {
  padding: 18px 22px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px 12px;
  line-height: 1.15;
  overflow: auto;
}

.cloudWord {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-family: Georgia, serif;
  line-height: 1.05;
  color: var(--ink);
  transition: color 0.12s ease, transform 0.12s ease;
}

.cloudWord:hover {
  color: var(--accent);
  transform: translateY(-1px);
}

.cloudWord[data-kind="concept"] {
  color: var(--concept);
}

.cloudWord[data-kind="entity"] {
  color: var(--entity);
}

.cloudWord[data-kind="concept"]:hover,
.cloudWord[data-kind="entity"]:hover {
  color: var(--accent);
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.workCard {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  background: #f8f3e9;
  overflow: hidden;
}

.workCard-head {
  padding: 12px 14px;
  background: #ebe4d7;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.workCard-head h4 {
  font-family: Georgia, serif;
  font-size: 15px;
  margin: 0;
  line-height: 1.2;
}

.workCard-head .counts {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.workCard-body {
  display: none;
  padding: 14px;
}

.workCard.is-open .workCard-body {
  display: block;
}

.workCard.is-open .workCard-head {
  background: #e2d9c5;
}

.workSection {
  margin-bottom: 14px;
}

.workSection h5 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 6px;
  font-weight: 600;
}

.workItem {
  border-left: 3px solid var(--line);
  padding: 6px 10px;
  margin-bottom: 6px;
  background: var(--panel);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  border-radius: 0 4px 4px 0;
  transition: border-color 120ms, background 120ms;
}

.workItem:hover {
  background: #fff7e3;
}

.workItem.is-active {
  border-left-color: var(--accent);
  background: #fff5d6;
}

.workItem.claim {
  border-left-color: var(--accent);
}

.workItem.concept {
  border-left-color: var(--concept);
}

.workItem.entity {
  border-left-color: var(--entity);
}

.workItem .type-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-right: 6px;
}

.workItem .role {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  font-style: italic;
}

.argList {
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
}

.argList li {
  margin-bottom: 4px;
  color: var(--muted);
}

.argList li strong {
  color: var(--ink);
}

.limits {
  font-size: 12px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}

.limits li {
  margin-bottom: 6px;
}

.argCanvas {
  width: 100%;
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f6efe2;
  margin-top: 8px;
}

.rolledUp {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 12px;
}

.rolledUp h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 8px;
}

.rolledUp .badge {
  display: block;
  font-size: 12px;
  padding: 6px 10px;
  background: #f8f3e9;
  border-left: 3px solid var(--accent);
  margin-bottom: 6px;
  cursor: pointer;
  border-radius: 0 4px 4px 0;
}

.rolledUp .badge:hover {
  background: #fff5d6;
}

.lensWork {
  border-left: 3px solid var(--concept);
  padding: 10px 12px;
  margin-bottom: 10px;
  background: #f8f3e9;
  border-radius: 0 4px 4px 0;
}

.lensWork h4 {
  font-family: Georgia, serif;
  font-size: 14px;
  margin: 0 0 6px;
}

.lensWork .role {
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
}

.lensWork .lensName {
  font-size: 12px;
  color: var(--ink);
  margin-bottom: 4px;
}

.chat {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
}

#tabAsk.is-active {
  display: grid;
  height: 100%;
  min-height: 0;
}

.chatLog {
  padding: 16px 18px;
  overflow: auto;
  min-height: 0;
}

.chatMsg {
  margin-bottom: 14px;
  font-size: 13.5px;
  line-height: 1.45;
}

.chatMsg.user {
  border-left: 3px solid var(--accent);
  padding: 4px 10px;
  background: #fff5d6;
  border-radius: 0 4px 4px 0;
}

.chatMsg.assistant {
  border-left: 3px solid var(--concept);
  padding: 8px 12px;
  background: #f0f4f1;
  border-radius: 0 6px 6px 0;
}

.chatMsg.assistant p {
  margin: 0 0 6px;
}

.chatMsg.assistant strong, .chatMsg.assistant em {
  color: var(--ink);
}

.chatMsg.error {
  border-left: 3px solid var(--entity);
  padding: 6px 10px;
  background: #fbeae6;
  color: var(--entity);
  font-size: 12.5px;
}

.toolTrace {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.toolTrace details {
  margin-bottom: 4px;
}

.toolTrace summary {
  cursor: pointer;
  color: var(--muted);
}

.toolTrace pre {
  background: #ebe4d7;
  padding: 6px 8px;
  border-radius: 4px;
  max-height: 180px;
  overflow: auto;
  font-size: 10.5px;
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.chatForm {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  background: #ebe4d7;
  display: grid;
  gap: 8px;
}

.chatForm textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
  resize: vertical;
  font: inherit;
  min-height: 50px;
}

.chatActions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.chatStatus {
  font-size: 11px;
  color: var(--muted);
  flex: 1;
}

#chatSend {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#chatSend:disabled {
  background: var(--muted);
  border-color: var(--muted);
  cursor: not-allowed;
}

.details h3 {
  font-family: Georgia, serif;
  font-size: 22px;
  line-height: 1.1;
  margin-bottom: 10px;
}

.details dl {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 18px 0;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.evidence {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin-top: 16px;
  color: #39352e;
}

@media (max-width: 980px) {
  .shell,
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .details,
  .rightPanel {
    border: 0;
  }

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

  .workspace {
    grid-template-rows: minmax(520px, 62vh) auto;
  }

  body {
    overflow: auto;
  }

  .stage,
  .sidebar {
    height: auto;
    max-height: none;
  }
}
