:root {
  --background: #09090b;
  --foreground: #fafafa;
  --card: #0d0d10;
  --card-foreground: #fafafa;
  --muted: #18181b;
  --muted-foreground: #a1a1aa;
  --border: #27272a;
  --input: #27272a;
  --ring: #52525b;
  --primary: #fafafa;
  --primary-foreground: #09090b;
  --secondary: #18181b;
  --secondary-foreground: #fafafa;
  --accent: #1f1f24;
  --accent-foreground: #fafafa;
  --destructive: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 0.625rem;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(circle 700px at 50% -180px, rgba(37, 99, 235, 0.16), transparent 70%),
    var(--background);
  color: var(--foreground);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(34, 197, 94, 0.3); }

a { color: var(--foreground); text-decoration: none; }
a:hover { text-decoration: none; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9999px; border: 2px solid var(--background); }
::-webkit-scrollbar-thumb:hover { background: var(--ring); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(9, 9, 11, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 0.5rem;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.18), rgba(34, 197, 94, 0.05));
  border: 1px solid rgba(34, 197, 94, 0.25);
  font-size: 0.95rem;
}
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.625rem 0.25rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--muted);
}
.user-name { font-weight: 500; font-size: 0.875rem; }
.avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  flex: 1;
}

.footer {
  text-align: center;
  color: var(--muted-foreground);
  padding: 1.5rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring);
}
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: #e4e4e7; }

.btn-ghost { background: transparent; color: var(--foreground); border-color: transparent; }
.btn-ghost:hover { background: var(--accent); }

.btn-outline { background: transparent; color: var(--foreground); border-color: var(--border); }
.btn-outline:hover { background: var(--accent); }

.btn-danger { background: transparent; color: #f87171; border-color: rgba(239, 68, 68, 0.35); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.55); }

.btn-lg { padding: 0.75rem 1.75rem; font-size: 1rem; border-radius: 0.625rem; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; border-radius: 0.375rem; }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 6rem 0 7rem; }
.hero h1 {
  font-size: clamp(2.25rem, 5vw, 3.25rem);
  margin: 0 0 0.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, #ffffff 0%, #a1a1aa 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p {
  color: var(--muted-foreground);
  margin: 0 0 2rem;
  font-size: 1.05rem;
}

