:root {
  --bg: #0d0e10;
  --panel: #15171a;
  --panel-2: #1b1e22;
  --line: #262a30;
  --line-2: #323740;
  --text: #e9e7e2;
  --muted: #8d929a;
  --faint: #5d626a;
  --accent: #e8a447;
  --accent-ink: #1a1306;
  --danger: #d9614c;
  --ok: #6fbf73;
  --r-common: #9aa0a6;
  --r-uncommon: #5fb86a;
  --r-rare: #4f9be0;
  --r-epic: #a97de0;
  --r-legendary: #e5b93f;
  --radius: 10px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* Marque */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 500; letter-spacing: 0.14em; font-size: 13px; }
.brand b { font-weight: 800; color: var(--accent); }
.brand-mark { width: 18px; height: 18px; border: 2px solid var(--accent); border-radius: 4px; transform: rotate(45deg) scale(.8); }
.brand-lg { font-size: 20px; justify-content: center; }

/* Boutons et champs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; font-weight: 550; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s; }
.btn:hover { background: #22262b; border-color: #3b414b; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #f0b25c; border-color: #f0b25c; }
.btn-danger { background: transparent; border-color: #5a2c24; color: #f08d7a; }
.btn-danger:hover { background: #2a1714; border-color: #7a3a2f; }
.btn-ghost { background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-discord { background: #5865f2; border-color: #5865f2; color: #fff; height: 44px; padding: 0 20px; font-size: 15px; }
.btn-discord:hover { background: #4752c4; border-color: #4752c4; }
.btn-discord svg { width: 20px; height: 20px; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.input { height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg); outline: none; min-width: 0; }
.input:focus { border-color: var(--accent); }
.select { padding-right: 28px; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 500px at 50% -10%, #1c1a16 0%, transparent 60%), var(--bg); }
.login-card { width: min(420px, 100%); text-align: center; padding: 40px 32px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.login-text { color: var(--muted); margin: 18px 0 28px; }
.login-error { color: var(--danger); margin: 16px 0 0; }

/* Mise en page */
.app { display: grid; grid-template-columns: 250px 1fr; grid-template-rows: 56px 1fr; height: 100%; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 20px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.live { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.live.is-off .live-dot { background: var(--faint); }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); object-fit: cover; }

.sidebar { border-right: 1px solid var(--line); padding: 20px 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.side-title, .eyebrow, .d-section { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); }
.side-title { padding: 0 8px; }
.accounts { display: flex; flex-direction: column; gap: 2px; }
.acc { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid transparent; background: none; cursor: pointer; text-align: left; }
.acc:hover { background: var(--panel); }
.acc.is-active { background: var(--panel-2); border-color: var(--line-2); }
.acc.is-active .acc-name { color: var(--text); }
.acc-icon { width: 26px; height: 26px; flex: none; border-radius: 7px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line-2); font-size: 12px; font-weight: 700; color: var(--muted); }
.acc.is-active .acc-icon { border-color: var(--accent); color: var(--accent); }
.acc-name { flex: 1; color: #c9c7c2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.acc-count { color: var(--faint); font-size: 12px; }
.acc-sep { height: 1px; background: var(--line); margin: 6px 8px; }

.main { overflow-y: auto; padding: 28px 32px 60px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; align-items: center; gap: 12px; }
.head-tools { display: flex; gap: 6px; margin-top: 6px; }
.tabs { display: flex; padding: 3px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line); }
.tab { height: 30px; padding: 0 14px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; font-weight: 550; }
.tab.is-active { background: var(--panel-2); color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 22px 0; }
.stat { padding: 14px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; gap: 10px; }
.search { flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 18px; }
.chip { height: 28px; padding: 0 11px; border-radius: 99px; border: 1px solid var(--line-2); background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; }
.chip:hover { color: var(--text); }
.chip.is-active { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 600; }
.chip span { opacity: .6; margin-left: 4px; }

