:root {
  --bg: #0f1016;
  --bg2: #161722;
  --card: #1c1d2b;
  --card2: #232436;
  --border: #2d2f45;
  --text: #e8e8f2;
  --muted: #9a9cb8;
  --accent: #8b5cf6;
  --accent2: #a78bfa;
  --accent-soft: rgba(139, 92, 246, .15);
  --ok: #22c55e;
  --err: #ef4444;
  --warn: #f59e0b;
  --info: #3b82f6;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f5fb; --bg2: #ffffff; --card: #ffffff; --card2: #f3f2fa; --border: #e3e1f0;
    --text: #1d1b2e; --muted: #6b6889; --accent-soft: rgba(139, 92, 246, .1); --shadow: 0 8px 24px rgba(40, 20, 90, .08);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f5f5fb; --bg2: #ffffff; --card: #ffffff; --card2: #f3f2fa; --border: #e3e1f0;
  --text: #1d1b2e; --muted: #6b6889; --accent-soft: rgba(139, 92, 246, .1); --shadow: 0 8px 24px rgba(40, 20, 90, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent2); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; font-size: 20px; color: var(--muted); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(139, 92, 246, .25), transparent), radial-gradient(800px 500px at 110% 110%, rgba(59, 130, 246, .18), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 520px; background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 32px; box-shadow: var(--shadow); }
.auth-card .logo { font-size: 46px; }
.auth-card h1 { margin: 8px 0 4px; font-size: 26px; }
.auth-card p.lead { color: var(--muted); margin: 0 0 24px; }
.steps { margin: 0 0 18px; padding-left: 20px; color: var(--muted); font-size: 14px; }
.steps li { margin-bottom: 6px; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg2); border-right: 1px solid var(--border); padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand .sock { font-size: 30px; }
.brand b { font-size: 20px; display: block; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; }
.guild-select { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; }
.guild-select img, .guild-select .gi { width: 34px; height: 34px; border-radius: 10px; flex: none; background: var(--accent-soft); display: grid; place-items: center; font-weight: 700; }
.guild-select select { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; font-weight: 600; cursor: pointer; }
.guild-select select option { background: var(--card); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav .navsec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 12px 10px 4px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
nav a:hover { background: var(--card); }
nav a.active { background: var(--accent-soft); color: var(--accent2); }
nav a .ico { width: 22px; text-align: center; }
nav a .dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
nav a .dot.on { background: var(--ok); }
.sidebar .bottom { margin-top: auto; display: flex; gap: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--bg2); position: sticky; top: 0; z-index: 5; }
.topbar .menu-btn { display: none; }
.topbar h2 { margin: 0; font-size: 18px; flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ready::before { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.pill.error::before { background: var(--err); }
.pill.starting::before { background: var(--warn); }
.content { padding: 28px; max-width: 1180px; width: 100%; }
.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0 0 4px; font-size: 26px; display: flex; align-items: center; gap: 10px; }
.page-head p { margin: 0; color: var(--muted); }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; }
.card h3 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card > .desc { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat .k { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat .s { color: var(--muted); font-size: 12px; }

/* ---------- Forms ---------- */
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label { font-weight: 600; font-size: 14px; }
.field .help { color: var(--muted); font-size: 12.5px; }
.field .vars { display: flex; flex-wrap: wrap; gap: 4px; }
.field .vars code { cursor: pointer; }
input[type=text], input[type=number], input[type=password], input[type=url], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=color] { width: 54px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); cursor: pointer; }
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input[type=text] { max-width: 140px; }
code { background: var(--card2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }

.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle .sw { width: 44px; height: 24px; border-radius: 999px; background: var(--border); position: relative; transition: background .2s; flex: none; }
.toggle .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + .sw { background: var(--accent); }
.toggle input:checked + .sw::after { transform: translateX(20px); }
.toggle .tl { font-weight: 600; font-size: 14px; }
.toggle .th { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; min-height: 44px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--card2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 13px; }
.chip .rc { width: 10px; height: 10px; border-radius: 50%; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 2px; }
.chip button:hover { color: var(--err); }
.chips select, .chips input { flex: 1; min-width: 140px; border: 0; background: transparent; padding: 4px; box-shadow: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); background: var(--card2); padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text); white-space: nowrap; transition: transform .05s, background .15s, border-color .15s; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #7c4ff0; }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Listes éditables */
.list-item { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; background: var(--card2); }
.list-item > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; font-weight: 600; }
.list-item > summary::-webkit-details-marker { display: none; }
.list-item > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.list-item[open] > summary::before { transform: rotate(90deg); }
.list-item > .body { padding: 4px 14px 16px; border-top: 1px solid var(--border); }
.list-item .list-item { background: var(--card); }
.list-item .body > .fields { margin-top: 12px; }
.sub-list { margin-top: 16px; }
.sub-list > .lbl { font-weight: 600; font-size: 14px; margin-bottom: 8px; }

/* Barre d'enregistrement */
.savebar { position: sticky; bottom: 16px; z-index: 6; display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-top: 8px; background: var(--card); border: 1px solid var(--accent); border-radius: 14px; box-shadow: var(--shadow); animation: up .2s ease; }
.savebar span { flex: 1; font-weight: 600; }
.savebar[hidden] { display: none; }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }

/* Onglets */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--accent2); border-bottom-color: var(--accent); }

