:root {
  --bg: #0d0b1a;
  --bg-2: #141129;
  --card: #1a1636;
  --card-2: #221d45;
  --line: #2f2860;
  --text: #ece9ff;
  --muted: #9d97c7;
  --indigo: #5b5bd6;
  --violet: #9b6bff;
  --gold: #e8b84a;
  --gold-2: #ffd77a;
  --good: #4fd08a;
  --bad: #ff6b7a;
  --bonta: #5aa9ff;
  --brakmar: #ff5a5a;
  --neutre: #b9b4d6;
  --radius: 14px;
  --header-h: 0px;
  --font-title: 'Cinzel', Georgia, serif;
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(91, 91, 214, .22), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(155, 107, 255, .16), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
}
a { color: var(--gold-2); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(13, 11, 26, .86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1920px; margin: 0 auto; padding: 12px 20px;
  display: grid; grid-template-columns: auto 1fr; gap: 10px 24px; align-items: center;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 {
  margin: 0; font: 700 24px/1.1 var(--font-title); letter-spacing: .5px;
  background: linear-gradient(90deg, var(--gold-2), var(--gold) 50%, var(--violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.live-badge {
  font-size: 12px; font-weight: 700; color: #fff; background: #e91916;
  padding: 2px 8px; border-radius: 999px; letter-spacing: .5px;
}

.stats { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 14px; min-width: 150px; display: flex; flex-direction: column;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-sub { font-size: 12px; color: var(--muted); min-height: 16px; }
.stat.gold { border-color: rgba(232, 184, 74, .45); background: linear-gradient(180deg, rgba(232, 184, 74, .12), var(--card)); }
.stat.gold .stat-value { color: var(--gold-2); }
.stat .stat-value.over { color: var(--bad); }
.progress { display: inline-block; width: 100%; height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; vertical-align: middle; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--indigo), var(--violet)); transition: width .3s; }

.controls { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-end; }
.ctrl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ctrl input, .ctrl select {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 10px; font-size: 14px; color: var(--text); min-width: 90px;
}
.ctrl input#level { width: 90px; }
.count-ctrls { display: contents; }
.count-ctrls input { width: 90px; min-width: 0 !important; }
.day-label {
  display: inline-block; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--gold-2);
}
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 14px;
}
.seg button[aria-checked="true"][data-align="bonta"] { background: rgba(90, 169, 255, .2); color: var(--bonta); }
.seg button[aria-checked="true"][data-align="brakmar"] { background: rgba(255, 90, 90, .2); color: var(--brakmar); }
.seg button[aria-checked="true"][data-align="neutre"] { background: rgba(185, 180, 214, .2); color: var(--text); }
.right-ctrls { margin-left: auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.admin-ctrls { display: flex; gap: 8px; align-items: center; }
.btn.twitch {
  background: #9146ff; border-color: #9146ff; color: #fff; text-decoration: none; display: inline-flex; align-items: center;
  padding: 9px 16px; box-shadow: 0 4px 18px rgba(145, 70, 255, .35);
}
.btn.twitch:hover { background: #a970ff; border-color: #a970ff; }
.user-chip { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 4px; }
.user-chip img, .avatar-ph { width: 28px; height: 28px; border-radius: 50%; flex: none; background: var(--card-2); }
.user-name { display: flex; flex-direction: column; line-height: 1.15; font-size: 13px; font-weight: 600; }
.user-name small { font-size: 10px; font-weight: 600; color: var(--gold-2); text-transform: uppercase; letter-spacing: .5px; }
.user-chip .btn { text-decoration: none; border-radius: 999px; }
.twitch-link { color: #bf94ff; font-size: 13px; }
.editor-add { display: flex; gap: 8px; margin: 10px 0 14px; }
.editor-add input { flex: 1; max-width: 320px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.editors { list-style: none; margin: 0; padding: 0; }
.editors li { display: flex; justify-content: space-between; align-items: center; padding: 8px 2px; border-top: 1px solid var(--line); font-weight: 600; }
.save-state { font-size: 12px; color: var(--muted); min-width: 80px; }

.btn {
  border: 1px solid var(--line); background: var(--card-2); border-radius: 10px;
  padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.btn:hover { border-color: var(--violet); }
.btn.gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #241a00; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.active { border-color: var(--gold); color: var(--gold-2); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1920px; margin: 0 auto; padding: 20px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start;
}
:root { --stream-w: clamp(380px, 28vw, 520px); }
/* Colonne stream + chat fixée à droite : les listes occupent le reste à gauche */
.layout.has-stream { padding-right: calc(var(--stream-w) + 40px); }
.layout.has-stream ~ .suggest, .layout.has-stream ~ .footer { padding-right: calc(var(--stream-w) + 40px); }
.content { min-width: 0; display: flex; flex-direction: column; gap: 16px; }

.panel, .module {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.panel h2 { margin: 0; font: 600 17px var(--font-title); color: var(--gold-2); }
.muted { color: var(--muted); font-size: 13px; }

.edit-hint {
  font-size: 13px; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px;
}

/* ---------- Tables ressources ---------- */
.res-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.res-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.res-table td { padding: 5px 8px; border-bottom: 1px solid rgba(47, 40, 96, .5); }
.res-table tr:last-child td { border-bottom: 0; }
.res-table tr.sum td { color: var(--muted); }
.res-table tr.sum b { color: var(--gold-2); }
.alma-rewards input.price { width: 90px; }
.res-table .num { text-align: right; white-space: nowrap; }
.res-table td.over input.price { color: var(--bad); border-color: rgba(255,107,122,.5); }
.res-table input.price {
  width: 100px; text-align: right; background: var(--bg-2); border: 1px solid var(--line); border-radius: 7px; padding: 3px 6px;
}
.over { color: var(--bad); font-weight: 600; }
.ok { color: var(--good); }
.cap { font-size: 12px; color: var(--muted); }
.cap.over { color: var(--bad); }

/* ---------- Modules ---------- */
.modules { display: flex; flex-direction: column; gap: 12px; }
.module { display: grid; grid-template-columns: auto 1fr; gap: 12px; position: relative; transition: opacity .2s, border-color .2s; }
.module.action { border-left: 3px solid var(--violet); }
.module.quest { border-left: 3px solid var(--gold); }
.module.done { opacity: .55; }
.module.done .m-title { text-decoration: line-through; text-decoration-color: var(--muted); }
/* Quête terminée : repliée sur sa ligne de titre, clic sur le titre pour la rouvrir */
.module.done:not(.expanded) .m-body > :not(.m-head):not(.m-tools) { display: none; }
.module.done { padding-top: 10px; padding-bottom: 10px; }
.module.done .m-head { cursor: pointer; }
.module.done .m-head::after { content: '▸'; color: var(--muted); font-size: 12px; margin-left: 4px; order: 99; }
.module.done.expanded .m-head::after { content: '▾'; }
.module.done:not(.expanded) .m-reward .net { display: none; }
.module.hidden-today { opacity: .4; border-style: dashed; }
.module.disabled { opacity: .3; }
.module.sortable-ghost { opacity: .3; border-color: var(--gold); }
.module.sortable-chosen { box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }

.m-left { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-top: 2px; }
.handle { cursor: grab; color: var(--muted); font-size: 18px; line-height: 1; user-select: none; touch-action: none; }
.done-box {
  appearance: none; width: 22px; height: 22px; border: 2px solid var(--line); border-radius: 6px; cursor: pointer; display: grid; place-items: center;
  background: var(--bg-2);
}
.done-box:checked { background: var(--good); border-color: var(--good); }
.done-box:checked::after { content: '✓'; color: #062; font-weight: 800; font-size: 14px; }

.m-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.m-title { margin: 0; font-size: 17px; font-weight: 700; }
.m-reward { margin-left: auto; text-align: right; white-space: nowrap; }
.m-reward .k { font-size: 18px; font-weight: 700; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.m-reward .net { display: block; font-size: 12px; color: var(--muted); }
.tag {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--card-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.tag.quest { color: var(--gold-2); border-color: rgba(232, 184, 74, .4); }
.tag.action { color: var(--violet); border-color: rgba(155, 107, 255, .4); }
.tag.bonta { color: var(--bonta); }
.tag.brakmar { color: var(--brakmar); }
.tag.warn { color: var(--bad); border-color: rgba(255, 107, 122, .4); }
.m-desc { margin: 6px 0 0; color: #d6d2f5; white-space: pre-wrap; }
.m-section { margin-top: 10px; }
.m-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 4px; }
.m-other { font-size: 13px; color: var(--muted); margin-top: 8px; }
.m-tools { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.coord {
  display: inline-flex; align-items: center; gap: 4px;
  font: 600 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(91, 91, 214, .18); color: #c9c8ff; border: 1px solid rgba(91, 91, 214, .5);
  padding: 4px 8px; border-radius: 7px; cursor: pointer; vertical-align: baseline;
}
.coord:hover { background: rgba(91, 91, 214, .35); color: #fff; }
.coord.copied { background: rgba(79, 208, 138, .25); border-color: var(--good); color: var(--good); }
.positions { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.pos { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }

.empty { text-align: center; color: var(--muted); padding: 30px; }

/* ---------- Lecteur Twitch ---------- */
.stream {
  position: fixed; z-index: 15; width: var(--stream-w);
  top: calc(var(--header-h) + 20px);
  right: max(20px, calc((100vw - 1920px) / 2 + 20px));
}
.stream-box {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; height: calc(100vh - var(--header-h) - 40px); min-height: 420px;
}
.stream-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #e91916; box-shadow: 0 0 0 0 rgba(233, 25, 22, .6); animation: pulse 1.8s infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(233, 25, 22, 0); } 100% { box-shadow: 0 0 0 0 rgba(233, 25, 22, 0); } }
.stream-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-toggle { background: none; border: 0; cursor: pointer; font-size: 18px; line-height: 1; color: var(--muted); display: none; }
.stream-frame { aspect-ratio: 16 / 9; background: #000; flex: none; }
.stream-chat { flex: 1; min-height: 0; border-top: 1px solid var(--line); background: #18181b; }
.stream-chat iframe { width: 100%; height: 100%; border: 0; display: block; }
.stream-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

@media (max-width: 1100px) {
  .layout.has-stream { padding-right: 20px; }
  .stream { position: fixed; right: 12px; bottom: 12px; top: auto; width: min(340px, calc(100vw - 24px)); z-index: 30; }
  .stream-box { box-shadow: 0 12px 40px rgba(0, 0, 0, .6); }
  .stream-toggle { display: block; }
  .stream.collapsed .stream-frame { display: none; }
  .stream-box { height: auto; min-height: 0; }
  .stream-chat { display: none; }
  .layout.has-stream ~ .suggest, .layout.has-stream ~ .footer { padding-right: 20px; }
}

/* ---------- Onglets admin / messagerie ---------- */
.tabs { display: inline-flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 4px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 600; position: relative; }
.tabs button.active { background: var(--card-2); color: var(--gold-2); }
.unread-dot {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px;
  background: #e91916; color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; vertical-align: 1px;
}
.controls.dim .ctrl, .controls.dim .admin-ctrls { opacity: .35; pointer-events: none; }
.inbox { max-width: 1000px; margin: 0 auto; padding: 20px; }
.inbox .panel-head { flex-wrap: wrap; }
.msg { border-top: 1px solid var(--line); padding: 12px 2px; }
.msg:first-child { border-top: 0; }
.msg.unread { background: linear-gradient(90deg, rgba(233, 25, 22, .08), transparent 60%); }
.msg-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.msg-dot { width: 9px; height: 9px; border-radius: 50%; background: #e91916; flex: none; }
.msg-tools { margin-left: auto; display: flex; gap: 6px; }
.msg-text { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; }
.tag.twitch { color: #bf94ff; border-color: rgba(145, 70, 255, .5); }
.tag.late { color: var(--gold-2); border-color: rgba(232, 184, 74, .5); background: rgba(232, 184, 74, .1); }

/* ---------- Suggestions ---------- */
.suggest { max-width: 1920px; margin: 0 auto; padding: 0 20px; }
.suggest form { display: flex; flex-direction: column; gap: 8px; max-width: 960px; }
.suggest .panel-head { flex-wrap: wrap; }
.suggest input, .suggest textarea {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 14px; resize: vertical;
}
.suggest input { max-width: 280px; }
.suggest-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.unprofit-note { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
.linkish { background: none; border: 0; padding: 0; color: var(--gold-2); text-decoration: underline; cursor: pointer; font-size: inherit; }

/* ---------- Panneau repliable ---------- */
.panel-toggle {
  width: 100%; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: left;
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.panel-toggle h2 { flex: none; }
.panel-toggle .muted { margin-left: auto; text-align: right; }
.panel-toggle .muted b { color: var(--text); }
.panel-toggle .chev { color: var(--gold-2); font-size: 14px; transition: transform .2s; display: inline-block; }
.collapsible.open .chev { transform: rotate(90deg); }
.collapsible.open .panel-toggle { margin-bottom: 8px; }
.panel-toggle:hover h2 { text-decoration: underline; text-decoration-color: var(--line); }

/* ---------- Almanax ---------- */
.module.almanax {
  border-left: 3px solid #4fc3d0;
  background: linear-gradient(135deg, rgba(79, 195, 208, .10), var(--card) 45%);
}
.tag.alma { color: #7fe3ec; border-color: rgba(79, 195, 208, .5); }
.alma-item { display: inline-flex; align-items: center; gap: 8px; }
.alma-item img { width: 28px; height: 28px; object-fit: contain; flex: none; }
.alma-rewards { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-size: 14px; }
.alma-rewards b { color: var(--gold-2); font-variant-numeric: tabular-nums; }
.alma-rewards .sep { color: var(--muted); }
.alma-buy tr.bought td { opacity: .45; }
.alma-buy tr.target td { background: rgba(232, 184, 74, .08); }
.alma-buy tr.late td:nth-child(2) { color: var(--bad); }
.alma-buy .buy-box { width: 18px; height: 18px; accent-color: var(--good); cursor: pointer; }
.nowrap { white-space: nowrap; }

/* ---------- Footer / toast ---------- */
.footer {
  max-width: 1920px; margin: 0 auto; padding: 20px; display: flex; justify-content: space-between; gap: 10px;
  color: var(--muted); font-size: 13px; flex-wrap: wrap;
}
.footer a { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--card-2); border: 1px solid var(--good); color: var(--text); padding: 8px 16px; border-radius: 10px;
  font-size: 14px; transition: .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Éditeur ---------- */
.editor {
  width: min(820px, calc(100vw - 24px)); max-height: calc(100vh - 40px); padding: 0;
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
}
.editor::backdrop { background: rgba(5, 4, 12, .7); backdrop-filter: blur(3px); }
.editor form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.editor h2 { margin: 0; font: 700 20px var(--font-title); color: var(--gold-2); }
.editor label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.editor small { color: var(--muted); font-weight: 400; opacity: .8; }
.editor input, .editor select, .editor textarea {
  background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; color: var(--text); font-size: 14px; width: 100%;
}
.editor fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.editor legend { font-size: 13px; color: var(--muted); padding: 0 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips-check { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-check label { flex-direction: row; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer; color: var(--text); }
.chips-check input { width: auto; }
.rows { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.row { display: grid; gap: 6px; align-items: center; }
.row.positions-row { grid-template-columns: 1fr 80px 80px auto; }
.row.resources-row { grid-template-columns: 1fr 90px 120px auto; }
.row.kamas-row { grid-template-columns: 100px 1fr auto; }
.row.reward-row, .row-labels.reward-row { grid-template-columns: 1fr 64px 92px 92px 82px 92px 26px; }
.mini-check { flex-direction: row !important; align-items: center; gap: 4px !important; font-size: 12px !important; white-space: nowrap; }
.mini-check input { width: auto !important; }
.count-in { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.count-in input { width: 80px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 7px; padding: 3px 6px; text-align: right; }
.res-table tr.alt td { opacity: .55; }
.row .rm { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; padding: 0 6px; }
.row .rm:hover { color: var(--bad); }
.row-labels { display: grid; gap: 6px; font-size: 11px; color: var(--muted); width: 100%; }
.kamas-hint { margin: 0; font-size: 12px; color: var(--muted); }
.kamas-hint.ok { color: var(--good); }
.inline-check { flex-direction: row !important; align-items: center; gap: 8px !important; }
.inline-check input { width: auto !important; }
.editor-actions { display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: -20px; background: var(--bg-2); padding: 10px 0 0; }

@media (max-width: 760px) {
  .topbar { position: static; }
  .stream { top: auto; }
  .topbar-inner { grid-template-columns: 1fr; padding: 10px 12px; }
  .stats { justify-content: stretch; }
  .stat { flex: 1; min-width: 0; padding: 6px 10px; }
  .stat-value { font-size: 18px; }
  .layout { padding: 12px; }
  .right-ctrls { margin-left: 0; width: 100%; justify-content: space-between; }
  .grid2 { grid-template-columns: 1fr; }
  .m-reward { margin-left: 0; text-align: left; width: 100%; }
  .res-table .hide-sm { display: none; }
  .row.resources-row { grid-template-columns: 1fr 64px 90px auto; }
  .row.reward-row, .row-labels.reward-row { grid-template-columns: 1fr 60px 80px; }
}
