:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #f0f3f7;
  --border: #dde3ea;
  --text: #1c2430;
  --muted: #64707f;
  --accent: #1f6feb;
  --accent-soft: #e3edff;
  --ok: #1a7f37;
  --ok-soft: #dcf5e3;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #cf222e;
  --bad-soft: #ffe3e5;
  --info: #6639ba;
  --info-soft: #efe6ff;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --panel: #161c24;
    --panel-2: #1d252f;
    --border: #2a3441;
    --text: #e3e8ee;
    --muted: #8b97a6;
    --accent: #4c8dff;
    --accent-soft: #1a2a45;
    --ok: #3fb950;
    --ok-soft: #12301c;
    --warn: #d29922;
    --warn-soft: #362a0d;
    --bad: #f85149;
    --bad-soft: #3d1517;
    --info: #a371f7;
    --info-soft: #2a1f42;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1em; }
.nowrap { white-space: nowrap; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; min-width: 0;
}
textarea { font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
button {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.danger:hover { border-color: var(--bad); }
button.small { padding: 2px 8px; font-size: 12.5px; }
button.link { background: none; border: none; color: var(--accent); padding: 0; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: 100%; max-width: 340px; display: grid; gap: 14px; }
.login-card label { display: grid; gap: 4px; color: var(--muted); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.brand img { width: 28px; height: 28px; }

.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar nav a { color: var(--text); padding: 7px 10px; border-radius: 6px; }
.sidebar nav a:hover { background: var(--panel-2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.me { margin-top: auto; display: grid; gap: 4px; font-size: 13px; }
.version { color: var(--muted); font-size: 11.5px; }
main { padding: 22px 26px; min-width: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.card .label { color: var(--muted); font-size: 12.5px; }
.card .value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: center; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th.left, td.left { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; position: sticky; top: 0; background: var(--panel); }
tbody tr:hover { background: var(--panel-2); }
tr.clickable { cursor: pointer; }
td.preview { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; }
td.num { font-variant-numeric: tabular-nums; }
.small { font-size: 11.5px; }
.empty { color: var(--muted); padding: 16px 8px; text-align: center; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow: auto; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 320px; margin: 0; }

.chart { width: 100%; height: 140px; display: block; }
.chart .ok { fill: var(--ok); }
.chart .bad { fill: var(--bad); }
.chart .other { fill: var(--info); }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }
.bar.warn > div { background: var(--warn); }
.bar.bad > div { background: var(--bad); }

.form-row { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; margin-bottom: 10px; }
.form-row label { display: grid; gap: 4px; color: var(--muted); font-size: 12.5px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: start center; padding: 40px 16px; overflow: auto; z-index: 10; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: 100%; max-width: 960px; position: relative; }
.modal-close { position: absolute; top: 10px; right: 12px; border: none; background: none; font-size: 22px; line-height: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 12px 0; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 10px; color: var(--muted); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.toast { position: fixed; bottom: 18px; right: 18px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; z-index: 20; max-width: 420px; }
.toast.bad { background: var(--bad); color: #fff; }

.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .sidebar nav { display: flex; flex-wrap: wrap; }
  .me { margin: 0 0 0 auto; }
  main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
}