/* ---------- Guild grid ---------- */
.guild-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.875rem;
  margin-top: 1.5rem;
}
.guild-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  transition: border-color 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
}
.guild-card:hover { border-color: var(--ring); background: #101014; transform: translateY(-1px); }
.guild-card-icon {
  width: 48px;
  height: 48px;
  border-radius: 0.875rem;
  object-fit: cover;
  background: var(--muted);
  flex-shrink: 0;
}
.guild-card-icon-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--muted-foreground);
  font-weight: 600;
  font-size: 1.1rem;
}
.guild-card-info { display: flex; flex-direction: column; min-width: 0; }
.guild-card-name { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guild-card-meta { color: var(--muted-foreground); font-size: 0.8rem; }

.empty-card {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  margin-top: 1.5rem;
}
.empty-card p { margin: 0 0 1.25rem; color: var(--muted-foreground); }

/* ---------- Guild nav (top tabs) ---------- */
.guild-nav {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.guild-head { display: flex; align-items: center; gap: 0.625rem; min-width: 0; }
.guild-icon {
  width: 34px;
  height: 34px;
  border-radius: 0.625rem;
  object-fit: cover;
  background: var(--muted);
  flex-shrink: 0;
}
.guild-icon-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--muted-foreground);
  font-weight: 600;
  font-size: 0.9rem;
}
.guild-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-nav { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }
.tab-link {
  padding: 0.5rem 0.875rem;
  border-radius: 0.5rem;
  color: var(--muted-foreground);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tab-link:hover { background: var(--accent); color: var(--foreground); }
.tab-link.is-active { background: var(--accent); color: var(--foreground); }
.back-link { color: var(--muted-foreground); font-size: 0.8rem; font-weight: 500; white-space: nowrap; }
.back-link:hover { color: var(--foreground); }

.guild-content { min-width: 0; }
.guild-content h1 {
  margin: 0 0 0.375rem;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h2 { margin: 0 0 0.75rem; font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.card-head h2 { margin: 0; }
.card > h2 + p.muted { margin: -0.25rem 0 1rem; font-size: 0.875rem; line-height: 1.5; }

/* ---------- Forms ---------- */
.form h2 { margin: 1.5rem 0 0.875rem; font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.form h2:first-child { margin-top: 0; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.form-grid label { display: flex; flex-direction: column; gap: 0.375rem; }
.form-grid label span { font-size: 0.8rem; font-weight: 500; color: var(--muted-foreground); }
.span-2 { grid-column: span 2; }

input, select, textarea {
  background: transparent;
  border: 1px solid var(--input);
  border-radius: 0.5rem;
  color: var(--foreground);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: #52525b; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(82, 82, 91, 0.25);
}
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] {
  width: 1rem;
  height: 1rem;
  padding: 0;
  margin: 0;
  accent-color: var(--success);
  vertical-align: middle;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  padding-right: 2.25rem;
}
select option { background: #0d0d10; color: var(--foreground); }

.inline-form { display: flex; gap: 0.625rem; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { flex: 1; min-width: 160px; }

/* ---------- Banners (alerts) ---------- */
.banner {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
}
.banner-success {
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #86efac;
}
.banner-error {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
.banner-warn {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fcd34d;
}
.banner-error ul { margin: 0; padding-left: 1.125rem; }
.banner-error li + li { margin-top: 0.25rem; }

/* ---------- Item lists ---------- */
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.item-list li:last-child { border-bottom: none; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace; font-size: 0.875rem; }
.role-mention { color: var(--success); font-weight: 500; }

/* ---------- Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.875rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.stat-value {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-label { color: var(--muted-foreground); font-size: 0.8rem; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.table th {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.table tbody tr { transition: background-color 0.15s ease; }
.table tbody tr:hover { background: var(--muted); }
.table tbody tr:last-child td { border-bottom: none; }

/* ---------- Error ---------- */
.error-card { text-align: center; padding: 4rem 1.5rem; }
.error-card h1 { margin: 0 0 0.75rem; font-size: 1.5rem; font-weight: 600; }
.error-card p { color: var(--muted-foreground); margin: 0 0 1.5rem; }

.muted { color: var(--muted-foreground); }

/* ---------- Edit layout + live preview ---------- */
.edit-layout { display: flex; gap: 1rem; align-items: flex-start; }
.edit-main { flex: 1; min-width: 0; }
.edit-side { width: 360px; flex-shrink: 0; position: sticky; top: 5.5rem; }

.form-actions { display: flex; align-items: center; gap: 1rem; margin-top: 0.5rem; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--muted-foreground); font-size: 0.85rem; cursor: pointer; user-select: none; }
.check input { accent-color: var(--success); width: 1rem; height: 1rem; margin: 0; }

.preview-card { margin-bottom: 0; }

.discord-msg { display: flex; gap: 0.75rem; }
.discord-avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--muted);
  font-size: 1.25rem;
}
.discord-body { flex: 1; min-width: 0; }
.discord-author {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.375rem;
}
.discord-bot-tag {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0 0.3rem;
  background: #5865F2;
  color: #fff;
  border-radius: 0.25rem;
  line-height: 1.4;
}
.discord-time { color: #949BA4; font-weight: 400; font-size: 0.7rem; }

.discord-embed {
  display: flex;
  gap: 0.75rem;
  background: #2B2D31;
  border-left: 4px solid #2B2D31;
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem 0.625rem 0.75rem;
  max-width: 100%;
}
.discord-embed-inner { flex: 1; min-width: 0; }
.discord-embed-title { color: #fff; font-weight: 600; font-size: 0.95rem; margin-bottom: 0.25rem; }
.discord-embed-desc {
  color: #DBDEE1;
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.discord-embed-footer { color: #949BA4; font-size: 0.7rem; margin-top: 0.5rem; }
.discord-embed-thumb { flex-shrink: 0; }
.discord-embed-thumb img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 0.25rem;
  display: block;
}

.discord-button {
  margin-top: 0.5rem;
  display: inline-flex;
  align-items: center;
  padding: 0.375rem 1rem;
  border-radius: 0.25rem;
  background: #5865F2;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.3;
}

/* ---------- Misc ---------- */
.card textarea { width: 100%; }
.webhook-url { word-break: break-all; }
.item-actions { display: inline-flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.form-grid label.check-row {
  flex-direction: row;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
  padding: 0.375rem 0;
}
.form-grid label.check-row span { color: var(--foreground); font-size: 0.9rem; font-weight: 500; }
input[type="file"] { padding: 0.5rem; cursor: pointer; }
input[type="file"]::file-selector-button {
  background: var(--accent);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.375rem 0.75rem;
  margin-right: 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
input[type="file"]::file-selector-button:hover { background: var(--muted); }
.file-drop { display: flex; flex-direction: column; gap: 0.375rem; }
.file-drop span { font-size: 0.8rem; font-weight: 500; color: var(--muted-foreground); }
.or-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted-foreground);
  font-size: 0.8rem;
  margin: 0.875rem 0;
}
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

@media (max-width: 800px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .edit-layout { flex-direction: column; }
  .edit-side { width: 100%; position: static; }
}
