:root {
  --bg: #f3f0fa;
  --panel: #ffffff;
  --text: #16121f;
  --muted: #6a6478;
  --line: #d9d3e8;
  --purple: #7c3aed;
  --purple-deep: #6d28d9;
  --purple-dim: rgba(124, 58, 237, 0.1);
  --danger: #dc2626;
  --side: #ebe6f7;
  --font: "DM Sans", sans-serif;
  --display: "Syne", sans-serif;
  --mono: "JetBrains Mono", monospace;
  --side-w: 240px;
}

[data-theme="dark"] {
  --bg: #050508;
  --panel: #111018;
  --text: #f0eef6;
  --muted: #8b8798;
  --line: #1c1a26;
  --purple: #a855f7;
  --purple-deep: #7c3aed;
  --purple-dim: rgba(168, 85, 247, 0.18);
  --danger: #ef4444;
  --side: #0c0b12;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  display: flex;
  transition: background 0.25s ease, color 0.25s ease;
}

.side {
  position: sticky;
  top: 0;
  width: var(--side-w);
  min-height: 100vh;
  background: var(--side);
  border-right: 1px solid var(--line);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex-shrink: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: "Space Grotesk", var(--display), sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  padding: 0 0.35rem;
}

.brand-mark {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  object-fit: contain;
  flex-shrink: 0;
  background: #0a0a0f;
}

.side-server {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0 0.35rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.server-av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--line);
}

.server {
  font-weight: 600;
  font-size: 0.9rem;
}

.demo {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--purple);
  background: var(--purple-dim);
  border: 1px solid rgba(124, 58, 237, 0.35);
  border-radius: 5px;
  padding: 0.15rem 0.4rem;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.side-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}

.side-nav a:hover {
  color: var(--text);
  background: var(--purple-dim);
}

.side-nav a.on {
  color: var(--purple);
  background: var(--purple-dim);
  font-weight: 600;
}

.side-foot {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-right: 0.15rem;
}

.theme {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.theme:hover {
  color: var(--text);
  border-color: rgba(124, 58, 237, 0.5);
  background: var(--purple-dim);
}

.theme svg {
  width: 16px;
  height: 16px;
  display: none;
}

html:not([data-theme="dark"]) .theme-moon,
html[data-theme="dark"] .theme-sun {
  display: block;
}

.main {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 1.75rem 2rem 3rem;
}

.page {
  display: none;
}

.page.on {
  display: block;
}

.page-head {
  margin-bottom: 1.5rem;
}

.page-head.bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-head h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
}

.sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

.sub.tight {
  margin-top: 0.4rem;
  margin-bottom: 0;
}

.bar-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

.search {
  width: 200px;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  outline: none;
}

.search:focus {
  border-color: var(--purple);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem 1.35rem;
  margin-bottom: 1rem;
}

.panel.pad-0 {
  padding: 0;
  overflow: hidden;
}

.panel h2 {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.stat-val {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.on {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.split {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1rem;
}

.mini-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.mini-list li {
  font-size: 0.9rem;
  color: var(--muted);
}

.mini-list strong {
  color: var(--text);
  font-weight: 600;
}

.mini-list .when {
  font-size: 0.78rem;
  color: var(--muted);
  margin-left: 0.35rem;
}

.link {
  color: var(--purple);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}

.quick {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}

.quick .btn {
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, filter 0.15s;
}

.btn-main {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-deep) 100%);
  color: #fff;
}

.btn-main:hover {
  filter: brightness(1.06);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: rgba(124, 58, 237, 0.45);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
}

.btn-danger {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
}

.btn-danger:hover {
  background: rgba(220, 38, 38, 0.08);
}

.rules {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.rule {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.rule:hover {
  border-color: rgba(124, 58, 237, 0.4);
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.06);
}

.rule-kw {
  min-width: 110px;
}

.rule-kw .mono {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.95rem;
}

.rule-path {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.rule-path .mono {
  font-family: var(--mono);
  color: var(--text);
  font-size: 0.88rem;
}

.rule-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.chip {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: var(--line);
  color: var(--muted);
  margin-left: 0.35rem;
  vertical-align: middle;
}

.badge.on {
  background: var(--purple-dim);
  color: var(--purple);
}

.rule-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0.55;
  transition: opacity 0.15s;
}

.rule:hover .rule-actions,
.rule:focus-within .rule-actions {
  opacity: 1;
}

.empty {
  display: none;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.empty.show {
  display: block;
}

.empty p {
  margin-bottom: 1rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 0.8rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--purple-dim);
}

.mono {
  font-family: var(--mono);
  font-size: 0.85em;
}

.muted {
  color: var(--muted);
}

.group-card {
  display: flex;
  align-items: center;
  gap: 1.15rem;
  flex-wrap: wrap;
}

.group-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--line);
  flex-shrink: 0;
}

.group-info {
  flex: 1;
  min-width: 160px;
}

.group-info h2 {
  margin-bottom: 0.15rem;
}

.group-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.plan {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--purple);
  background: var(--purple-dim);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
}

.changelog {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.changelog li {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.15rem 1.25rem;
}

.changelog .date {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--purple);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.changelog h3 {
  font-family: var(--display);
  font-size: 1.05rem;
  margin-bottom: 0.3rem;
}

.changelog p {
  color: var(--muted);
  font-size: 0.92rem;
}

.form-panel {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

input,
select {
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  outline: none;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--purple);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
  margin: 0.15rem 0 0.5rem;
}

.check input {
  width: auto;
  accent-color: var(--purple);
}

.toast {
  display: none;
  color: var(--purple);
  font-size: 0.9rem;
  font-weight: 600;
}

.toast.show {
  display: block;
}

.drawer-bg {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 16, 0.4);
  z-index: 30;
  opacity: 1;
  transition: opacity 0.2s;
}

.drawer-bg.hidden {
  display: none;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(400px, 100%);
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.25s ease;
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.12);
}

.drawer.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 {
  font-family: var(--display);
  font-size: 1.15rem;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
}

.icon-btn:hover {
  background: var(--purple-dim);
  color: var(--text);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem 1.25rem 1.5rem;
}

.group-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin: 1rem 0 0.65rem;
}

.group-label:first-child {
  margin-top: 0;
}

.drawer-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--line);
}

.panel-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.panel-bar h2 {
  margin-bottom: 0.25rem;
}

.view-as {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.view-as select {
  width: auto;
  min-width: 110px;
}

.invite-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.invite-row input {
  flex: 1;
  min-width: 200px;
}

.hint-line {
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.admin-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  flex-wrap: wrap;
}

.admin-av {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--purple-dim);
  color: var(--purple);
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.admin-info {
  flex: 1;
  min-width: 140px;
}

.admin-info strong {
  display: block;
  font-size: 0.95rem;
}

.admin-info span {
  font-size: 0.82rem;
  color: var(--muted);
}

.admin-tags {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}

.help {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.45;
}

body.is-admin .owner-only {
  display: none !important;
}

@media (max-width: 900px) {
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .split {
    grid-template-columns: 1fr;
  }

  .rule {
    flex-wrap: wrap;
  }

  .rule-chips {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  body {
    flex-direction: column;
  }

  .side {
    position: relative;
    width: 100%;
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .side-nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: none;
  }

  .side-foot {
    flex-direction: row;
  }

  .main {
    padding: 1.25rem 1rem 2.5rem;
  }
}
