:root {
  --bg: #eef0f4;
  --bg-deep: #e6e8ee;
  --surface: #fbfbfc;
  --card: #ffffff;
  --ink: #14171f;
  --ink-2: #3d4454;
  --muted: #6b7385;
  --line: #dfe3ea;
  --line-strong: #c9d0db;
  --indigo: #3d3ce0;
  --indigo-soft: #ececff;
  --indigo-ink: #2b2bc4;
  --ok: #15803d;
  --ok-soft: #e9f7ee;
  --rose: #d21f4a;
  --rose-soft: #fde8ee;
  --amber: #c27803;
  --amber-soft: #fff4dc;
  --shadow: 0 1px 0 rgba(20, 23, 31, 0.04), 0 8px 24px rgba(20, 23, 31, 0.06);
  --radius: 10px;
  --font: "IBM Plex Sans", "PingFang SC", "Noto Sans SC", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --topbar: #11131a;
  --topbar-ink: #f4f5f8;
}
html[data-theme="dark"] {
  --bg: #0b1220;
  --bg-deep: #101a2c;
  --surface: #101a2c;
  --card: #132033;
  --ink: #e6edf3;
  --ink-2: #c5d0e0;
  --muted: #8b9bb4;
  --line: #1e2b45;
  --line-strong: #2a3b5c;
  --indigo: #8b8af8;
  --indigo-soft: #1c1f4a;
  --indigo-ink: #c7c6ff;
  --shadow: none;
  --topbar: #070b14;
  --topbar-ink: #e6edf3;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  letter-spacing: -0.01em;
}
button, input { font-family: inherit; }
button { cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 56px 40px 1fr;
  height: 100%;
  min-width: 0;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 16px 0 18px;
  background: var(--topbar);
  color: var(--topbar-ink);
  flex-wrap: nowrap;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; font-weight: 600; font-size: 14px; white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: conic-gradient(from 210deg, #7c83ff, #3d3ce0 40%, #14b8a6 80%, #7c83ff);
}
.brand-sub { opacity: 0.72; font-weight: 500; }
.switch { display: flex; flex: 0 0 auto; padding: 3px; background: #1c2030; border-radius: 8px; }
.switch button {
  border: 0; background: transparent; color: #9aa3b5;
  font-size: 12.5px; font-weight: 500; padding: 6px 10px; border-radius: 6px; white-space: nowrap;
}
.switch button.on { background: #2a3148; color: #fff; }
.switch button:active { transform: scale(0.97); }
.switch .lbl-short { display: none; }
.top-search {
  flex: 1 1 140px; min-width: 0; max-width: 420px; height: 32px;
  border: 0; border-radius: 7px; background: #1c2030; color: #d7dce6; padding: 0 12px; font-size: 12.5px;
}
.ghost {
  border: 1px solid #2a3148; background: transparent; color: #c5cad6;
  border-radius: 8px; padding: 6px 10px; font-size: 12px; white-space: nowrap; flex: 0 0 auto;
}
.ghost:active { transform: scale(0.97); }
.userpill { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: 0 0 auto; font-size: 12px; color: #c5cad6; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: #3d3ce0;
  display: grid; place-items: center; font-size: 11px; font-weight: 600; color: #fff;
}
.user-meta { white-space: nowrap; line-height: 1.2; }
.user-role { color: #8b93a7; font-size: 11px; }

.scene-tabs {
  grid-column: 1 / -1;
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  min-width: 0;
}
.scene-tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 0 16px; font-size: 13px; font-weight: 600; white-space: nowrap;
  border-bottom: 2px solid transparent; height: 40px;
}
.scene-tabs button:hover { color: var(--ink); }
.scene-tabs button.on { color: var(--indigo-ink); border-bottom-color: var(--indigo); }

.nav {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 2px;
  overflow: auto;
}
.nav-label {
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); padding: 8px 10px 6px;
}
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: transparent; color: var(--ink-2);
  text-align: left; padding: 8px 10px; border-radius: 8px; font-size: 13px;
}
.nav button:hover { background: var(--bg-deep); }
.nav button.active { background: var(--indigo-soft); color: var(--indigo-ink); font-weight: 600; }
.nav .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.55; }

