:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e0e4ea;
  --text: #1a1d21;
  --muted: #757a82;
  --green: #10a37f;
  --green-bg: #e6f7f2;
  --blue: #207ab6;
  --blue-bg: #e8f2fa;
  --red: #de2f1b;
  --red-bg: #fce8e6;
  --yellow: #d97706;
  --yellow-bg: #fdf3e0;
  --unknown-bg: #eef0f3;
  --violet: #7c3aed;
  --violet-bg: #f0e9fd;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --border: #2a2f3a;
    --text: #e5e9f0;
    --muted: #8b93a7;
    --green: #2fbf8a;
    --green-bg: rgba(47,191,138,.12);
    --blue: #5aa9dd;
    --blue-bg: rgba(90,169,221,.12);
    --red: #f2635a;
    --red-bg: rgba(242,99,90,.12);
    --yellow: #f0b429;
    --yellow-bg: rgba(240,180,41,.12);
    --unknown-bg: #22262f;
    --violet: #a78bfa;
    --violet-bg: rgba(167,139,250,.12);
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page-wrap { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Masthead ── */
.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; flex-wrap: wrap;
}
.masthead-inner { display: flex; align-items: center; gap: 14px; }
.logo-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  flex-shrink: 0;
}
.masthead-text h1 { font-size: 20px; font-weight: 600; line-height: 1.2; }
.masthead-sub { font-size: 13px; color: var(--muted); }
.meta-text { font-size: 13px; color: var(--muted); }

/* ── Content ── */
.content {
  flex: 1; max-width: 760px; width: 100%;
  margin: 0 auto; padding: 28px 24px 48px;
}

/* ── Stats row ── */
.stats-row {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px;
}
.stat-chip {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 16px; text-align: center;
  box-shadow: var(--shadow); flex: 1; min-width: 70px;
}
.stat-num { display: block; font-size: 20px; font-weight: 700; font-family: ui-monospace, monospace; }
.stat-label { font-size: 11px; color: var(--muted); }

/* ── Status Banner ── */
.status-banner {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 24px; border-radius: 10px; margin-bottom: 24px;
  border: 1px solid var(--border); background: var(--surface);
  box-shadow: var(--shadow); transition: background .3s, border-color .3s;
}
.banner-icon {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.banner-icon svg { display: none; }
.banner-text h2 { font-size: 18px; font-weight: 600; line-height: 1.3; }
.banner-sub { margin-top: 2px; font-size: 13px; opacity: .75; }

.status-banner.status-green { background: var(--green-bg); border-color: rgba(16,163,127,.3); }
.status-banner.status-green .banner-icon { background: var(--green); color: #fff; }
.status-banner.status-green .icon-check { display: block; }
.status-banner.status-blue { background: var(--blue-bg); border-color: rgba(32,122,182,.3); }
.status-banner.status-blue .banner-icon { background: var(--blue); color: #fff; }
.status-banner.status-blue .icon-warn { display: block; }
.status-banner.status-red { background: var(--red-bg); border-color: rgba(222,47,27,.3); }
.status-banner.status-red .banner-icon { background: var(--red); color: #fff; }
.status-banner.status-red .icon-error { display: block; }
.status-banner.status-unknown .banner-icon { background: var(--border); color: var(--muted); }
.status-banner.status-unknown .icon-unknown { display: block; }

/* ── Components ── */
.components-section { margin-bottom: 32px; }
.components-list {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.component-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.component-row:last-child { border-bottom: none; }
.component-empty { justify-content: center; padding: 32px 20px; }
.component-name {
  font-weight: 500; font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all; flex: 1; min-width: 120px;
  display: flex; align-items: center; gap: 8px;
}
.component-right { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }

/* mode badge */
.mode-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 6px; white-space: nowrap;
}
.mode-v6 { background: var(--violet-bg); color: var(--violet); }
.mode-v4 { background: var(--blue-bg); color: var(--blue); }

/* status pill */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-pill.pill-green { color: var(--green); background: var(--green-bg); }
.status-pill.pill-green .dot { background: var(--green); }
.status-pill.pill-blue { color: var(--blue); background: var(--blue-bg); }
.status-pill.pill-blue .dot { background: var(--blue); }
.status-pill.pill-red { color: var(--red); background: var(--red-bg); }
.status-pill.pill-red .dot { background: var(--red); }
.status-pill.pill-yellow { color: var(--yellow); background: var(--yellow-bg); }
.status-pill.pill-yellow .dot { background: var(--yellow); }
.status-pill.pill-unknown { color: var(--muted); background: var(--unknown-bg); }
.status-pill.pill-unknown .dot { background: var(--muted); }

/* uptime bar */
.uptime-bar {
  display: flex; gap: 2px; height: 22px; width: 220px; flex-shrink: 0;
}
.uptime-bar i {
  flex: 1; border-radius: 2px; background: var(--border); opacity: .5;
  transition: background .2s;
}
.uptime-bar i.g { background: var(--green); opacity: .85; }
.uptime-bar i.b { background: var(--blue); opacity: .85; }
.uptime-bar i.r { background: var(--red); opacity: .85; }
.uptime-bar i.y { background: var(--yellow); opacity: .85; }

/* detail line */
.component-detail {
  width: 100%; display: flex; gap: 20px;
  font-size: 12px; color: var(--muted); padding: 0 0 2px;
  flex-wrap: wrap;
}
.component-detail span { white-space: nowrap; }
.component-detail .exit { font-family: ui-monospace, monospace; }

/* ── Incidents ── */
.incidents-section { margin-bottom: 32px; }
.section-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.incidents-list {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.incidents-day-header {
  padding: 10px 20px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.incident-row {
  display: flex; gap: 12px; align-items: baseline; padding: 10px 20px;
  border-bottom: 1px solid var(--border); font-size: 13px; flex-wrap: wrap;
}
.incident-row:last-child { border-bottom: none; }
.incident-time { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 70px; }
.incident-model {
  font-family: ui-monospace, monospace; font-size: 12px;
  background: var(--unknown-bg); padding: 1px 6px; border-radius: 4px;
  white-space: nowrap;
}
.incident-arrow { color: var(--muted); }
.incident-reason { color: var(--muted); font-size: 12px; flex: 1; min-width: 100px; }

.free-model {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; background: var(--unknown-bg);
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
#freeModels { flex-wrap: wrap; gap: 8px; }

/* ── Footer ── */
.page-footer {
  text-align: center; padding: 16px 24px;
  border-top: 1px solid var(--border); font-size: 12px;
}

.muted { color: var(--muted); }
.hidden { display: none; }

@media (max-width: 640px) {
  .masthead { padding: 14px 16px; }
  .content { padding: 20px 14px 36px; }
  .status-banner { padding: 16px; gap: 12px; }
  .banner-text h2 { font-size: 16px; }
  .component-row { padding: 12px 14px; }
  .uptime-bar { width: 140px; height: 18px; }
  .incident-row { padding: 8px 14px; }
}
