:root {
  --bg: #0b0e14; --bg2: #0f131b; --panel: #141922; --panel2: #1a2030; --line: #232b3b; --line2: #2d3750;
  --text: #e8edf6; --mut: #8a95aa; --acc: #6d7cff; --acc2: #8b5cf6; --accbg: rgba(109, 124, 255, .13);
  --ok: #34d399; --okbg: rgba(52, 211, 153, .12); --bad: #f87171; --badbg: rgba(248, 113, 113, .12);
  --warn: #fbbf24; --warnbg: rgba(251, 191, 36, .12); --info: #60a5fa; --infobg: rgba(96, 165, 250, .12);
  --shadow: 0 10px 30px rgba(0, 0, 0, .35); --r: 12px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9; --bg2: #eceff5; --panel: #fff; --panel2: #f7f8fb; --line: #e1e6ee; --line2: #cfd7e4;
    --text: #172033; --mut: #5f6c82; --acc: #4f5fe6; --acc2: #7c3aed; --accbg: rgba(79, 95, 230, .1);
    --ok: #0f9f6e; --okbg: rgba(15, 159, 110, .1); --bad: #dc2626; --badbg: rgba(220, 38, 38, .08);
    --warn: #b7791f; --warnbg: rgba(183, 121, 31, .1); --info: #2563eb; --infobg: rgba(37, 99, 235, .08);
    --shadow: 0 10px 30px rgba(23, 32, 51, .12);
  }
}
* { box-sizing: border-box; }
html { color-scheme: dark light; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 Inter, system-ui, 'Segoe UI', Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accbg); }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
h3 { margin: 0 0 10px; font-size: 15px; }
p { margin: 0 0 10px; }
code, .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12.5px; }
.mut { color: var(--mut); }
.sm { font-size: 12px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; background: var(--bg2); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--acc), var(--acc2)); display: grid; place-items: center; color: #fff; box-shadow: 0 6px 16px rgba(109, 124, 255, .35); }
.navlabel { padding: 14px 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--mut); }
.nav { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 12px; border: 0; border-radius: 9px; background: none; color: var(--mut); cursor: pointer; text-align: left; transition: background .15s, color .15s; }
.nav:hover { background: var(--panel); color: var(--text); }
.nav.on { background: var(--accbg); color: var(--acc); font-weight: 600; }
.nav .count { margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel2); color: var(--mut); }
.side .sp { flex: 1; }
.userbox { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); margin-top: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--acc), var(--acc2)); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.userbox .who { flex: 1; min-width: 0; line-height: 1.25; }
.main { min-width: 0; padding: 26px 32px 60px; max-width: 1280px; width: 100%; }
.head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.head .t { flex: 1; min-width: 200px; }
.head .t p { margin: 4px 0 0; color: var(--mut); }
.btn.menu-btn { display: none; }

