:root {
  --bg: #f3f6f4;
  --bg-elev: #ffffff;
  --bg-soft: #e8f0eb;
  --ink: #1a2e24;
  --ink-2: #3d5348;
  --ink-3: #6b8075;
  --line: #d5e0d9;
  --line-strong: #b8c9bf;
  --brand: #1b7a4e;
  --brand-2: #0f5c3a;
  --brand-soft: #d8f0e4;
  --accent: #c45c26;
  --accent-soft: #fceee6;
  --warn: #b8860b;
  --warn-soft: #fff4d6;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --info: #1a5f8a;
  --info-soft: #e4f2fa;
  --ok: #1b7a4e;
  --ok-soft: #d8f0e4;
  --shadow: 0 1px 2px rgba(26, 46, 36, 0.06), 0 8px 24px rgba(26, 46, 36, 0.06);
  --radius: 10px;
  --sidebar-w: 240px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "Cascadia Code", "Consolas", "Sarasa Mono SC", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--brand); text-decoration: none; }
.hidden { display: none !important; }

/* Login */
.login-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  position: relative;
  padding: 32px 16px;
  overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 10% 20%, rgba(27, 122, 78, 0.18), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 80%, rgba(196, 92, 38, 0.12), transparent 50%),
    linear-gradient(160deg, #eef5f1 0%, #f7faf8 45%, #e8f0eb 100%);
}
.login-bg::after {
  content: "";
  position: absolute; inset: 0;
  background-image: linear-gradient(rgba(27,122,78,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(27,122,78,0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
}
.login-card {
  position: relative;
  width: min(440px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
  animation: rise 0.45s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
.login-brand { text-align: center; margin-bottom: 28px; }
.brand-mark { color: var(--brand); display: inline-flex; margin-bottom: 10px; }
.brand-mark.sm { margin: 0; color: var(--brand); }
.login-brand h1 { font-size: 1.55rem; font-weight: 700; letter-spacing: 0.02em; }
.login-brand p { color: var(--ink-3); font-size: 0.88rem; margin-top: 6px; }
.role-label { font-size: 0.82rem; color: var(--ink-3); margin-bottom: 10px; }
.role-btn {
  display: flex; align-items: flex-start; gap: 14px;
  width: 100%; text-align: left;
  padding: 14px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 10px;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.role-btn:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  transform: translateY(-1px);
}
.role-ico {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; flex-shrink: 0;
}
.role-btn strong { display: block; font-size: 0.98rem; }
.role-btn small { display: block; color: var(--ink-3); font-size: 0.78rem; margin-top: 2px; }
.login-hint { text-align: center; color: var(--ink-3); font-size: 0.75rem; margin-top: 16px; }

/* App shell */
.app { display: flex; min-height: 100%; }
.sidebar {
  width: var(--sidebar-w);
  background: #13261d;
  color: #dce8e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  flex-shrink: 0; z-index: 40;
  transition: transform 0.2s;
}
.side-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.side-title { font-weight: 700; font-size: 0.95rem; color: #fff; }
.side-sub { font-size: 0.72rem; color: #8fa89a; margin-top: 2px; }
.side-nav { flex: 1; overflow-y: auto; padding: 10px 8px 20px; }
.nav-group { margin-bottom: 14px; }
.nav-group-title {
  font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: #6f8a7c; padding: 6px 10px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 12px;
  border-radius: 8px; color: #c5d6cc;
  font-size: 0.88rem; text-align: left;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-item .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-left: auto;
}
.side-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.ghost-btn {
  width: 100%; padding: 8px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px; color: #c5d6cc; font-size: 0.82rem;
}
.ghost-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.breadcrumb { font-weight: 600; font-size: 0.98rem; flex: 1; min-width: 0; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.search-box input {
  width: 220px; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); outline: none;
}
.search-box input:focus { border-color: var(--brand); background: #fff; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px;
  display: grid; place-items: center;
  color: var(--ink-2); position: relative;
}
.icon-btn:hover { background: var(--bg-soft); }
.badge-wrap .badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--danger); color: #fff;
  font-size: 0.65rem; border-radius: 99px;
  display: grid; place-items: center;
}
.ai-chip {
  padding: 6px 12px; border-radius: 8px;
  background: var(--brand-soft); color: var(--brand-2);
  font-size: 0.82rem; font-weight: 600;
  border: 1px solid #b7dcc9;
}
.ai-chip:hover { background: #c8e8d8; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: 99px; background: var(--bg);
  font-size: 0.82rem;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 0.75rem; font-weight: 700;
}

.content { padding: 20px; flex: 1; animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* Panels & cards */
.page-hd {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-hd h2 { font-size: 1.25rem; font-weight: 700; }
.page-hd p { color: var(--ink-3); font-size: 0.86rem; margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  font-size: 0.86rem; font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #f5c2bc; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(26,46,36,0.04);
}
.kpi .label { font-size: 0.78rem; color: var(--ink-3); }
.kpi .value {
  font-size: 1.55rem; font-weight: 700; margin-top: 4px;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.kpi .meta { font-size: 0.75rem; margin-top: 6px; color: var(--ink-3); }
.kpi .meta.up { color: var(--danger); }
.kpi .meta.down { color: var(--ok); }
.kpi.accent { border-left: 3px solid var(--brand); }
.kpi.warn { border-left: 3px solid var(--warn); }
.kpi.danger { border-left: 3px solid var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 1.2fr; gap: 14px; }
@media (max-width: 1100px) {
  .grid-2, .grid-3, .grid-1-2 { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.panel-hd {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-hd h3 { font-size: 0.95rem; font-weight: 650; }
.panel-bd { padding: 14px 16px; }
.panel-tools { display: flex; gap: 6px; align-items: center; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  padding: 6px 12px; border-radius: 6px;
  font-size: 0.82rem; color: var(--ink-3);
}
.tab.active { background: var(--brand-soft); color: var(--brand-2); font-weight: 600; }
.tab:hover:not(.active) { background: var(--bg); }

.filters {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 12px; align-items: center;
}
.filters select, .filters input, .field input, .field select, .field textarea {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  outline: none;
  min-width: 120px;
}
.filters select:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
}
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 0.78rem; color: var(--ink-3); }
.field textarea { min-height: 80px; resize: vertical; }

table.data {
  width: 100%; border-collapse: collapse;
  font-size: 0.84rem;
}
table.data th, table.data td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th {
  font-size: 0.75rem; color: var(--ink-3);
  font-weight: 600; background: #f7faf8;
  white-space: nowrap;
}
table.data tr:hover td { background: #f7faf8; }
table.data .num { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 0.8rem; }
table.data .linkish { color: var(--brand); font-weight: 600; cursor: pointer; }
table.data .linkish:hover { text-decoration: underline; }

.tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 99px;
  font-size: 0.72rem; font-weight: 600;
  white-space: nowrap;
}
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-warn { background: var(--warn-soft); color: #8a6508; }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-info { background: var(--info-soft); color: var(--info); }
.tag-muted { background: #eef1ef; color: var(--ink-3); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }

.progress {
  height: 8px; background: var(--bg-soft); border-radius: 99px; overflow: hidden;
}
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.progress.warn > i { background: var(--warn); }
.progress.danger > i { background: var(--danger); }

.chart-box { position: relative; width: 100%; height: 240px; }
.chart-box.sm { height: 180px; }
.chart-box.lg { height: 300px; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 0.75rem; color: var(--ink-3); margin-top: 8px;
}
.chart-legend span::before {
  content: ""; display: inline-block;
  width: 10px; height: 10px; border-radius: 2px;
  margin-right: 6px; vertical-align: -1px;
  background: var(--c, var(--brand));
}

.list-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: none; }
.list-row .rank {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--bg-soft); display: grid; place-items: center;
  font-size: 0.75rem; font-weight: 700; color: var(--ink-3); flex-shrink: 0;
}
.list-row .rank.top { background: var(--brand); color: #fff; }
.list-row .body { flex: 1; min-width: 0; }
.list-row .body strong { display: block; font-size: 0.88rem; }
.list-row .body small { color: var(--ink-3); font-size: 0.75rem; }
.list-row .right { text-align: right; flex-shrink: 0; }
.list-row .right .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.list-row .right small { display: block; color: var(--ink-3); font-size: 0.72rem; }

.timeline { position: relative; padding-left: 18px; }
.timeline::before {
  content: ""; position: absolute; left: 4px; top: 4px; bottom: 4px;
  width: 2px; background: var(--line);
}
.tl-item { position: relative; padding: 0 0 16px 12px; }
.tl-item::before {
  content: ""; position: absolute; left: -16px; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--brand); border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--brand);
}
.tl-item.done::before { background: var(--ok); box-shadow: 0 0 0 1px var(--ok); }
.tl-item.warn::before { background: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.tl-item .t { font-size: 0.72rem; color: var(--ink-3); }
.tl-item .c { font-size: 0.86rem; margin-top: 2px; }

.flow-steps {
  display: flex; gap: 0; overflow-x: auto; padding: 8px 0 4px;
}
.flow-step {
  flex: 1; min-width: 90px; text-align: center; position: relative;
  font-size: 0.75rem; color: var(--ink-3); padding: 0 4px;
}
.flow-step::after {
  content: ""; position: absolute; top: 12px; left: 50%; right: -50%;
  height: 2px; background: var(--line); z-index: 0;
}
.flow-step:last-child::after { display: none; }
.flow-step .n {
  width: 26px; height: 26px; border-radius: 50%;
  margin: 0 auto 6px; display: grid; place-items: center;
  background: var(--bg-soft); border: 2px solid var(--line);
  font-weight: 700; position: relative; z-index: 1;
}
.flow-step.active .n { background: var(--brand); color: #fff; border-color: var(--brand); }
.flow-step.done .n { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.flow-step.active, .flow-step.done { color: var(--ink); font-weight: 600; }

.sankey-mock {
  display: grid; grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 8px; align-items: center; font-size: 0.78rem;
}
.sankey-col { display: flex; flex-direction: column; gap: 8px; }
.sankey-node {
  padding: 10px 12px; border-radius: 8px;
  background: var(--brand-soft); border: 1px solid #b7dcc9;
}
.sankey-node.mid { background: var(--info-soft); border-color: #b5d4e8; }
.sankey-node.out { background: var(--accent-soft); border-color: #f0c9b4; }
.sankey-node.loss { background: var(--danger-soft); border-color: #f5c2bc; }
.sankey-arrow { color: var(--ink-3); font-size: 1.2rem; }

.empty {
  text-align: center; padding: 40px 16px; color: var(--ink-3); font-size: 0.9rem;
}

.split-trace {
  display: grid; grid-template-columns: 280px 1fr; gap: 14px; min-height: 360px;
}
@media (max-width: 900px) { .split-trace { grid-template-columns: 1fr; } }
.trace-tree { border-right: 1px solid var(--line); padding-right: 10px; }
.tree-node {
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  font-size: 0.84rem; margin-bottom: 2px;
}
.tree-node:hover { background: var(--bg); }
.tree-node.active { background: var(--brand-soft); color: var(--brand-2); font-weight: 600; }
.tree-node.indent-1 { padding-left: 24px; }
.tree-node.indent-2 { padding-left: 40px; font-size: 0.8rem; color: var(--ink-2); }
.trace-detail .meta-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px;
}
.meta-item {
  background: var(--bg); border-radius: 8px; padding: 10px 12px;
}
.meta-item .k { font-size: 0.72rem; color: var(--ink-3); }
.meta-item .v { font-weight: 600; margin-top: 2px; font-size: 0.88rem; }

.map-mock {
  height: 280px; border-radius: 10px;
  background:
    radial-gradient(circle at 30% 40%, rgba(27,122,78,0.35), transparent 28%),
    radial-gradient(circle at 55% 55%, rgba(27,122,78,0.45), transparent 22%),
    radial-gradient(circle at 70% 35%, rgba(196,92,38,0.35), transparent 18%),
    radial-gradient(circle at 45% 70%, rgba(27,122,78,0.25), transparent 20%),
    linear-gradient(135deg, #d9ebe2, #c5ddd2 40%, #e8f0eb);
  position: relative; overflow: hidden;
  border: 1px solid var(--line);
}
.map-pin {
  position: absolute; transform: translate(-50%, -100%);
  background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px;
  font-size: 0.72rem; box-shadow: var(--shadow);
  cursor: pointer; white-space: nowrap;
}
.map-pin:hover { border-color: var(--brand); }
.map-pin strong { color: var(--brand-2); }
.map-pin.hot { border-color: var(--accent); }

/* Drawer / Modal / Toast */
.drawer-mask, .modal-mask {
  position: fixed; inset: 0; background: rgba(19, 38, 29, 0.35);
  z-index: 80;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(400px, 100%); background: #fff;
  z-index: 90; box-shadow: -8px 0 32px rgba(0,0,0,0.12);
  display: flex; flex-direction: column;
  animation: slidein 0.2s ease;
}
.ai-drawer { width: min(440px, 100%); }
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.drawer-hd h3 { font-size: 1rem; }
.drawer-bd { flex: 1; overflow-y: auto; padding: 12px 16px; }
.notify-item {
  padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 10px; cursor: pointer;
}
.notify-item:hover { border-color: var(--brand); background: var(--bg); }
.notify-item .t { font-size: 0.72rem; color: var(--ink-3); margin-bottom: 4px; }
.notify-item .c { font-size: 0.86rem; font-weight: 600; }

.ai-tips {
  padding: 8px 16px; font-size: 0.75rem;
  background: var(--warn-soft); color: #8a6508;
  border-bottom: 1px solid #f0e0a8;
}
.ai-chat { display: flex; flex-direction: column; gap: 10px; }
.msg {
  max-width: 92%; padding: 10px 12px; border-radius: 12px;
  font-size: 0.86rem; line-height: 1.55;
}
.msg.bot { background: var(--bg); align-self: flex-start; border: 1px solid var(--line); }
.msg.user { background: var(--brand); color: #fff; align-self: flex-end; }
.msg .cite {
  display: block; margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--line); font-size: 0.75rem; color: var(--ink-3);
}
.ai-quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 16px; border-top: 1px solid var(--line); }
.ai-quick button {
  font-size: 0.72rem; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 99px; background: #fff;
}
.ai-quick button:hover { border-color: var(--brand); color: var(--brand); }
.ai-input {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.ai-input input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; outline: none;
}
.ai-input input:focus { border-color: var(--brand); }
.ai-input button {
  padding: 9px 14px; background: var(--brand); color: #fff;
  border-radius: 8px; font-weight: 600;
}

.modal-mask { display: grid; place-items: center; padding: 20px; z-index: 100; }
.modal {
  width: min(720px, 100%); max-height: 88vh;
  background: #fff; border-radius: 14px;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: rise 0.2s ease;
}
.modal-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-bd { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-ft {
  padding: 12px 18px; border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 8px;
}

.toast-wrap {
  position: fixed; top: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #13261d; color: #fff;
  padding: 12px 16px; border-radius: 10px;
  font-size: 0.86rem; box-shadow: var(--shadow);
  animation: rise 0.2s ease; min-width: 220px;
}
.toast.ok { background: var(--brand); }
.toast.warn { background: var(--warn); color: #1a2e24; }
.toast.err { background: var(--danger); }

.foot-note {
  font-size: 0.72rem; color: var(--ink-3); margin-top: 8px;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; transform: translateX(-100%);
  }
  .sidebar.open { transform: none; }
  .search-box input { width: 140px; }
  #btn-menu { display: grid; }
}
@media (min-width: 861px) {
  #btn-menu { display: none; }
}
