:root {
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --surface-2: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success: #006300;

  --series-1: #2a78d6; /* blue: PV */
  --series-2: #1baf7a; /* aqua: UV */
  --series-3: #eda100; /* yellow */
  --series-4: #008300; /* green */
  --series-5: #4a3aa7; /* violet */
  --series-6: #e34948; /* red */
  --series-7: #e87ba4; /* magenta */
  --series-8: #eb6834; /* orange */

  --seq-100: #cde2fb;
  --seq-400: #3987e5;
  --seq-700: #0d366b;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --surface-2: #222221;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --success: #0ca30c;

    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --series-4: #008300;
    --series-5: #9085e9;
    --series-6: #e66767;
    --series-7: #d55181;
    --series-8: #d95926;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ---- login ---- */
#loginView {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
}
.login-card h1 {
  font-size: 18px;
  margin: 0 0 20px;
}
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 12px;
}
.login-error {
  color: var(--status-critical);
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 8px;
}

/* ---- buttons ---- */
button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  padding: 8px 14px;
}
button:hover { background: var(--gridline); }
button.primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}
button.primary:hover { opacity: 0.9; }
button.danger {
  color: var(--status-critical);
}
button.ghost {
  border-color: transparent;
  background: transparent;
}

/* ---- layout ---- */
header.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
header.topbar h1 {
  font-size: 16px;
  margin: 0;
  white-space: nowrap;
}
header.topbar select {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 13px;
  max-width: 220px;
}
.spacer { flex: 1; }

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

.range-row {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
}
.range-row button {
  border: none;
  background: transparent;
  border-radius: 7px;
  padding: 6px 14px;
}
.range-row button.active {
  background: var(--series-1);
  color: #fff;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.tile .label { color: var(--text-secondary); font-size: 12px; margin-bottom: 6px; }
.tile .value { font-size: 26px; font-weight: 600; }
.tile.online .value { color: var(--status-good); }
.tile .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--status-good);
  margin-right: 6px;
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h2 { font-size: 14px; margin: 0; color: var(--text-primary); }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}
@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
th { color: var(--text-muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; }
.bar-cell { position: relative; }
.bar-track {
  position: absolute;
  left: 0; bottom: 2px;
  height: 3px;
  background: var(--seq-100);
  border-radius: 2px;
}
.empty-note { color: var(--text-muted); font-size: 13px; padding: 12px 0; }

/* ---- sites panel ---- */
.site-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gridline);
}
.site-row:last-child { border-bottom: none; }
.site-row .meta { flex: 1; min-width: 0; }
.site-row .name { font-weight: 600; }
.site-row .domain { color: var(--text-secondary); font-size: 12px; }
.snippet-box {
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
  margin-top: 8px;
}
.add-site-form {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.add-site-form input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 13px;
}

/* ---- realtime feed ---- */
.feed-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 12px;
}
.feed-item:last-child { border-bottom: none; }
.feed-item .time { color: var(--text-muted); white-space: nowrap; width: 56px; }
.feed-item .path { flex: 1; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-item .loc { color: var(--text-secondary); white-space: nowrap; }
.badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--gridline);
  color: var(--text-secondary);
}

.chart-wrap { position: relative; height: 260px; }
.table-toggle { font-size: 12px; }