/* ---------- components ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; margin-bottom: 16px; }
.card.flat { padding: 0; overflow: hidden; }
.card h3 .mut { font-weight: 400; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.stat { display: flex; gap: 14px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.stat .ico { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; background: var(--accbg); color: var(--acc); flex: none; }
.stat.ok .ico { background: var(--okbg); color: var(--ok); } .stat.bad .ico { background: var(--badbg); color: var(--bad); } .stat.warn .ico { background: var(--warnbg); color: var(--warn); } .stat.info .ico { background: var(--infobg); color: var(--info); }
.stat b { display: block; font-size: 26px; line-height: 1.1; letter-spacing: -.02em; }
.stat span { color: var(--mut); font-size: 12.5px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row.c { align-items: center; }
.row .grow { flex: 1; min-width: 160px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--mut); min-width: 0; }
input, select, textarea { background: var(--bg2); border: 1px solid var(--line2); border-radius: 9px; padding: 9px 11px; min-width: 0; transition: border-color .15s, box-shadow .15s; width: 100%; }
input[type=number] { width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--acc); box-shadow: 0 0 0 3px var(--accbg); outline: none; }
input::placeholder, textarea::placeholder { color: var(--mut); opacity: .7; }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { border-color: var(--acc); }
.btn:active { transform: translateY(1px); }
.btn.pri { background: linear-gradient(135deg, var(--acc), var(--acc2)); border-color: transparent; color: #fff; box-shadow: 0 6px 16px rgba(109, 124, 255, .25); }
.btn.pri:hover { filter: brightness(1.08); }
.btn.dng { color: var(--bad); } .btn.dng:hover { border-color: var(--bad); background: var(--badbg); }
.btn.dng.solid { background: var(--bad); color: #fff; border-color: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn.ghost { background: none; border-color: transparent; color: var(--mut); } .btn.ghost:hover { color: var(--text); background: var(--panel2); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--panel2); color: var(--mut); }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active, .badge.ok { background: var(--okbg); color: var(--ok); }
.badge.banned, .badge.expired, .badge.bad { background: var(--badbg); color: var(--bad); }
.badge.unused, .badge.warn { background: var(--warnbg); color: var(--warn); }
.badge.info { background: var(--infobg); color: var(--info); }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.empty { text-align: center; padding: 44px 20px; color: var(--mut); }
.empty .ico { width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 16px; display: grid; place-items: center; background: var(--accbg); color: var(--acc); }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; align-items: center; margin-bottom: 4px; }
.kv > span { color: var(--mut); font-size: 12.5px; }
.copy { display: flex; gap: 8px; align-items: center; min-width: 0; }
.copy code { background: var(--bg2); border: 1px solid var(--line); border-radius: 7px; padding: 3px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.hr { height: 1px; background: var(--line); margin: 16px 0; }
.danger { border-color: rgba(248, 113, 113, .35); }
details.snip { margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); }
details.snip summary { padding: 10px 14px; cursor: pointer; font-weight: 500; }
details.snip pre { margin: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
pre { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; max-height: 340px; overflow: auto; margin: 8px 0; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-all; }

/* ---------- tables ---------- */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--mut); background: var(--panel2); white-space: nowrap; }
tbody tr { transition: background .12s; } tbody tr:hover { background: var(--panel2); }
tr:last-child td { border-bottom: 0; }
td .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
td.wrap { word-break: break-word; }
.tfoot { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--mut); font-size: 12.5px; }
.tfoot .sp { flex: 1; }
.bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.bar input[type=search], .bar .grow { flex: 1; min-width: 200px; }
.bar select { width: auto; }

/* ---------- chart ---------- */
.chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px; align-items: end; height: 170px; padding-top: 8px; }
.chart .col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; gap: 4px; align-items: flex-end; flex: 1; width: 100%; justify-content: center; }
.chart .b { width: 38%; max-width: 22px; min-height: 3px; border-radius: 5px 5px 2px 2px; background: var(--ok); position: relative; transition: filter .15s; }
.chart .b.f { background: var(--bad); }
.chart .b:hover { filter: brightness(1.25); }
.chart .lbl { font-size: 11px; color: var(--mut); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--mut); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

/* ---------- modal / toast ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line2); border-radius: 16px; padding: 0; width: min(560px, 94vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 8, 14, .6); backdrop-filter: blur(3px); }
.dlg-h { padding: 18px 22px 0; font-size: 17px; font-weight: 650; }
.dlg-b { padding: 14px 22px; display: flex; flex-direction: column; gap: 12px; }
.dlg-f { padding: 14px 22px 18px; display: flex; gap: 10px; justify-content: flex-end; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 99; }
.toast { background: var(--panel); border: 1px solid var(--line2); border-left: 4px solid var(--acc); border-radius: 10px; padding: 11px 16px; box-shadow: var(--shadow); max-width: 380px; animation: tin .2s ease-out; }
.toast.ok { border-left-color: var(--ok); } .toast.bad { border-left-color: var(--bad); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(900px 500px at 15% 0%, var(--accbg), transparent), radial-gradient(700px 500px at 100% 100%, rgba(139, 92, 246, .1), transparent), var(--bg); }
.login { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login .brand { padding: 0 0 4px; }
.login h2 { font-size: 20px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 18px 16px 50px; }
  .kv { grid-template-columns: 1fr; }
}

/* ---------- forms: checkboxes, permission editor ---------- */
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; padding: 0; margin: 2px 0 0; accent-color: var(--acc); flex: none; box-shadow: none; }
input:disabled, textarea:disabled, select:disabled { opacity: .6; cursor: not-allowed; }
.chk { display: flex; gap: 9px; align-items: flex-start; font-size: 13px; color: var(--text); cursor: pointer; padding: 3px 0; font-weight: 400; }
.chk span { line-height: 1.4; }
.permgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.permgroup { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg2); }
.pg-h, .sec-h { font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--mut); margin-bottom: 4px; }
.sec { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 2px 18px; padding-left: 25px; }
dialog.wide { width: min(880px, 96vw); }
dialog > .dlg-b { max-height: min(70vh, 720px); overflow: auto; }
