@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #101116;
  --bg1: #15161c;
  --bg2: #1b1d24;
  --bg3: #22242d;
  --bg4: #2a2d38;
  --border: #333644;
  --border-soft: #262935;
  --text: #e6e8ee;
  --text-dim: #8a8e9c;
  --text-faint: #5c6070;
  --accent: #5865f2;
  --accent-hover: #6a76f7;
  --accent-soft: rgba(88, 101, 242, 0.14);
  --accent-glow: rgba(88, 101, 242, 0.35);
  --green: #57f287;
  --red: #ed4245;
  --yellow: #fee75c;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-w: 288px;
  --topbar-h: 56px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1400px 700px at 100% -5%, rgba(88, 101, 242, 0.10), transparent 55%),
    radial-gradient(900px 500px at -10% 110%, rgba(88, 101, 242, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app { min-height: 100%; }

button, a, .sys-item, summary, input[type=checkbox], input[type=color] { touch-action: manipulation; }

::selection { background: var(--accent-glow); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bg4); border-radius: 20px;
  border: 3px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #3a3d4a; background-clip: padding-box; }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.loading {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 15px; letter-spacing: 0.2px;
}

/* ============================================================
   LOGIN
   ============================================================ */

.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-card {
  width: 100%; max-width: 420px;
  background: linear-gradient(180deg, var(--bg2), var(--bg1));
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: 36px 26px;
  text-align: center;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  background: var(--accent-soft);
  border: 1px solid rgba(88, 101, 242, 0.3);
  border-radius: 18px;
  box-shadow: 0 0 30px rgba(88, 101, 242, 0.2);
}
.login-card h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.login-sub { margin: 6px 0 0; color: var(--accent); font-weight: 600; font-size: 14px; }
.login-desc { margin: 16px 0 24px; color: var(--text-dim); font-size: 14px; line-height: 1.6; }
.login-card button {
  width: 100%; padding: 14px 24px; font-size: 15px; font-weight: 600;
  justify-content: center;
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(88, 101, 242, 0.3);
}
.login-foot { margin-top: 22px; color: var(--text-faint); font-size: 11.5px; }
.btn-ico { margin-right: 2px; }

/* ============================================================
   TOP BAR (mobile) — masquée sur desktop
   ============================================================ */

.topbar {
  position: sticky; top: 0; z-index: 45;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: rgba(21, 22, 28, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-title {
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-logo { margin-right: 4px; }

.menu-toggle {
  width: var(--tap); height: var(--tap); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg3); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 0; box-shadow: none;
}
.burger, .burger::before, .burger::after {
  content: ''; display: block;
  width: 20px; height: 2px; border-radius: 2px; background: var(--text);
  transition: transform var(--transition), opacity var(--transition);
}
.burger { position: relative; }
.burger::before { position: absolute; top: -6px; }
.burger::after { position: absolute; top: 6px; }
.menu-toggle.is-open .burger { background: transparent; }
.menu-toggle.is-open .burger::before { top: 0; transform: rotate(45deg); }
.menu-toggle.is-open .burger::after { top: 0; transform: rotate(-45deg); }

/* ============================================================
   LAYOUT SHELL  (mobile-first : sidebar = drawer off-canvas)
   ============================================================ */

.layout { position: relative; }

.backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0; visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}
.backdrop.show { opacity: 1; visibility: visible; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
  width: 300px; max-width: 86vw;
  transform: translateX(-100%);
  transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(180deg, var(--bg2), var(--bg1));
  border-right: 1px solid var(--border-soft);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto; overscroll-behavior: contain;
  box-shadow: var(--shadow-lg);
}
.sidebar.open { transform: translateX(0); }

/* brand */
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 14px; }
.brand-logo {
  width: 42px; height: 42px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  background: var(--accent-soft); border: 1px solid rgba(88, 101, 242, 0.25);
  border-radius: 12px;
}
.brand-text { min-width: 0; }
.brand-name {
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-tag { font-size: 11.5px; color: var(--text-dim); font-weight: 500; }

/* stat card */
.stat-card {
  display: flex; align-items: stretch; gap: 4px;
  background: var(--bg3); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 12px 8px; margin-bottom: 10px;
}
.stat { flex: 1; text-align: center; }
.stat-num { font-size: 22px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.stat:first-child .stat-num { color: var(--green); }
.stat-label { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 5px; font-weight: 600; }
.stat-sep { width: 1px; background: var(--border-soft); }

/* nav */
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint); font-weight: 700;
  margin: 14px 8px 6px;
}

.sys-item {
  min-height: var(--tap);
  padding: 10px 12px; border-radius: var(--radius-xs); cursor: pointer;
  border: 1px solid transparent;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  transition: background var(--transition), border-color var(--transition);
  font-weight: 500; font-size: 14px;
}
.sys-item.active {
  background: linear-gradient(90deg, var(--accent-soft), transparent);
  border-color: rgba(88, 101, 242, 0.35);
  box-shadow: inset 2px 0 0 var(--accent);
}
.sys-item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sys-item .badge {
  flex-shrink: 0;
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 20px;
  background: var(--bg4); color: var(--text-dim);
  letter-spacing: 0.03em; text-transform: uppercase;
}
.sys-item .badge.on { background: rgba(87, 242, 135, 0.14); color: var(--green); }
.sys-item .badge.off { background: rgba(237, 66, 69, 0.14); color: var(--red); }

.nav-btn {
  width: 100%; min-height: var(--tap); text-align: left; justify-content: flex-start;
  background: transparent; color: var(--text-dim);
  padding: 10px 12px; font-size: 14px; font-weight: 500;
  border-radius: var(--radius-xs); box-shadow: none;
  display: flex; align-items: center; gap: 10px;
}
.nav-btn .nav-ico { width: 18px; text-align: center; font-size: 14px; }
.nav-btn-add { color: var(--accent); font-weight: 600; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.sidebar-foot a {
  display: flex; align-items: center; gap: 10px; min-height: var(--tap);
  color: var(--text-dim); font-size: 14px; font-weight: 500;
  padding: 8px 12px; border-radius: var(--radius-xs);
  transition: background var(--transition), color var(--transition);
}
.sidebar-foot .nav-ico { width: 18px; text-align: center; }

/* content */
.main { padding: 20px 16px 56px; overscroll-behavior: contain; }
.main > h2 {
  margin: 0 0 20px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em;
  padding-bottom: 14px; border-bottom: 1px solid var(--border-soft);
}

/* ============================================================
   FIELDSETS / CARDS
   ============================================================ */

fieldset {
  border: 1px solid var(--border-soft); border-radius: var(--radius); margin: 0 0 20px;
  padding: 18px 16px 20px; background: var(--bg2);
  box-shadow: var(--shadow-sm);
  max-width: 1040px;
}
legend {
  padding: 4px 12px; font-weight: 700; color: var(--text);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--bg3); border: 1px solid var(--border-soft);
  border-radius: 20px; margin-left: -4px;
}

label { display: block; margin: 14px 0 6px; color: var(--text-dim); font-size: 13px; font-weight: 600; }

input[type=text], input[type=number], textarea, select {
  width: 100%; background: var(--bg1); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-xs); padding: 12px; font-family: inherit; font-size: 16px;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); background: var(--bg);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