/* Tableau du stock */
.stock { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.group-head { display: flex; justify-content: space-between; padding: 10px 16px; background: #121417; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.thumb { --rc: var(--line-2); width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 8px; overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #23262b, #121417 75%); border: 1px solid var(--line-2); box-shadow: inset 0 -2px 0 var(--rc); }
.thumb img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.thumb-letter { color: var(--faint); font-weight: 700; }
.thumb-sm { width: 32px; height: 32px; border-radius: 7px; }
.thumb-lg { width: 72px; height: 72px; border-radius: 12px; }
.thumb-lg img { padding: 6px; }
.item-text { display: flex; flex-direction: column; min-width: 0; }
.item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-head { justify-content: flex-start; }
.drawer-title { flex: 1; min-width: 0; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) 110px 120px 92px; align-items: center; gap: 12px; padding: 0 16px; height: 58px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--panel-2); }
.item-name { display: flex; align-items: center; gap: 12px; min-width: 0; font-weight: 550; }
.item-sub { color: var(--faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-qty { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; font-size: 15px; }
.item-actions { display: flex; justify-content: flex-end; gap: 4px; }
.step { width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line-2); background: transparent; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; }
.step:hover { color: var(--text); background: var(--panel); }
.dot { width: 8px; height: 8px; border-radius: 2px; flex: none; background: var(--faint); transform: rotate(45deg); }
.r-common { --rc: var(--r-common); } .r-uncommon { --rc: var(--r-uncommon); } .r-rare { --rc: var(--r-rare); }
.r-epic { --rc: var(--r-epic); } .r-legendary { --rc: var(--r-legendary); }
.dot[class*="r-"] { background: var(--rc); }
.rarity { font-size: 12px; color: var(--rc, var(--faint)); }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 6px; }

/* Historique */
.log { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.log-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 12px; align-items: center; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.log-row:last-child { border-bottom: 0; }
.log-time { color: var(--faint); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.log-what { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-what em { color: var(--faint); font-style: normal; }
.delta { font-weight: 650; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--ok); } .delta.down { color: var(--danger); }
.log-compact .log-row { grid-template-columns: 1fr auto; padding: 9px 12px; }
.log-compact .log-time { grid-column: 1 / -1; margin-bottom: -6px; }

/* Fiche objet */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); background: var(--panel); border-left: 1px solid var(--line); z-index: 21;
  display: flex; flex-direction: column; animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 22px 22px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 20px; margin: 4px 0; }
.drawer-body { padding: 18px 22px 30px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.drawer-body > * { flex-shrink: 0; }
.d-total { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--line); }
.d-total span { color: var(--muted); }
.d-total strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.d-section { margin-top: 10px; }
.d-accounts { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.d-acc { display: flex; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.d-acc:last-child { border-bottom: 0; }
.d-acc.is-zero { color: var(--faint); }
.d-form { display: flex; flex-direction: column; gap: 8px; }
.d-row { display: flex; gap: 8px; align-items: center; }
.d-row > * { flex: 1; }
.d-row .arrow { flex: none; color: var(--faint); }

/* Fenêtres */
.dialog { padding: 0; border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel); color: var(--text); width: min(420px, calc(100% - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog-wide { width: min(640px, calc(100% - 32px)); }
.dialog-inner { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.chips-sm { margin: 0; }
.results { height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.result { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; text-align: left; }
.result:hover { background: var(--panel); }
.result.is-picked { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.result-name { flex: 1; font-weight: 550; }
.result-meta { color: var(--faint); font-size: 12px; }
.add-footer { display: grid; grid-template-columns: 1fr 160px 90px auto; gap: 8px; align-items: center; }
.picked { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picked.is-empty { color: var(--faint); font-weight: 400; }

/* Notifications */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { padding: 10px 16px; border-radius: 9px; background: #23272c; border: 1px solid var(--line-2); box-shadow: 0 8px 24px rgba(0, 0, 0, .35); animation: pop .16s ease-out; }
.toast.is-error { border-color: #6b3328; color: #f2a090; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Mobile */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; overflow-x: auto; padding: 10px 12px; }
  .side-title, .acc-sep { display: none; }
  .accounts { flex-direction: row; }
  .acc { width: auto; white-space: nowrap; }
  .acc-count { display: none; }
  .sidebar .btn-block { width: auto; }
  .main { padding: 20px 16px 60px; }
  .live, #user-name { display: none; }
  .item { grid-template-columns: minmax(0, 1fr) 70px 70px; }
  .item .rarity { display: none; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .stat-value { font-size: 18px; }
  .add-footer { grid-template-columns: 1fr 1fr; }
  .picked { grid-column: 1 / -1; }
  .log-row { grid-template-columns: 1fr auto; }
  .log-time { grid-column: 1 / -1; margin-bottom: -6px; }
}
