:root {
  --bg: #0f1412;
  --panel: #171d1a;
  --card: #1d2621;
  --line: #2c3932;
  --text: #e8f0ea;
  --muted: #8aa193;
  --accent: #d6ff4b;
  --accent-2: #3dd6c3;
  --danger: #ff6b6b;
  --warn: #ffb020;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 214, 195, 0.12), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(214, 255, 75, 0.08), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: "Syne", sans-serif;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.rail {
  border-right: 1px solid var(--line);
  background: rgba(15, 20, 18, 0.92);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #102018; font-weight: 800; display: grid; place-items: center;
}
.brand-name { font-weight: 800; letter-spacing: 0.02em; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 8px; }
.nav-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.nav-item.active {
  color: #102018;
  background: var(--accent);
  border-color: #b6e030;
}

.rail-foot { margin-top: auto; color: var(--muted); font-size: 12px; font-family: "IBM Plex Mono", monospace; }
.muted { color: var(--muted); font-size: 12px; font-family: "IBM Plex Mono", monospace; }

.main { padding: 24px 28px 36px; overflow-x: hidden; }
.panel { display: none; animation: fade .25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none;} }

.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 22px; gap: 16px; flex-wrap: nowrap;
}
.panel-head h1 {
  margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.02em;
  flex: 1; min-width: 0;
}
.head-actions {
  display: flex; gap: 10px; align-items: center;
  flex-shrink: 0;
}

input, textarea, select, .btn {
  font: inherit;
}
input, textarea, select {
  width: 100%;
  background: #121815;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
}
.head-actions select,
.head-actions input {
  width: auto;
  min-width: 132px;
  flex: 0 0 auto;
}
textarea {
  resize: vertical;
  line-height: 1.5;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
}
label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.model-desc {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #151b18;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  min-height: 64px;
}

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 700;
  flex-shrink: 0;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary {
  background: var(--accent);
  color: #102018;
  border-color: #c5ef45;
}
.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.kpi {
  background: linear-gradient(180deg, #222c27, var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value {
  margin-top: 8px;
  font-size: 26px;
  font-weight: 800;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: -0.03em;
}
.kpi .hint { margin-top: 4px; color: var(--accent-2); font-size: 12px; }

.gate-card {
  margin-bottom: 14px;
}
.gate-body {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 18px;
  align-items: center;
  min-height: 72px;
}
.gate-rate {
  text-align: center;
}
.gate-rate .num {
  font-size: 36px;
  font-weight: 800;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: -0.03em;
  color: var(--accent);
}
.gate-rate .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}
.gate-bars { display: flex; flex-direction: column; gap: 10px; }
.gate-row {
  display: grid;
  grid-template-columns: 72px 1fr 48px 64px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}
