:root {
  --sidebar: #0b1e45;
  --sidebar-2: #081735;
  --nav: #d7e3f8;
  --nav-active: #2f6bff;
  --bg: #f4f7fb;
  --card: #ffffff;
  --line: #e7eef6;
  --text: #1d2939;
  --text-2: #667085;
  --text-3: #98a2b3;
  --blue: #2f6bff;
  --blue-soft: #eaf1ff;
  --green: #12b76a;
  --green-soft: #e8f8f0;
  --orange: #f79009;
  --red: #f04438;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.045);
  --radius: 14px;
  --sidebar-w: 228px;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.7; }

#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: white;
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; background: var(--blue);
  display: grid; place-items: center; font-weight: 750; font-size: 22px;
  box-shadow: 0 8px 16px rgba(47, 107, 255, 0.35);
}
.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name strong { font-size: 15px; letter-spacing: 0.2px; }
.brand-name span { font-size: 13px; color: #b9c8e4; font-weight: 500; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; border: 0; background: transparent; color: var(--nav);
  border-radius: 10px; padding: 10px 12px; text-align: left;
}
.nav-item svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-item:hover { background: rgba(255, 255, 255, 0.06); }
.nav-item.active { background: var(--nav-active); color: white; box-shadow: 0 8px 16px rgba(47, 107, 255, 0.28); }

