:root {
  color-scheme: dark;
  --bg: #0f0e15;
  --sidebar: #13121b;
  --surface-1: #1b1925;
  --surface-2: #232031;
  --surface-3: #2c2840;
  --border: #2e2a40;
  --grid: #2a2738;
  --text-primary: #f2f0f7;
  --text-secondary: #b9b4c9;
  --text-muted: #857f99;
  --brand: #9146ff;
  --brand-soft: rgba(145, 70, 255, .14);
  --series-1: #9146ff;
  --good: #3ba55d;
  --good-soft: rgba(59, 165, 93, .15);
  --warning: #e0a800;
  --warning-soft: rgba(224, 168, 0, .15);
  --danger: #ed4245;
  --danger-soft: rgba(237, 66, 69, .15);
  --info: #5865f2;
  --info-soft: rgba(88, 101, 242, .15);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: #b794ff; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
::selection { background: var(--brand); color: #fff; }

/* ── Démarrage / connexion ─────────────────────────────── */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(145, 70, 255, .25), transparent 70%), var(--bg);
}
.login-card {
  width: min(420px, 100%); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 20px; padding: 36px 32px; text-align: center; box-shadow: var(--shadow);
}
.login-card .logo { width: 76px; height: 76px; border-radius: 22px; margin: 0 auto 18px; background: var(--brand); display: grid; place-items: center; font-size: 36px; }
.login-card .logo img { width: 100%; height: 100%; border-radius: 22px; object-fit: cover; }
.login-card h1 { margin: 0 0 6px; font-size: 24px; font-weight: 800; }
.login-card p { margin: 0 0 26px; color: var(--text-secondary); }
.btn-discord {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 13px 18px; border-radius: 12px; border: 0; background: #5865f2; color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
  transition: transform .15s, background .15s;
}
.btn-discord:hover { background: #4752c4; text-decoration: none; transform: translateY(-1px); }
.login-error { margin-top: 18px; padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: #ff9c9e; font-size: 13px; }
.login-foot { margin-top: 22px; font-size: 12px; color: var(--text-muted); }

/* ── Structure ─────────────────────────────────────────── */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--sidebar); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 10px; }
.brand img, .brand .ph { width: 40px; height: 40px; border-radius: 12px; background: var(--brand); object-fit: cover; }
.brand b { display: block; font-size: 15px; }
.brand span { font-size: 12px; color: var(--text-muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); padding: 12px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px;
  color: var(--text-secondary); font-weight: 500; transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-1); color: var(--text-primary); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: #fff; }
.nav a.active .ico { filter: none; }
.nav .ico { width: 20px; text-align: center; font-size: 16px; }
.nav .count { margin-left: auto; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: var(--surface-1); }
.sidebar-foot img { width: 34px; height: 34px; border-radius: 50%; }
.sidebar-foot div { min-width: 0; flex: 1; }
.sidebar-foot b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot a { font-size: 12px; color: var(--text-muted); }

.main { min-width: 0; padding: 28px 32px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--text-secondary); }
.menu-toggle { display: none; }

/* ── Cartes, grilles ───────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.card-head .sub { font-size: 12px; color: var(--text-muted); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: 12px; }
.empty { padding: 28px 10px; text-align: center; color: var(--text-muted); }

/* Tuiles de stats */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.tile .label { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 7px; }
.tile .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
.tile .hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.tile.hero { grid-column: span 2; background: linear-gradient(135deg, rgba(145, 70, 255, .22), rgba(145, 70, 255, .04)), var(--surface-1); }
.tile.hero .value { font-size: 52px; font-weight: 700; line-height: 1.1; }

/* Filtres (une rangée au-dessus du contenu) */
.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 13px; border-radius: 7px; cursor: pointer; color: var(--text-secondary); font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--surface-3); color: var(--text-primary); }
.seg button:hover:not(.on) { color: var(--text-primary); }

