:root {
  --bg: #0b0d14;
  --bg-alt: #10131c;
  --surface: #151926;
  --surface-hover: #1b202f;
  --border: #232838;
  --text: #e7e9f0;
  --text-dim: #8890a6;
  --text-faint: #5b6178;
  --accent: #6d5bff;
  --accent-hover: #7f6dff;
  --accent-soft: rgba(109, 91, 255, 0.14);
  --success: #34d399;
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, 'Inter', Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }

.icon {
  font-size: 16px; line-height: 1; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 1em; height: 1em; vertical-align: -0.15em;
}
.icon-sm { font-size: 14px; }
.icon-xs { font-size: 11px; }
.icon-xl { font-size: 40px; }

/* ── Layout ────────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1;
}

.brand-mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white;
}
.brand-mark.lg { width: 56px; height: 56px; border-radius: 16px; }
.brand-mark.lg .icon { width: 28px; height: 28px; }
.brand-mark.error { background: linear-gradient(135deg, var(--danger), #fca5a5); }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-hover); }

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 6px; }
.sidebar-user-info { display: flex; flex-direction: column; overflow: hidden; flex: 1; }
.sidebar-user-info strong { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-info span { font-size: 0.72rem; color: var(--text-faint); }

.avatar-pill { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); }

.icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.mobile-toggle {
  display: none;
  position: fixed; top: 14px; left: 14px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  align-items: center; justify-content: center;
}

.main-content { flex: 1; padding: 28px 34px 60px; max-width: 1280px; }

.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.topbar-with-back { display: flex; align-items: center; gap: 14px; }
.topbar-stats { display: flex; gap: 10px; }
.stat-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 999px; font-size: 0.82rem; color: var(--text-dim);
}

.page-title { font-size: 1.6rem; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.01em; }
.page-description { color: var(--text-dim); margin: 0; font-size: 0.88rem; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 18px; font-size: 1.05rem; font-weight: 700; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 80px 20px; color: var(--text-faint); text-align: center;
}

/* ── Search ────────────────────────────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; margin-bottom: 20px; max-width: 380px; color: var(--text-faint);
}
.search-bar input { background: none; border: none; outline: none; color: var(--text); width: 100%; font-size: 0.9rem; }

/* ── Server grid ───────────────────────────────────────────────────────── */
.servers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }

