:root {
  /* Base palette — same tokens the panel already used, kept as the source of truth. */
  --bg: #1b1d24;
  --card: #23262f;
  --line: #333744;
  --text: #e6e8ee;
  --muted: #969bab;
  --accent: #5865f2;
  --danger: #d9534f;
  --ok: #43b581;
  --warn: #e0a33e;

  /* Extensions built from the same palette — no new hues, just more steps of it. */
  --bg-soft: #16171d;
  --card-2: #191b21;
  --card-hover: #282b36;
  --line-soft: #2a2d38;
  --accent-hover: #6e79f5;
  --accent-soft: rgba(88, 101, 242, 0.16);
  --accent-soft-border: rgba(88, 101, 242, 0.4);
  --danger-soft: rgba(217, 83, 79, 0.14);
  --ok-soft: rgba(67, 181, 129, 0.14);
  --warn-soft: rgba(224, 163, 62, 0.14);
  --text-dim: #c7cad4;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.24), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-pop: 0 8px 30px -8px rgba(0, 0, 0, 0.55);
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 480px at 15% -10%, rgba(88, 101, 242, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 4px; }

h2 {
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.card > h2:first-child,
.card > form > h2:first-child {
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

h3 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

code {
  background: var(--card-2);
  border: 1px solid var(--line-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.92em;
}

::selection { background: var(--accent-soft-border); color: #fff; }

/* Scrollbars — cosmetic only, degrades gracefully on browsers that ignore it. */
* { scrollbar-color: var(--line) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; border: 2px solid var(--bg); }

/* Layout */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(155deg, var(--accent), #8a55e8);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
  flex: 0 0 auto;
  box-shadow: 0 4px 14px -4px rgba(88, 101, 242, 0.65);
}

.brand strong { font-size: 16px; letter-spacing: -0.01em; }
.brand .muted { font-size: 13px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-dim);
}

.user-chip:empty { display: none; }
.user-chip-name { white-space: nowrap; }

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 14px 24px 0;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  position: relative;
  background: transparent;
  border: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}

.tabs button:hover { color: var(--text-dim); background: rgba(255, 255, 255, 0.03); }

.tabs button.active { color: var(--text); }

.tabs button.active::after {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

main { padding: 24px 24px 72px; max-width: 1100px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
}

/* Spacing goes *between* cards rather than living on .card itself, so the
   first card in a tab sits flush under `main`'s own padding even when a
   (possibly hidden) non-card element like a warning pill precedes it. The
   general sibling combinator (not just `+`) also covers a non-card element
   sitting between two cards. */
.tab-panel .card ~ .card {
  margin-top: 18px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input[type="text"], .row > input[type="url"], .row > select { flex: 1 1 180px; }
.actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

@media (max-width: 620px) {
  .grid-2 { grid-template-columns: 1fr; }
  main { padding: 18px 14px 60px; }
  .topbar { padding: 12px 14px; }
}

/* Form controls */
label {
  display: block;
  margin: 14px 0 6px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
}

label:first-child { margin-top: 0; }

input[type="text"], input[type="url"], input[type="password"], textarea, select {
  width: 100%;
  padding: 9px 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}

input[type="text"]::placeholder,
input[type="url"]::placeholder,
input[type="password"]::placeholder,
textarea::placeholder { color: #6b7080; }

input[type="text"]:hover, input[type="url"]:hover, input[type="password"]:hover,
textarea:hover, select:hover { border-color: #454a5c; }

textarea { resize: vertical; }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select { cursor: pointer; }
select:disabled, input:disabled:not(.switch-input), textarea:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="color"] {
  width: 46px;
  height: 38px;
  padding: 3px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  flex: 0 0 auto;
  cursor: pointer;
}

/* Checkboxes that are still plain checkboxes (embed field "inline"). Excludes
   .switch-input, which sets its own (larger, invisible) hit-area size below —
   input[type="checkbox"] otherwise outranks a single class on specificity and
   would clobber it regardless of source order. */
input[type="checkbox"]:not(.switch-input) {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Buttons */
button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s var(--ease), transform 0.05s linear, box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}

button:hover { background: var(--accent-hover); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button:disabled { opacity: 0.55; cursor: progress; transform: none; }

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
}
button.ghost:hover { background: var(--card-hover); border-color: #454a5c; color: var(--text); }

button.danger { background: var(--danger); }
button.danger:hover { background: #e2645f; }
button.danger.ghost { background: transparent; color: var(--danger); border-color: rgba(217, 83, 79, 0.45); }
button.danger.ghost:hover { background: var(--danger-soft); border-color: var(--danger); }

button.small { padding: 6px 11px; font-size: 12.5px; border-radius: var(--radius-sm); }

/* Feedback */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 10px;
  background: var(--ok);
  color: #0c1f16;
  font-weight: 600;
  font-size: 13.5px;
  box-shadow: var(--shadow-pop);
  z-index: 50;
  max-width: 90vw;
}

.toast.error { background: var(--danger); color: #fff; }
.toast.warn { background: var(--warn); color: #241a05; }

.error { color: #ff8683; }
.error-list { color: #ff8683; margin: 14px 0 0; padding-left: 20px; }
.error-list li { margin-bottom: 2px; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--card-2);
}

.pill.warn { color: var(--warn); border-color: rgba(224, 163, 62, 0.45); background: var(--warn-soft); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--line-soft);
  color: var(--text-dim);
}

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.role-badge.role-admin { background: var(--accent-soft); color: #b3bafc; border: 1px solid var(--accent-soft-border); }
.role-badge.role-mod { background: var(--line-soft); color: var(--text-dim); border: 1px solid var(--line); }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
  flex-wrap: wrap;
}

.list-item .stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.list-item .stack span { overflow-wrap: anywhere; font-weight: 600; }
.list-item small { color: var(--muted); font-size: 12.5px; }
.clickable { cursor: pointer; }
.clickable:hover { border-color: var(--accent-soft-border); background: var(--card-hover); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 7px; }
.dot.live { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* Empty / loading states */
.empty-state, .loading-state {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13.5px;
  background: rgba(255, 255, 255, 0.015);
}

.loading-state::before {
  content: '';
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Embed fields */
.field-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  background: var(--card-2);
}

.field-row .row { margin-top: 8px; }
.field-row label { margin-top: 0; }
.inline-check { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; cursor: pointer; }
.inline-check input { width: auto; }

/* Toggle switches (Features tab) */
.switch-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  cursor: pointer;
}

.switch-input {
  position: absolute;
  inset: 0;
  width: 40px;
  height: 22px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background 0.15s var(--ease);
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s var(--ease);
}

.switch-input:checked ~ .switch-track { background: var(--accent); }
.switch-input:checked ~ .switch-track::after { transform: translateX(18px); }
.switch-input:focus-visible ~ .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-input:disabled ~ .switch-track { opacity: 0.5; cursor: not-allowed; }

/* Features tab */
.feature-group { margin-top: 20px; }
.feature-group:first-child { margin-top: 0; }

.feature-group-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.feature-group-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.feature-group-count { font-size: 12px; }

.feature-list { display: flex; flex-direction: column; gap: 6px; }

.feature-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.feature-label { font-size: 13.5px; }

/* Users tab */
.user-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.user-actions select { width: auto; min-width: 100px; }

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(900px 480px at 50% -10%, rgba(88, 101, 242, 0.16), transparent 60%),
    var(--bg);
}

.login-card {
  width: min(380px, 92vw);
  margin: 0;
  padding: 28px 26px;
  text-align: center;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.login-card .brand-mark { width: 46px; height: 46px; border-radius: 13px; font-size: 21px; }
.login-card h1 { margin: 0; }
.login-card p.muted { margin: 0; font-size: 13.5px; }

.login-card label, .login-card input { text-align: left; }
.login-card button { width: 100%; margin-top: 18px; padding: 11px; font-size: 14px; }
.login-card p.error { margin-top: 14px; margin-bottom: 0; text-align: left; }

/* Embed live preview (Embed Builder tab) */
.embed-layout { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.embed-layout-main { min-width: 0; }
.embed-layout-preview { position: sticky; top: 16px; }

@media (max-width: 960px) {
  .embed-layout { grid-template-columns: 1fr; }
  .embed-layout-preview { position: static; }
}

.preview-card { background: var(--bg-soft); }
#preview-empty { margin: 10px 0 0; font-size: 13px; }

.discord-message { display: flex; gap: 12px; }

.discord-avatar {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}

.discord-message-body { min-width: 0; flex: 1; }

.discord-message-header { display: flex; align-items: baseline; gap: 7px; margin-bottom: 3px; }
.discord-username { color: #fff; font-weight: 600; font-size: 15px; }
.discord-bot-tag {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.4;
}

.discord-message-content {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-bottom: 6px;
}

.discord-embed {
  display: flex;
  gap: 12px;
  background: var(--card-2);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  padding: 12px 14px;
  max-width: 100%;
}

.discord-embed-main { min-width: 0; flex: 1; }

.discord-embed-author {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 7px;
}

.discord-embed-author-icon, .discord-embed-footer-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}

.discord-embed-title { font-size: 16px; font-weight: 600; color: #fff; margin-bottom: 7px; overflow-wrap: anywhere; }
.discord-embed-title a { color: #00aff4; text-decoration: none; }
.discord-embed-title a:hover { text-decoration: underline; }

.discord-embed-description {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-dim);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-bottom: 8px;
}

.discord-embed-fields { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 8px; }
.discord-embed-field { flex: 1 1 100%; min-width: 0; }
.discord-embed-field.inline { flex: 1 1 30%; }
.discord-embed-field-name { font-size: 13px; font-weight: 600; color: #fff; margin-bottom: 2px; overflow-wrap: anywhere; }
.discord-embed-field-value { font-size: 13px; color: var(--text-dim); white-space: pre-wrap; overflow-wrap: anywhere; }

.discord-embed-image { max-width: 100%; border-radius: 4px; margin-top: 4px; display: block; }

.discord-embed-thumbnail {
  flex: 0 0 auto;
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
}

.discord-embed-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

/* Markdown rendered inside the preview (content, description, field text) */
.discord-message-content code.md-code,
.discord-embed-description code.md-code,
.discord-embed-field-value code.md-code {
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

.discord-message-content pre,
.discord-embed-description pre,
.discord-embed-field-value pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 10px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 4px 0;
}

.discord-message-content pre code,
.discord-embed-description pre code,
.discord-embed-field-value pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
}

.md-spoiler {
  background: #1a1a1e;
  color: transparent;
  border-radius: 3px;
  padding: 0 2px;
  cursor: pointer;
}

.md-spoiler.revealed {
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  cursor: default;
}
