:root {
  --bg: #070a0f;
  --bg-glow: #0d1a1f;
  --panel: #0e141c;
  --panel-2: #121b25;
  --panel-3: #16222e;
  --line: #1e2b3a;
  --line-soft: #17222e;
  --text: #e6edf4;
  --muted: #8ea3b8;
  --accent: #57e6a1;
  --accent-dim: #2f8f66;
  --accent-2: #4cc9f0;
  --danger: #ff6b6b;
  --warn: #ffc857;
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(680px 420px at 12% -10%, rgba(87, 230, 161, 0.10), transparent 60%),
    radial-gradient(760px 500px at 100% 0%, rgba(76, 201, 240, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }

/* ---------- login ---------- */
.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

.login-panel .stack { margin-top: 26px; display: grid; gap: 16px; }

/* ---------- brand ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand.large { gap: 14px; }
.brand.large .brand-mark { width: 46px; height: 46px; font-size: 22px; }

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), #2bb985);
  color: #04120c;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
  box-shadow: 0 6px 18px rgba(87, 230, 161, 0.25);
}

.brand strong { display: block; letter-spacing: 1.5px; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 11px; letter-spacing: 0.4px; }

/* ---------- shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  background: linear-gradient(180deg, rgba(14, 20, 28, 0.94), rgba(9, 13, 19, 0.94));
  border-right: 1px solid var(--line-soft);
  backdrop-filter: blur(8px);
}

.nav { display: grid; gap: 4px; }

.nav-group {
  margin: 14px 10px 6px;
  font-size: 10px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #5d7288;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav button:hover { background: var(--panel-2); color: var(--text); }

.nav button.active {
  background: linear-gradient(90deg, rgba(87, 230, 161, 0.14), rgba(87, 230, 161, 0.03));
  border-color: rgba(87, 230, 161, 0.25);
  color: var(--accent);
}

.nav .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.65;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding: 12px;
  border-top: 1px solid var(--line-soft);
}

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 32px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(7, 10, 15, 0.6);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 { margin: 0; font-size: 22px; letter-spacing: -0.3px; }
.topbar p { margin: 3px 0 0; }

.user-chip { display: flex; align-items: center; gap: 12px; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel-3);
  border: 1px solid var(--line);
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
}

.user-meta { display: grid; line-height: 1.2; }

.view { padding: 26px 32px 60px; display: grid; gap: 22px; align-content: start; }

/* ---------- cards & grid ---------- */
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}

.stat .label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.stat .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.6px;
  margin-top: 6px;
}

.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-head h2 { margin: 0; font-size: 16px; letter-spacing: 0.2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-3);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 9px 14px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.btn:hover { background: #1b2a38; }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: linear-gradient(180deg, #57e6a1, #33b47c);
  border-color: #2f9c6e;
  color: #04120c;
}

.btn.primary:hover { filter: brightness(1.06); }

.btn.danger { color: var(--danger); border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.08); }
.btn.danger:hover { background: rgba(255, 107, 107, 0.16); }

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }

.btn.tiny { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- tables ---------- */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

table { width: 100%; border-collapse: collapse; min-width: 640px; }

th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

th {
  font-size: 10px;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: #6f859b;
  background: rgba(18, 27, 37, 0.7);
  position: sticky;
  top: 0;
  backdrop-filter: blur(4px);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(87, 230, 161, 0.03); }

td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }

.cell-title { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 12px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  color: var(--muted);
  text-transform: uppercase;
}

.badge.ok { color: var(--accent); border-color: rgba(87, 230, 161, 0.35); background: rgba(87, 230, 161, 0.08); }
.badge.warn { color: var(--warn); border-color: rgba(255, 200, 87, 0.35); background: rgba(255, 200, 87, 0.08); }
.badge.bad { color: var(--danger); border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.08); }
.badge.info { color: var(--accent-2); border-color: rgba(76, 201, 240, 0.35); background: rgba(76, 201, 240, 0.08); }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-2);
}

/* ---------- forms ---------- */
.stack { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: 0.2px; }

input, select, textarea {
  width: 100%;
  background: #0a1119;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(87, 230, 161, 0.5);
  box-shadow: 0 0 0 3px rgba(87, 230, 161, 0.10);
}