.server-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 20px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px;
  transition: border-color 0.15s, transform 0.15s;
  height: 100%;
}
.server-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.server-card-main { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.server-card-icon {
  width: 64px; height: 64px; min-width: 64px; min-height: 64px; border-radius: 50%; overflow: hidden;
  background: var(--bg-alt); flex-shrink: 0; position: relative;
  display: flex; align-items: center; justify-content: center; color: var(--text-faint);
  font-size: 24px;
}
.server-card-icon.no-image { background: linear-gradient(135deg, var(--accent), #a78bfa); color: #fff; }
.server-card-icon img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: block; border-radius: 50%;
}
.server-card h2 { margin: 0; font-size: 1rem; font-weight: 700; }
.server-card .page-description { display: flex; align-items: center; justify-content: center; gap: 4px; }

.server-card-features { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; flex: 1; align-content: flex-start; }
.badge {
  background: var(--accent-soft); color: var(--accent-hover);
  font-size: 0.72rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
}
.badge.muted { background: var(--bg-alt); color: var(--text-faint); }

.server-card-footer { width: 100%; margin-top: auto; padding-top: 4px; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 700; font-size: 0.88rem;
  border: 1px solid transparent; transition: filter 0.15s, background 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-block { width: 100%; }
.btn-lg { padding: 13px 20px; font-size: 0.95rem; }
.btn-sm { padding: 6px 10px; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group.span-2 { grid-column: 1 / -1; }

label { font-size: 0.82rem; font-weight: 700; color: var(--text-dim); }

input[type="text"], input:not([type]), textarea, select {
  background: var(--bg-alt); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.88rem; outline: none;
  font-family: inherit; transition: border-color 0.15s;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { min-height: 88px; resize: vertical; }
select[multiple] { min-height: 120px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-weight: 600; font-size: 0.88rem; }
.toggle { position: relative; width: 42px; height: 24px; display: inline-block; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.toggle-track { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background 0.15s; }
.toggle-track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  background: white; border-radius: 50%; transition: transform 0.15s;
}
.toggle.checked .toggle-track { background: var(--accent); }
.toggle.checked .toggle-track::after { transform: translateX(18px); }

/* ── Config layout (tabs) ──────────────────────────────────────────────── */
.config-layout { display: flex; gap: 22px; align-items: flex-start; }
.section-nav { display: flex; flex-direction: column; gap: 4px; width: 190px; flex-shrink: 0; position: sticky; top: 24px; }
.section-tab {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; color: var(--text-dim);
  padding: 10px 12px; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.85rem; text-align: left;
}
.section-tab:hover { background: var(--surface); color: var(--text); }
.section-tab.active { background: var(--accent-soft); color: var(--accent-hover); }
.config-form { flex: 1; min-width: 0; }
.config-section { display: none; }
.config-section.active { display: block; }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 100;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.85rem;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); }

/* ── Activity list ─────────────────────────────────────────────────────── */
.activity-list { display: flex; flex-direction: column; gap: 10px; }
.activity-list li { display: flex; align-items: center; gap: 10px; font-size: 0.83rem; color: var(--text-dim); }
.activity-list time { margin-left: auto; color: var(--text-faint); font-size: 0.75rem; }

/* ── Stats grid (admin) ────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; align-items: center; gap: 14px; color: var(--accent-hover);
}
.stat-card div { display: flex; flex-direction: column; }
.stat-card strong { font-size: 1.3rem; color: var(--text); }
.stat-card span { font-size: 0.78rem; color: var(--text-faint); }

/* ── Table ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th { text-align: left; color: var(--text-faint); font-weight: 700; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-icon { width: 30px; height: 30px; border-radius: 8px; overflow: hidden; background-color: var(--bg-alt); display: flex; align-items: center; justify-content: center; color: var(--text-faint); }
.table-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ── Custom select (channel/role picker à la Discord) ─────────────────── */
.picker { position: relative; }
.picker-input {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  min-height: 42px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 10px; cursor: pointer; transition: border-color 0.15s;
}
.picker-input:hover, .picker.open .picker-input { border-color: var(--accent); }
.picker-placeholder { color: var(--text-faint); font-size: 0.88rem; padding: 3px 2px; }
.picker-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-hover); border: 1px solid var(--border);
  padding: 3px 8px 3px 6px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; color: var(--text);
  max-width: 100%;
}
.picker-chip .chip-dot, .picker-chip .opt-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--text-faint); }
.picker-chip .chip-remove {
  display: flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; color: var(--text-faint); font-size: 10px;
  flex-shrink: 0;
}
.picker-chip .chip-remove:hover { background: var(--border); color: var(--text); }
.picker-caret { margin-left: auto; color: var(--text-faint); font-size: 12px; flex-shrink: 0; transition: transform 0.15s; }
.picker.open .picker-caret { transform: rotate(180deg); }

.picker-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden; display: none;
}
.picker.open .picker-menu { display: block; }
.picker-search {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--border);
}
.picker-search i { color: var(--text-faint); font-size: 13px; }
.picker-search input { border: none; background: none; padding: 0; font-size: 0.85rem; }
.picker-list { max-height: 220px; overflow-y: auto; padding: 6px; }
.picker-option {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 0.86rem; font-weight: 600; color: var(--text-dim);
  background: none; border: none;
}
.picker-option:hover { background: var(--surface-hover); color: var(--text); }
.picker-option.selected { background: var(--accent-soft); color: var(--accent-hover); }
.picker-option .opt-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--text-faint); }
.picker-option .opt-icon { color: var(--text-faint); font-size: 12px; width: 14px; text-align: center; flex-shrink: 0; }
.picker-empty { padding: 14px 10px; text-align: center; color: var(--text-faint); font-size: 0.82rem; }


