:root {
  --brand: #50568e;
  --brand-dark: #3c4172;
  --brand-soft: #eef0f8;
  --mint: #e5f2f4;
  --bg: #f4f5fa;
  --card: #fff;
  --ink: #23263b;
  --dim: #7b8098;
  --line: #e6e8f0;
  --ok: #1e9e61;
  --bad: #d9364c;
  --warn: #c98206;
  --shadow: 0 1px 2px rgba(35, 38, 59, .05), 0 8px 24px rgba(35, 38, 59, .06);
  --radius: 12px;
}
* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; font-weight: 600; }
code, pre, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92em; }
.ico { width: 18px; height: 18px; flex: none; }
.dim { color: var(--dim); }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 236px; flex: none; background: var(--card); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: block; margin: 16px; border-radius: var(--radius); background: var(--brand); padding: 10px; text-align: center; }
.brand img { height: 62px; max-width: 100%; display: block; margin: 0 auto; }
.side nav { padding: 6px 0 20px; border-top: 1px solid var(--line); }
.side nav a, .side nav button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 11px 22px; color: #4a4f68; font: inherit; font-weight: 500; background: none; border: 0; border-left: 3px solid transparent; cursor: pointer; text-align: left; }
.side nav a:hover, .side nav button:hover { background: var(--bg); text-decoration: none; }
.side nav a.on { background: var(--brand-soft); color: var(--brand); border-left-color: var(--brand); font-weight: 600; }
.side nav form { margin: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--card); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 1.25rem; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 20px; color: #4a4f68; }
.top-right form { margin: 0; }
.when { display: flex; align-items: center; gap: 6px; color: var(--dim); }
.who b { color: var(--brand); }
.power { width: 38px; height: 38px; border-radius: 10px; border: 0; background: var(--bad); color: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 6px 14px rgba(217, 54, 76, .35); }
.power:hover { filter: brightness(.93); }
.burger { display: none; background: none; border: 0; color: var(--ink); cursor: pointer; padding: 4px; }
.content { padding: 28px; flex: 1; }
.foot { padding: 16px; text-align: center; color: var(--dim); border-top: 1px solid var(--line); background: var(--card); }
.foot b { color: var(--brand); }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 22px 24px; }
.pad h2 { font-size: 1.05rem; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 24px; margin: 18px 0 24px; }
.stat { position: relative; display: block; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 22px 18px; text-align: right; color: var(--ink); transition: transform .15s; }
.stat:hover { transform: translateY(-2px); text-decoration: none; }
.stat strong { display: block; font-size: 2.1rem; line-height: 1.2; font-weight: 700; }
.stat small { color: var(--dim); font-size: .95rem; }
.tile { position: absolute; left: 22px; top: -16px; width: 58px; height: 58px; border-radius: 14px; display: grid; place-items: center; color: #fff; }
.tile .ico { width: 26px; height: 26px; }
.c1 { background: var(--brand); box-shadow: 0 10px 20px rgba(80, 86, 142, .4); }
.c2 { background: #f0a030; box-shadow: 0 10px 20px rgba(240, 160, 48, .4); }
.c3 { background: #27a9b5; box-shadow: 0 10px 20px rgba(39, 169, 181, .4); }
.c4 { background: #e8344e; box-shadow: 0 10px 20px rgba(232, 52, 78, .4); }

.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 24px; }
.strip > div { display: flex; align-items: center; gap: 12px; padding: 16px 22px; border-right: 1px solid var(--line); }
.strip > div:last-child { border-right: 0; }
.strip small { display: block; color: var(--dim); }
.strip b { font-size: 1.15rem; }
.dot { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; }
.dot.in { background: #e3f5ec; color: var(--ok); }
.dot.out { background: var(--brand-soft); color: var(--brand); }
.dot.ok { background: var(--mint); color: #1d8791; }
.dot.wait { background: #fdf2dc; color: var(--warn); }

/* ---------- Panels & tables ---------- */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 24px; overflow: hidden; }
.panel > header { display: flex; align-items: center; gap: 10px; padding: 14px 22px; background: var(--brand); color: #fff; font-size: 1.08rem; font-weight: 600; }
.panel > header a { margin-left: auto; color: #fff; font-size: .88rem; font-weight: 400; opacity: .85; }
.table-wrap { overflow-x: auto; padding: 8px 20px 14px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-weight: 500; color: var(--dim); font-size: .88rem; border-bottom-width: 2px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfe; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--dim); padding: 34px 12px; white-space: normal; }
.row-actions { display: flex; gap: 6px; }
.row-actions form, td form { margin: 0; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 22px 16px; color: var(--dim); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; letter-spacing: .02em; }
.badge.ok { background: #e3f5ec; color: #14794a; }
.badge.bad { background: #fde8eb; color: #b3243a; }
.badge.warn { background: #fdf2dc; color: #94600a; }
.badge.mute { background: var(--bg); color: var(--dim); }
.badge.in { background: var(--mint); color: #17727b; }
.badge.out { background: var(--brand-soft); color: var(--brand); }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--brand); background: var(--brand); color: #fff; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--brand); border-color: #cfd2e3; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.sm { padding: 4px 10px; font-size: .86rem; border-radius: 6px; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; padding: 12px; font-size: 1.05rem; }
.btn.off { opacity: .45; pointer-events: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .side nav a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.bar p { margin: 0; color: #4a4f68; max-width: 70ch; }
label { display: block; font-weight: 500; font-size: .92rem; color: #4a4f68; }
label small, .note { display: block; font-weight: 400; color: var(--dim); font-size: .86rem; margin-top: 4px; }
input, select, textarea { display: block; width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid #cfd2e3; border-radius: 8px; font: inherit; color: var(--ink); background: #fff; }
input[type=checkbox] { display: inline-block; width: auto; margin: 0 6px 0 0; }
.form > * + * { margin-top: 14px; }
.form h2 { font-size: 1.15rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.two > label { margin: 0; }
.actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 6px; }
.checks { display: grid; gap: 8px; max-height: 260px; overflow-y: auto; padding: 4px; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; padding: 16px 20px; margin-bottom: 20px; }
.filters label { min-width: 120px; }
.filters .grow { flex: 1; min-width: 220px; }

dialog { border: 0; border-radius: 14px; padding: 26px 28px; width: min(600px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(35, 38, 59, .35); color: var(--ink); }
dialog::backdrop { background: rgba(35, 38, 59, .5); }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; border: 1px solid; }
.alert.ok { background: #e3f5ec; border-color: #b5e2cb; color: #14794a; }
.alert.bad { background: #fde8eb; border-color: #f6c1c9; color: #a01f33; }
.keybox { margin-bottom: 20px; border-left: 4px solid var(--warn); display: grid; gap: 10px; justify-items: start; }
.keybox code { background: var(--bg); padding: 10px 14px; border-radius: 8px; word-break: break-all; font-size: 1rem; }

.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; margin: 0; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; font-weight: 500; }

.docs { display: grid; gap: 20px; max-width: 900px; }
.docs h2 .dim { font-weight: 400; font-size: .92rem; }
.docs p { margin: 0 0 10px; max-width: 75ch; }
.docs pre { background: #2b2e4a; color: #e8eaf6; padding: 14px 16px; border-radius: 10px; overflow-x: auto; margin: 0 0 12px; }
.docs code { background: var(--brand-soft); color: var(--brand-dark); padding: 1px 5px; border-radius: 4px; }
.docs .table-wrap { padding: 0; }
.docs td { white-space: normal; }

/* ---------- Login ---------- */
body.login { background: linear-gradient(#fff, #fff) no-repeat; background: var(--bg); min-height: 100vh; }
.login-hero { background: var(--brand); color: #fff; text-align: center; padding: 44px 20px 120px; box-shadow: 0 18px 0 var(--mint); }
.login-hero img { height: 110px; }
.login-hero h1 { font-weight: 300; font-size: 2.3rem; margin-top: 4px; }
.login-hero p { margin: 8px 0 0; font-size: 1.25rem; font-weight: 300; opacity: .8; }
.login-card { width: min(420px, calc(100vw - 32px)); margin: -78px auto 40px; background: #fff; border-radius: 14px; box-shadow: 0 24px 60px rgba(35, 38, 59, .18); padding: 30px 32px 22px; position: relative; }
.login-card > * + * { margin-top: 16px; }
.login-foot { text-align: center; color: var(--dim); font-size: .86rem; margin-bottom: 0; }

@media (max-width: 900px) {
  .side { position: fixed; z-index: 20; left: -260px; transition: left .2s; box-shadow: var(--shadow); }
  .side.open { left: 0; }
  .burger { display: block; }
  .when { display: none; }
  .top { padding: 12px 16px; }
  .content { padding: 22px 16px; }
  .two { grid-template-columns: 1fr; }
  .bar { flex-direction: column; align-items: flex-start; }
  .strip > div { border-right: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 560px) { .who { display: none; } }

/* ---------- Two-factor ---------- */
input.otp { font-size: 1.6rem; letter-spacing: .45em; text-align: center; font-variant-numeric: tabular-nums; padding: 12px; }
.login-card form > * + * { margin-top: 16px; }
.login-links { display: flex; justify-content: space-between; align-items: center; }
.login-links > * + * { margin-top: 0 !important; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }

/* ---------- Groups & permissions ---------- */
td.wrap { white-space: normal; max-width: 320px; }
.perm-form { padding: 18px 22px 20px; }
.perm-form .note { margin: 0 0 16px; font-size: .95rem; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.perm-grid fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px 14px; margin: 0; }
.perm-grid legend { font-weight: 600; color: var(--brand); padding: 0 6px; }
.perm-grid .check { display: flex; align-items: flex-start; gap: 4px; font-weight: 400; color: var(--ink); padding: 5px 0; }
.perm-grid .check input { margin-top: 3px; }
.perm-grid input:disabled + * , .perm-grid .check:has(input:disabled) { color: var(--dim); }
.checks-cell { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
