:root {
  --bg: #f0f2f5;
  --sider: #001529;
  --card: #ffffff;
  --text: rgba(0, 0, 0, 0.88);
  --muted: rgba(0, 0, 0, 0.45);
  --faint: rgba(0, 0, 0, 0.25);
  --line: #f0f0f0;
  --line-strong: #d9d9d9;
  --primary: #1890ff;
  --primary-soft: #e6f7ff;
  --ok: #52c41a;
  --ok-soft: #f6ffed;
  --warn: #faad14;
  --warn-soft: #fffbe6;
  --bad: #f5222d;
  --bad-soft: #fff1f0;
  --purple: #975fe4;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  --radius: 2px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "Cascadia Mono", Consolas, ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
::selection { background: #bae0ff; }

.progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  z-index: 50;
  pointer-events: none;
}
body.is-loading .progress {
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  background-size: 36% 100%;
  animation: slide 0.9s ease-in-out infinite;
}
@keyframes slide { from { background-position: -40% 0; } to { background-position: 140% 0; } }
@media (prefers-reduced-motion: reduce) {
  body.is-loading .progress { animation: none; background: var(--primary); }
}

.sider {
  width: 216px;
  flex: none;
  background: var(--sider);
  color: rgba(255, 255, 255, 0.65);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 64px;
  padding: 0 16px;
  color: #fff;
  text-decoration: none;
}
.logo {
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  border-radius: 2px;
  transform: rotate(45deg);
  flex: none;
  margin: 0 8px 0 4px;
}
.brand-name { color: #fff; font-weight: 600; font-size: 16px; letter-spacing: 0.01em; }
.nav-label {
  margin: 4px 16px 0;
  padding-top: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.35);
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 8px 16px;
  overflow: auto;
}
.side-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  border: 0;
  border-radius: 0;
  padding: 0 16px;
  height: 40px;
  margin: 4px 0;
  cursor: pointer;
}
.side-nav button svg { width: 16px; height: 16px; flex: none; }
.side-nav button:hover { color: #fff; }
.side-nav button.active { color: #fff; background: var(--primary); }

.shell { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.top {
  height: 56px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}
.top-left, .top-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.crumb { color: var(--muted); white-space: nowrap; font-size: 14px; }
.crumb span { margin: 0 6px; color: rgba(0, 0, 0, 0.25); }
.crumb strong { color: var(--text); font-weight: 500; }
#navToggle { display: none; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: rgba(0, 0, 0, 0.65);
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.04); color: var(--text); }
.search {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  background: #f5f5f5;
  color: rgba(0, 0, 0, 0.45);
}
.search input {
  width: 128px;
  height: 28px;
  border: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}
.search input:focus { outline: none; box-shadow: none; }
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
}
.health {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--ok-soft);
  color: #389e0d;
}
.health::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.health.warn { background: var(--warn-soft); color: #d48806; }
.health.bad { background: var(--bad-soft); color: #cf1322; }
.key-box { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
input, select {
  height: 32px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.12); outline: none; }
#apiKey { width: 148px; }
button.btn, button.btn-primary, button.btn-danger, .channel-form button, .toolbar button, td button {
  height: 32px;
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
  background: #fff;
  border: 1px solid var(--line-strong);
}
button.btn-primary, .channel-form button.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
button.btn-primary:hover { background: #4096ff; border-color: #4096ff; }
button.btn:hover, td button:hover { color: var(--primary); border-color: var(--primary); }
button.btn-danger { color: #cf1322; border-color: #ffccc7; background: #fff; }
button.btn-danger:hover { background: var(--bad-soft); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.live-toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.live-toggle input { accent-color: var(--primary); width: 14px; height: 14px; }
.clock { font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.notice {
  margin: 16px 24px 0;
  background: var(--bad-soft);
  color: #a8071a;
  border: 1px solid #ffccc7;
  border-radius: var(--radius);
  padding: 10px 12px;
}

main { padding: 24px; }
.panel { display: none; }
.panel.active { display: block; }

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 24px 12px;
  box-shadow: var(--shadow);
  min-width: 0;
  min-height: 170px;
  display: flex;
  flex-direction: column;
}
.kpi .lbl { color: var(--muted); font-size: 14px; }
.kpi .val {
  margin-top: 6px;
  font-size: 30px;
  line-height: 38px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  font-variant-numeric: tabular-nums;
}
.kpi .spark { display: block; width: 100%; height: 46px; margin-top: 8px; }
.kpi .sub {
  margin-top: auto;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
}
.plot-title { margin: 12px 0 0; font-size: 14px; font-weight: 500; }
.mini-chart { height: 40px; margin-top: 6px; }
.mini-chart .spark { width: 100%; height: 40px; margin: 0; display: block; }
.foot-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.trend { font-weight: 600; margin-right: 6px; }
.trend.up { color: #cf1322; }
.trend.down { color: #389e0d; }
.trend.good { color: #389e0d; }
.trend.bad { color: #cf1322; }
.status-track { height: 8px; border-radius: 99px; background: #f5f5f5; margin: 16px 0 10px; overflow: hidden; }
.status-track > span { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.status-track.bad > span { background: var(--bad); }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  gap: 16px;
}
.span-16 { grid-column: span 16; }
.span-14 { grid-column: span 14; }
.span-10 { grid-column: span 10; }
.span-8 { grid-column: span 8; }
.span-24 { grid-column: span 24; }
.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 24px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
  margin-bottom: 16px;
}
#dlqCard[hidden] { display: none; }
#dashDlq td:nth-child(2) { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-grid > .card, .grid-2 > .card { margin-bottom: 0; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.card h2, .subhead {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.subhead { margin: 18px 0 8px; font-size: 14px; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.head-actions, .toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar { margin-bottom: 12px; }
.card-head .toolbar { margin: 0; }
.toolbar label, .channel-form label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.channel-form label { flex-direction: column; align-items: stretch; }
.channel-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
  margin-top: 12px;
}
.channel-form .check { flex-direction: row; align-items: center; }
.channel-form input { width: 100%; }

.text-tabs { display: flex; gap: 4px; }
.text-tabs button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 6px 12px 8px;
  cursor: pointer;
  border-radius: 0;
}
.text-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.seg {
  display: inline-flex;
  padding: 2px;
  background: #f5f5f5;
  border-radius: 6px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 4px;
  padding: 4px 10px;
  height: 28px;
  cursor: pointer;
}
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }

.chart { position: relative; height: 260px; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart-tip {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  z-index: 2;
  white-space: nowrap;
  color: var(--text);
}
.chart-tip b { font-weight: 600; }

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding-bottom: 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.pair .lbl { display: block; color: var(--muted); font-size: 13px; }
.pair strong { display: block; margin-top: 6px; font-size: 24px; font-weight: 500; letter-spacing: -0.02em; }

.rank { list-style: none; margin: 8px 0 0; padding: 0; }
.rank li { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.rank-no {
  width: 20px; height: 20px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: #f5f5f5;
  color: var(--muted);
  font-size: 12px;
  flex: none;
}
.rank-no.top { background: var(--primary); color: #fff; }
.rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank b { font-variant-numeric: tabular-nums; font-weight: 500; }

.share {
  display: flex;
  align-items: center;
  gap: 12px;
}
.donut { width: 160px; height: 160px; flex: none; }
.donut-val { font: 500 18px var(--sans); fill: rgba(0, 0, 0, 0.88); }
.donut-lbl { font: 12px var(--sans); fill: rgba(0, 0, 0, 0.45); }
.share-list { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; }
.share-list li {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 7px 0;
  font-size: 14px;
}
.share-list i { width: 8px; height: 8px; border-radius: 50%; }
.share-list em { color: var(--muted); font-style: normal; font-variant-numeric: tabular-nums; }
.share-list b { font-weight: 500; font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.stat-list { margin-top: 8px; }
.stat {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.stat span { color: var(--muted); }
.stat b { font-weight: 600; font-variant-numeric: tabular-nums; }

.dlq-layout { display: grid; grid-template-columns: minmax(200px, 280px) 1fr; gap: 20px; align-items: start; }
#dlqCard.is-clear .dlq-layout { grid-template-columns: 1fr; }
#dlqCard.is-clear .table-wrap { display: none; }
.reason { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; margin-bottom: 12px; font-size: 13px; }
.reason span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.reason b { font-variant-numeric: tabular-nums; }
.track, .bar, .meter { height: 6px; background: #f5f5f5; border-radius: 99px; overflow: hidden; }
.track { grid-column: 1 / -1; }
.track > span { display: block; height: 100%; background: var(--bad); }
.bar > span { display: block; height: 100%; background: var(--primary); }
.meter { width: 72px; display: inline-block; vertical-align: middle; margin-right: 8px; }
.meter > span { display: block; height: 100%; background: var(--primary); }
.reason-inline { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bad-soft);
  color: #a8071a;
  font-size: 12px;
}
.chip b { font-weight: 650; }

.table-wrap { overflow: auto; max-height: 480px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  padding: 12px 8px;
  background: #fafafa;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}
td { padding: 12px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: #fafafa; }
.mono { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.cell-title { font-weight: 600; }
.pill {
  display: inline-block;
  padding: 0 7px;
  height: 22px;
  line-height: 20px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid var(--line-strong);
  background: #fafafa;
}
.pill.insert, .pill.ok { color: #389e0d; background: var(--ok-soft); border-color: #b7eb8f; }
.pill.update { color: #0958d9; background: var(--primary-soft); border-color: #91caff; }
.pill.delete, .pill.error, .pill.bad { color: #cf1322; background: var(--bad-soft); border-color: #ffccc7; }
.pill.warn { color: #d48806; background: var(--warn-soft); border-color: #ffe58f; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.worker {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 4px 0;
}
.worker .id { font-family: var(--mono); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: #d9d9d9; flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.err-line { padding: 8px 0; border-top: 1px solid var(--line); }
.err-line p { margin: 4px 0 0; }
.muted { color: var(--muted); }
.empty {
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  gap: 4px;
}
.empty strong { color: var(--text); font-weight: 600; }
.quiet { color: #389e0d; }
td .actions { display: flex; gap: 6px; }
td .actions button { height: 28px; font-size: 12px; }

dialog {
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  width: min(920px, 92vw);
  padding: 16px 16px 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
pre {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 70vh;
  overflow: auto;
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
}

@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-16, .span-14, .span-10, .span-8, .span-24 { grid-column: span 24; }
  .dlq-layout, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  #navToggle { display: grid; }
  .sider {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  body.nav-open .sider { transform: none; }
  .top { padding: 0 12px; }
  .clock, .dashUpdated, .live-toggle { display: none; }
  main { padding: 12px; }
  .kpis { grid-template-columns: 1fr; }
  #apiKey { width: 96px; }
}
