:root {
  --bg: oklch(16% 0.02 250);
  --surface: oklch(21% 0.02 250);
  --surface-2: oklch(25% 0.025 250);
  --border: oklch(32% 0.02 250);
  --text: oklch(92% 0.01 250);
  --muted: oklch(65% 0.02 250);
  --accent: oklch(78% 0.16 155);
  --accent-dim: oklch(78% 0.16 155 / 0.15);
  --danger: oklch(68% 0.19 25);
  --mono: "SF Mono", ui-monospace, Menlo, monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "PingFang TC", "Noto Sans TC", sans-serif;
}

h1 { font-size: 1.05rem; margin: 0; letter-spacing: 0.02em; }
h2 { font-size: 0.78rem; font-weight: 600; color: var(--muted); margin: 0; text-transform: uppercase; letter-spacing: 0.08em; }

.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  display: inline-block;
}

/* ---- top bar ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.9rem 1.4rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { display: flex; align-items: center; gap: 0.7rem; }

.pill {
  font-family: var(--mono); font-size: 0.72rem;
  padding: 0.2rem 0.65rem; border-radius: 99px;
  border: 1px solid var(--border);
}
.pill-on  { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.pill-off { color: var(--danger); border-color: var(--danger); }

.logout { color: var(--muted); text-decoration: none; font-size: 0.85rem; }
.logout:hover, .logout:focus-visible { color: var(--text); text-decoration: underline; }

main { padding: 1.4rem; max-width: 1200px; margin: 0 auto; }

/* ---- stats ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.4rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.stat p {
  margin: 0.3rem 0 0;
  font-family: var(--mono);
  font-size: 1.5rem;
  color: var(--accent);
}
.stat .stat-small { font-size: 0.9rem; color: var(--text); }

/* ---- panels ---- */
.panels { display: grid; grid-template-columns: 2fr 1fr; gap: 0.9rem; align-items: start; }
@media (max-width: 900px) { .panels { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.feed-panel table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.feed-panel th {
  text-align: left; padding: 0.45rem 1rem;
  color: var(--muted); font-weight: 600; font-size: 0.72rem;
  border-bottom: 1px solid var(--border);
}
.feed-panel td { padding: 0.4rem 1rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.feed-panel .ts { font-family: var(--mono); color: var(--muted); white-space: nowrap; }
.feed-panel .topic { font-family: var(--mono); color: var(--accent); word-break: break-all; }
.feed-panel .payload { font-family: var(--mono); word-break: break-all; }
.row-new { animation: flash 0.8s ease-out; }
@keyframes flash { from { background: var(--accent-dim); } to { background: transparent; } }
.empty-hint { padding: 1.2rem 1rem; margin: 0; }

/* ---- forms ---- */
form { display: flex; flex-direction: column; gap: 0.45rem; padding: 1rem; }
label { font-size: 0.78rem; color: var(--muted); }
input:not([type="checkbox"]), textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.55rem 0.7rem;
}
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: 0.45rem; }
button {
  margin-top: 0.4rem;
  background: var(--accent);
  color: oklch(18% 0.03 155);
  border: none; border-radius: 6px;
  padding: 0.6rem;
  font-weight: 700; font-size: 0.9rem;
  cursor: pointer;
  transition: filter 120ms;
}
button:hover { filter: brightness(1.12); }
button:active { filter: brightness(0.95); }
.muted { color: var(--muted); font-size: 0.8rem; }

/* ---- login ---- */
.login-body {
  display: grid; place-items: center; min-height: 100dvh;
  background:
    radial-gradient(60rem 30rem at 70% -10%, var(--accent-dim), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(92vw, 360px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 1.8rem;
  box-shadow: 0 20px 60px oklch(0% 0 0 / 0.45);
}
.login-brand { text-align: center; margin-bottom: 1.4rem; }
.login-brand h1 { font-size: 1.2rem; margin-top: 0.6rem; }
.brand-sub { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; margin: 0.2rem 0 0; }
.form-error {
  color: var(--danger);
  background: oklch(68% 0.19 25 / 0.12);
  border: 1px solid oklch(68% 0.19 25 / 0.4);
  border-radius: 6px;
  font-size: 0.8rem;
  padding: 0.5rem 0.7rem;
  margin: 0 0 0.3rem;
}
