:root {
  --bg: #1a1b1e;
  --bg-2: #232428;
  --bg-3: #2b2d31;
  --bg-4: #313338;
  --line: #3a3c41;
  --text: #dbdee1;
  --text-dim: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a55a;
  --red: #f23f43;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "gg sans", "Noto Sans", system-ui, -apple-system, sans-serif;
}
a { color: #00a8fc; }
button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  transition: background .15s;
}
button:hover { background: var(--accent-hover); }
button.secondary { background: var(--bg-4); color: var(--text); }
button.secondary:hover { background: var(--line); }
button.danger { background: var(--red); }
button.danger:hover { background: #c62c34; }
button.ghost { background: transparent; color: var(--text-dim); padding: 6px 10px; }
button.ghost:hover { background: var(--bg-4); color: var(--text); }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { resize: vertical; min-height: 84px; }
label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim); margin: 14px 0 6px; font-weight: 700; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.hint { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; background: var(--bg-2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { font-weight: 800; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 14px; }
.topbar img.avatar { width: 26px; height: 26px; border-radius: 50%; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 22px 18px; }

/* Center screens */
.center { min-height: 70vh; display: grid; place-items: center; text-align: center; }
.center .card { background: var(--bg-2); padding: 40px; border-radius: 12px; max-width: 420px; }
.discord-btn { background: #5865f2; display: inline-flex; align-items: center; gap: 10px; font-weight: 600; padding: 12px 22px; border-radius: 8px; color:#fff; text-decoration:none; }

/* Guild grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.guild-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
}
.guild-card .icon { width: 60px; height: 60px; border-radius: 50%; background: var(--bg-4); display:grid; place-items:center; font-size:22px; font-weight:700; overflow:hidden; }
.guild-card .icon img { width: 100%; height: 100%; object-fit: cover; }
.guild-card .name { font-weight: 600; }

/* Guild dashboard */
.guild-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.guild-header .icon { width: 52px; height: 52px; border-radius: 50%; background: var(--bg-4); display: grid; place-items: center; font-weight: 700; overflow: hidden; flex-shrink: 0; }
.guild-header .icon img { width: 100%; height: 100%; object-fit: cover; }
.dash { display: grid; grid-template-columns: 210px 1fr; gap: 20px; }
.sidenav { display: flex; flex-direction: column; gap: 4px; }
.sidenav button { background: transparent; color: var(--text-dim); text-align: left; border-radius: 6px; padding: 10px 12px; }
.sidenav button.active, .sidenav button:hover { background: var(--bg-3); color: #fff; }
.panel-box { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.panel-box h2 { margin: 0 0 4px; }
.panel-box .sub { color: var(--text-dim); margin-bottom: 18px; font-size: 14px; }
.actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.toggle-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle-line:last-child { border-bottom: none; }

/* Pastille d'activation (switch) */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; vertical-align: middle; }
.switch .sw-input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }
.switch .sw-track { position: absolute; inset: 0; border-radius: 999px; background: var(--bg-4); transition: background .15s; }
.switch .sw-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #b5bac1; transition: transform .15s, background .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch .sw-input:checked ~ .sw-track { background: var(--accent); }
.switch .sw-input:checked ~ .sw-thumb { transform: translateX(18px); background: #fff; }
.switch .sw-input:focus-visible ~ .sw-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Panels list */
.plist { display: flex; flex-direction: column; gap: 10px; }
.pitem { display: flex; align-items: center; gap: 12px; background: var(--bg-3); border-radius: 8px; padding: 12px 14px; }
.pitem .grow { flex: 1; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--bg-4); color: var(--text-dim); }
.badge.on { background: rgba(35,165,90,.15); color: #3bd67e; }
.badge.warn { background: rgba(240,178,50,.18); color: #f0b232; font-weight: 700; }
.tag { font-size: 11px; color: var(--text-dim); }

/* Editor */
.editor-mask { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: grid; place-items: stretch; }
.editor { background: var(--bg); margin: 24px auto; max-width: 1180px; width: calc(100% - 48px); border-radius: 12px; overflow: hidden; display: grid; grid-template-rows: auto 1fr auto; max-height: calc(100vh - 48px); }
.editor header, .editor footer { padding: 14px 20px; background: var(--bg-2); display: flex; align-items: center; gap: 12px; }
.editor header .spacer, .editor footer .spacer { flex: 1; }
.editor .body { display: grid; grid-template-columns: 1fr 420px; overflow: hidden; }
.editor .body.single { display: block; overflow-y: auto; }
.editor .form { overflow-y: auto; padding: 20px; }
.editor .preview-pane { overflow-y: auto; padding: 20px; background: var(--bg-3); border-left: 1px solid var(--line); }

/* WYSIWYG surface */
.surface { padding: 20px; max-width: 1040px; margin: 0 auto; }
.mock-wrap { background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin: 8px 0 20px; }
.editable { display: block; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; cursor: text; min-height: 1.2em; }
.editable:hover { background: rgba(255,255,255,.05); box-shadow: inset 0 0 0 1px var(--line); }
.editable .ph { color: var(--text-dim); font-style: italic; }
.editable input, .editable textarea { width: 100%; background: var(--bg); border: 1px solid var(--accent); border-radius: 4px; padding: 6px 8px; font: inherit; line-height: 1.5; }
.editable textarea { min-height: 96px; }
.editable.e-desc textarea, .editable.dc-text textarea { min-height: 130px; }
.editable.tiny { font-size: 12px; }
.editable.e-title { font-weight: 700; font-size: 16px; }
.editable.e-desc { font-size: 14px; }
.editable.dc-text { font-size: 15px; margin-bottom: 8px; }
.editable img { max-height: 20px; }
.sub-link { margin: 2px 0 6px; }

.editable-wrap { position: relative; }
.editable-wrap > .editable { padding-right: 30px; }
.emoji-insert-btn { position: absolute; top: 2px; right: 2px; background: var(--bg-4); border: 1px solid var(--line); border-radius: 6px; padding: 2px 5px; font-size: 14px; line-height: 1; opacity: .55; }
.emoji-insert-btn:hover { opacity: 1; background: var(--bg-4); }

.add-chip { background: transparent; border: 1px dashed var(--line); color: var(--text-dim); font-size: 13px; padding: 6px 10px; margin: 6px 6px 0 0; border-radius: 6px; }
.add-chip:hover { border-color: var(--accent); color: var(--text); background: transparent; }
.x-btn { background: transparent; color: var(--text-dim); padding: 2px 6px; font-size: 12px; flex-shrink: 0; }
.x-btn:hover { background: var(--red); color: #fff; }

.dc-embed.dc-embed-edit { max-width: 100%; width: 100%; }
.color-control { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.color-control .tag { text-transform: none; letter-spacing: 0; }
.color-control .colorbar { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; background: transparent; flex-shrink: 0; }
.color-control .colorbar::-webkit-color-swatch-wrapper { padding: 2px; }
.color-control .colorbar::-webkit-color-swatch { border: none; border-radius: 4px; }
.color-control .color-hex { width: 90px; font-family: monospace; text-transform: uppercase; padding: 6px 8px; }
.color-control button { padding: 6px 10px; }

.swatch-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
input[type=range] { accent-color: var(--accent); }
.embed-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; }
.embed-side { min-width: 0; max-width: 170px; }
@media (max-width: 620px) { .embed-grid { grid-template-columns: 1fr; } }
.editable-block { display: flex; align-items: flex-start; gap: 8px; background: rgba(255,255,255,.03); border-radius: 6px; padding: 6px; margin: 6px 0; }
.editable-block .editable { flex: 1; }
.icon-slot { width: 34px; height: 34px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); display: grid; place-items: center; font-size: 15px; flex-shrink: 0; overflow: hidden; padding: 0; }
.icon-slot.mini { width: 22px; height: 22px; font-size: 11px; }
.icon-slot img { width: 100%; height: 100%; object-fit: cover; }
.e-fields-edit { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.e-field-edit { display: flex; gap: 8px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.e-field-edit .drag { cursor: grab; color: var(--text-dim); user-select: none; }
.e-field-edit .ff { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.e-field-edit .fn { font-weight: 700; }
.e-image-edit, .e-thumb-edit { flex-direction: column; align-items: stretch; }
.e-image-edit .e-image { max-width: 100%; border-radius: 4px; }
.e-thumb-edit .e-thumb { width: 90px; height: 90px; object-fit: cover; border-radius: 4px; }
.img-tools { display: flex; gap: 6px; align-items: center; width: 100%; flex-wrap: wrap; }
.ph.mini { font-size: 11px; }

/* Réactions & rôles card MEE6-style */
.rr-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-top: 16px; }
.rr-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.rr-head strong { flex: 1; font-size: 16px; }
.rr-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 8px; padding: 4px; margin-bottom: 14px; }
.rr-tabs button { flex: 1; background: transparent; color: var(--text-dim); border-radius: 6px; padding: 8px; }
.rr-tabs button.active { background: var(--bg-4); color: #fff; }
.rr-toggle { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); font-weight: 400; }
.rr-rows { display: flex; flex-direction: column; gap: 10px; }
.rr-row { background: var(--bg-3); border-radius: 8px; padding: 10px 12px; }
.rr-main { display: flex; align-items: center; gap: 10px; }
.emoji-btn { width: 40px; height: 40px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); display: grid; place-items: center; font-size: 20px; flex-shrink: 0; padding: 0; }
.emoji-btn:hover { border-color: var(--accent); background: var(--bg); }
.emoji-btn img { width: 24px; height: 24px; }
.rr-label { width: 140px; flex-shrink: 0; padding: 7px 9px; background: var(--bg); }
.rr-roles { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 160px; }
.rr-roles .pill { background: var(--bg-4); border-radius: 20px; padding: 3px 6px 3px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.rr-roles .pill .x { background: transparent; padding: 0 3px; font-size: 11px; color: var(--text-dim); }
.rr-roles .pill .x:hover { color: var(--red); background: transparent; }
.rr-addsel { width: auto; min-width: 120px; padding: 5px 8px; font-size: 13px; background: var(--bg); }
.rr-row .trash { background: transparent; color: var(--text-dim); padding: 4px 8px; }
.rr-row .trash:hover { background: var(--red); color: #fff; }
.rr-extras { display: flex; gap: 8px; margin-top: 8px; padding-left: 50px; }
.rr-extras .rr-style { width: auto; }
.rr-extras .rr-desc { flex: 1; }
.rr-warn { color: #f0b232; font-size: 12px; margin-top: 6px; padding-left: 50px; }
.rr-add { width: 100%; margin-top: 12px; background: var(--bg-3); color: var(--text); border: 1px dashed var(--line); }
.rr-add:hover { border-color: var(--accent); background: var(--bg-3); }
.rr-radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); }
.rr-radio input { width: auto; margin-top: 3px; }

.e-legend { margin: 8px 0; padding: 8px 10px; background: rgba(255,255,255,.03); border-left: 2px solid var(--line); border-radius: 4px; }
.e-legend .legend-tag { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; font-style: italic; }
.e-legend .legend-line { font-size: 14px; padding: 1px 0; }
.e-legend .legend-line img { vertical-align: middle; }

@media (max-width: 640px) {
  .rr-main { flex-wrap: wrap; }
  .rr-label { width: 100%; }
}

.sub-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 10px; }
.list-row { display: flex; gap: 8px; align-items: flex-start; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-top: 8px; }
.list-row .drag { cursor: grab; color: var(--text-dim); padding-top: 8px; user-select: none; }
.list-row .fields { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.list-row .fields .row { gap: 6px; }
.inline-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); text-transform: none; letter-spacing: 0; margin: 0; cursor: pointer; }
.inline-check input:not(.sw-input) { width: auto; }

.seg { display: flex; gap: 6px; }
.seg button { flex: 1; background: var(--bg-3); color: var(--text-dim); }
.seg button.active { background: var(--accent); color: #fff; }

.emoji-field { display: flex; gap: 6px; align-items: center; }
.emoji-field input { flex: 1; }
.emoji-field .emoji-preview { width: 34px; height: 34px; flex-shrink: 0; display: grid; place-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; font-size: 18px; }
.emoji-field .emoji-preview img { width: 22px; height: 22px; }
.emoji-field button { flex-shrink: 0; white-space: nowrap; }

.emoji-popover {
  position: fixed; z-index: 200; width: 320px; max-height: 380px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.emoji-popover > input { flex-shrink: 0; }
.emoji-grid { overflow-y: auto; flex: 1; }
.emoji-grid-label { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim); font-weight: 700; margin: 8px 2px 4px; }
.emoji-grid-items { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-grid-items img, .emoji-grid-items .uni { width: 100%; aspect-ratio: 1; border-radius: 5px; cursor: pointer; display: grid; place-items: center; font-size: 18px; object-fit: contain; padding: 3px; }
.emoji-grid-items img:hover, .emoji-grid-items .uni:hover { background: var(--bg-4); }
.emoji-pop-foot { display: flex; justify-content: space-between; flex-shrink: 0; border-top: 1px solid var(--line); padding-top: 6px; }

/* Discord-like preview */
.dc-msg { display: flex; gap: 14px; }
.dc-msg .pfp { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.dc-msg .content { min-width: 0; flex: 1; }
.dc-author { font-weight: 600; color: #f2f3f5; }
.dc-author span { font-size: 11px; background: var(--accent); padding: 1px 5px; border-radius: 4px; margin-left: 6px; vertical-align: middle; }
.dc-text { margin: 2px 0 8px; white-space: pre-wrap; word-wrap: break-word; }
.dc-embed { border-left: 4px solid var(--accent); background: var(--bg-2); border-radius: 4px; padding: 12px 16px 16px; max-width: 432px; }
.dc-embed .e-author { font-size: 13px; font-weight: 600; display:flex; align-items:center; gap:6px; margin-bottom: 6px; }
.dc-embed .e-title { font-weight: 700; margin-bottom: 6px; }
.dc-embed .e-desc { font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.dc-embed .e-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.dc-embed .e-field { font-size: 13px; grid-column: span 3; }
.dc-embed .e-field.inline { grid-column: span 1; }
.dc-embed .e-field .fn { font-weight: 700; }
.dc-embed img.e-image { margin-top: 12px; border-radius: 4px; max-width: 100%; }
.dc-embed img.e-thumb { float: right; width: 60px; height: 60px; border-radius: 4px; margin-left: 10px; object-fit: cover; }
.dc-embed .e-footer { font-size: 12px; color: var(--text-dim); margin-top: 10px; }
.role-chip { background: rgba(88,101,242,.3); color: #c9cdfb; border-radius: 4px; padding: 0 3px; }

.dc-components { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; max-width: 432px; }
.dc-btn { background: var(--bg-4); border-radius: 4px; padding: 8px 14px; font-size: 14px; font-weight: 500; }
.dc-select { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 9px 12px; width: 100%; color: var(--text-dim); max-width: 432px; }
.dc-reactions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.dc-reaction { background: var(--bg-4); border-radius: 8px; padding: 3px 8px; font-size: 14px; display: flex; align-items: center; gap: 5px; }
.dc-reaction img { width: 16px; height: 16px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bg-4); border: 1px solid var(--line); padding: 12px 20px; border-radius: 8px; z-index: 100; }
.toast.err { border-color: var(--red); }

.spinner { border: 3px solid var(--bg-4); border-top-color: var(--accent); border-radius: 50%; width: 28px; height: 28px; animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .dash { grid-template-columns: 1fr; }
  .editor .body { grid-template-columns: 1fr; }
  .editor .preview-pane { border-left: none; border-top: 1px solid var(--line); }
}
