:root {
  color-scheme: dark;
  --bg: #060813;
  --bg-2: #0b0e1b;
  --panel: rgba(17, 20, 34, 0.94);
  --panel-2: rgba(25, 28, 45, 0.9);
  --field: rgba(8, 11, 21, 0.9);
  --line: rgba(205, 194, 255, 0.14);
  --line-2: rgba(205, 194, 255, 0.28);
  --text: #f7f3ff;
  --muted: #aaa4bd;
  --soft: #d8d1ed;
  --accent: #8b62ff;
  --accent-2: #62d4ff;
  --ok: #4ade80;
  --warn: #f5c869;
  --danger: #ff6b8b;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.44);
}

* { box-sizing: border-box; }
html, body, .app { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 0%, rgba(139, 98, 255, 0.2), transparent 30%),
    radial-gradient(circle at 90% 8%, rgba(98, 212, 255, 0.1), transparent 26%),
    linear-gradient(180deg, #090b17 0%, var(--bg) 62%, #040610 100%);
  color: var(--text);
  font: 13px/1.45 Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; }
button {
  cursor: pointer;
  border: 0;
  color: inherit;
  transition: background .16s ease, border-color .16s ease, transform .16s ease, opacity .16s ease;
}
button:active { transform: scale(.985); }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }

.is-hidden { display: none !important; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}
.login-card {
  width: min(440px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(150deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.015)),
    var(--panel);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #5cc7ff);
  box-shadow: 0 14px 42px rgba(139, 98, 255, 0.32);
  color: #fff;
  font-weight: 900;
}
.brand h1 { font-size: 22px; line-height: 1.05; }
.brand p, .muted { color: var(--muted); }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: rgba(7, 9, 18, 0.86);
  backdrop-filter: blur(18px);
}
.nav {
  min-height: 0;
  display: grid;
  gap: 4px;
  overflow: auto;
  padding-right: 2px;
}
.nav-btn {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}
.nav-btn:hover, .nav-btn.active {
  color: var(--text);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.055);
}
.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: .8;
}
.sidebar-footer {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 10, 19, 0.82);
  backdrop-filter: blur(18px);
}
.topbar h2 { font-size: 18px; }
.topbar-actions, .toolbar, .filters, .row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.content {
  min-width: 0;
  padding: 18px 20px 28px;
}

.btn {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--soft);
  font-weight: 750;
}
.btn:hover { border-color: var(--line-2); background: rgba(255, 255, 255, 0.08); }
.btn.primary {
  border-color: rgba(139, 98, 255, 0.58);
  background: linear-gradient(135deg, #8b62ff, #6846db);
  color: #fff;
}
.btn.danger {
  border-color: rgba(255, 107, 139, 0.44);
  background: rgba(255, 107, 139, 0.12);
  color: var(--danger);
}

.input, .select, textarea {
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: var(--field);
  color: var(--text);
}
textarea {
  min-height: 96px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.input:focus, .select:focus, textarea:focus { border-color: rgba(139, 98, 255, 0.7); }
.field { display: grid; gap: 6px; }
.field label { color: var(--muted); font-size: 12px; font-weight: 750; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid .wide { grid-column: 1 / -1; }

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.012)),
    var(--panel);
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.045);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3 { font-size: 14px; }
.panel-body { padding: 14px; }

.cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.metric {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
}
.metric span { color: var(--muted); font-size: 12px; }
.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 21px;
  line-height: 1;
}
.cards.compact {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  margin-bottom: 0;
}
.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.service-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
}
.service-card:hover {
  border-color: var(--line-2);
  background: rgba(255, 255, 255, 0.07);
}
.service-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.mini-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}
.mini-metrics b { color: var(--text); }

.table-wrap {
  width: 100%;
  overflow: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(205, 194, 255, 0.09);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #121524;
  color: #cbc4df;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
td {
  color: var(--soft);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
tr:hover td { background: rgba(255, 255, 255, 0.035); }
.click-row { cursor: pointer; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--soft);
  font-size: 12px;
  font-weight: 800;
}
.badge.ok { border-color: rgba(74, 222, 128, .42); color: var(--ok); background: rgba(74, 222, 128, .1); }
.badge.warn { border-color: rgba(245, 200, 105, .42); color: var(--warn); background: rgba(245, 200, 105, .1); }
.badge.bad { border-color: rgba(255, 107, 139, .42); color: var(--danger); background: rgba(255, 107, 139, .1); }
.badge.accent { border-color: rgba(139, 98, 255, .5); color: #cbbcff; background: rgba(139, 98, 255, .14); }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
  gap: 14px;
}
.stack { display: grid; gap: 14px; }
.spacer { height: 14px; }
.spacer.small { height: 12px; }
.json {
  max-height: 520px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  color: #dbd4ef;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
.perm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.perm-group {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
}
.perm-group-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.perm-group h4 {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.perm-group p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.perm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--soft);
}
.perm-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.perm-check span {
  min-width: 0;
  display: grid;
  gap: 1px;
}
.perm-check b { font-weight: 800; }
.perm-check em {
  color: var(--muted);
  font-style: normal;
  font-size: 11px;
}
.perm-check small {
  margin-left: auto;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.perm-check small.role { color: #cbbcff; background: rgba(139, 98, 255, .12); }
.scope-box {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
}
.scope-box h3 { margin: 0 0 4px; font-size: 14px; }
.scope-box p { margin: 0; color: var(--muted); }
.scope-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
}
.scope-chip input { accent-color: var(--accent); }
.advanced-scope summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
}
.advanced-scope textarea { margin-top: 8px; }
.empty, .error {
  padding: 18px;
  color: var(--muted);
}
.error { color: var(--danger); }

.drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 560px);
  background: rgba(0, 0, 0, 0.46);
}
.drawer-panel {
  min-width: 0;
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: #0b0e1b;
  box-shadow: -28px 0 90px rgba(0, 0, 0, .46);
}
.drawer-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 14, 27, .92);
  backdrop-filter: blur(16px);
}
.drawer-body { padding: 14px; }
.drawer-backdrop { min-width: 0; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.52);
}
.modal-card {
  width: min(960px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0b0e1b;
  box-shadow: var(--shadow);
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 14, 27, .94);
}
.modal-body { padding: 14px; }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(460px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #111625;
  box-shadow: var(--shadow);
}

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .nav-btn { flex: 0 0 auto; }
  .content, .topbar { padding-left: 12px; padding-right: 12px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .perm-grid { grid-template-columns: 1fr; }
  .drawer { grid-template-columns: 1fr; }
  .drawer-backdrop { display: none; }
}