/* Tableaux */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
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: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; background: var(--card2); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--card2); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--card2); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: rgba(34, 197, 94, .4); background: rgba(34, 197, 94, .1); }
.badge.err { color: var(--err); border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .1); }
.badge.warn { color: var(--warn); border-color: rgba(245, 158, 11, .4); background: rgba(245, 158, 11, .1); }
.badge.info { color: var(--info); border-color: rgba(59, 130, 246, .4); background: rgba(59, 130, 246, .1); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Alertes */
.alert { display: flex; gap: 12px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--card2); margin-bottom: 18px; }
.alert.warn { border-color: rgba(245, 158, 11, .5); background: rgba(245, 158, 11, .08); }
.alert.err { border-color: rgba(239, 68, 68, .5); background: rgba(239, 68, 68, .08); }
.alert.ok { border-color: rgba(34, 197, 94, .5); background: rgba(34, 197, 94, .08); }
.alert.info { border-color: rgba(139, 92, 246, .5); background: var(--accent-soft); }
.alert .ai { font-size: 20px; }
.alert p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

/* Aperçu façon Discord */
.preview { background: #313338; color: #dbdee1; border-radius: 10px; padding: 14px; font-size: 14px; }
.preview .emb { border-left: 4px solid var(--accent); background: #2b2d31; border-radius: 4px; padding: 10px 14px; margin-top: 6px; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.preview .emb b { color: #fff; display: block; margin-bottom: 4px; }
.preview .emb .ft { grid-column: 1 / -1; font-size: 12px; color: #949ba4; }
.preview .av { width: 56px; height: 56px; border-radius: 50%; background: #5865f2; display: grid; place-items: center; font-size: 26px; }
.preview .txt { white-space: pre-wrap; word-break: break-word; }

/* Graphiques */
.chart { width: 100%; height: 240px; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.hbar { display: grid; grid-template-columns: 140px 1fr 40px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 14px; }
.hbar .track { height: 10px; border-radius: 99px; background: var(--card2); overflow: hidden; }
.hbar .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Logs */
.log { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.log:last-child { border-bottom: 0; }
.log .lt { flex: none; width: 128px; }
.log .lc { white-space: pre-wrap; word-break: break-word; font-size: 13.5px; color: var(--muted); }
.log .lc b { color: var(--text); display: block; }
.log time { font-size: 12px; color: var(--muted); }

/* Fenêtres */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 5, 15, .6); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 18px; width: 100%; max-width: 760px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.sm { max-width: 460px; }
.modal header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 10px; }
.modal header h3 { margin: 0; flex: 1; font-size: 17px; }
.modal .mbody { padding: 20px; overflow-y: auto; }
.modal footer { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }
.tmsg { display: flex; gap: 10px; padding: 8px 0; }
.tmsg img { width: 36px; height: 36px; border-radius: 50%; flex: none; }
.tmsg .tc { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.tmsg .tq { border-left: 3px solid var(--accent); padding-left: 8px; color: var(--muted); font-size: 13px; margin-top: 4px; white-space: pre-wrap; }

/* Toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--ok); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); animation: up .2s ease; max-width: 420px; }
.toast.err { border-left-color: var(--err); }

/* Responsive */
@media (max-width: 1000px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar { padding: 12px 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 18px 16px; }
  .fields, .grid.c2 { grid-template-columns: 1fr; }
  .hbar { grid-template-columns: 90px 1fr 34px; }
  .log { flex-direction: column; gap: 4px; }
  .auth-card { padding: 24px 18px; }
}
@media (max-width: 520px) {
  .grid.c4, .grid.c3 { grid-template-columns: 1fr 1fr; }
  .stat .v { font-size: 22px; }
}

/* Annonces */
.ann-grid { align-items: start; }
.ann-side { position: sticky; top: 16px; }
.ann-head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.ann-head img, .ann-head .av { width: 40px; height: 40px; border-radius: 50%; font-size: 20px; }
.ann-head b { color: #fff; margin-right: 6px; }
.bot-tag { background: #5865f2; color: #fff; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; margin-right: 6px; }
.ann-mention span { background: rgba(88,101,242,.3); color: #c9cdfb; padding: 0 3px; border-radius: 3px; font-weight: 500; }
.ann-emb { max-width: 520px; }
.ann-title { color: #fff; font-weight: 700; font-size: 16px; margin-bottom: 6px; }
.ann-body { min-width: 0; }
.ann-img { max-width: 100%; border-radius: 6px; margin-top: 10px; display: block; }
.ann-thumb { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; }
.dmd-h1 { font-size: 20px; font-weight: 700; color: #fff; margin: 6px 0 2px; }
.dmd-h2 { font-size: 17px; font-weight: 700; color: #fff; margin: 6px 0 2px; }
.dmd-h3 { font-size: 15px; font-weight: 700; color: #fff; margin: 4px 0 2px; }
.dmd-li { padding-left: 8px; }
.dmd-q { border-left: 4px solid #4e5058; padding-left: 10px; }
.preview code { background: #1e1f22; padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.preview a { color: #00a8fc; }
.ann-preview .txt { white-space: normal; }
.preview .dmd-ch { background: rgba(88,101,242,.3); color: #c9cdfb; padding: 0 3px; border-radius: 3px; font-weight: 500; }
