:root {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #e2e5ec;
  --text: #1a1d24;
  --muted: #667085;
  --accent: #3b5bdb;
  --accent-soft: #e8edfd;
  --ok: #2f9e44;
  --ok-soft: #e6f6ea;
  --warn: #c77c02;
  --warn-soft: #fdf3e1;
  --bad: #d63939;
  --bad-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e6e8ee;
    --muted: #9aa3b2;
    --accent: #7c95f5;
    --accent-soft: #232b45;
    --ok: #5cc777;
    --ok-soft: #1b2e21;
    --warn: #f0b64a;
    --warn-soft: #33291a;
    --bad: #f07272;
    --bad-soft: #3a1f22;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot { min-height: 100vh; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 16px; height: 16px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count { background: var(--bad); color: #fff; font-size: 11px; border-radius: 10px; padding: 0 7px; font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .foot { padding: 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }

.main { padding: 28px 32px 60px; min-width: 0; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 8px 0 0; }
  .nav { display: flex; gap: 2px; overflow-x: auto; width: 100%; }
  .nav a { white-space: nowrap; gap: 6px; }
  .sidebar .spacer { display: none; }
  .sidebar .foot { flex-direction: row; padding: 4px 0; width: 100%; justify-content: space-between; }
  .main { padding: 20px 16px 48px; }
}

/* ---------- cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }

.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat.attention { border-color: var(--warn); }
.stat.attention .value { color: var(--warn); }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { border-color: var(--accent); }

/* ---------- list / table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 11px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); margin: 0 4px 4px 0; }

/* ---------- forms / buttons ---------- */
button, .btn {
  font: inherit; font-weight: 550; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 7px 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; line-height: 1.3;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.small { padding: 4px 10px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.form-grid { display: grid; gap: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 12px; }
@media (max-width: 700px) { .form-row { grid-template-columns: 1fr; } }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.check input { width: auto; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 160px; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.segmented button { border: 0; background: transparent; padding: 5px 12px; color: var(--muted); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- details ---------- */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12.5px; }
dl.kv dd { margin: 0; word-break: break-word; }
.prose { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
pre.json { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; overflow: auto; max-height: 320px; margin: 6px 0 0; }

.service { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-top: 12px; }
.service-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.service-head code { font-size: 13.5px; font-weight: 700; }
.params { width: 100%; margin-top: 6px; font-size: 13px; }
.params td, .params th { padding: 6px 10px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 4px; }

/* ---------- messages ---------- */
.msg { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: 0; }
.msg-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.msg-head .who { font-weight: 650; }
.msg-subject { font-weight: 600; margin-top: 4px; }
.msg-body { white-space: pre-wrap; word-break: break-word; margin-top: 4px; }
.msg.system { background: var(--surface-2); }

/* ---------- events ---------- */
.ev-type { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.ev-details { font-family: var(--mono); font-size: 11.5px; color: var(--muted); word-break: break-all; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-top: 6px; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); } .dot.info { background: var(--accent); }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 70px; padding: 0 18px 14px; }
.bars div { flex: 1; background: var(--accent); opacity: .75; border-radius: 3px 3px 0 0; min-height: 2px; }
.bars div:hover { opacity: 1; }
.bars-axis { display: flex; justify-content: space-between; padding: 0 18px 12px; font-size: 11px; color: var(--muted); }

/* ---------- login / review ---------- */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card .brand { padding: 0 0 18px; }
.review-card { width: 100%; max-width: 720px; }
.error-text { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 18, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; }
.modal .card-head { position: sticky; top: 0; background: var(--surface); }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 360px; font-size: 13px; }
.toast.bad { background: var(--bad); color: #fff; }
.key-box { font-family: var(--mono); background: var(--surface-2); padding: 10px; border-radius: 8px; word-break: break-all; user-select: all; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.mt { margin-top: 16px; }
.mt-s { margin-top: 8px; }
