:root {
  --bg: #f2f2f7;
  --bg-elev: rgba(255, 255, 255, 0.72);
  --card: #ffffff;
  --card-sub: #f2f2f7;
  --text: #1c1c1e;
  --text-2: #3c3c43;
  --muted: #8e8e93;
  --hair: rgba(60, 60, 67, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --accent: #007aff;
  --good: #34c759;
  --warn: #ff9f0a;
  --bad: #ff3b30;
  --idle: #c7c7cc;
  --ring-track: rgba(60, 60, 67, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: rgba(28, 28, 30, 0.72);
    --card: #1c1c1e;
    --card-sub: #2c2c2e;
    --text: #ffffff;
    --text-2: #ebebf5;
    --muted: #8e8e93;
    --hair: rgba(84, 84, 88, 0.4);
    --shadow: none;
    --accent: #0a84ff;
    --good: #30d158;
    --warn: #ff9f0a;
    --bad: #ff453a;
    --idle: #48484a;
    --ring-track: rgba(120, 120, 128, 0.24);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Helvetica Neue", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    calc(env(safe-area-inset-bottom) + 32px) env(safe-area-inset-left);
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-elev);
  border-bottom: 0.5px solid var(--hair);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.head-row,
.wrap {
  width: min(100%, 980px);
  margin: 0 auto;
  padding-inline: 16px;
}

.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 14px;
}

.title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.title-copy {
  min-width: 0;
}

.title h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.title .sub {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.pill {
  flex: none;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}

.pill.demo {
  background: var(--warn);
}

.pill.admin-link {
  background: var(--text-2);
  color: var(--card);
  text-decoration: none;
}

.view-switch {
  display: inline-flex;
  flex: none;
  gap: 2px;
  border: 0.5px solid var(--hair);
  border-radius: 12px;
  padding: 2px;
  background: var(--card-sub);
}

.view-tab {
  min-width: 88px;
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.view-tab.is-active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.admin-wrap {
  padding-top: 18px;
}

.view-panel[hidden] {
  display: none;
}

.dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.admin-dashboard {
  min-height: 340px;
}

.channel-summary {
  margin-top: 0;
}

.channel-launch-row,
.channel-model-grid {
  display: grid;
  gap: 12px;
}

.channel-launch-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0 0 12px;
}

.channel-launch-row .stat {
  min-width: 0;
  border: 0.5px solid var(--hair);
  border-radius: 16px;
  padding: 13px 14px;
}

.channel-launch-row .stat .k {
  font-size: 11px;
}

.channel-launch-row .stat .v {
  margin-top: 5px;
  font-size: 26px;
}

.channel-model-grid {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.channel-model-card {
  background: var(--card);
  box-shadow: var(--shadow);
}

.channel-model-card {
  border: 0.5px solid transparent;
  border-radius: 22px;
  padding: 16px 18px;
}

.recent-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.recent-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  border: 0.5px solid var(--hair);
  border-radius: 16px;
  padding: 10px 12px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.recent-row b,
.recent-row small,
.recent-row strong,
.recent-row em {
  display: block;
}

.recent-row b {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-style: normal;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-row small {
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-row strong {
  color: var(--text-2);
  font-size: 12px;
}

.recent-row em {
  max-width: 120px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty.error {
  border: 0.5px solid rgba(255, 59, 48, 0.24);
}

.channel-panel {
  margin: 18px 0 12px;
}

.channel-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 1px 1px 10px;
  scrollbar-width: none;
}

.channel-filter::-webkit-scrollbar {
  display: none;
}

.channel-chip {
  display: inline-flex;
  flex: none;
  gap: 4px;
  border: 0.5px solid var(--hair);
  border-radius: 14px;
  padding: 3px;
  background: var(--card-sub);
}

.channel-chip.is-disabled {
  opacity: 0.72;
}

.channel-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  flex: none;
  border: 0;
  border-radius: 11px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.channel-btn.is-disabled {
  color: var(--muted);
}

.channel-btn b {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.channel-btn.is-active {
  border-color: rgba(0, 122, 255, 0.28);
  background: var(--accent);
  color: #ffffff;
}

.channel-btn.is-active b {
  color: rgba(255, 255, 255, 0.78);
}

.channel-toggle {
  min-height: 34px;
  border: 0;
  border-radius: 11px;
  padding: 8px 10px;
  color: #ffffff;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.channel-toggle.danger {
  background: var(--bad);
}

.channel-toggle.enable {
  background: var(--good);
}

.channel-toggle:disabled {
  cursor: wait;
  opacity: 0.7;
}

.group-panel {
  margin: 18px 0 12px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 4px 10px;
}

.panel-head h2 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.panel-head span {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.filter-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-control .group-filter,
.filter-control .channel-filter {
  flex: 1;
  min-width: 0;
}

.filter-scroll-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border: 0.5px solid var(--hair);
  border-radius: 12px;
  background: var(--card);
  color: var(--text-2);
  box-shadow: var(--shadow);
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.filter-scroll-btn:active {
  transform: translateY(1px);
}

.filter-select {
  display: none;
  width: 100%;
  min-height: 40px;
  border: 0.5px solid var(--hair);
  border-radius: 13px;
  padding: 0 38px 0 12px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
}

.group-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 1px 1px 10px;
  scrollbar-width: none;
}

.group-filter::-webkit-scrollbar {
  display: none;
}

.group-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  flex: none;
  border: 0.5px solid var(--hair);
  border-radius: 12px;
  padding: 8px 11px;
  background: var(--card);
  color: var(--text-2);
  box-shadow: var(--shadow);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.group-btn b {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.group-btn.is-active {
  border-color: rgba(0, 122, 255, 0.28);
  background: var(--accent);
  color: #ffffff;
}

.group-btn.is-active b {
  color: rgba(255, 255, 255, 0.78);
}

.group-stats,
.channel-stats {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  margin-inline: -16px;
  padding: 1px 16px 10px;
  background: transparent;
  scrollbar-width: none;
}

.group-stats::-webkit-scrollbar,
.channel-stats::-webkit-scrollbar {
  display: none;
}

.group-status,
.channel-status {
  min-width: 0;
  border: 0;
  border-radius: 18px;
  padding: 13px 14px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
}

.channel-status {
  flex: 0 0 240px;
}

.group-status {
  flex: 0 0 240px;
}

.group-status.is-active,
.channel-status.is-active {
  outline: 2px solid rgba(0, 122, 255, 0.32);
  outline-offset: -2px;
}

.group-status-top,
.channel-status-top {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 700;
}

.group-status-value,
.channel-status-value {
  margin-top: 9px;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.group-status-value small,
.channel-status-value small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.group-status-meta,
.channel-status-meta {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.ring {
  position: relative;
  width: 56px;
  height: 56px;
  flex: none;
}

.ring svg {
  display: block;
  width: 56px;
  height: 56px;
  transform: rotate(-90deg);
}

.ring .track,
.ring .bar {
  fill: none;
  stroke-width: 5;
}

.ring .track {
  stroke: var(--ring-track);
}

.ring .bar {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s linear;
}

.ring .lbl {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.ring .lbl b {
  font-size: 16px;
  font-weight: 700;
}

.ring .lbl small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 9px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 8px;
}

.stat,
.card {
  background: var(--card);
  box-shadow: var(--shadow);
}

.stat {
  border-radius: 18px;
  padding: 16px;
}

.stat .k {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.stat .v {
  margin-top: 6px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
}

.stat .v small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 2px 16px;
  color: var(--muted);
  font-size: 12.5px;
}

.dot-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.5);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(52, 199, 89, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(52, 199, 89, 0);
  }
}

.section-h {
  margin: 4px 4px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.card {
  border: 0.5px solid transparent;
  border-radius: 22px;
  padding: 16px 18px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.card:hover {
  transform: translateY(-1px);
}

@media (prefers-color-scheme: dark) {
  .card {
    border-color: var(--hair);
  }
}

.card-top {
  display: flex;
  align-items: center;
  gap: 9px;
}

.hdot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.hdot.good {
  background: var(--good);
}

.hdot.warn {
  background: var(--warn);
}

.hdot.bad {
  background: var(--bad);
}

.hdot.idle {
  background: var(--idle);
}

.mname {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15.5px;
  font-weight: 600;
}

.group-chip {
  flex: none;
  border-radius: 999px;
  padding: 3px 7px;
  background: var(--card-sub);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
}

.ttft {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin: 14px 0 2px;
}

.ttft .n {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 0.9;
}

.ttft .u {
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
}

.ttft-cap {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.bar-meter {
  height: 5px;
  margin: 12px 0 14px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--card-sub);
}

.bar-meter > i {
  display: block;
  height: 100%;
  border-radius: 3px;
}

.bar-meter > i.good {
  background: var(--good);
}

.bar-meter > i.warn {
  background: var(--warn);
}

.bar-meter > i.bad {
  background: var(--bad);
}

.bar-meter > i.idle {
  background: var(--idle);
}

.trace-block {
  margin: 0 0 14px;
}

.trace-head,
.trace-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
}

.trace-head b {
  color: var(--text-2);
  font-size: 10px;
}

.trace-strip {
  display: grid;
  grid-template-columns: repeat(50, minmax(2px, 1fr));
  gap: 2px;
  margin: 7px 0 6px;
}

.trace-strip > i {
  display: block;
  height: 20px;
  border-radius: 999px;
  background: var(--idle);
  opacity: 0.4;
}

.trace-strip > i.good,
.trace-legend i.good {
  background: var(--good);
  opacity: 1;
}

.trace-strip > i.warn,
.trace-legend i.warn {
  background: var(--warn);
  opacity: 1;
}

.trace-strip > i.bad,
.trace-legend i.bad {
  background: var(--bad);
  opacity: 1;
}

.trace-legend {
  justify-content: flex-start;
  gap: 10px;
  font-size: 10px;
}

.trace-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.trace-legend i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.kv {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.kv .b {
  min-width: 0;
  border-radius: 12px;
  padding: 9px 10px;
  background: var(--card-sub);
}

.kv .b .kk {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
}

.kv .b .vv {
  margin-top: 3px;
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 700;
}

.skeleton .card {
  min-height: 168px;
}

.skeleton .card * {
  visibility: hidden;
}

.empty {
  padding: 64px 16px;
  color: var(--muted);
  text-align: center;
}

.empty .big {
  color: var(--text-2);
  font-size: 17px;
  font-weight: 600;
}

.empty .small {
  margin-top: 6px;
  font-size: 13px;
}

.banner {
  margin: 12px 0;
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 159, 10, 0.14);
  color: var(--warn);
  font-size: 13px;
  font-weight: 600;
}

footer {
  width: min(100%, 980px);
  margin: 26px auto 0;
  padding-inline: 16px;
  color: var(--muted);
  text-align: center;
  font-size: 11.5px;
}

@media (max-width: 700px) {
  .admin-head-row,
  .dashboard-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .view-switch {
    width: 100%;
  }

  .view-tab {
    flex: 1;
  }

  .filter-control {
    display: none;
  }

  .filter-select {
    display: block;
  }

  .group-status,
  .channel-status {
    flex-basis: 230px;
  }

  .summary {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .channel-model-grid {
    grid-template-columns: 1fr;
  }

  .channel-launch-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .head-row {
    align-items: flex-start;
  }

  .title {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .title h1 {
    font-size: 19px;
  }

  .stat .v {
    font-size: 28px;
  }
}
