:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --panel-2: #222c38;
  --line: #2d3846;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4c9aff;
  --up: #3fb950;
  --down: #f85149;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.controls { display: flex; align-items: center; gap: 16px; }
.auth-form { display: flex; align-items: center; gap: 8px; }
.auth-form[hidden] { display: none; }
.auth-form input {
  width: 180px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
}
.controls select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
}
.updated { color: var(--muted); font-size: 12px; }
.refresh {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.refresh:hover { border-color: var(--accent); }
.refresh[disabled] { opacity: .5; cursor: default; }

.status {
  margin: 0; padding: 10px 28px; font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.status.error { background: rgba(248, 81, 73, .12); color: var(--down); }
.status.loading { background: var(--panel-2); color: var(--muted); }

main { padding: 24px 28px; max-width: 1100px; margin: 0 auto; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px; cursor: pointer; transition: border-color .15s;
}
.card:hover, .card.active { border-color: var(--accent); }
.card .name { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.card .dau { font-size: 34px; font-weight: 700; line-height: 1; }
.card .dau small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.card .delta { font-size: 13px; margin-top: 8px; }
.card .delta.up { color: var(--up); }
.card .delta.down { color: var(--down); }
.card .delta.flat { color: var(--muted); }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 10px; }

.detail { margin-top: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.detail-head { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; margin-bottom: 16px; }
.detail-head h2 { font-size: 15px; margin: 0; }
.tabs { display: flex; gap: 8px; flex: 1; }
.tabs button, .metric-toggle button {
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.tabs button.active, .metric-toggle button.active { color: var(--text); border-color: var(--accent); }
.tabs button.compare-toggle { margin-left: auto; }
.tabs button.compare-toggle.active { color: var(--accent); }

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.stat {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px;
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; line-height: 1; }
.stat .value small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 4px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; }
.legend .item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend .swatch { width: 12px; height: 3px; border-radius: 2px; }

.chart { width: 100%; overflow-x: auto; position: relative; }
.chart svg { display: block; }
.chart .dot { fill: var(--accent); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 12px;
  color: var(--text); white-space: nowrap; transform: translate(-50%, -110%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
}
.tooltip .t-day { color: var(--muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; }
.tooltip .t-row .swatch { width: 10px; height: 3px; border-radius: 2px; }
.chart .hover-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hover-band { fill: transparent; cursor: crosshair; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .val-label { fill: var(--text); font-size: 11px; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

.table { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 13px; }
.table th, .table td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table th:first-child, .table td:first-child { text-align: left; color: var(--muted); }
.table th { color: var(--muted); font-weight: 500; }

/* card last-seen / live status */
.card .last-seen {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 12px; margin-top: 10px;
  padding-top: 10px; border-top: 1px solid var(--line);
}
.card .last-seen.dormant { color: var(--down); }
.card.is-dormant { opacity: .82; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-live.live { background: var(--up); box-shadow: 0 0 0 3px rgba(63,185,80,.18); }
.dot-live.dormant { background: var(--muted); }

/* recent activity feed */
.activity { margin-top: 28px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed-empty { color: var(--muted); padding: 24px; text-align: center; font-size: 13px; }
.feed-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.feed-row:last-child { border-bottom: none; }
.dot-proj { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.feed-proj { min-width: 130px; color: var(--text); }
.feed-event {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--accent);
}
.feed-user { color: var(--muted); font-size: 12px; }
.feed-time { margin-left: auto; color: var(--muted); font-size: 12px; }