textarea { min-height: 92px; resize: vertical; font-family: var(--mono); font-size: 12px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check span { color: var(--text); font-size: 13px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 11px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 10, 0.7);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  animation: fade 0.12s ease;
}

.modal {
  width: min(620px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6);
}

.modal h2 { margin: 0 0 18px; font-size: 18px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 10px;
  z-index: 80;
}

.toast {
  min-width: 240px;
  max-width: 380px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  animation: slide 0.18s ease;
}

.toast.ok { border-color: rgba(87, 230, 161, 0.4); }
.toast.error { border-color: rgba(255, 107, 107, 0.45); }
.toast .t-title { font-weight: 700; margin-bottom: 2px; }
.toast.ok .t-title { color: var(--accent); }
.toast.error .t-title { color: var(--danger); }

@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- misc ---------- */
.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
}

.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 20px; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: #0a1119;
  overflow: hidden;
  border: 1px solid var(--line-soft);
}

.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

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

@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { display: flex; flex-wrap: wrap; }
  .nav-group, .sidebar-foot { display: none; }
  .nav button { width: auto; }
  .topbar { padding: 16px 18px; }
  .view { padding: 18px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}

/* ---------- additions: impersonation, charts, console, polish ---------- */

.impersonation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 9px 18px;
  background: linear-gradient(90deg, rgba(255, 200, 87, 0.16), rgba(255, 200, 87, 0.05));
  border-bottom: 1px solid rgba(255, 200, 87, 0.35);
  color: var(--warn);
  font-size: 13px;
  flex-wrap: wrap;
}

.impersonation strong { color: var(--text); }

.row-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

select.compact {
  width: auto;
  min-width: 180px;
  padding: 7px 30px 7px 10px;
}

.stat .value.small-value { font-size: 16px; letter-spacing: 0; line-height: 1.35; word-break: break-word; }

.secret { filter: blur(4px); user-select: none; transition: filter 0.15s ease; }

.chart { margin-top: 14px; }
.spark { width: 100%; height: 120px; display: block; }

.console-out {
  margin: 14px 0 0;
  padding: 16px;
  background: #060b11;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: #cfe3d8;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.view > * { animation: rise 0.22s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card { transition: border-color 0.16s ease, transform 0.16s ease; }
.card:hover { border-color: #26384b; }

.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .nav button:focus-visible {
  outline: 2px solid rgba(87, 230, 161, 0.7);
  outline-offset: 2px;
}

.nav button.active { position: relative; }
.nav button.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

.badge { white-space: nowrap; }
td { font-size: 13px; overflow-wrap: anywhere; }
th { white-space: nowrap; }

.table-wrap::-webkit-scrollbar, .console-out::-webkit-scrollbar { width: 10px; height: 10px; }
.table-wrap::-webkit-scrollbar-thumb, .console-out::-webkit-scrollbar-thumb {
  background: #1d2b3a; border-radius: 999px; border: 2px solid var(--panel);
}
.table-wrap::-webkit-scrollbar-track { background: transparent; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(87, 230, 161, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(87, 230, 161, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 30% 0%, #000 0%, transparent 70%);
  z-index: 0;
}

.shell, .login-screen { position: relative; z-index: 1; }

.login-panel {
  position: relative;
  overflow: hidden;
}

.login-panel::after {
  content: "";
  position: absolute;
  inset: -40% -40% auto auto;
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(87, 230, 161, 0.22), transparent 70%);
  pointer-events: none;
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 12px 14px;
    overflow-x: auto;
    gap: 14px;
  }
  .brand small { display: none; }
  .nav { flex-wrap: nowrap; }
  .nav button { white-space: nowrap; padding: 7px 10px; }
  .nav button.active::before { display: none; }
  .topbar {
    position: static;
    padding: 16px 18px;
    flex-wrap: wrap;
  }
  .topbar h1 { font-size: 19px; }
  .view { padding: 16px; gap: 16px; }
  .user-meta { display: none; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 120px 1fr; }
  .modal { padding: 18px; }
  .section-head { align-items: flex-start; flex-direction: column; gap: 10px; }
}

@media (max-width: 520px) {
  .sidebar { border-right: none; border-bottom: 1px solid var(--line-soft); }
  .stat .value { font-size: 22px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
}