.side-status {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 12px 12px 10px;
  color: #d5e2f6;
  font-size: 12px;
}
.side-status-title { display: flex; align-items: center; gap: 8px; font-weight: 650; margin-bottom: 8px; color: white; }
.side-status p { margin: 4px 0; color: #b7c6e2; }
.side-status strong { color: #eef3fb; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 99px; background: var(--green); box-shadow: 0 0 0 4px rgba(18, 183, 106, 0.16); display: inline-block; }
.dot.warn { background: var(--orange); box-shadow: 0 0 0 4px rgba(247, 144, 9, 0.16); }
.dot.bad { background: var(--red); box-shadow: 0 0 0 4px rgba(240, 68, 56, 0.16); }
.text-link { border: 0; background: none; color: #8eb4ff; padding: 4px 0 0; font-size: 12px; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  display: flex; justify-content: space-between; gap: 16px; align-items: flex-start;
  padding: 18px 22px 6px;
}
.titles { min-width: 0; }
#page-title { margin: 0; font-size: 22px; line-height: 1.35; font-weight: 750; letter-spacing: -0.2px; }
#page-title .accent { color: var(--blue); }
#page-sub { margin: 6px 0 0; color: var(--text-2); font-size: 13px; line-height: 1.5; }
.top-actions { display: flex; align-items: center; gap: 12px; flex: none; padding-top: 4px; }
.updated { color: var(--text-3); font-size: 13px; }
.updated strong { color: var(--text-2); font-weight: 600; }
.chip {
  background: #fff6e8; color: #b54708; border: 1px solid #fde2c2;
  border-radius: 99px; padding: 3px 8px; font-size: 12px; font-weight: 650;
}
.btn {
  border: 1px solid var(--line); background: white; border-radius: 8px;
  padding: 8px 12px; font-weight: 600; color: var(--text);
}
.btn:hover { border-color: #cdd8ea; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: white; box-shadow: 0 6px 14px rgba(47, 107, 255, 0.25); }
.btn-primary:hover { background: #1f5ef5; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); border-color: #fecdca; background: #fff6f5; }

#view { flex: 1; overflow: auto; padding: 12px 22px 22px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card); border: 1px solid rgba(231, 238, 246, 0.9);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px 14px;
}
.card-title { margin: 0 0 12px; font-size: 15px; font-weight: 700; }
.muted { color: var(--text-3); }
.small { font-size: 12px; color: var(--text-2); line-height: 1.55; }

.pipeline { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; align-items: start; }
.pipe-item { display: flex; gap: 10px; min-width: 0; position: relative; padding-right: 16px; }
.pipe-item:not(:last-child)::after {
  content: "→"; position: absolute; right: 0; top: 8px; color: #c5d0e0; font-size: 14px;
}
.pipe-icon {
  width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; flex: none;
}
.pipe-icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.pipe-item strong { display: block; font-size: 13px; margin-bottom: 2px; }
.pipe-item p { margin: 0; color: var(--text-3); font-size: 12px; line-height: 1.45; }

.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { display: flex; justify-content: space-between; gap: 8px; align-items: center; min-height: 92px; }
.kpi-label { margin: 0 0 8px; color: var(--text-2); font-size: 13px; }
.kpi-value { font-size: 28px; font-weight: 750; letter-spacing: -0.6px; font-variant-numeric: tabular-nums; line-height: 1; }
.kpi-value .unit { font-size: 14px; font-weight: 600; color: var(--text-3); margin-left: 4px; }
.delta { display: inline-flex; align-items: center; gap: 2px; margin-left: 8px; font-size: 12px; font-weight: 700; color: var(--green); vertical-align: 4px; }
.delta.down { color: var(--red); }
.spark { width: 92px; height: 36px; flex: none; }

.chart-grid { display: grid; grid-template-columns: 1.05fr 1fr 1.2fr; gap: 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; }
.donut-wrap { display: flex; align-items: center; gap: 8px; }
.donut-wrap svg { width: 168px; height: 168px; flex: none; }
.legend { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.legend-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.swatch { width: 8px; height: 8px; border-radius: 99px; }
.legend-row b { font-variant-numeric: tabular-nums; }

.bars { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.bar-row { display: grid; grid-template-columns: 56px 1fr 42px; gap: 10px; align-items: center; font-size: 13px; }
.track { height: 10px; background: #f2f4f7; border-radius: 99px; overflow: hidden; }
.track span { display: block; height: 100%; background: #3b6cff; border-radius: 99px; }
.bar-row b { text-align: right; color: var(--text-2); font-weight: 650; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 600; padding: 0 8px 8px 0; }
td { padding: 9px 8px 9px 0; border-top: 1px solid #f2f4f7; font-size: 13px; vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fbff; }
.new-badge {
  display: inline-block; background: #12b76a; color: white; font-size: 10px; font-weight: 750;
  border-radius: 4px; padding: 1px 5px; margin-right: 6px; letter-spacing: 0.3px; vertical-align: 1px;
}
.src { color: #475467; }
.time { color: var(--text-3); white-space: nowrap; }

.workflow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.step { background: #f8fafc; border-radius: 12px; padding: 12px; min-height: 168px; }
.step-no {
  width: 22px; height: 22px; border-radius: 99px; background: var(--blue); color: white;
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; margin-bottom: 8px;
}
.step h3 { margin: 0 0 8px; font-size: 14px; }
.step li { color: var(--text-2); font-size: 12px; line-height: 1.55; margin-left: 16px; }

.foot-grid { display: grid; grid-template-columns: 1.05fr 0.95fr 0.8fr 1.7fr; gap: 12px; }
.table-scroll { overflow-x: auto; }
table.compact { width: 100%; table-layout: fixed; }
table.compact th, table.compact td { white-space: nowrap; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
table.compact td.clip { width: 46%; }
.logo-row { display: flex; gap: 10px; flex-wrap: wrap; }
.brand-pill { width: 64px; text-align: center; font-size: 11px; color: var(--text-2); }
.brand-pill i {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  margin: 0 auto 6px; font-style: normal; font-weight: 750; background: #f4f7fb; border: 1px solid var(--line);
}
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checks li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: #344054; }
.checks i {
  width: 16px; height: 16px; border-radius: 99px; background: var(--green-soft); color: var(--green);
  display: inline-grid; place-items: center; font-style: normal; font-weight: 800; flex: none; margin-top: 1px;
}
.switch-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; }
.switch {
  width: 42px; height: 24px; border-radius: 99px; border: 0; background: #d0d5dd; position: relative; flex: none;
}
.switch.on { background: var(--blue); }
.switch i {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: white;
  transition: left 0.15s ease; display: block;
}
.switch.on i { left: 21px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.tag { background: #f2f4f7; color: #475467; border-radius: 99px; padding: 3px 8px; font-size: 12px; }
.tag.on { background: var(--blue-soft); color: #1d4ed8; }
.disclaimer {
  text-align: center; color: #98a2b3; font-size: 12px; background: #f8fafc;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
}

.page-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-end; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field, select.field, input.field {
  height: 36px; border: 1px solid #e4e7ec; border-radius: 8px; background: white; padding: 0 10px; min-width: 0;
}
input.field { min-width: 220px; }
textarea.field { height: auto; min-height: 72px; padding: 8px 10px; width: 100%; }
label.lbl { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-2); }
label.lbl input, label.lbl select, label.lbl textarea { color: var(--text); }

.table-wrap { overflow: auto; }
.pager { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-top: 12px; color: var(--text-2); font-size: 13px; }
.pages { display: flex; gap: 4px; }
.pages button { min-width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: white; }
.pages button.on { background: var(--blue); color: white; border-color: var(--blue); }

.pill { display: inline-flex; align-items: center; border-radius: 99px; padding: 2px 8px; font-size: 12px; font-weight: 650; background: #f2f4f7; color: #475467; }
.pill.new { background: #eaf1ff; color: #1d4ed8; }
.pill.active { background: var(--green-soft); color: #027a48; }
.pill.pending { background: #fff6e8; color: #b54708; }
.pill.archived { background: #f2f4f7; color: #667085; }
.mini { font-style: normal; margin-left: 4px; font-size: 10px; color: #b54708; background: #fff6e8; border-radius: 4px; padding: 1px 4px; }

.banner {
  background: #f8fbff; border: 1px solid #dbe7ff; color: #344054; border-radius: 12px; padding: 10px 12px; font-size: 13px;
}
.grid-2 { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 12px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.source-list { display: flex; flex-direction: column; gap: 12px; }
.source-card h3 { margin: 0; font-size: 16px; }
.source-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.test-msg { margin-top: 8px; font-size: 13px; }
.test-msg.ok { color: #027a48; }
.test-msg.bad { color: var(--red); }

#drawer[hidden], #modal[hidden] { display: none; }
#drawer {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.28); display: flex; justify-content: flex-end; z-index: 20;
}
.drawer-panel {
  width: min(440px, 100%); height: 100%; background: white; box-shadow: -12px 0 40px rgba(16, 24, 40, 0.12);
  padding: 20px; overflow: auto;
}
.drawer-panel h2 { margin: 8px 0 4px; font-size: 20px; line-height: 1.35; }
.kv { display: grid; grid-template-columns: 88px 1fr; gap: 8px 10px; font-size: 13px; margin: 14px 0; }
.kv span { color: var(--text-3); }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { background: #f8fafc; border-radius: 8px; padding: 8px 10px; font-size: 12px; color: #475467; }

#modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.35); display: grid; place-items: center; z-index: 30; padding: 20px; }
.modal-card { width: min(520px, 100%); background: white; border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.modal-card h3 { margin: 0 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1d2939; color: white; border-radius: 10px; padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow); max-width: 460px; }
.toast.error { background: #b42318; }

.empty, .loading, .error-box { padding: 28px 8px; text-align: center; color: var(--text-2); }
.error-box { color: var(--red); }
.level-INFO { color: #175cd3; }
.level-WARN { color: #b54708; }
.level-ERROR { color: var(--red); font-weight: 700; }

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-grid, .foot-grid, .workflow, .pipeline { grid-template-columns: 1fr 1fr; }
  .pipe-item:nth-child(2n)::after { content: none; }
}
.menu-btn { display: none; }
@media (max-width: 860px) {
  #sidebar { position: fixed; z-index: 15; inset: 0 auto 0 0; transform: translateX(-105%); transition: 0.2s ease; }
  #sidebar.open { transform: none; }
  #main { width: 100%; }
  #topbar, .page-head, .chart-grid, .foot-grid, .workflow, .pipeline, .grid-2, .grid-form { display: flex; flex-direction: column; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .menu-btn { display: inline-flex; }
}
