:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #f0f3f4;
  --border: #d9e0e3;
  --text: #17222b;
  --muted: #5b6b76;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #e0f2f0;
  --ok: #15803d;   --ok-bg: #dcfce7;
  --warn: #a15c07; --warn-bg: #fef3c7;
  --err: #b91c1c;  --err-bg: #fee2e2;
  --info: #1d4ed8; --info-bg: #dbeafe;
  --mute: #55636d; --mute-bg: #e6eaec;
  --shadow: 0 8px 30px rgba(0, 0, 0, .18);
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1417;
    --surface: #151d21;
    --surface-2: #1b2529;
    --border: #2b373d;
    --text: #e6edf0;
    --muted: #93a4ad;
    --accent: #2dd4bf;
    --accent-text: #04201c;
    --accent-soft: #12332f;
    --ok: #4ade80;   --ok-bg: #12301d;
    --warn: #fbbf24; --warn-bg: #3a2d0a;
    --err: #f87171;  --err-bg: #3b1616;
    --info: #7db0ff; --info-bg: #14264a;
    --mute: #a3b1b8; --mute-bg: #243036;
    --shadow: 0 8px 30px rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 14px;
}
.brand { font-weight: 700; font-size: 15px; padding: 0 8px; }
.brand span { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: block; padding: 8px 10px; border-radius: 8px; color: var(--text);
  text-decoration: none; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }
.main { padding: 20px 24px 60px; min-width: 0; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .tools { display: flex; gap: 8px; flex-wrap: wrap; }
.section-title { margin: 22px 0 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row.center { align-items: center; }
.grow { flex: 1 1 200px; min-width: 0; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; min-width: 0;
}
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head .title { font-weight: 700; font-size: 15px; word-break: break-word; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat .v { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; }
.stat.bad .v { color: var(--err); }
.blocks { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.block { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--surface-2); min-width: 0; }
.block h3 { margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; word-break: break-word; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-ok { color: var(--ok); background: var(--ok-bg); }
.b-warn { color: var(--warn); background: var(--warn-bg); }
.b-err { color: var(--err); background: var(--err-bg); }
.b-info { color: var(--info); background: var(--info-bg); }
.b-mute { color: var(--mute); background: var(--mute-bg); }

/* Alerts */
.alert { border: 1px solid; border-radius: 8px; padding: 8px 10px; margin: 6px 0; font-size: 13px; }
.alert.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn); }
.alert.err { color: var(--err); background: var(--err-bg); border-color: var(--err); }
.alert.info { color: var(--info); background: var(--info-bg); border-color: var(--info); }
.alert.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok); }

/* Meter */
.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 16px; margin: 8px 0; }
.meter-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 3px; gap: 8px; }
.meter { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); width: 0; }
.meter.hot > i { background: var(--warn); }
.meter.full > i { background: var(--err); }

/* Buttons and forms */
.btn {
  font: inherit; cursor: pointer; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-height: 32px;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.sm { padding: 3px 9px; min-height: 26px; font-size: 12.5px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; text-decoration: underline; min-height: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin-bottom: 10px; }
.field > label, .field > .lbl { font-weight: 600; font-size: 12.5px; }
.hint { color: var(--muted); font-size: 12px; }
input[type="text"], input[type="password"], input[type="number"], input[type="url"], input[type="time"],
input[type="datetime-local"], input[type="search"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; width: 100%; min-height: 34px;
}
textarea { resize: vertical; min-height: 70px; }
input[type="number"] { max-width: 140px; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 2px 12px 2px 0; font-weight: 400 !important; font-size: 13px !important; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.checks { display: flex; flex-wrap: wrap; }
.range { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.range input { width: 90px; max-width: 90px; }
.group { border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: var(--surface-2); margin-bottom: 10px; }
.group .var { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.group .var textarea { flex: 1; }
.section-form { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.section-form:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.preview { border-left: 3px solid var(--accent); background: var(--surface-2); padding: 8px 10px; border-radius: 0 8px 8px 0; white-space: pre-wrap; word-break: break-word; }

/* Tables */
.tscroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); max-width: 100%; }
table.t { border-collapse: collapse; width: 100%; font-size: 13px; }
.t th, .t td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.t th { background: var(--surface-2); font-size: 12px; color: var(--muted); white-space: nowrap; }
.t tr:last-child td { border-bottom: 0; }
.t td.wrap { word-break: break-word; min-width: 160px; }
.t td.nowrap { white-space: nowrap; }

.empty { text-align: center; padding: 26px 14px; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }
.empty strong { color: var(--text); display: block; margin-bottom: 4px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { font: inherit; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
details.ev > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; margin: 6px 0 12px; white-space: pre; }
.codebox { position: relative; }
.codebox .btn { position: absolute; top: 6px; right: 6px; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); width: 100%; max-width: 520px; padding: 18px; }
.modal h2 { margin-bottom: 12px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.cred { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; margin-bottom: 8px; }
.cred .lbl { grid-column: 1 / -1; font-weight: 600; font-size: 12.5px; }
.cred code { padding: 6px 8px; display: block; }
.qr { display: block; margin: 8px auto; width: 260px; max-width: 100%; height: auto; background: #fff; padding: 8px; border-radius: 8px; image-rendering: pixelated; }
.pair { text-align: center; font-size: 32px; font-weight: 700; letter-spacing: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; padding: 14px 0; word-break: break-all; }

/* Toasts */
.toasts { position: fixed; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 24px); }
.toast { padding: 10px 14px; border-radius: 8px; border: 1px solid; box-shadow: var(--shadow); max-width: 380px; background: var(--surface); word-break: break-word; }
.toast.err { color: var(--err); border-color: var(--err); background: var(--err-bg); }
.toast.ok { color: var(--ok); border-color: var(--ok); background: var(--ok-bg); }
.toast.info { color: var(--info); border-color: var(--info); background: var(--info-bg); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 22px; }
.login h1 { margin-bottom: 4px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 8px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
  .brand { padding: 0 4px; }
  .nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; padding: 0; }
  .side-foot .small { display: none; }
  .main { padding: 14px 16px 50px; }
  .stat .v { font-size: 20px; }
  .tabs { overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
