:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fbfbfd;
  --line: #e5e7eb;
  --line-strong: #d5d8de;
  --text: #14161a;
  --text-2: #4b5563;
  --muted: #8b93a1;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --teal: #0d9488;
  --amber: #d97706;
  --bad: #dc2626;
  --good: #15803d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #16181d;
    --panel-2: #1b1e25;
    --line: #262a33;
    --line-strong: #333846;
    --text: #eceef2;
    --text-2: #b6bcc8;
    --muted: #7d8695;
    --accent: #8b87ff;
    --accent-soft: #23213a;
    --teal: #2dd4bf;
    --amber: #f59e0b;
    --bad: #f87171;
    --good: #4ade80;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--accent); text-decoration: none; }

.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ------------------------------- auth screen ------------------------------ */

.auth-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.auth-card h1 { font-size: 19px; margin: 0 0 6px; }
.auth-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
}
.field input:focus { border-color: var(--accent); background: var(--panel); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: var(--line); }
.btn.wide { width: 100%; padding: 11px; }

.err {
  color: var(--bad);
  font-size: 12.5px;
  min-height: 18px;
  margin-top: 4px;
}

/* --------------------------------- layout -------------------------------- */

#app { display: flex; min-height: 100%; }

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 18px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--text-2);
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.nav-item .ico { width: 16px; display: inline-grid; place-items: center; opacity: 0.9; }

.sidebar-foot {
  margin-top: auto;
  padding: 10px 8px 4px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar h2 { font-size: 15px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }

.select {
  appearance: none;
  padding: 7px 30px 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%238b93a1'/></svg>") no-repeat right 10px center;
  cursor: pointer;
  max-width: 240px;
}

.segmented {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  border: none;
  background: none;
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--text-2);
  cursor: pointer;
  font-size: 12.5px;
}
.segmented button.active { background: var(--accent); color: #fff; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-2);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 4px 8px;
  border-radius: 999px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); }
.dot.file { background: var(--amber); }

.content { padding: 20px 22px 40px; display: flex; flex-direction: column; gap: 16px; }

/* --------------------------------- cards --------------------------------- */

.grid { display: grid; gap: 14px; }
.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.card-head h3 {
  font-size: 13px;
  margin: 0;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.card-head .hint { font-size: 11.5px; color: var(--muted); margin-left: auto; }

.kpi-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 26px; font-weight: 620; margin-top: 6px; letter-spacing: -0.02em; }
.kpi-foot { font-size: 11.5px; color: var(--muted); margin-top: 6px; display: flex; align-items: center; gap: 6px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.delta-flat { color: var(--muted); }

/* --------------------------------- charts -------------------------------- */

.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.chart-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12px;
  box-shadow: 0 6px 20px rgba(16, 24, 40, 0.12);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 4;
}
.tooltip.show { opacity: 1; }
.tooltip b { font-weight: 600; }

/* bars */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(64px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.bar-track { background: var(--panel-2); border-radius: 5px; height: 7px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 5px; }
.bar-fill.t2 { background: var(--teal); }
.bar-val { color: var(--muted); font-size: 12px; min-width: 46px; text-align: right; }

/* table */
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 11.5px;
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 8px; border-bottom: 1px solid var(--line); color: var(--text-2); }
.table tr:last-child td { border-bottom: none; }
.table td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text); }
.table .right { text-align: right; }
.table tr:hover td { background: var(--panel-2); }

/* realtime */
.realtime { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.rt-main { display: flex; flex-direction: column; }
.rt-num { font-size: 40px; font-weight: 650; line-height: 1.05; letter-spacing: -0.03em; }
.rt-cap { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pulse {
  width: 7px; height: 7px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 0 0 rgba(21, 128, 61, 0.5);
  animation: pulse 2.2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(21, 128, 61, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(21, 128, 61, 0); }
  100% { box-shadow: 0 0 0 0 rgba(21, 128, 61, 0); }
}

.mini-list { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.mini-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--text-2); }
.mini-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.mini-row b { font-weight: 550; color: var(--text); }

/* donut */
.donut-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut { width: 96px; height: 96px; flex: 0 0 96px; }
.donut-legend { flex: 1; min-width: 120px; display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.donut-legend .row { display: flex; align-items: center; gap: 6px; }
.donut-legend .sw { width: 8px; height: 8px; border-radius: 2px; }
.donut-legend .grow { flex: 1; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend .v { color: var(--muted); }

/* funnel */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.fn-step { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
.fn-label { font-size: 12.5px; color: var(--text-2); }
.fn-count { font-size: 12.5px; color: var(--text); font-weight: 550; }
.fn-bar { grid-column: 1 / -1; height: 10px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.fn-bar i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.fn-note { font-size: 11.5px; color: var(--muted); }
.fn-drop { font-size: 11.5px; color: var(--muted); }

/* forms / site cards */
.site-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.site-row:last-child { border-bottom: none; }
.site-name { font-weight: 550; }
.site-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 7px;
}

.code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.65;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-2);
}

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin-bottom: 0; }
.inline-form input { min-width: 160px; }

.empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.hr { height: 1px; background: var(--line); margin: 16px 0; }

.note { font-size: 12px; color: var(--muted); line-height: 1.7; }
.note b { color: var(--text-2); font-weight: 600; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(12px);
  background: #111827;
  color: #fff;
  padding: 9px 15px;
  border-radius: 9px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.18s;
  z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1180px) {
  .cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 12px 0 0; }
  .sidebar-foot { display: none; }
  .nav-item { width: auto; white-space: nowrap; }
  .cols-5, .cols-3, .cols-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
}
