:root {
  --bg: #050918;
  --bg-2: #080e26;
  --panel: #0c1433;
  --panel-2: #111c45;
  --line: #1b2a60;
  --line-2: #29408a;
  --text: #e9efff;
  --muted: #8d9cc9;
  --blue: #1f7bff;
  --cyan: #3cc8ff;
  --ok: #3ddc97;
  --warn: #ffc857;
  --danger: #ff5d6c;
  --radius: 14px;
  --font: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.55 var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(31,123,255,.22), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, rgba(60,200,255,.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
a { color: var(--cyan); }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 8px; }

/* ---------- logo ---------- */
.logo { width: 38px; height: 38px; flex: none; filter: drop-shadow(0 0 10px rgba(31,123,255,.7)); }
.logo-lg { width: 84px; height: 84px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(440px, 100%); text-align: center; padding: 44px 32px 36px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 0 0 1px rgba(31,123,255,.08), 0 30px 80px -20px rgba(31,123,255,.35);
}
.login-card .logo { margin: 0 auto 22px; }
.login-card p { margin: 10px 0 26px; color: var(--muted); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 276px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 22px; padding: 22px 16px;
  background: linear-gradient(180deg, rgba(12,20,51,.92), rgba(6,10,26,.96));
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand b { font-size: 1.05rem; }
.picker { display: flex; flex-direction: column; gap: 6px; }
.picker label { font-size: .8rem; color: var(--muted); padding: 0 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; border-radius: 10px; cursor: pointer;
  background: none; color: var(--muted); font: inherit; transition: background .15s, color .15s;
}
.nav button:hover { background: rgba(31,123,255,.10); color: var(--text); }
.nav button[aria-current="page"] {
  background: linear-gradient(90deg, rgba(31,123,255,.28), rgba(31,123,255,.06));
  color: #fff; box-shadow: inset 2px 0 0 var(--blue);
}
.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.me img, .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2); flex: none; object-fit: cover; }
.me div { min-width: 0; flex: 1; }
.me .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me a { font-size: .8rem; color: var(--muted); }

.main { padding: 34px clamp(18px, 4vw, 56px) 70px; max-width: 1060px; width: 100%; }
.head { display: flex; align-items: center; gap: 16px; margin-bottom: 30px; flex-wrap: wrap; }
.head .icon { width: 56px; height: 56px; border-radius: 16px; object-fit: cover; background: var(--panel-2); border: 1px solid var(--line-2); }
.head .grow { flex: 1; min-width: 0; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px;
  font-size: .8rem; font-weight: 600; border: 1px solid var(--line-2); color: var(--cyan); background: rgba(60,200,255,.08);
}
.badge.owner { color: var(--warn); border-color: rgba(255,200,87,.45); background: rgba(255,200,87,.08); }

/* ---------- panels & forms ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-head p { color: var(--muted); margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 7px; margin-top: 18px; }
.field > label, .field > .lbl { font-weight: 600; font-size: .92rem; }
.hint { color: var(--muted); font-size: .85rem; }
select, textarea, input[type=text] {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; transition: border-color .15s, box-shadow .15s;
}
select:hover, textarea:hover { border-color: var(--line-2); }
select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31,123,255,.25); }
textarea { min-height: 150px; resize: vertical; line-height: 1.5; }
.count { align-self: flex-end; font-size: .8rem; color: var(--muted); }
.count.over { color: var(--danger); }
.actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 600; color: #fff; text-decoration: none;
  background: linear-gradient(180deg, #3b8dff, var(--blue)); box-shadow: 0 6px 20px -8px rgba(31,123,255,.9);
  transition: transform .1s, filter .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line-2); box-shadow: none; }
.btn.ghost:hover { background: rgba(31,123,255,.12); }

.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 44px; height: 24px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line-2); position: relative; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .2s, background .2s; }
.switch input:checked + .track { background: var(--blue); border-color: var(--blue); }
.switch input:checked + .track::after { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid var(--cyan); outline-offset: 2px; }

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; }
.chip span {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line); transition: border-color .15s, background .15s;
}
.chip i { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.chip input:checked + span { border-color: var(--blue); background: rgba(31,123,255,.16); }
.chip input:disabled + span { opacity: .4; cursor: not-allowed; }
.chip input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---------- overview ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.tile {
  text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 8px; transition: border-color .15s, background .15s;
}
button.tile:hover { border-color: var(--blue); background: var(--panel-2); }
div.tile { cursor: default; }
.tile .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pill { font-size: .78rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.pill.on { color: var(--ok); background: rgba(61,220,151,.12); }
.pill.off { color: var(--muted); background: rgba(141,156,201,.12); }
.notice { padding: 12px 16px; border-radius: 12px; border: 1px solid rgba(255,200,87,.4); background: rgba(255,200,87,.07); color: var(--warn); margin-bottom: 16px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; background: var(--bg-2); }
tr:last-child td { border-bottom: 0; }
td.reason { max-width: 320px; overflow-wrap: anywhere; }
.tag { padding: 2px 9px; border-radius: 8px; background: rgba(31,123,255,.16); color: var(--cyan); font-size: .82rem; font-weight: 600; }
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar select { width: auto; min-width: 180px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 14px; }
.empty { text-align: center; padding: 44px 16px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line-2); box-shadow: 0 12px 40px rgba(0,0,0,.5); animation: pop .2s ease-out; max-width: 340px; }
.toast.ok { border-color: rgba(61,220,151,.5); }
.toast.bad { border-color: rgba(255,93,108,.6); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: column; gap: 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .nav button { width: auto; white-space: nowrap; border: 1px solid var(--line); }
  .me { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