.main { overflow: auto; padding: 18px 22px 40px; min-width: 0; }
.crumb { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.crumb h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.03em; }
.crumb p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.row { display: grid; gap: 14px; }
.row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.row.cols-2 { grid-template-columns: 1.3fr 1fr; }
.row.cols-graph { grid-template-columns: 1.7fr 1fr; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card h2 { margin: 0; padding: 12px 14px; font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--line); }
.pad { padding: 14px; }
.kpi { padding: 14px 16px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { margin-top: 6px; font-size: 24px; font-weight: 600; letter-spacing: -0.04em; }
.kpi .s { margin-top: 4px; font-size: 12px; color: var(--muted); }

.chip { display: inline-flex; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.chip.high { background: var(--rose-soft); color: var(--rose); }
.chip.mid { background: var(--amber-soft); color: var(--amber); }
.chip.low, .chip.idle { background: var(--ok-soft); color: var(--ok); }
.chip.idle { background: var(--bg-deep); color: var(--muted); }
.chip.alert { background: var(--rose-soft); color: var(--rose); }

.idbtn {
  border: 0; background: var(--indigo-soft); color: var(--indigo-ink);
  border-radius: 6px; padding: 1px 6px; font-family: var(--mono); font-size: 11.5px;
}
.idbtn:hover { outline: 1px solid var(--indigo); }
.idbtn:active { transform: scale(0.97); }

.item {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center;
  padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--bg-deep); }
.item .t { font-size: 13.5px; font-weight: 550; }
.item .d { font-size: 12px; color: var(--muted); margin-top: 2px; }

.btn {
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  border-radius: 8px; padding: 7px 12px; font-size: 12.5px; font-weight: 550;
}
.btn:hover { background: var(--bg-deep); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--rose); border-color: var(--rose); color: #fff; }

.props { width: 100%; border-collapse: collapse; font-size: 13px; }
.props th, .props td { padding: 8px 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.props th { width: 120px; color: var(--muted); font-weight: 500; }

.graph-box { height: 460px; }
.qbar { display: flex; gap: 8px; }
.qbar input {
  flex: 1; min-width: 0; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; background: var(--card); color: var(--ink);
}
.qchips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.qchips button {
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px;
}
.qchips button.on, .qchips button:hover { border-color: var(--indigo); color: var(--indigo-ink); background: var(--indigo-soft); }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.compare .head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.rag-head { background: #f6f4f0; }
html[data-theme="dark"] .rag-head { background: #1a1730; }
.oag-head { background: var(--indigo-soft); }
.chunk { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: var(--bg); }
.chunk b { display: block; font-size: 12px; margin-bottom: 4px; }
.chunk p { margin: 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }
.gap { font-size: 12px; color: var(--rose); background: var(--rose-soft); border-radius: 6px; padding: 6px 8px; margin-top: 6px; }
.ev { padding: 6px 8px; margin: 4px 0; background: var(--bg); border-radius: 6px; font-size: 12px; cursor: pointer; }
.ev:hover { outline: 1px solid var(--indigo); }
.ev .rel { color: var(--indigo-ink); font-weight: 600; }

.form .field { margin-bottom: 10px; }
.form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form input, .form textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; background: var(--card); color: var(--ink);
}
.banner { background: var(--amber-soft); color: #7a4d00; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin-bottom: 12px; }
html[data-theme="dark"] .banner { color: #fbbf24; }
.empty { color: var(--muted); font-size: 13px; padding: 20px; }
.toast {
  position: fixed; right: 20px; bottom: 20px; background: #11131a; color: #fff;
  padding: 10px 14px; border-radius: 10px; font-size: 13px; z-index: 20;
}
.engine { font-size: 11px; color: var(--muted); margin-bottom: 8px; }

@media (max-width: 1180px) {
  .user-meta { display: none; }
}
@media (max-width: 980px) {
  .switch .lbl-full { display: none; }
  .switch .lbl-short { display: inline; }
  .brand-sub { display: none; }
  .top-search { max-width: 180px; }
}
@media (max-width: 820px) {
  .top-search { display: none; }
  .row.cols-3, .row.cols-2, .row.cols-graph, .compare { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 72px 1fr; }
  .nav button span.label { display: none; }
  .brand-name { display: none; }
}
