:root {
  color-scheme: dark;
  --bg: #0e1015;
  --bg-glow: rgba(88, 101, 242, 0.16);
  --surface: #161920;
  --surface-2: #1e222b;
  --surface-3: #262b36;
  --border: #2a2f3b;
  --border-strong: #3a4050;
  --text: #eceef3;
  --muted: #959cad;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-soft: rgba(88, 101, 242, 0.14);
  --ok: #3fb96a;
  --ok-soft: rgba(63, 185, 106, 0.14);
  --warn: #e8a90f;
  --warn-soft: rgba(232, 169, 15, 0.14);
  --error: #f0484b;
  --error-soft: rgba(240, 72, 75, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.18);
  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f4f8;
    --bg-glow: rgba(88, 101, 242, 0.1);
    --surface: #ffffff;
    --surface-2: #f4f5f9;
    --surface-3: #e9ebf1;
    --border: #e1e4eb;
    --border-strong: #c9cdd8;
    --text: #1a1d24;
    --muted: #5d6474;
    --accent-soft: rgba(88, 101, 242, 0.1);
    --ok: #23803f;
    --ok-soft: rgba(35, 128, 63, 0.1);
    --warn: #a36a00;
    --warn-soft: rgba(163, 106, 0, 0.1);
    --error: #c4282b;
    --error-soft: rgba(196, 40, 43, 0.09);
    --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 6px 20px rgba(20, 24, 40, 0.06);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 500px at 15% -10%, var(--bg-glow), transparent 70%),
    radial-gradient(900px 400px at 100% 0%, rgba(235, 69, 158, 0.07), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 750; }
h2 { font-size: 18px; font-weight: 700; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.min-w0 { min-width: 0; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; color: var(--muted); }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px max(16px, calc((100vw - 1040px) / 2));
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
}
.brand img { border-radius: 7px; }
.user { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.user img { width: 30px; height: 30px; border-radius: 50%; }
@media (max-width: 480px) { .user span { display: none; } }

.container { max-width: 1040px; margin: 0 auto; padding: 28px 16px 72px; }

/* ---------- Card ---------- */

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

.section-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
}
.section-head .text { flex: 1; min-width: 0; }
.section-head h2 { margin: 0 0 2px; }
.section-head p { margin: 0; color: var(--muted); font-size: 14px; }
.section-icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 21px;
  background: var(--accent-soft);
}

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

/* ---------- Bottoni ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-small { padding: 5px 11px; font-size: 13px; }
.btn-large { padding: 12px 22px; font-size: 15px; }
.btn img { width: 20px; height: 20px; }

/* ---------- Login ---------- */

.login {
  max-width: 440px;
  margin: 8vh auto 0;
  padding: 36px 32px;
  text-align: center;
}
.login .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 18px; box-shadow: 0 10px 30px var(--bg-glow); }
.login h1 { margin-bottom: 6px; }
.login > p { margin: 0 0 24px; }
.features { list-style: none; padding: 0; margin: 0 0 26px; display: grid; gap: 8px; text-align: left; }
.features li {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.features li span:first-child { font-size: 18px; }

.verify .verify-emoji { font-size: 52px; line-height: 1; margin-bottom: 14px; }
.verify p { margin: 0 0 24px; }

/* ---------- Elenco server ---------- */

.page-title { margin-bottom: 4px; }
.page-sub { margin: 0 0 22px; color: var(--muted); }

.guild-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.guild-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  min-width: 0;
  transition: border-color 0.15s, transform 0.15s;
}
.guild-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.guild-card .top { display: flex; align-items: center; gap: 14px; }
.guild-card .name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.guild-icon {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--surface-3);
  display: grid;
  place-items: center;
  font-weight: 750;
  color: var(--muted);
  object-fit: cover;
}
.guild-icon.large { width: 68px; height: 68px; border-radius: 18px; font-size: 22px; }

/* ---------- Badge / chip ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  background: var(--surface-3);
  color: var(--muted);
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge.plain::before { display: none; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-error { background: var(--error-soft); color: var(--error); }

/* ---------- Pagina server ---------- */

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.back:hover { color: var(--text); }

.hero {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 20px;
}
.hero h1 { margin: 0 0 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat .label { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat .value { font-size: 28px; font-weight: 750; letter-spacing: -0.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
}
.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { background: var(--accent); color: #fff; }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); }
.tab .dot.on { background: var(--ok); }
.tab[aria-selected="true"] .dot.on { background: #fff; }

/* ---------- Controlli ---------- */

.checks { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 8px; }
.checks li {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface-2);
}
.checks li::before { flex: none; font-weight: 800; }
.checks .ok { background: var(--ok-soft); }
.checks .ok::before { content: "✓"; color: var(--ok); }
.checks .warn { background: var(--warn-soft); }
.checks .warn::before { content: "!"; color: var(--warn); }
.checks .error { background: var(--error-soft); }
.checks .error::before { content: "✕"; color: var(--error); }

/* ---------- Form ---------- */

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px 20px; }
@media (max-width: 680px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

/* min-width: 0 evita che i nomi lunghi nelle select allarghino la pagina su mobile */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-weight: 650; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); }
.field.full, .spaced { margin-top: 18px; }
.spaced .switch-row { margin-bottom: 0; }

input[type="number"],
input[type="search"],
input[type="text"],
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Toggle */
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 650; font-size: 14px; }
.switch input {
  appearance: none;
  flex: none;
  position: relative;
  width: 42px;
  height: 24px;
  margin: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background 0.2s;
}
.switch input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch input:checked { background: var(--ok); }
.switch input:checked::before { transform: translateX(18px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

/* Liste con checkbox */
.role-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-top: 8px;
}
.role-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}
.role-item:hover { background: var(--surface-3); }
.role-item:last-child { border-bottom: 0; }
.role-item input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.role-item.strong { font-weight: 650; }
.role-item .muted { margin-left: auto; }
.role-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--role-color, var(--muted)); flex: none; }
.channel-icon { width: 18px; text-align: center; color: var(--muted); flex: none; }

.logger-rows { display: grid; gap: 8px; }
.logger-row > * { min-width: 0; }
.logger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 300px);
  align-items: center;
  gap: 10px 18px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.logger-row .hint { margin: 4px 0 0 54px; }
@media (max-width: 680px) {
  .logger-row { grid-template-columns: minmax(0, 1fr); }
  .logger-row .hint { margin-left: 0; }
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.status { font-size: 14px; font-weight: 600; }
.status.ok { color: var(--ok); }
.status.error { color: var(--error); }
.updated { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- Tabelle ---------- */

.table-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.incident-user { display: flex; align-items: center; gap: 10px; }
.incident-user img { width: 30px; height: 30px; border-radius: 50%; }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.empty .emoji { display: block; font-size: 30px; margin-bottom: 6px; }

.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.loading::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
