:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1c2330;
  --muted: #647084;
  --line: #e1e4ea;
  --brand: #1f5fbf;
  --brand-ink: #ffffff;
  --side: #17202e;
  --side-ink: #c9d2e0;
  --ok: #1a7f4b;
  --ok-bg: #e3f4ea;
  --warn: #9a6200;
  --warn-bg: #fdf1d6;
  --err: #b3261e;
  --err-bg: #fbe5e3;
  --info: #1f5fbf;
  --info-bg: #e3edfb;
  --off-bg: #eceef2;
  --radius: 8px;
}

* { box-sizing: border-box; }

html { font-size: 15px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0.15rem 0; }
h2 { font-size: 1.05rem; margin: 0; }
code, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.9em; }
pre { background: var(--bg); padding: 0.75rem; border-radius: var(--radius); overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 0.87rem; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--side);
  color: var(--side-ink);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.8rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; padding: 0 0.6rem 1rem; }
.brand span { font-weight: 400; opacity: 0.7; margin-left: 0.25rem; }
.brand:hover { text-decoration: none; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: var(--side-ink); padding: 0.5rem 0.6rem; border-radius: 6px; }
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.sidebar nav a.active { background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 0.6rem; border-top: 1px solid rgba(255, 255, 255, 0.12); }
.sidebar-foot .who { color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .muted { color: #8f9bb0; margin-bottom: 0.6rem; }
.content { padding: 1.5rem 2rem 3rem; max-width: 1280px; width: 100%; }
.centered { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.8rem; }
.empty { text-align: center; padding: 2.5rem 1.25rem; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 0.9rem; }
.auth-card h1 { font-size: 1.3rem; }
.auth-card p { margin: 0; }
.danger-zone { border-color: #efc6c2; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { margin: 0; }
.kpi-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.kpi-value span { font-size: 1rem; color: var(--muted); font-weight: 400; }
.kpi-label { color: var(--muted); font-size: 0.9rem; }
.kpi-alert { border-color: var(--err); }
.kpi-alert .kpi-value { color: var(--err); }

/* Source lights */
.source-lights { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; }
.source-lights li { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.light { width: 11px; height: 11px; border-radius: 50%; flex: none; background: #b5bcc9; }
.light-ok { background: var(--ok); }
.light-degraded { background: #d99a00; }
.light-blocked, .light-error { background: var(--err); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.badge { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--off-bg); color: var(--muted); white-space: nowrap; }
.badge-ok, .badge-health-ok { background: var(--ok-bg); color: var(--ok); }
.badge-running, .badge-queued { background: var(--info-bg); color: var(--info); }
.badge-partial, .badge-health-degraded { background: var(--warn-bg); color: var(--warn); }
.badge-error, .badge-blocked, .badge-health-error, .badge-health-blocked { background: var(--err-bg); color: var(--err); }

/* Facts */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.9rem 1.5rem; margin: 0; }
.facts dt { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.facts dd { margin: 0.1rem 0 0; overflow-wrap: anywhere; }

/* Forms */
label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"], select, textarea {
  font: inherit;
  font-weight: 400;
  padding: 0.5rem 0.6rem;
  border: 1px solid #c3c9d4;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input:disabled { background: var(--off-bg); color: var(--muted); }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 0.9rem; resize: vertical; }
.form { display: flex; flex-direction: column; gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.83rem; }
.field-error { font-weight: 400; color: var(--err); font-size: 0.85rem; }
.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 400; }
.filters { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.filters label { min-width: 200px; }
.code { font-size: 1.4rem; letter-spacing: 0.3em; text-align: center; }
.qr { display: grid; place-items: center; }
details { margin-top: 0.75rem; }
summary { cursor: pointer; color: var(--brand); font-weight: 600; margin-bottom: 0.75rem; }

/* Buttons */
.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  border-radius: 6px;
  border: 1px solid #c3c9d4;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: #194f9f; }
.btn-danger { background: #fff; border-color: var(--err); color: var(--err); }
.btn-danger:hover { background: var(--err-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.87rem; }
.sidebar .btn-ghost { color: var(--side-ink); border-color: rgba(255, 255, 255, 0.25); }
.sidebar .btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }

/* Flash messages */
.flash { padding: 0.65rem 0.9rem; border-radius: 6px; margin-bottom: 1rem; background: var(--ok-bg); color: var(--ok); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-error { background: var(--err-bg); color: var(--err); }

/* Scan log */
.log { background: #111823; color: #d5dbe6; border-radius: 6px; padding: 0.75rem; height: 420px; overflow-y: auto; font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.log-line { display: flex; gap: 0.75rem; padding: 1px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-ts { color: #7f8ba0; flex: none; }
.log-warning { color: #f2c462; }
.log-error { color: #ff8f85; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin-top: 0.8rem; }
  .content { padding: 1rem; }
}
