:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #697586;
  --line: #d9e1e8;
  --accent: #1f6f5b;
  --blue: #235c9f;
  --red: #a82f3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

a {
  color: var(--accent);
  font-weight: 750;
  text-decoration: none;
}

.layout {
  width: min(1180px, calc(100vw - 28px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
}

.chat,
.side section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chat {
  min-height: calc(100vh - 32px);
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.bar {
  min-height: 76px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 750;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 16px;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.top-actions a {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  background: #fff;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.selected-action {
  background: var(--blue);
}

.inline-trace {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 12px;
}

.messages {
  padding: 16px;
  overflow: auto;
}

.bubble {
  max-width: 78%;
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.user {
  margin-left: auto;
  background: #e6eef8;
}

.assistant {
  background: #edf5f1;
}

.system {
  max-width: 100%;
  background: #fff6df;
  color: #624b17;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 10px;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
}

.side {
  display: grid;
  gap: 14px;
  align-content: start;
}

.side section {
  padding: 14px;
}

dl {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px 12px;
  margin: 14px 0 0;
}

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

dd {
  margin: 0;
  font-weight: 700;
}

pre {
  margin: 12px 0 0;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.45;
}

.admin-layout {
  width: min(1280px, calc(100vw - 28px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.admin-header,
.asset-shell,
.asset-list,
.asset-editor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-header {
  min-height: 76px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.asset-shell {
  min-height: calc(100vh - 122px);
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 0;
  overflow: hidden;
}

.logs-shell {
  min-height: calc(100vh - 122px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.flow-shell {
  min-height: calc(100vh - 122px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.flow-grid {
  padding: 0;
  border-bottom: 1px solid var(--line);
}

.key-flow-summary {
  min-height: 72px;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 220px)) 1fr;
  align-items: center;
  gap: 26px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.key-flow-summary div {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  justify-content: start;
  column-gap: 9px;
}

.key-flow-summary span,
.key-flow-summary small {
  color: var(--muted);
  font-size: 12px;
}

.key-flow-summary strong {
  font-size: 22px;
}

.flow-error-alert {
  justify-self: end;
  padding: 6px 9px;
  border: 1px solid #d98c88;
  border-radius: 6px;
  color: #9b302c;
  background: #fff3f1;
  font-weight: 700;
}

.node-kind {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.key-flow-stages {
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(210px, 0.8fr) minmax(230px, 0.9fr) minmax(360px, 1.4fr);
  gap: 30px;
}

.key-flow-stage {
  min-height: 190px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  align-content: start;
  gap: 9px;
  position: relative;
}

.key-flow-stage:not(:last-child)::after {
  content: "→";
  position: absolute;
  right: -22px;
  top: 82px;
  color: var(--muted);
  font-weight: 800;
}

.key-flow-stage > strong {
  font-size: 18px;
}

.key-flow-stage p {
  min-height: 34px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.key-flow-stage dl {
  grid-template-columns: 1fr auto;
  margin-top: auto;
  font-size: 12px;
}

.stage-router {
  border-color: #8bb8e8;
  background: #f0f6ff;
}

.stage-retrieval {
  border-color: #a7cbbd;
  background: #f0f8f4;
}

.stage-decision {
  border-color: #d8bd7f;
  background: #fffaf0;
}

.allocation-bar {
  height: 10px;
  margin: 4px 0 6px;
  display: flex;
  overflow: hidden;
  border-radius: 5px;
  background: #e7ebef;
}

.allocation-rule {
  background: #227c67;
}

.allocation-model {
  min-width: 3px;
  background: #c58a28;
}

.allocation-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.allocation-row span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.allocation-row em {
  color: var(--muted);
  font-style: normal;
}

.allocation-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-rule {
  background: #227c67;
}

.dot-model {
  background: #c58a28;
}

.flow-detail-grid {
  padding: 14px;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
}

.flow-detail-grid > section {
  min-width: 0;
}

.trace-list {
  display: grid;
  gap: 8px;
  max-height: 620px;
  overflow: auto;
}

.trace-button {
  min-height: 74px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
  display: grid;
  gap: 4px;
}

.trace-button span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.trace-detail {
  display: grid;
  gap: 10px;
  max-height: 620px;
  overflow: auto;
}

.trace-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.trace-error {
  border-color: var(--red);
  background: #fff6f6;
}

.trace-skipped {
  opacity: 0.76;
}

details {
  margin-top: 10px;
}

summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 750;
}

.knowledge-map {
  padding: 14px;
  display: grid;
  gap: 14px;
}

.knowledge-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

.knowledge-summary article,
.knowledge-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.knowledge-summary strong {
  display: block;
  font-size: 24px;
}

.knowledge-summary span {
  color: var(--muted);
  font-size: 12px;
}

.knowledge-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.eval-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.eval-grid {
  padding: 14px;
  display: grid;
  grid-template-columns: 280px 340px minmax(0, 1fr);
  gap: 14px;
}

.review-grid {
  padding: 14px;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
}

.eval-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.eval-panel label {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.eval-panel input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  font: inherit;
}

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

.eval-report-list,
.eval-case-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  max-height: 720px;
  overflow: auto;
}

.eval-detail {
  display: grid;
  gap: 12px;
}

.eval-detail-panel {
  max-height: calc(100vh - 160px);
  overflow: auto;
}

.eval-summary {
  grid-template-columns: repeat(4, minmax(110px, 1fr));
}

.eval-risk {
  border-color: #e3aaa9;
  background: #fff9f8;
}

.selected-review {
  border-color: #9ec4f5;
  background: #edf5ff;
}

.review-detail,
.review-editor {
  display: grid;
  gap: 12px;
}

.review-editor h3 {
  margin: 0;
  font-size: 18px;
}

.review-editor label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.review-editor select {
  max-width: 240px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.review-editor textarea {
  min-height: 96px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

.review-editor textarea[readonly] {
  background: #f7f9fb;
  color: #344054;
}

.asset-mini-list {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.asset-mini-list div {
  display: grid;
  gap: 2px;
}

.asset-mini-list span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.logs-bar {
  min-height: 76px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.logs-list {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.log-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.log-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.log-head strong {
  color: var(--ink);
  font-size: 14px;
}

.log-user,
.log-reply,
.log-assets,
.empty-state {
  margin: 10px 0 0;
  line-height: 1.45;
}

.log-user {
  padding: 10px;
  border-radius: 8px;
  background: #e6eef8;
}

.log-reply {
  padding: 10px;
  border-radius: 8px;
  background: #edf5f1;
}

.log-assets {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.log-meta {
  margin-top: 10px;
}

.asset-list {
  border-width: 0 1px 0 0;
  border-radius: 0;
  padding: 14px;
  overflow: auto;
}

.asset-list-title p {
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.asset-button {
  width: 100%;
  min-height: 62px;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
  display: grid;
  gap: 4px;
}

.asset-button span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.asset-button.selected {
  border-color: var(--accent);
  background: #edf5f1;
}

.asset-editor {
  border: 0;
  border-radius: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
}

.editor-bar {
  min-height: 76px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.asset-editor textarea {
  min-height: 560px;
  resize: none;
  border: 0;
  border-radius: 0;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
}

.editor-footer {
  min-height: 42px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.status-error {
  color: var(--red);
  font-weight: 750;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .chat {
    min-height: 70vh;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .admin-header,
  .editor-bar,
  .logs-bar,
  .editor-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .asset-shell {
    grid-template-columns: 1fr;
  }

  .key-flow-summary {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .key-flow-summary div {
    grid-template-columns: 110px auto 1fr;
  }

  .key-flow-stages {
    grid-template-columns: 1fr;
  }

  .key-flow-stage:not(:last-child)::after {
    content: "↓";
    right: 50%;
    top: auto;
    bottom: -25px;
  }

  .flow-detail-grid,
  .knowledge-groups,
  .knowledge-summary {
    grid-template-columns: 1fr;
  }

  .asset-list {
    border-width: 0 0 1px;
  }
}
