:root {
  --bg: #f4f5f7;
  --surface: #fff;
  --text: #1c2026;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #2563eb;
  --accent-fg: #fff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef9c3;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e6e8eb;
    --muted: #8b929c;
    --border: #2a2e36;
    --accent: #3b82f6;
    --ok: #4ade80;
    --ok-bg: #14301f;
    --warn: #facc15;
    --warn-bg: #33300f;
    --err: #f87171;
    --err-bg: #3a1717;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.right { text-align: right; white-space: nowrap; }

/* ---------- шапка ---------- */
header {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a {
  text-decoration: none; padding: 6px 12px; border-radius: 6px; color: var(--muted); white-space: nowrap;
}
nav a:hover { color: var(--text); }
nav a.active { color: var(--text); background: var(--bg); font-weight: 500; }
body.anon nav, body.anon #logout { visibility: hidden; }

main { max-width: 1480px; margin: 0 auto; padding: 20px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* ---------- карточки ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.wide { grid-template-columns: 1fr; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; min-width: 0;
}
.card.error { border-color: var(--err); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; margin: 0; flex: 1; }
h2 { font-size: 15px; margin: 0 0 12px; }
.tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- таблицы ---------- */
.card { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.compact td { padding: 4px 8px; }
.tbl td .btn + .btn { margin-left: 4px; }

/* ---------- бейджи, полоски ---------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-bg); color: var(--err); border-color: transparent; }

.meters { display: grid; gap: 14px; }
.meters label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.meter { position: relative; height: 22px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.meter .bar { height: 100%; background: var(--accent); opacity: .25; transition: width .4s; }
.meter.hot .bar { background: var(--err); }
.meter span { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 8px; font-size: 12px; }

/* ---------- клиенты ---------- */
.dot-status { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--border); vertical-align: middle; }
.dot-status.ok { background: var(--ok); }
.dot-status.warn { background: var(--warn); }
.summary { display: flex; gap: 6px; flex-wrap: wrap; }
.filters { display: flex; gap: 16px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.filters .search { max-width: 320px; }
.check-inline { display: flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.tbl.clients td { white-space: nowrap; }
.tbl tr.off td { color: var(--muted); }
.sub { font-size: 12px; color: var(--muted); font-family: system-ui, sans-serif; }
.warn-text { color: var(--warn); }
.note { font-size: 12px; margin: 12px 0 0; }
input[readonly] { opacity: .7; }

/* ---------- Wi-Fi ---------- */
.iface { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.iface.off { opacity: .55; }
.iface-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.clients { margin-top: 6px; }

/* ---------- кнопки, формы ---------- */
.btn {
  font: inherit; padding: 7px 14px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--err); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: progress; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); }
.field small { color: var(--muted); font-size: 12px; }
.field.check { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
.field.check > span { color: var(--text); }
input, select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg); color: var(--text); width: 100%;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.pw { display: flex; gap: 4px; }
.eye { border: 1px solid var(--border); background: var(--bg); border-radius: 7px; cursor: pointer; padding: 0 10px; }
.form-error { color: var(--err); min-height: 1.2em; margin-bottom: 8px; }

.login { max-width: 360px; margin: 10vh auto 0; }
.login .btn { width: 100%; }

dialog.modal {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  background: var(--surface); color: var(--text); width: min(440px, calc(100vw - 32px));
}
dialog.modal::backdrop { background: rgb(0 0 0 / .4); }
dialog h3 { margin: 0 0 16px; font-size: 16px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- уведомления ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast {
  padding: 10px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgb(0 0 0 / .12); max-width: 360px; transition: opacity .4s;
}
.toast.ok { border-left: 4px solid var(--ok); }
.toast.error { border-left: 4px solid var(--err); }
.toast.hide { opacity: 0; }

@media (max-width: 640px) {
  header { gap: 10px; padding: 0 12px; }
  .brand #hostname { display: none; }
  main { padding: 12px; }
  .grid { grid-template-columns: 1fr; }
}
