/* ---------- Colours (light mode) ---------- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #14171c;
  --text-muted: #5f6873;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --up: #16a34a;
  --up-soft: #dcfce7;
  --down: #dc2626;
  --down-soft: #fee2e2;
  --pending: #a1a8b3;
  --pending-soft: #eceef1;
  --empty-bar: #e6e8ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Colours (dark mode, follows the device setting) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1015;
    --surface: #151920;
    --surface-2: #1c212a;
    --border: #262c36;
    --text: #e8ebef;
    --text-muted: #949ca8;
    --accent: #818cf8;
    --accent-text: #0d1015;
    --up: #4ade80;
    --up-soft: rgba(74, 222, 128, 0.14);
    --down: #f87171;
    --down-soft: rgba(248, 113, 113, 0.14);
    --pending: #6b7380;
    --pending-soft: #222832;
    --empty-bar: #222832;
    --shadow: none;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; padding-bottom: 64px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.8rem); font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 16px; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 12px; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.mono { font-family: var(--mono); font-size: 0.88em; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.text-up { color: var(--up); }
.text-down { color: var(--down); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a {
  color: var(--text-muted); font-size: 0.92rem; font-weight: 500;
  padding: 6px 10px; border-radius: 8px; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); }

/* ---------- Hero ---------- */
.hero { padding: 48px 0 28px; max-width: 720px; }
.hero h1 { margin-bottom: 14px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.82rem; font-weight: 500; color: var(--text-muted);
  margin-bottom: 14px;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--up);
  box-shadow: 0 0 0 0 var(--up); animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 60%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.lead { font-size: 1.05rem; color: var(--text-muted); max-width: 680px; }

/* ---------- Summary tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
}
.tile-label { font-size: 0.8rem; color: var(--text-muted); }
.tile-value { font-size: 1.45rem; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.section { margin-top: 44px; }

/* ---------- Monitor cards ---------- */
.monitors { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.card-title { min-width: 0; }
.url { display: block; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.card-error {
  margin: 14px 0 0; padding: 8px 12px; border-radius: 8px;
  background: var(--down-soft); color: var(--down); font-size: 0.85rem;
}

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-up { background: var(--up-soft); color: var(--up); }
.pill-down { background: var(--down-soft); color: var(--down); }
.pill-pending { background: var(--pending-soft); color: var(--pending); }

.bars { display: flex; gap: 2px; height: 30px; }
.bar { flex: 1; border-radius: 2px; min-width: 2px; }
.bar-up { background: var(--up); }
.bar-down { background: var(--down); }
.bar-empty { background: var(--empty-bar); }
.bar:not(.bar-empty):hover { opacity: 0.7; }
.bars-legend { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0 0; }
.stats div { min-width: 0; }
.stats dt { font-size: 0.74rem; color: var(--text-muted); }
.stats dd { margin: 2px 0 0; font-weight: 600; font-size: 0.92rem; font-variant-numeric: tabular-nums; }

/* ---------- Events ---------- */
.events { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.event { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.event:first-child { border-top: 0; }
.event-body { flex: 1; min-width: 0; font-size: 0.92rem; }
.event time { font-size: 0.82rem; white-space: nowrap; }
.event-icon {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 0.85rem;
}
.event-up { background: var(--up-soft); color: var(--up); }
.event-down { background: var(--down-soft); color: var(--down); }

/* ---------- Panels, forms, buttons ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.narrow { max-width: 420px; padding-top: 48px; }
.narrow h1 { margin-bottom: 10px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 40px 0 20px; }
.admin-head h1 { margin-bottom: 8px; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { flex-direction: row; align-items: flex-end; flex-wrap: wrap; }
.form-row .grow { flex: 1; min-width: 200px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 500; }
input[type='text'], input[type='password'] {
  font: inherit; font-size: 0.95rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.btn {
  font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--down); }
.btn-small { padding: 6px 10px; font-size: 0.8rem; border-radius: 8px; }

.flash { padding: 12px 16px; border-radius: 10px; font-size: 0.92rem; margin-bottom: 16px; }
.flash-success { background: var(--up-soft); color: var(--up); }
.flash-error { background: var(--down-soft); color: var(--down); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; background: var(--surface); }
.table th { text-align: left; font-size: 0.78rem; font-weight: 500; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.section > .table-scroll { border: 1px solid var(--border); border-radius: var(--radius); }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.actions form { margin: 0; }

/* ---------- How it works ---------- */
.flow { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.flow-step {
  display: flex; gap: 16px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.flow-step h3 { margin-bottom: 4px; }
.flow-step p { margin: 0; color: var(--text-muted); }
.flow-num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 0.9rem;
  background: var(--accent); color: var(--accent-text);
}
.steps { margin: 8px 0 14px; padding-left: 22px; display: grid; gap: 8px; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); padding: 20px 0; font-size: 0.85rem; color: var(--text-muted); }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.footer-links { display: flex; gap: 16px; }

/* ---------- Phones and small screens ---------- */
@media (max-width: 820px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .monitors { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .hero { padding-top: 32px; }
  .stats { grid-template-columns: repeat(2, 1fr); row-gap: 12px; }
  .tile-value { font-size: 1.2rem; }
  .nav a { padding: 6px 8px; font-size: 0.85rem; }
  .flow-step { padding: 16px; gap: 12px; }
  .admin-head { flex-direction: column; }
  .event { flex-wrap: wrap; }
}
