:root {
  --bg: #0b0d12;
  --bg-elev: #14171e;
  --bg-elev-2: #1c202a;
  --bg-elev-3: #242938;
  --border: #2a2f3d;
  --text: #eceef2;
  --text-dim: #9aa1b0;
  --accent: #5865f2;
  --accent-2: #7c5cff;
  --accent-hover: #4752c4;
  --green: #3ba55d;
  --red: #ed4245;
  --yellow: #faa61a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef0f3;
  --bg-elev-3: #e3e6ea;
  --border: #dde1e6;
  --text: #1a1d24;
  --text-dim: #676e7b;
  --shadow: 0 1px 2px rgba(20,23,30,0.05), 0 8px 20px -12px rgba(20,23,30,0.15);
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color 0.15s ease; }
a:hover { color: var(--accent-2); }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  /* Pinned to the viewport regardless of how long the page content is —
     only .main scrolls, the sidebar never grows/shrinks or scrolls away. */
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  padding: 4px 10px 18px;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 0.9rem;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(88,101,242,0.4);
}

.sidebar .guild-name {
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 0 10px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.nav-icon { width: 17px; flex-shrink: 0; opacity: 0.85; font-size: 0.95rem; text-align: center; }

.nav-link:hover { background: var(--bg-elev-2); color: var(--text); }
.nav-link.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; box-shadow: 0 2px 10px rgba(88,101,242,0.35); }
.nav-link.active .nav-icon { opacity: 1; }

.sidebar .spacer { flex: 1; }

.main { flex: 1; padding: 28px 32px; min-width: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar h1 { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.badge.owner { background: #f2c744; color: #1a1a1a; border-color: #f2c744; }
.badge.head_admin, .badge.head-admin { background: #ed4245; color: white; border-color: #ed4245; }
.badge.admin { background: #faa61a; color: #1a1a1a; border-color: #faa61a; }
.badge.mod { background: #5865f2; color: white; border-color: #5865f2; }
.badge.staff { background: #3ba55d; color: white; border-color: #3ba55d; }
.badge.dangerous { background: var(--red); color: white; border: none; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card h2, .card h3 { margin-top: 0; }
.card h3 { font-size: 1.02rem; font-weight: 700; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.stat-tile {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.stat-tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.stat-tile .value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; }
.stat-tile .label { color: var(--text-dim); font-size: 0.82rem; margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: var(--bg-elev-2); }
.table-wrap { overflow-x: auto; }

input, select, textarea, button { font-family: inherit; font-size: 0.9rem; }

input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,101,242,0.2); }

label { display: block; margin-bottom: 5px; color: var(--text-dim); font-size: 0.8rem; font-weight: 500; }
.field { margin-bottom: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.1s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 2px 8px rgba(88,101,242,0.3);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(88,101,242,0.4); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); box-shadow: none; }
.btn.secondary:hover { background: var(--bg-elev-3); box-shadow: none; }
.btn.danger { background: var(--red); box-shadow: 0 2px 8px rgba(237,66,69,0.3); }
.btn.success { background: var(--green); box-shadow: 0 2px 8px rgba(59,165,93,0.3); }
.btn.small { padding: 6px 12px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

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

.progress { height: 6px; border-radius: 4px; background: var(--bg-elev-3); overflow: hidden; margin-top: 4px; }
.progress-bar { height: 100%; background: var(--accent); transition: width 0.3s ease; }
.progress-bar.warn { background: var(--yellow); }
.progress-bar.full { background: var(--red); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { display: flex; align-items: center; gap: 10px; }
.error-text { color: var(--red); font-size: 0.85rem; margin-bottom: 10px; }

.guild-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.guild-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.guild-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.guild-card img { width: 56px; height: 56px; border-radius: 50%; margin-bottom: 8px; }

.countdown { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--yellow); }

.embed-preview {
  border-left: 4px solid var(--accent);
  background: var(--bg-elev-2);
  border-radius: 6px;
  padding: 10px 14px;
  max-width: 480px;
}
.embed-preview .e-author { font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.embed-preview .e-title { font-weight: 700; margin-bottom: 4px; }
.embed-preview .e-desc { font-size: 0.9rem; white-space: pre-wrap; color: var(--text-dim); }
.embed-preview .e-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.embed-preview .e-field.full { grid-column: 1 / -1; }
.embed-preview .e-field-name { font-weight: 600; font-size: 0.82rem; }
.embed-preview .e-field-value { font-size: 0.82rem; color: var(--text-dim); }
.embed-preview .e-footer { font-size: 0.75rem; color: var(--text-dim); margin-top: 8px; }
.embed-preview img.e-thumb { float: right; width: 64px; height: 64px; border-radius: 4px; margin-left: 8px; }
.embed-preview img.e-image { width: 100%; border-radius: 4px; margin-top: 8px; }

.builder-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: var(--radius-sm); z-index: 50;
  box-shadow: var(--shadow);
}

.filters { margin-bottom: 14px; }
.hidden { display: none !important; }

/* Setup checklist */
.checklist { display: flex; flex-direction: column; gap: 2px; }
.checklist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.checklist-item:last-child { border-bottom: none; }
.check-dot {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 800;
}
.check-dot.done { background: var(--green); color: white; }
.check-dot.todo { background: var(--bg-elev-3); border: 2px solid var(--border); }
.checklist-item .label { flex: 1; font-size: 0.9rem; }
.checklist-item.done .label { color: var(--text-dim); text-decoration: line-through; }

/* Emoji picker */
.emoji-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.emoji-row:last-child { border-bottom: none; }
.emoji-preview {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0; overflow: hidden;
}
.emoji-preview img { width: 24px; height: 24px; }
.emoji-row .label { min-width: 140px; font-weight: 500; }
.emoji-picker-wrap { position: relative; flex: 1; min-width: 180px; }
.emoji-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: var(--bg-elev-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 240px; overflow-y: auto; z-index: 30; display: none;
  box-shadow: var(--shadow);
}
.emoji-option {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; font-size: 0.85rem;
}
.emoji-option:hover { background: var(--bg-elev-2); }
.emoji-option img { width: 20px; height: 20px; }
.category-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); margin: 18px 0 6px; font-weight: 700; }
.category-title:first-child { margin-top: 0; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    align-items: center;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar .brand, .sidebar .guild-name { display: none; }
  .sidebar .spacer { display: none; }
  .nav-link { white-space: nowrap; }
  .main { padding: 16px; }
  .builder-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .grid { grid-template-columns: 1fr !important; }
  .row { gap: 8px; }
  th, td { padding: 7px 8px; font-size: 0.85rem; }
  .card { padding: 14px; }
}
