:root {
  --bg: #1a1b1e;
  --surface: #232428;
  --surface-2: #2b2d31;
  --input: #1e1f22;
  --border: #3a3c42;
  --text: #dbdee1;
  --text-strong: #f2f3f5;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --success: #23a55a;
  --danger: #da373c;
  --warn: #f0b232;
  --discord-bg: #313338;
  --embed-bg: #2b2d31;
  --link: #00a8fc;
  --radius: 8px;
  --font: "gg sans", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --mono: "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--font);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 13px; }
.error { color: var(--danger); }

/* ---------- Boutons & champs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: #35373c; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger { color: #ff8a8d; }
.btn.danger:hover:not(:disabled) { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.dashed { width: 100%; background: transparent; border-style: dashed; color: var(--muted); }
.btn.dashed:hover:not(:disabled) { color: var(--text); border-color: var(--muted); background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.large { padding: 12px 22px; font-size: 15px; }

.icon-btn {
  width: 26px; height: 26px; display: inline-grid; place-items: center;
  border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: #3a3c42; color: var(--text-strong); }
.icon-btn:disabled { opacity: .3; cursor: default; }

input[type="text"], input[type="url"], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--input); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; field-sizing: content; min-height: 2.6em; max-height: 420px; }
input::placeholder, textarea::placeholder { color: #6d727a; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.label {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
}
.counter { font-weight: 500; text-transform: none; letter-spacing: 0; color: #6d727a; font-size: 11px; }
.counter.warn { color: var(--warn); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; user-select: none; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.tools { display: inline-flex; gap: 2px; margin-left: auto; align-items: center; }

/* ---------- Mise en page ---------- */

body.app { height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr); }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand > div { display: flex; flex-direction: column; line-height: 1.2; }
.brand .muted { font-size: 12px; }
.guild-icon, .avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.avatar { width: 28px; height: 28px; }
.user { margin-left: auto; }
.user { display: flex; align-items: center; gap: 8px; }

.edit-banner {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 16px; background: #3d3520; color: #f8dd96; border-bottom: 1px solid #5c4d20;
}
.edit-banner[hidden] { display: none; }
.edit-banner .btn { margin-left: auto; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.editor-col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.editor { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.preview-col { display: flex; flex-direction: column; min-height: 0; background: var(--discord-bg); }
.preview-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid #26282c;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
}
.preview-head .counter { font-size: 12px; }

.sendbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border);
}
.sendbar select { flex: 1; min-width: 180px; width: auto; }
.sendbar .check[hidden] { display: none; }
.sendbar #send { min-width: 130px; }

/* ---------- Cartes de l'éditeur ---------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.embed-card { padding: 0; }
.embed-card > summary {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  cursor: pointer; list-style: none; user-select: none;
}
.embed-card > summary::-webkit-details-marker { display: none; }
.chevron { color: var(--muted); transition: transform .15s; font-size: 12px; }
.embed-card[open] .chevron { transform: rotate(90deg); }
.card-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--c, #4e5058); flex: none; }
.card-body { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--border); }

.group { border: 0; border-top: 1px solid var(--border); margin: 0; padding: 12px 0 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.group > legend { padding: 0 8px 0 0; font-weight: 600; color: var(--text-strong); font-size: 13px; }

.color-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.color-row input[type="color"] { width: 38px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--input); cursor: pointer; }
.color-row .color-text { width: 96px; }
.preset { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--surface); outline: 1px solid var(--border); background: var(--c); cursor: pointer; padding: 0; }
.preset:hover { transform: scale(1.12); }

.field-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.field-item-head { display: flex; align-items: center; gap: 12px; font-size: 13px; }

/* ---------- Aperçu façon Discord ---------- */

