:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7684;
  --line: #e4e8ee;
  --blue: #2563eb;
  --blue-soft: #dbe7fe;
  --orange: #f59e0b;
  --green: #16a34a;
  --green-soft: #e8f6ee;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber-soft: #fff6e0;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
/* the hidden attribute must win over display rules (e.g. the filter labels' flex) */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 22px; margin: 4px 0 2px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.hint { color: var(--muted); font-size: 13px; margin: -6px 0 10px; }
.muted { color: var(--muted); }
button, input, select {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px;
}
button { cursor: pointer; }
button:hover { border-color: var(--blue); }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.link { border: none; background: none; color: var(--muted); padding: 6px 4px; }
button.link:hover { color: var(--text); }

/* header */
.top {
  display: flex; align-items: center; gap: 0 24px; flex-wrap: wrap;
  padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; padding: 14px 0; }
/* tabs wrap onto a second line on narrow windows: none is ever hidden */
.tabs { display: flex; flex-wrap: wrap; gap: 0 4px; flex: 1 1 420px; min-width: 0; }
.tabs a {
  padding: 14px 10px 12px; color: var(--muted); text-decoration: none; white-space: nowrap;
  border-bottom: 3px solid transparent; font-weight: 500;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }
.account { display: flex; align-items: center; gap: 4px; margin-left: auto; }
a.link { color: var(--muted); text-decoration: none; padding: 6px 4px; font-size: 15px; }
a.link:hover { color: var(--text); }
.logout { margin: 0; }

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  max-width: 1200px; margin: 16px auto 0; padding: 0 20px;
}
.filters label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 14px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets button.on { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }

main { max-width: 1200px; margin: 0 auto; padding: 16px 20px 40px; }
.page { display: none; }
.page.active { display: block; }
.status { padding: 10px 14px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); }
.status.error { border-color: var(--red); color: var(--red); background: var(--red-soft); }

/* number tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.tile .label { color: var(--muted); font-size: 14px; }
.tile .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tile.good { border-left: 4px solid var(--green); }
.tile.bad { border-left: 4px solid var(--red); }
.tile.warn { border-left: 4px solid var(--orange); }

/* cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px; min-width: 0;
}
.card h2 { font-size: 16px; margin: 0 0 12px; }
.chart { position: relative; height: 280px; }
.chart.short { height: 220px; }
.chart .empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); }

/* engine status banner */
.banner { border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; border: 1px solid var(--line); }
.banner .title { font-size: 20px; font-weight: 700; }
.banner .sub { color: var(--muted); margin-top: 2px; }
.banner.good { background: var(--green-soft); border-color: var(--green); }
.banner.good .title { color: var(--green); }
.banner.bad { background: var(--red-soft); border-color: var(--red); }
.banner.bad .title { color: var(--red); }
.banner.warn { background: var(--amber-soft); border-color: var(--orange); }

/* needs attention */
ul.attention { list-style: none; margin: 0; padding: 0; }
ul.attention li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
ul.attention li:last-child { border-bottom: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; transform: translateY(1px); }
.dot.ok { background: var(--green); }
.dot.warn { background: var(--orange); }
.dot.bad { background: var(--red); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f0f5ff; }
.up { color: var(--green); }
.down { color: var(--red); }

/* lookup */
.search { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; align-items: center; }
.search input { flex: 1 1 260px; min-width: 0; padding: 9px 12px; }
.search select { padding: 8px 10px; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.pager .muted { margin-right: auto; font-size: 14px; }
.pager button:disabled { opacity: 0.4; cursor: default; }
pre.json {
  max-height: 380px; overflow: auto; background: var(--bg); padding: 12px; border-radius: 8px;
  font-size: 12px; border: 1px solid var(--line);
}
dl.fields { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0 0 14px; }
dl.fields dt { color: var(--muted); }
dl.fields dd { margin: 0; overflow-wrap: anywhere; }
.error { color: var(--red); }

/* login */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card form { display: grid; gap: 14px; margin-top: 18px; }
.login-card label { display: grid; gap: 4px; color: var(--muted); }
.login-card button { background: var(--blue); color: #fff; border-color: var(--blue); padding: 9px; }
.login-card .back { color: var(--muted); text-decoration: none; font-size: 14px; }
.login-card .back:hover { color: var(--text); }
.login-card p.ok { color: var(--green); background: var(--green-soft); padding: 8px 10px; border-radius: 8px; }
.login-card p.error { background: var(--red-soft); padding: 8px 10px; border-radius: 8px; }

@media (max-width: 640px) {
  .top { padding: 0 16px; }
  .filters, main { padding-left: 16px; padding-right: 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile .value { font-size: 22px; }
}