.gate-row .pct {
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
  color: var(--muted);
  font-size: 12px;
}
.gate-track { height: 10px; background: #121815; border-radius: 999px; overflow: hidden; }
.gate-fill { height: 100%; border-radius: 999px; }
.gate-fill.need_reply { background: var(--accent); }
.gate-fill.ignore { background: #5a6b62; }
.gate-fill.human { background: var(--warn); }

.dash-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  grid-template-rows: minmax(300px, 1fr) minmax(260px, 1fr);
  gap: 14px;
  min-height: calc(100vh - 320px);
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.dash-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.card-head h2,
.card h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.badge {
  font-size: 11px;
  font-weight: 600;
  color: #102018;
  background: var(--accent-2);
  border-radius: 999px;
  padding: 2px 8px;
  flex-shrink: 0;
}

.chart-legend {
  display: flex; gap: 14px; margin-bottom: 10px;
  color: var(--muted); font-size: 12px;
  flex-shrink: 0;
}
.chart-legend .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle;
}
.dot.replies { background: var(--accent); }
.dot.latency { background: var(--warn); }
.dot.tokens { background: var(--accent-2); }
.dot.cost { background: #c084fc; }

.chart {
  display: flex;
  align-items: stretch;
  gap: 6px;
  height: 100%;
  min-height: 180px;
}
.bar-col {
  flex: 1 1 0;
  min-width: 36px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.bar-stack {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
}
.bar {
  width: 8px;
  border-radius: 6px 6px 3px 3px;
  min-height: 3px;
  transition: height .25s ease;
  align-self: flex-end;
}
.bar.replies { background: linear-gradient(180deg, var(--accent), #9bcf2a); }
.bar.latency { background: linear-gradient(180deg, var(--warn), #d4890a); }
.bar.tokens { background: linear-gradient(180deg, var(--accent-2), #1fa896); }
.bar.cost { background: linear-gradient(180deg, #c084fc, #8b5cf6); }
.bar-meta {
  flex-shrink: 0;
  text-align: center;
  line-height: 1.25;
}
.bar-label {
  font-size: 10px; color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  white-space: nowrap;
}
.bar-cost {
  font-size: 9px;
  color: #c084fc;
  font-family: "IBM Plex Mono", monospace;
  white-space: nowrap;
}

.intent-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  justify-content: space-evenly;
}
.intent-row {
  display: grid;
  grid-template-columns: 76px 1fr 36px;
  gap: 8px 10px;
  align-items: center;
  font-size: 13px;
  padding: 10px 12px;
  background: #151b18;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.intent-row .label { font-weight: 700; }
.intent-row .count {
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
  color: var(--accent-2);
}
.intent-row .meta {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  font-family: "IBM Plex Mono", monospace;
}
.intent-track { height: 8px; background: #0f1412; border-radius: 999px; overflow: hidden; }
.intent-fill { height: 100%; background: var(--accent-2); border-radius: 999px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  height: auto;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 6px;
  border-bottom: 1px solid var(--line);
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.data-table td { font-family: "IBM Plex Mono", monospace; font-size: 12px; }
.data-table td.name { font-family: "Syne", sans-serif; font-weight: 600; }
.data-table tr:last-child td { border-bottom: 0; }

.recent-list {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.recent-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  flex: 1;
  align-content: center;
  min-height: 52px;
}
.recent-item:last-child { border-bottom: 0; }
.recent-item:hover .name { color: var(--accent); }
.recent-item .name { font-weight: 700; }
.recent-item .meta { color: var(--muted); font-size: 12px; font-family: "IBM Plex Mono", monospace; grid-column: 1 / -1; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: rgba(61,214,195,.15); color: var(--accent-2);
  align-self: start;
}
.tag.warn { background: rgba(255,176,32,.15); color: var(--warn); }

.editor-layout, .session-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 14px;
  min-height: 70vh;
}
.session-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 70vh;
  min-width: 0;
}
.filter-tabs { display: flex; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: #121815;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}
.chip.active {
  background: var(--accent);
  color: #102018;
  border-color: #c5ef45;
}
.composer textarea { width: 100%; }
.composer-meta {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-family: "IBM Plex Mono", monospace;
}
.composer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.hidden { display: none !important; }
.transcript { flex: 1; max-height: none; min-height: 320px; overflow: auto; }
.list {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 75vh;
}
.list-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 14px 14px;
  cursor: pointer;
  font: inherit;
}
.list-item:hover, .list-item.active { background: rgba(214, 255, 75, 0.08); }
.list-item .t { font-weight: 700; }
.list-item .s { color: var(--muted); font-size: 12px; margin-top: 4px; font-family: "IBM Plex Mono", monospace; }

.bubble {
  max-width: 85%;
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.user { background: #24312b; margin-left: 0; }
.bubble.assistant { background: rgba(61, 214, 195, 0.12); border: 1px solid rgba(61,214,195,.25); margin-left: auto; }
.bubble.note {
  max-width: 100%;
  margin: 12px 0;
  background: rgba(255, 176, 32, 0.08);
  border: 1px dashed rgba(255, 176, 32, 0.45);
  color: #f0d9a0;
  font-size: 13px;
}
.bubble.note::before {
  content: "客服备注";
  display: inline-block;
  margin-bottom: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(255, 176, 32, 0.2);
  color: var(--warn);
  font-size: 11px;
  font-weight: 700;
}
.bubble .meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  font-family: "IBM Plex Mono", monospace;
}

.toast {
  position: fixed; right: 20px; bottom: 20px;
  background: var(--accent); color: #102018;
  padding: 12px 16px; border-radius: 12px; font-weight: 700;
  box-shadow: var(--shadow);
}
.toast.hidden { display: none; }
.toast.error { background: var(--danger); color: white; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: relative; height: auto; }
  .kpi-grid, .dash-grid, .editor-layout, .session-layout { grid-template-columns: 1fr; }
  .dash-grid { grid-template-rows: none; min-height: 0; }
  .dash-card { height: auto; min-height: 260px; }
  .gate-body { grid-template-columns: 1fr; }
  .panel-head { flex-wrap: wrap; }
}
