:root {
  --bg: #070711; --side: #0b0b18; --card: #0f0f1e; --input: #14142a; --border: #1e1e38;
  --purple: #8b5cf6; --purple-hi: #a78bfa; --purple-dim: rgba(139, 92, 246, .16);
  --text: #e5e7eb; --muted: #8b8ba7; --danger: #ef4444; --ok: #22c55e; --warn: #f59e0b; --blue: #3b82f6;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--purple-hi); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #26264a; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- layout ---------- */
#app { height: 100%; display: flex; }
.side { width: 250px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 22px 16px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.logo { width: 40px; height: 40px; border-radius: 11px; background: linear-gradient(135deg, #8b5cf6, #5b3bd0); display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #fff; box-shadow: 0 0 24px rgba(139, 92, 246, .35); }
.brand b { font-size: 20px; letter-spacing: .5px; display: block; line-height: 1.1; }
.brand small { font-size: 10px; letter-spacing: 1.5px; color: var(--muted); font-weight: 700; }
.nav-sec { font-size: 10px; font-weight: 700; letter-spacing: 1.2px; color: var(--muted); margin: 16px 0 6px 14px; }
.nav-item { display: block; width: 100%; text-align: left; background: transparent; border: 0; border-left: 3px solid transparent; border-radius: 10px; padding: 10px 14px; margin-bottom: 4px; color: var(--muted); font-weight: 600; cursor: pointer; transition: background .15s, color .15s; text-decoration: none; }
.nav-item:hover { background: rgba(255, 255, 255, .04); color: var(--text); }
.nav-item.active { background: var(--purple-dim); color: var(--purple-hi); border-left-color: var(--purple); }
.side-foot { margin-top: auto; padding-top: 16px; }
.side-foot .who { font-size: 12px; color: var(--muted); margin: 8px 0 10px; word-break: break-all; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 64px; flex-shrink: 0; display: flex; align-items: center; justify-content: flex-end; gap: 18px; padding: 0 28px; border-bottom: 1px solid var(--border); }
.topbar .me { display: flex; align-items: center; gap: 12px; }
.topbar .me b { display: block; font-size: 12px; }
.topbar .me small { font-size: 11px; }
.content { flex: 1; min-height: 0; padding: 28px 32px; overflow-y: auto; display: flex; flex-direction: column; }
.footer { height: 40px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 32px; border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head > div:first-child { flex: 1; }
h1 { margin: 0; font-size: 28px; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.muted { color: var(--muted); }
.fill { flex: 1; min-height: 0; }

/* ---------- composants ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.pad { padding: 20px; }
.btn { background: var(--purple); border: 1px solid transparent; color: #fff; border-radius: 10px; padding: 9px 16px; font-weight: 700; cursor: pointer; transition: filter .15s, background .15s; white-space: nowrap; }
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: #26264a; color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(239, 68, 68, .4); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; background: var(--input); border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--purple); }
textarea { resize: vertical; min-height: 70px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; border: 1px solid; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.err { color: var(--danger); font-size: 12px; margin: 6px 0; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

.avatar { position: relative; flex-shrink: 0; border-radius: 50%; background: var(--purple-dim); border: 2px solid var(--purple); display: grid; place-items: center; color: var(--purple-hi); font-weight: 800; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.dot { position: absolute; right: 0; bottom: 0; width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--card); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { border-radius: var(--radius); padding: 16px 18px; border: 1px solid; }
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip { display: inline-flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border); color: var(--muted); border-radius: 20px; padding: 6px 14px; font-size: 12px; font-weight: 700; cursor: pointer; }
.chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip.sel { color: var(--text); }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; letter-spacing: .8px; color: var(--muted); padding: 12px 14px; background: var(--input); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.table td { padding: 10px 14px; border-top: 1px solid var(--border); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover { background: rgba(255, 255, 255, .03); }
.scroll { overflow: auto; }

.empty { text-align: center; padding: 70px 20px; }
.empty .ico { width: 70px; height: 70px; border: 2px solid var(--purple); border-radius: 50%; margin: 0 auto 14px; position: relative; }
.empty .ico::before { content: ""; position: absolute; left: 50%; top: 16px; width: 16px; height: 16px; background: var(--purple-hi); border-radius: 50%; transform: translateX(-50%); }
.empty .ico::after { content: ""; position: absolute; left: 50%; top: 37px; width: 30px; height: 14px; background: var(--purple-hi); border-radius: 15px 15px 0 0; transform: translateX(-50%); }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .68); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { width: 800px; max-width: 100%; max-height: 94vh; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 28px; }
.modal-head { display: flex; align-items: center; gap: 22px; margin-bottom: 24px; }
.modal-head h2 { margin: 0 0 8px; font-size: 24px; }
.modal-body { overflow-y: auto; min-height: 0; flex: 1; padding-right: 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 700; padding: 9px 14px; cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--purple-hi); border-bottom-color: var(--purple); }
.subtab { background: transparent; border: 0; border-radius: 8px; color: var(--muted); font-weight: 700; padding: 6px 12px; cursor: pointer; }
.box { background: var(--input); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.box h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: 1px; color: var(--muted); }
.entry { border: 1px solid var(--border); border-left: 3px solid var(--purple); border-radius: 10px; background: var(--card); padding: 12px 14px; margin-bottom: 8px; }
.qrow { margin-bottom: 10px; }
.qrow .top { display: flex; justify-content: space-between; font-size: 13px; }
.bar { height: 8px; background: var(--input); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; z-index: 100; pointer-events: none; }
.toast { background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 10px; padding: 12px 16px; font-weight: 600; max-width: 420px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5); }
.toast.bad { border-left-color: var(--danger); }

/* ---------- login ---------- */
.login { margin: auto; width: 420px; max-width: calc(100% - 32px); padding: 34px; text-align: left; }
.login .logo { margin: 0 auto 14px; width: 56px; height: 56px; font-size: 28px; }
.login h1 { text-align: center; font-size: 26px; }
.login p.sub { text-align: center; margin-bottom: 22px; }

/* ---------- permissions ---------- */
.perm-grid { border-collapse: collapse; width: 100%; }
.perm-grid th, .perm-grid td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: center; }
.perm-grid th:first-child, .perm-grid td:first-child { text-align: left; }
.perm-grid input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--purple); }

/* ---------- chat / ingame (2 colonnes) ---------- */
.split { display: flex; gap: 16px; flex: 1; min-height: 0; }
.split > .card { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.split .left { width: 330px; flex-shrink: 0; }
.split .right { flex: 1; min-width: 0; }
.pane-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.pane-head .t { flex: 1; font-size: 11px; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.pane-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.li { padding: 10px 16px; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; cursor: pointer; }
.li:hover { background: rgba(255, 255, 255, .03); }
.li.sel { background: var(--purple-dim); border-left-color: var(--purple); }
.li .n { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.li .p { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px; }
.msg { display: flex; flex-direction: column; margin-bottom: 10px; }
.msg.out { align-items: flex-end; }
.bubble { max-width: 78%; background: var(--input); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.msg.out .bubble { background: var(--purple-dim); border-color: rgba(139, 92, 246, .45); }
.bubble .who { font-size: 11px; font-weight: 700; color: var(--muted); }
.msg.out .bubble .who { color: var(--purple-hi); }
.bubble .txt { white-space: pre-wrap; word-break: break-word; margin-top: 3px; }
.embed { margin-top: 6px; background: rgba(0, 0, 0, .28); border-left: 4px solid #5865f2; border-radius: 4px; padding: 8px 10px; }
.embed .et { color: var(--purple-hi); font-weight: 700; }
.embed .ef b { display: block; font-size: 12px; margin-top: 6px; }
.embed .ef span { font-size: 12px; color: var(--muted); white-space: pre-wrap; }
.composer { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); }
.composer input { flex: 1; }
.code { width: 100%; min-height: 300px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }

@media (max-width: 900px) {
  .side { width: 200px; } .content { padding: 20px 16px; } .split { flex-direction: column; } .split .left { width: 100%; max-height: 280px; }
}

/* modal: ne pas écraser l'en-tête, les stats et les onglets */
.modal-head, .stats, .tabs { flex-shrink: 0; }

/* Effectif */
.eff-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut-wrap .legend { flex: 1; min-width: 190px; }
.legend-row { padding: 5px 0; font-size: 14px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; display: inline-block; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 12px 16px; font-size: 14px; }
.kv span { color: var(--muted); }
.eff-roles { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 800px) { .eff-grid { grid-template-columns: 1fr; } }

/* RH */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.form-grid .field { margin-bottom: 0; }
.hr-split { display: flex; gap: 16px; align-items: flex-start; }
.hr-split .left { width: 320px; flex-shrink: 0; overflow: hidden; }
.hr-split .right { flex: 1; min-width: 0; }
.hr-split .li .sal { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hr-split .li.sel { background: rgba(139, 92, 246, .12); border-left-color: var(--purple); }
.file-input { padding: 8px; border: 1px dashed var(--border); border-radius: 10px; width: 100%; background: var(--input); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=text], .toolbar select { width: auto; min-width: 200px; }
@media (max-width: 900px) { .hr-split { flex-direction: column; } .hr-split .left { width: 100%; } }

/* Creation de documents */
.doc-layout { display: grid; grid-template-columns: minmax(360px, 460px) 1fr; gap: 16px; align-items: start; }
.doc-left { max-height: calc(100vh - 170px); overflow-y: auto; }
.doc-right { min-width: 0; }
.line-row { display: grid; grid-template-columns: 1fr 70px 90px 34px; gap: 6px; margin-bottom: 6px; }
.line-row input { min-width: 0; }
.doc-prev { overflow: auto; max-height: calc(100vh - 230px); }
.paper { background: #fff; color: #1e1e32; width: 100%; max-width: 794px; margin: 0 auto; padding: 36px 40px; border-radius: 4px; box-shadow: 0 6px 30px rgba(0, 0, 0, .45); font-size: 13px; line-height: 1.5; border-top: 5px solid #6d3fdc; }
.p-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.p-title { font-size: 28px; font-weight: 800; letter-spacing: .5px; }
.p-num { text-align: right; color: #6e6e82; font-size: 12px; }
.p-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 16px; }
.p-party small { display: block; background: #f5f3ff; color: #6d3fdc; font-weight: 700; font-size: 10px; letter-spacing: 1px; padding: 4px 8px; border-radius: 4px; margin-bottom: 6px; }
.p-party b { display: block; }
.p-meta { margin-bottom: 14px; font-size: 12.5px; }
.p-meta span { color: #6e6e82; font-weight: 700; }
.p-table { width: 100%; border-collapse: collapse; margin: 10px 0 14px; font-size: 12.5px; }
.p-table th { background: #6d3fdc; color: #fff; text-align: left; padding: 7px 9px; font-weight: 700; }
.p-table td { border: 1px solid #e1e1ee; padding: 7px 9px; }
.p-table tbody tr:nth-child(even) td { background: #fafaff; }
.p-table .r { text-align: right; white-space: nowrap; }
.p-totals { margin-left: auto; width: 290px; margin-bottom: 14px; }
.p-totals > div { display: flex; justify-content: space-between; padding: 3px 0; }
.p-totals .strong { background: #6d3fdc; color: #fff; padding: 7px 12px; border-radius: 5px; margin-top: 4px; }
.p-sec h4 { color: #6d3fdc; margin: 14px 0 4px; font-size: 13px; }
.p-sec p { margin: 0; white-space: pre-wrap; }
.p-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 26px; }
.p-sign > div { border: 1px solid #c9c9dc; height: 110px; padding: 8px; }
.p-sign small { display: block; color: #6e6e82; }
.p-note { margin-top: 18px; font-size: 11px; color: #6e6e82; font-style: italic; }
@media (max-width: 1100px) { .doc-layout { grid-template-columns: 1fr; } .doc-left, .doc-prev { max-height: none; } }
@media print {
  body * { visibility: hidden; }
  .paper, .paper * { visibility: visible; }
  .paper { position: absolute; left: 0; top: 0; width: 100%; max-width: none; box-shadow: none; }
}