/* Boutons, champs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .12s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #7f35ec; }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: #ff9c9e; }
.btn.danger:hover { background: rgba(237, 66, 69, .25); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text-primary); }
.btn.sm { padding: 5px 10px; font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.field small { color: var(--text-muted); font-size: 12px; }
input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 96px; }
input[type=color] { width: 44px; height: 38px; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* Interrupteur */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border-radius: 99px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--brand-soft); }
.toggle-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--grid); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .txt { flex: 1; min-width: 0; }
.toggle-row .txt b { display: block; font-weight: 600; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-3); color: var(--text-secondary); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: #7fdc9b; }
.badge.warning { background: var(--warning-soft); color: #f3cd5b; }
.badge.danger { background: var(--danger-soft); color: #ff9c9e; }
.badge.info { background: var(--info-soft); color: #a9b1ff; }
.badge.brand { background: var(--brand-soft); color: #c7a6ff; }

/* Tableaux */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; transition: background .1s; }
tbody tr.click:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.user { display: flex; align-items: center; gap: 9px; min-width: 0; }
.user img, .user .av { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-3); flex: none; object-fit: cover; }
.user b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user small { display: block; color: var(--text-muted); font-size: 11px; }

.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* Listes */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.list-item:last-child { border-bottom: 0; }
.rank { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); font-weight: 700; font-size: 12px; flex: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--text-muted); }
.dot.good { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* Graphiques */
.chart { position: relative; width: 100%; height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); opacity: .1; }
.chart .bar { fill: var(--series-1); transition: opacity .1s; }
.chart .bar.dim { opacity: .55; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; }
.chart .marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .end-label { fill: var(--text-primary); font-size: 12px; font-weight: 600; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface-3); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 11px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; z-index: 5; transform: translate(-50%, calc(-100% - 12px));
}
.tooltip b { display: block; font-size: 15px; font-weight: 700; color: var(--text-primary); }
.tooltip .key { display: inline-block; width: 12px; height: 2px; background: var(--series-1); vertical-align: middle; margin-right: 6px; }
.tooltip span { color: var(--text-secondary); }
.chart-table { margin-top: 10px; max-height: 220px; overflow-y: auto; }
.link-btn { background: none; border: 0; padding: 0; color: var(--text-muted); font-size: 12px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--text-primary); }
.refetch { opacity: .55; transition: opacity .15s; }

/* Fenêtres */
.modal-back { position: fixed; inset: 0; background: rgba(6, 5, 10, .7); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade .15s; }
.modal { width: min(680px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); animation: pop .18s; }
.modal.wide { width: min(1000px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface-1); z-index: 1; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); }
.transcript-frame { width: 100%; height: 70vh; border: 0; border-radius: 12px; background: #313338; }
.answer { padding: 12px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; }
.answer b { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.answer p { margin: 0; white-space: pre-wrap; word-wrap: break-word; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* Aperçu d'embed Discord */
.embed-preview { background: #313338; border-radius: 12px; padding: 14px; }
.embed-preview .em { border-left: 4px solid var(--brand); background: #2b2d31; border-radius: 4px; padding: 10px 14px; }
.embed-preview .em b { display: block; margin-bottom: 4px; }
.embed-preview .em p { margin: 0; white-space: pre-wrap; color: #dbdee1; word-wrap: break-word; }
.embed-preview .em img { max-width: 100%; border-radius: 4px; margin-top: 10px; }

/* Logs du bot */
.logs { background: #0a0910; border: 1px solid var(--border); border-radius: 12px; padding: 14px; font: 12px/1.6 ui-monospace, "Cascadia Code", Consolas, monospace; max-height: 520px; overflow: auto; white-space: pre-wrap; word-break: break-word; color: #c9c4d8; }
.logs .lv-ERROR { color: #ff8a8c; }
.logs .lv-WARNING { color: #f3cd5b; }

/* Notifications */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--surface-3); border: 1px solid var(--border); border-left: 4px solid var(--good); border-radius: 10px; padding: 11px 15px; box-shadow: var(--shadow); max-width: 360px; animation: pop .2s; }
.toast.error { border-left-color: var(--danger); }

/* ── Configuration ─────────────────────────────────────── */
.cfg-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; align-items: start; }
.cfg-nav { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 2px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; }
.cfg-nav button { text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 9px; cursor: pointer; color: var(--text-secondary); font-weight: 500; }
.cfg-nav button:hover { background: var(--surface-2); color: var(--text-primary); }
.cfg-nav button.active { background: var(--brand-soft); color: #fff; font-weight: 600; }
.cfg-mobile { display: none; margin-bottom: 14px; }
.cfg-group { margin: 22px 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); padding-bottom: 6px; border-bottom: 1px solid var(--grid); }
.cfg-group:first-of-type { margin-top: 6px; }
.cfg-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-grid .toggle-row.full { grid-column: 1 / -1; }
.info-line { padding: 10px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; }
.chip-picker { display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--surface-3); font-size: 13px; font-weight: 500; }
.chip button { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; width: 20px; height: 20px; border-radius: 50%; line-height: 1; }
.chip button:hover { background: var(--danger-soft); color: #ff9c9e; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .main { padding: 18px 16px 40px; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .cfg-layout { grid-template-columns: 1fr; }
  .cfg-nav { display: none; }
  .cfg-mobile { display: block; }
  .tile.hero { grid-column: 1 / -1; }
  .tile.hero .value { font-size: 44px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