.fi { border-radius: 3px; vertical-align: -2px; width: 1.33em; height: 1em; background-size: cover; }
.lang-dropdown { position: relative; }
.lang-dropdown-summary {
  display: flex; align-items: center; gap: 8px; list-style: none; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 0.8rem; color: var(--text-dim); font-weight: 600;
}
.lang-dropdown-summary::-webkit-details-marker { display: none; }
.lang-dropdown[open] .chevron { transform: rotate(180deg); }
.chevron { transition: transform 0.15s; margin-left: auto; }
.lang-dropdown-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 20; min-width: 160px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden;
}
.lang-dropdown-item { display: block; padding: 9px 12px; font-size: 0.82rem; color: var(--text-dim); }
.lang-dropdown-item:hover { background: var(--surface-hover); color: var(--text); }
.lang-dropdown-item.active { color: var(--accent-hover); font-weight: 700; }

/* ── Auth pages ────────────────────────────────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: radial-gradient(circle at top, #171b29, var(--bg) 60%); }
.auth-shell { width: 100%; max-width: 420px; padding: 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 40px 32px; text-align: center; box-shadow: var(--shadow); }
.auth-brand { display: flex; justify-content: center; margin-bottom: 20px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.72rem; font-weight: 800; color: var(--accent-hover); margin: 0 0 10px; }
.auth-title { font-size: 1.4rem; font-weight: 800; margin: 0 0 8px; }
.auth-subtitle { color: var(--text-dim); font-size: 0.88rem; margin: 0 0 26px; }
.auth-lang { display: flex; justify-content: center; margin-top: 20px; }
.auth-lang .lang-dropdown-menu { bottom: auto; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: -260px; top: 0; z-index: 40; transition: left 0.2s; box-shadow: var(--shadow);
  }
  .sidebar.open { left: 0; }
  .mobile-toggle { display: flex; }
  .main-content { padding: 76px 18px 60px; }
  .config-layout { flex-direction: column; }
  .section-nav { flex-direction: row; overflow-x: auto; width: 100%; position: static; gap: 6px; padding-bottom: 4px; }
  .field-grid { grid-template-columns: 1fr; }
}

/* ── Téléchargeur média ────────────────────────────────────────────────── */
.dl-search-row { display: flex; gap: 10px; }
.dl-search-row input { flex: 1; }
.dl-search-row .btn span { white-space: nowrap; }
.dl-hint { margin: 12px 0 0; display: flex; align-items: center; gap: 6px; }

.dl-result { display: flex; flex-direction: column; gap: 18px; }
.dl-preview { display: flex; gap: 16px; align-items: center; }
.dl-thumb {
  width: 140px; height: 90px; border-radius: var(--radius-sm); flex-shrink: 0;
  background: var(--bg-alt); border: 1px solid var(--border); overflow: hidden;
  display: flex; align-items: center; justify-content: center; color: var(--text-faint);
}
.dl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dl-meta { min-width: 0; }
.dl-meta h2 { margin: 0 0 6px; font-size: 1.05rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dl-meta p { margin: 0; }

.dl-label { display: block; font-weight: 700; font-size: 0.85rem; margin-bottom: 8px; }
.dl-quality-select { max-width: 320px; }
.dl-selectors { display: flex; gap: 18px; flex-wrap: wrap; }
.dl-selectors .dl-quality-block { flex: 1; min-width: 200px; }

@media (max-width: 640px) {
  .dl-search-row { flex-direction: column; }
  .dl-preview { flex-direction: column; align-items: flex-start; }
  .dl-thumb { width: 100%; height: 160px; }
  .dl-quality-select { max-width: none; }
}

/* ── Test perf DM (admin) ─────────────────────────────────────────────── */
.dm-test-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.dm-test-input-id { min-width: 280px; }
.dm-test-input-count { width: 90px; }
