:root {
  --bg: #0b0e1a;
  --bg-card: #131729;
  --bg-input: #1a1f36;
  --border: #262c4d;
  --text: #e5e7f5;
  --text-muted: #8b91b3;
  --primary: #7c3aed;
  --accent: #06b6d4;
  --danger: #ed4245;
  --warn: #f59e0b;
  --success: #22c55e;
  --grad: linear-gradient(135deg, #7c3aed, #06b6d4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: rgba(19, 23, 41, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar nav a { color: var(--text-muted); text-decoration: none; transition: color 0.2s; }
.topbar nav a:hover { color: var(--text); }
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-chip img { width: 32px; height: 32px; border-radius: 50%; }
.logout { color: var(--danger) !important; font-size: 13px; }

.container { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 28px; }
.footer { text-align: center; padding: 18px; color: var(--text-muted); font-size: 13px; border-top: 1px solid var(--border); }

/* Buttons */
.btn {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary { background: var(--grad); color: #fff; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-lg { padding: 14px 36px; font-size: 17px; margin-top: 24px; }

/* Hero */
.hero { text-align: center; padding: 60px 20px; }
.hero h1 { font-size: 46px; margin-bottom: 14px; }
.gradient-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero > p { color: var(--text-muted); max-width: 640px; margin: 0 auto 40px; font-size: 17px; line-height: 1.8; }
.hero-features { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-bottom: 10px; }
.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  text-align: right;
  transition: border-color 0.2s, transform 0.2s;
}
.feature-card:hover { border-color: var(--primary); transform: translateY(-4px); }
.feature-card h3 { margin: 14px 0 8px; }
.feature-card p { color: var(--text-muted); font-size: 14px; line-height: 1.7; }

/* Layout with sidebar */
.layout { display: flex; gap: 24px; align-items: flex-start; }
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  position: sticky;
  top: 84px;
}
.sidebar-guild { display: flex; align-items: center; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.sidebar-guild img, .guild-icon-fallback { width: 38px; height: 38px; border-radius: 50%; }
.guild-icon-fallback {
  display: flex; align-items: center; justify-content: center;
  background: var(--grad); color: #fff; font-weight: 700;
}
.guild-icon-fallback.large { width: 72px; height: 72px; font-size: 28px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--text-muted); text-decoration: none; font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-nav a:hover { background: var(--bg-input); color: var(--text); }
.sidebar-nav a.active { background: linear-gradient(135deg, rgba(124,58,237,0.25), rgba(6,182,212,0.15)); color: var(--text); border-right: 3px solid var(--primary); }
.content { flex: 1; min-width: 0; }

/* Titles */
.page-title { font-size: 24px; margin-bottom: 8px; }
.page-desc { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; line-height: 1.7; }
.section-title { margin: 28px 0 14px; font-size: 18px; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  margin-bottom: 18px;
}
.card h3 { margin-bottom: 12px; font-size: 16px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 10px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; display: flex; flex-direction: column; gap: 6px;
  border-top: 3px solid var(--primary);
}
.stat-card.danger { border-top-color: var(--danger); }
.stat-card.success { border-top-color: var(--success); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 13px; }

/* Guild grid */
.guild-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-top: 20px; }
.guild-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
  padding: 26px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-decoration: none; color: var(--text); transition: border-color 0.2s, transform 0.2s;
}
.guild-card:hover { border-color: var(--primary); transform: translateY(-4px); }
.guild-card img { width: 72px; height: 72px; border-radius: 50%; }

/* Forms */
input[type="number"], input[type="text"], select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); }

/* Limits table */
.limits-table { margin-bottom: 20px; }
.limits-row {
  display: grid;
  grid-template-columns: 1.2fr 0.6fr 0.8fr 1.2fr;
  gap: 12px; align-items: center;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.limits-row:first-child { border-radius: 14px 14px 0 0; }
.limits-head { background: var(--bg-input); color: var(--text-muted); font-size: 13px; font-weight: 600; }
.limit-name { font-weight: 600; }
.override-row { background: var(--bg-card); border: 1px solid var(--border); border-top: none; padding: 8px 18px 12px; }
.override-row:last-of-type { border-radius: 0 0 14px 14px; margin-bottom: 6px; }
.override-row summary { color: var(--accent); cursor: pointer; font-size: 13px; }
.override-fields { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.override-item { display: flex; gap: 10px; }

/* Switch */
.switch { position: relative; display: inline-block; width: 46px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 24px;
  background: var(--bg-input); border: 1px solid var(--border);
  transition: 0.25s; cursor: pointer;
}
.slider::before {
  content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  top: 3px; right: 4px; background: var(--text-muted); transition: 0.25s;
}
.switch input:checked + .slider { background: linear-gradient(135deg, rgba(124,58,237,0.5), rgba(6,182,212,0.4)); border-color: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(-20px); background: #fff; }
.switch-row { display: flex; justify-content: space-between; align-items: center; }

/* Permissions table */
.perm-table { overflow-x: auto; padding: 0; }
.perm-row {
  display: grid;
  grid-template-columns: 140px repeat(7, minmax(80px, 1fr));
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  gap: 6px;
  min-width: 720px;
}
.perm-row:last-child { border-bottom: none; }
.perm-head { color: var(--text-muted); font-size: 12px; font-weight: 600; background: var(--bg-input); border-radius: 16px 16px 0 0; }
.perm-col { text-align: center; word-break: break-word; }
.perm-cell { display: flex; justify-content: center; }
.perm-cell input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.role-name { font-weight: 600; font-size: 14px; }

/* Events */
.event-list { display: flex; flex-direction: column; gap: 10px; }
.event-item {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
}
.event-body p { font-size: 14px; line-height: 1.7; }
.event-body small { color: var(--text-muted); }
.badge { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-danger { background: rgba(237, 66, 69, 0.18); color: var(--danger); }
.badge-warn { background: rgba(245, 158, 11, 0.18); color: var(--warn); }
.badge-info { background: rgba(88, 101, 242, 0.2); color: #8f9bff; }

/* Alerts */
.alert { padding: 12px 18px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; }
.alert-success { background: rgba(34, 197, 94, 0.15); border: 1px solid rgba(34, 197, 94, 0.4); color: var(--success); }
.alert-info { background: rgba(6, 182, 212, 0.15); border: 1px solid rgba(6, 182, 212, 0.4); color: var(--accent); }

/* Whitelist */
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; min-height: 30px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-input); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 20px; font-size: 13px;
  animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}
.tag-avatar { width: 20px; height: 20px; border-radius: 50%; }
.tag-name { font-weight: 600; }
.tag-id { color: var(--text-muted); font-size: 11px; }
.role-tag { border-left-width: 3px; border-left-style: solid; }
.tag-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 15px; padding: 0 4px; }
.add-row { display: flex; gap: 10px; }
.add-row input { flex: 1; }

/* Filter + pagination */
.filter-row { margin-bottom: 18px; }
.pagination { display: flex; gap: 6px; margin-top: 18px; }
.pagination a {
  padding: 7px 13px; border-radius: 8px; text-decoration: none;
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-muted);
}
.pagination a.active { background: var(--grad); color: #fff; border-color: transparent; }

.empty-state {
  background: var(--bg-card); border: 1px dashed var(--border); border-radius: 14px;
  padding: 40px; text-align: center; color: var(--text-muted);
}
.error-page { text-align: center; padding: 80px 20px; }
.error-page p { color: var(--text-muted); margin: 12px 0 24px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; }
  .limits-row { grid-template-columns: 1fr 1fr; }
}