select { cursor: pointer; }

.row { display: flex; flex-direction: column; gap: 4px; }
.row > div { flex: 1; min-width: 0; }
.check {
  display: flex; align-items: center; gap: 12px; margin: 12px 0; min-height: 40px;
}
.check label { margin: 0; color: var(--text); font-size: 14px; font-weight: 500; }
input[type=checkbox] {
  width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0;
}

.rolebox {
  max-height: 200px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg1); border: 1px solid var(--border);
  border-radius: var(--radius-xs); padding: 8px;
}
.rolebox .check { margin: 2px 0; min-height: 38px; }

.option-card {
  border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 16px;
  margin-bottom: 16px; background: var(--bg3);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition);
}
.option-card .opt-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-bottom: 4px;
}
.option-card .opt-head strong { font-size: 15px; font-weight: 700; }

.question-card {
  border-left: 3px solid var(--accent); padding: 12px 14px; margin: 12px 0; background: var(--bg2);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

/* ============================================================
   BUTTONS  (touch-first)
   ============================================================ */

button {
  min-height: var(--tap);
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 11px 18px; font-size: 14.5px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: background var(--transition), transform 90ms ease, box-shadow var(--transition), filter var(--transition);
  box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:active { transform: scale(0.97); }
button.secondary { background: var(--bg4); color: var(--text); box-shadow: none; }
button.danger { background: var(--red); }
button.success { background: #248046; }
button.small { min-height: 40px; padding: 8px 14px; font-size: 13px; }

@media (hover: hover) {
  button:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
  button.secondary:hover { background: #33363f; }
  button.danger:hover { background: #f2555a; }
  button.success:hover { background: #2a9350; }
  .sys-item:hover { background: var(--bg3); }
  .nav-btn:hover { background: var(--bg3); color: var(--text); }
  .nav-btn-add:hover { background: var(--accent-soft); color: var(--accent-hover); }
  .sidebar-foot a:hover { background: var(--bg3); color: var(--text); }
  .option-card:hover { border-color: var(--border); box-shadow: var(--shadow-md); }
  .menu-toggle:hover { background: var(--bg4); }
  .ss-item:hover { background: var(--accent-soft); }
  details.opt-msg summary:hover { color: var(--text); }
}

.actions {
  display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0 0;
  position: sticky; bottom: 0;
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
  padding: 16px 0 12px; border-top: 1px solid var(--border-soft);
  max-width: 1040px;
}
.actions button { flex: 1 1 auto; min-width: 140px; }
.actions button[style*="margin-left"] { flex-basis: 100%; }

/* ============================================================
   SEARCH SELECT
   ============================================================ */

.sselect { position: relative; }
.ss-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--bg3); border: 1px solid var(--accent); border-radius: var(--radius-xs);
  max-height: 280px; overflow-y: auto; overscroll-behavior: contain;
  box-shadow: var(--shadow-lg);
}
.ss-item {
  min-height: var(--tap);
  padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  transition: background var(--transition); font-size: 14px;
}
.ss-item.ss-none { color: var(--text-dim); font-style: italic; }
.ss-cat { color: var(--text-faint); font-size: 11px; }

.role-filter { margin-bottom: 8px; }

/* ============================================================
   MESSAGE EDITOR
   ============================================================ */

.msg-editor { margin-top: 10px; }
.embed-card {
  border: 1px solid var(--border-soft); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: 14px; margin: 12px 0; background: var(--bg4);
  box-shadow: var(--shadow-sm);
}
.embed-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.embed-head strong { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.embed-tools { display: flex; gap: 6px; flex-shrink: 0; }
.field-card {
  background: var(--bg2); border-radius: var(--radius-xs); padding: 12px; margin: 8px 0;
  border-left: 2px solid var(--border);
}
.field-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
input[type=color] {
  width: 100%; height: 44px; padding: 3px; background: var(--bg1);
  border: 1px solid var(--border); border-radius: var(--radius-xs); cursor: pointer;
}
details.opt-msg { margin: 14px 0; }
details.opt-msg summary {
  cursor: pointer; color: var(--text-dim); padding: 10px 0; font-weight: 600; font-size: 14px;
  transition: color var(--transition); list-style: none; min-height: 40px; display: flex; align-items: center;
}
details.opt-msg summary::before { content: '▸'; color: var(--accent); margin-right: 8px; }
details.opt-msg[open] summary::before { content: '▾'; }

/* ============================================================
   PERMISSION TABLE  (scroll horizontal sur mobile)
   ============================================================ */

details.perm-status {
  margin: 10px 0; border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 12px 14px; background: var(--bg3);
  overflow-x: auto; overscroll-behavior-x: contain;
}
details.perm-status summary { cursor: pointer; font-weight: 600; padding: 6px 0; min-height: 40px; display: flex; align-items: center; }
details.perm-status[open] summary { color: var(--accent); margin-bottom: 6px; }
.perm-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.perm-table th, .perm-table td { padding: 10px; text-align: left; white-space: nowrap; }
.perm-table th { color: var(--text-dim); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.perm-table tr:not(:first-child) { border-top: 1px solid var(--border-soft); }
.perm-table .perm-cell { text-align: center; }
.perm-table input[type=checkbox] { width: 20px; height: 20px; cursor: pointer; accent-color: var(--accent); }
.perm-table th.act-col, .perm-table td.act-col { background: rgba(88, 101, 242, 0.07); border-left: 1px solid var(--border); }
.perm-table th.act-col { color: var(--accent); }

/* ============================================================
   RANKS
   ============================================================ */

/* Types de liens (règles de modération) */
.link-types {
  display: flex; flex-direction: column; gap: 8px; margin-top: 6px;
  background: var(--bg2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-xs); padding: 10px 12px;
}
.link-type-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.link-type-label { font-size: 13.5px; font-weight: 500; }
.link-type-row select { width: auto; min-width: 150px; flex-shrink: 0; }

.rank-perms { display: flex; flex-wrap: wrap; margin-top: 8px; }
.ranks-log {
  font-family: 'Consolas', 'Fira Code', monospace; font-size: 12px; max-height: 300px; overflow-y: auto;
  background: var(--bg1); border-radius: var(--radius-xs); padding: 12px; overscroll-behavior: contain;
}
.ranks-log div { padding: 3px 0; border-bottom: 1px solid var(--border-soft); }

/* ============================================================
   TOAST / MISC
   ============================================================ */

.toast {
  position: fixed; top: calc(var(--topbar-h) + 12px); right: 12px; left: 12px;
  padding: 14px 18px; border-radius: var(--radius);
  background: var(--bg3); border: 1px solid var(--border); z-index: 100;
  box-shadow: var(--shadow-lg);
  animation: toast-in 240ms cubic-bezier(0.16, 1, 0.3, 1);
  font-weight: 500;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast.ok { border-color: rgba(87, 242, 135, 0.5); box-shadow: var(--shadow-lg), inset 3px 0 0 var(--green); }
.toast.err { border-color: rgba(237, 66, 69, 0.5); box-shadow: var(--shadow-lg), inset 3px 0 0 var(--red); }

.hint { font-size: 12.5px; color: var(--text-dim); margin-top: 6px; line-height: 1.55; }
.empty {
  color: var(--text-dim); padding: 60px 24px; text-align: center; font-size: 14.5px; line-height: 1.75;
  max-width: 480px; margin: 20px auto 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .sidebar { transition: none !important; }
}

/* ============================================================
   ≥ 640px : formulaires en lignes, toast compact
   ============================================================ */

@media (min-width: 640px) {
  .row { flex-direction: row; flex-wrap: wrap; gap: 16px; }
  .row > div { min-width: 180px; }
  .toast { left: auto; right: 18px; max-width: 360px; }
  .main { padding: 24px 24px 60px; }
  fieldset { padding: 20px 22px 22px; }
  .actions button { flex: 0 1 auto; min-width: 0; }
  .actions button[style*="margin-left"] { flex-basis: auto; }
  input[type=text], input[type=number], textarea, select { font-size: 14px; padding: 10px 12px; }
}

/* ============================================================
   ≥ 1024px : sidebar persistante (desktop / tablette paysage)
   ============================================================ */

@media (min-width: 1024px) {
  .topbar { display: none; }
  .backdrop { display: none; }

  /* Shell centré : sidebar + contenu forment un bloc centré, encadré */
  .layout {
    display: flex; height: 100vh; overflow: hidden;
    max-width: 1500px; margin: 0 auto;
    border-inline: 1px solid var(--border-soft);
  }

  .sidebar {
    position: static; transform: none; z-index: auto;
    width: var(--sidebar-w); max-width: none; flex-shrink: 0;
    box-shadow: none; padding: 20px 16px;
    border-right: 1px solid var(--border-soft);
  }

  .main { flex: 1; overflow-y: auto; height: 100vh; padding: 32px 40px 64px; }
  /* Contenu centré dans l'espace à droite de la sidebar */
  .main > h2,
  .main > fieldset,
  .main > .actions,
  .main > .empty { margin-left: auto; margin-right: auto; }
  .main > h2 { max-width: 1040px; width: 100%; margin-bottom: 24px; font-size: 22px; padding-bottom: 16px; }

  .toast { top: 20px; right: 20px; }

  /* densité desktop : cibles tactiles moins critiques */
  button.small { min-height: 34px; padding: 6px 11px; font-size: 12px; }
  .sys-item, .nav-btn, .sidebar-foot a, .ss-item { min-height: 0; }
  .nav-btn { padding: 10px 12px; }
  .sys-item { padding: 10px 12px; }
}