.discord { flex: 1; overflow-y: auto; padding: 20px 16px 32px; color: #dbdee1; font-size: 16px; line-height: 1.375; }
.msg { display: flex; gap: 16px; }
.msg-avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; background: var(--accent); object-fit: cover; }
.msg-main { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: center; gap: 6px; }
.msg-author { font-weight: 500; color: var(--text-strong); }
.app-tag { background: var(--accent); color: #fff; font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 3px; }
.msg-time { color: var(--muted); font-size: 12px; margin-left: 2px; }
.msg-content { margin-top: 2px; }

.embed {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 16px;
  max-width: 520px; margin-top: 8px; padding: 8px 16px 16px 12px;
  background: var(--embed-bg); border-radius: 4px; border-left: 4px solid var(--c, #1e1f22);
}
.embed.empty { display: block; color: var(--muted); font-style: italic; font-size: 14px; padding: 12px 16px; border-left: 4px dashed #4e5058; }
.e-main { min-width: 0; }
.e-main > * { margin-top: 8px; }
.e-author { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--text-strong); }
.e-author img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.e-author a { color: inherit; }
.e-title { font-weight: 600; color: var(--text-strong); font-size: 16px; }
.e-title a { color: var(--link); }
.e-desc { font-size: 14px; }
.e-fields { display: flex; flex-direction: column; gap: 8px; }
.e-row { display: grid; gap: 8px; }
.e-row.cols-1 { grid-template-columns: 1fr; }
.e-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.e-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.e-fname { font-size: 14px; font-weight: 600; color: var(--text-strong); margin-bottom: 2px; }
.e-fvalue { font-size: 14px; }
.e-thumb { grid-column: 2; grid-row: 1; margin-top: 8px; max-width: 80px; max-height: 80px; border-radius: 4px; object-fit: contain; }
.e-image { grid-column: 1 / -1; margin-top: 16px; max-width: 100%; max-height: 300px; border-radius: 4px; object-fit: contain; justify-self: start; }
.e-footer { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--text); }
.e-footer img { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }
img.broken { display: none; }

.md { white-space: pre-wrap; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { margin: 8px 0 4px; color: var(--text-strong); line-height: 1.25; }
.md h1 { font-size: 24px; } .md h2 { font-size: 20px; } .md h3 { font-size: 16px; }
.md ul, .md ol { margin: 4px 0; padding-left: 24px; white-space: normal; }
.md blockquote { margin: 2px 0; padding: 0 0 0 12px; border-left: 4px solid #4e5058; }
.md code { background: #1e1f22; border-radius: 4px; padding: 0 .2em; font-family: var(--mono); font-size: .85em; }
.md pre { margin: 6px 0; }
.md pre code { display: block; padding: 8px; border: 1px solid #1a1b1e; white-space: pre-wrap; }
.md .subtext { display: block; font-size: 12px; color: var(--muted); }
.md a { text-decoration: none; }
.md a:hover { text-decoration: underline; }
.mention { --c: initial; } /* ne pas hériter de la couleur de l'embed */
.mention { background: color-mix(in srgb, var(--c, #5865f2) 30%, transparent); color: var(--c, #c9cdfb); border-radius: 3px; padding: 0 2px; font-weight: 500; }
.timestamp { background: rgba(255, 255, 255, .06); border-radius: 3px; padding: 0 2px; }
.spoiler { background: #1e1f22; color: transparent; border-radius: 3px; transition: color .1s; }
.spoiler:hover { color: inherit; background: rgba(255, 255, 255, .08); }
.emoji { width: 1.375em; height: 1.375em; vertical-align: bottom; object-fit: contain; }

/* ---------- Fenêtre modale & notifications ---------- */

dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
  padding: 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; color: var(--text-strong); }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-body p { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.json-area { min-height: 320px; field-sizing: fixed; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 6px; }
.list-main { display: flex; flex-direction: column; min-width: 0; }
.list-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; max-width: calc(100vw - 32px); }
.toast {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 8px;
  background: #111214; border-left: 4px solid var(--accent); box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  animation: toast-in .18s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast a { font-weight: 600; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Page de connexion ---------- */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%); padding: 36px 28px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.login-card h1 { margin: 10px 0 8px; font-size: 22px; color: var(--text-strong); }
.login-card p { margin: 0 0 22px; }
.login-logo { width: 56px; height: 56px; margin: 0 auto; display: grid; place-items: center; border-radius: 16px; background: var(--accent); color: #fff; font-size: 28px; }
.login-error { padding: 10px 12px; border-radius: 8px; background: rgba(218, 55, 60, .15); color: #ff9a9c; }

/* ---------- Mobile ---------- */

@media (max-width: 960px) {
  body.app { height: auto; display: block; }
  .topbar { flex-wrap: wrap; }
  .user { margin-left: auto; }
  .user #user-name { display: none; }
  .layout { display: flex; flex-direction: column; }
  .editor-col { border-right: 0; }
  .editor { overflow: visible; }
  .sendbar { position: sticky; bottom: 0; z-index: 5; }
  .preview-col { order: -1; max-height: 55vh; border-bottom: 1px solid var(--border); }
}


/* ---------- Menu à gauche et sections ---------- */

.menu-btn { display: none; font-size: 18px; }
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 0; }
.sidebar {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 10px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.nav-section {
  margin: 14px 8px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
}
.nav-section:first-child { margin-top: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-strong); }
.nav-item.active { background: rgba(88, 101, 242, .18); color: var(--text-strong); }
.nav-ico { width: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.nav-item.active .nav-ico { color: var(--accent); }
.nav-foot { margin-top: auto; padding: 12px 8px 4px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.nav-foot .warn-box { margin-bottom: 8px; }

.content { min-height: 0; min-width: 0; overflow: hidden; }
.view { display: none; height: 100%; min-height: 0; flex-direction: column; }
.view.active { display: flex; }
.view-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.view-toolbar h1 { margin: 0; font-size: 16px; color: var(--text-strong); }
.toolbar-actions { display: flex; gap: 4px; }
#view-editor .layout { flex: 1; min-height: 0; }

.page { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; max-width: 980px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.panel-head h2 { margin: 0; font-size: 15px; color: var(--text-strong); }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.setting-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 300px); align-items: center; gap: 14px; padding: 10px 0; border-top: 1px solid var(--border); }
.setting-row:first-of-type { border-top: 0; }
.setting-row strong { display: block; color: var(--text-strong); font-weight: 600; }
.setting-row small { color: var(--muted); font-size: 12.5px; }
.panel-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.panel-foot .muted { margin-right: auto; font-size: 12px; }
.warn-box { padding: 10px 12px; border-radius: 6px; background: rgba(240, 178, 50, .12); color: #f8d27a; font-size: 13px; line-height: 1.45; }
.info-box { padding: 10px 12px; border-radius: 6px; background: rgba(88, 101, 242, .12); color: #c3c8ff; font-size: 13px; line-height: 1.45; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 0 0 2px; font-size: 14px; }
.chip button:hover { color: #ff8a8d; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 22px; background: #4e5058; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }
.switch-row { display: flex; align-items: center; gap: 12px; }
.readonly-note { font-size: 12.5px; color: var(--muted); }
.words { font-family: var(--mono); font-size: 12px; color: var(--text); }

/* Journal */
.journal-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.journal-tools select { width: auto; min-width: 200px; }
.journal-tools input { flex: 1; min-width: 200px; }
.events { display: flex; flex-direction: column; gap: 6px; }
.event { display: grid; grid-template-columns: 4px minmax(0, 1fr); gap: 12px; padding: 10px 12px 10px 0; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.event-bar { border-radius: 0 3px 3px 0; }
.event-head { display: flex; justify-content: space-between; gap: 10px; }
.event-head strong { color: var(--text-strong); }
.event-head span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.event-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.event-body { margin-top: 4px; font-size: 13px; line-height: 1.5; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.event-body .mention { color: #c9cdfb; background: rgba(88, 101, 242, .25); padding: 0 2px; border-radius: 3px; }
.empty { padding: 30px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 8px; }

@media (max-width: 960px) {
  .menu-btn { display: inline-grid; }
  .shell { display: block; }
  .sidebar { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: 250px; transform: translateX(-100%); transition: transform .18s; box-shadow: 0 0 30px rgba(0,0,0,.5); }
  .sidebar.open { transform: none; }
  .content, .view { overflow: visible; height: auto; }
  .page { padding: 14px; }
  .setting-row { grid-template-columns: 1fr; }
}

/* un élément caché reste caché, même un bouton */
[hidden] { display: none !important; }
