:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1b2430; --muted: #657186; --line: #e2e6ec;
  --brand: #1f5fd1; --brand-ink: #ffffff; --ok: #15803d; --ok-bg: #dcfce7; --bad: #b91c1c; --bad-bg: #fee2e2;
  --warn: #92400e; --warn-bg: #fef3c7; --none: #d6dbe3; --hover: #f0f4fb;
  --radius: 8px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b; --panel: #1a2029; --ink: #e6ebf2; --muted: #9aa6b8; --line: #2b3441;
    --brand: #5b8def; --ok: #4ade80; --ok-bg: #12301f; --bad: #f87171; --bad-bg: #3a1717;
    --warn: #fbbf24; --warn-bg: #3a2c0c; --none: #3a4352; --hover: #222a36;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 4px 0 12px; } h2 { font-size: 17px; margin: 16px 0 8px; } h3 { font-size: 15px; margin: 14px 0 6px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: ui-monospace, Consolas, monospace; }
.err { color: var(--bad); } .empty { text-align: center; color: var(--muted); padding: 24px; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; color: var(--ink); } .brand span, .login h1 span { color: var(--brand); font-weight: 600; }
.topbar nav { display: flex; gap: 4px; } .topbar nav a { padding: 6px 12px; border-radius: 6px; color: var(--ink); }
.topbar nav a.on { background: var(--hover); color: var(--brand); font-weight: 600; }
.who { margin-left: auto; display: flex; gap: 12px; align-items: center; color: var(--muted); }
main { padding: 16px 20px; } main.center { display: grid; place-items: center; min-height: 80vh; }
main.with-side { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.login { width: min(360px, 100%); display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-weight: 500; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
textarea { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); text-decoration: none; } .btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--hover); }
.pill.warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.okbox { background: var(--ok-bg); color: var(--ok); padding: 8px 12px; border-radius: 6px; }
.warnbox { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: 6px; }

.tree { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.tree a, .tree summary { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 5px; color: var(--ink); }
.tree summary { cursor: pointer; } .tree summary a { padding: 0; flex: 1; font-weight: 600; }
.tree a.st { padding-left: 22px; font-size: 13px; }
.tree a.on, .tree-all.on { background: var(--hover); color: var(--brand); }
.tree b { margin-left: auto; font-weight: 500; color: var(--muted); font-size: 12px; }
.tree .ratio { font-style: normal; font-size: 11px; color: var(--ok); min-width: 28px; text-align: right; }
.tree-all { font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; color: var(--ink); display: grid; }
.stat b { font-size: 22px; } .stat b.small { font-size: 13px; } .stat span { color: var(--muted); font-size: 12px; }
.stat.online b { color: var(--ok); } .stat.offline b { color: var(--bad); } .stat.failed b { color: var(--warn); }
.stat:hover { text-decoration: none; border-color: var(--brand); } .stat.meta:hover { border-color: var(--line); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.filters .grow { flex: 1 1 260px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--ink); }
.chip.on { border-color: var(--brand); color: var(--brand); } .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.selbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 10px; position: sticky; top: 56px; z-index: 3; }
.selbar .muted { margin-left: auto; }

.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); }
.grid th, .grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--panel); position: sticky; top: 0; }
.grid tbody tr:hover { background: var(--hover); }
.grid.compact td, .grid.compact th { padding: 5px 8px; }
td.ck, th.ck { width: 32px; } .w40 { width: 30%; }
td.mono { white-space: nowrap; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.st-online { background: var(--ok-bg); color: var(--ok); } .st-offline { background: var(--bad-bg); color: var(--bad); }
.st-check_failed { background: var(--warn-bg); color: var(--warn); } .st-unknown, .st-none { background: var(--hover); color: var(--muted); }
.geo { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; font-size: 11px; font-weight: 700; }
.geo.ok { background: var(--ok-bg); color: var(--ok); } .geo.bad { background: var(--warn-bg); color: var(--warn); } .geo.none { color: var(--muted); }
.mapbtn { border: 1px solid var(--line); background: var(--panel); color: var(--brand); border-radius: 6px; cursor: pointer; font-size: 16px; line-height: 1; padding: 3px 7px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 12px 0; }

.mappanel { position: fixed; right: 16px; top: 72px; width: min(420px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 14px; z-index: 10; }
.mappanel .close { position: absolute; right: 8px; top: 6px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.mappanel h3 { margin: 0 24px 4px 0; }
.mapframe { width: 100%; aspect-ratio: 4 / 3; background: var(--hover); border-radius: 6px; margin: 8px 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 8px; }
.mapframe iframe { width: 100%; height: 100%; border: 0; border-radius: 6px; }

.detail { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 12px 0; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
.strip { display: flex; gap: 3px; flex-wrap: wrap; } .day { display: inline-block; width: 14px; height: 22px; border-radius: 3px; }
.strip .st-online, .legend .st-online { background: var(--ok); } .strip .st-offline, .legend .st-offline { background: var(--bad); }
.strip .st-check_failed, .legend .st-check_failed { background: var(--warn); } .strip .st-none, .legend .st-none { background: var(--none); }
.legend .day { width: 10px; height: 10px; vertical-align: middle; margin-left: 8px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
.head-row { display: flex; align-items: center; gap: 16px; justify-content: space-between; flex-wrap: wrap; }
meter { width: 70%; height: 14px; vertical-align: middle; }
.retitle { display: flex; gap: 8px; align-items: end; margin-bottom: 12px; } .retitle label { flex: 1; max-width: 520px; }
.report { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; overflow-x: auto; margin-bottom: 16px; }

@media (max-width: 900px) {
  main.with-side, .detail, .cols { grid-template-columns: 1fr; }
  .tree { position: static; max-height: 260px; }
  main { padding: 12px 16px; }
  .selbar { position: static; }
}
@media print {
  .topbar, .foot, .noprint, .selbar, .mappanel { display: none !important; }
  body, .report, table.grid { background: #fff; color: #000; }
  .report { border: 0; padding: 0; }
  .grid th, .grid td { border-bottom: 1px solid #ccc; font-size: 11px; }
}
