:root {
  --bleu: #0055a4;
  --rouge: #ef4135;
  --navy: #14213d;
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e6ec;
  --text: #111827;
  --muted: #6b7280;
  --accent: #14213d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 8px 24px -12px rgba(17, 24, 39, .15);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.tricolore {
  position: fixed; inset: 0 0 auto 0; height: 4px; z-index: 50;
  background: linear-gradient(90deg, var(--bleu) 0 33.3%, #fff 33.3% 66.6%, var(--rouge) 66.6%);
}

/* ---------- composants ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  padding: .55em 1em; border-radius: 10px; border: 1px solid transparent;
  background: var(--surface-2); cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { filter: brightness(.97); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.accent { background: var(--rouge); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.big { width: 100%; padding: .85em 1em; font-size: 1.05em; }

.icon-btn {
  display: none; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 18px;
}

.input {
  width: 100%; padding: .7em .9em; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--bleu); box-shadow: 0 0 0 3px rgba(0, 85, 164, .15); }

.hint { color: var(--muted); font-size: .85em; }
.error { color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; padding: .6em .8em; border-radius: 10px; font-size: .9em; }
.badge {
  display: inline-flex; align-items: center; gap: .35em;
  padding: .1em .55em; border-radius: 999px; font-size: .74em; font-weight: 700; letter-spacing: .01em;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, white); border: 1px solid color-mix(in srgb, var(--c) 30%, white);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: .8em; letter-spacing: .02em;
}

/* ---------- écran d'entrée ---------- */
.join-screen { min-height: 100%; display: grid; place-items: start center; padding: 48px 16px; }
.join-card {
  width: min(880px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow); padding: 36px;
}
.join-head { text-align: center; margin-bottom: 28px; }
.join-head h1 { font-size: 44px; letter-spacing: -.03em; line-height: 1; color: var(--navy); }
.join-head h1 span { color: var(--rouge); }
.tagline { margin-top: 6px; font-weight: 600; color: var(--bleu); text-transform: uppercase; letter-spacing: .12em; font-size: .78em; }
.lead { margin: 14px auto 0; max-width: 560px; color: var(--muted); }

.field-label { display: block; font-weight: 600; margin: 18px 0 8px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.label-row .hint { margin-top: 18px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.cand {
  position: relative; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 12px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .06s;
}
.cand:hover { border-color: color-mix(in srgb, var(--c) 55%, var(--border)); }
.cand .info { display: flex; flex-direction: column; min-width: 0; }
.cand .name { font-weight: 600; font-size: .95em; line-height: 1.2; }
.cand .party { color: var(--muted); font-size: .78em; margin-top: 2px; }
.cand .status {
  margin-top: 3px; font-size: .62em; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: color-mix(in srgb, var(--c) 70%, black);
}
.cand[aria-checked="true"] {
  border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent);
  background: color-mix(in srgb, var(--c) 5%, white);
}
.cand.undecided { grid-column: 1 / -1; border-style: dashed; }
.cand.undecided .avatar { background: #e5e7eb; color: #374151; font-size: 1.1em; }

#join-error { margin-top: 14px; }
#join-btn { margin-top: 18px; }
.legal { text-align: center; color: var(--muted); font-size: .8em; margin-top: 14px; }

/* ---------- écran tchat ---------- */
.chat-screen { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-top: 4px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: -.02em; color: var(--navy); white-space: nowrap; }
.brand span { color: var(--rouge); }
.spacer { flex: 1; }
.me-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px 5px 6px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
}
.me-chip .avatar { width: 24px; height: 24px; border-radius: 7px; font-size: .68em; }
.me-chip .pseudo { font-weight: 600; }
.me-chip:hover { border-color: var(--bleu); }

.layout { flex: 1; min-height: 0; display: flex; }
.sidebar {
  width: 290px; flex: none; display: flex; flex-direction: column; gap: 10px; padding: 12px;
  background: var(--bg); border-right: 1px solid var(--border); overflow: hidden;
}
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  display: flex; flex-direction: column; min-height: 0;
}
.panel.grow { flex: 1; }
.panel h2 { font-size: .8em; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.count { background: var(--navy); color: #fff; border-radius: 999px; padding: 0 .55em; font-size: .9em; }

.stats { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.stat { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: .85em; }
.stat .label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.stat .label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.stat .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.stat .bar { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.stat .bar i { display: block; height: 100%; background: var(--c); border-radius: 3px; transition: width .3s ease; }
.stats .empty { color: var(--muted); font-size: .85em; }

.user-list { list-style: none; margin: 10px 0 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.user-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.user-list li:hover { background: var(--surface-2); }
.user-list li.me { cursor: default; opacity: .8; }
.user-list .avatar { width: 28px; height: 28px; border-radius: 8px; font-size: .7em; }
.user-list .info { min-width: 0; display: flex; flex-direction: column; }
.user-list .pseudo { font-weight: 600; font-size: .92em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-list .badge { align-self: flex-start; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px 10px 0 0;
  border: 1px solid transparent; border-bottom: none; cursor: pointer; background: transparent; color: var(--muted);
  font-weight: 600; white-space: nowrap; position: relative; top: 1px;
}
.tab.active { background: var(--surface); border-color: var(--border); color: var(--text); }
.tab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tab .unread { background: var(--rouge); color: #fff; border-radius: 999px; font-size: .72em; padding: 0 .5em; min-width: 1.6em; text-align: center; }
.tab .close { border: none; background: transparent; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 1.1em; line-height: 1; }
.tab .close:hover { color: var(--rouge); }

.tab-header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: .9em; }
.tab-header .title { font-weight: 700; white-space: nowrap; }
.tab-header .sub { color: var(--muted); }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.msg { display: flex; gap: 10px; max-width: 78%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg .body { min-width: 0; }
.msg .meta { display: flex; align-items: center; gap: 6px; font-size: .82em; margin-bottom: 3px; }
.msg.me .meta { justify-content: flex-end; }
.msg .meta .pseudo { font-weight: 700; }
.msg .meta .time { color: var(--muted); }
.msg .text {
  padding: 8px 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border);
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.me .text { background: var(--navy); color: #fff; border-color: var(--navy); border-top-right-radius: 4px; }
.msg:not(.me) .text { border-top-left-radius: 4px; }
.msg.system { align-self: center; max-width: 100%; text-align: center; color: var(--muted); font-size: .82em; padding: 2px 0; }
.msg.system.highlight { color: var(--navy); font-weight: 600; background: #fff7ed; border: 1px solid #fed7aa; padding: 8px 14px; border-radius: 10px; }
.messages .empty { margin: auto; text-align: center; color: var(--muted); max-width: 380px; }
.messages .empty strong { display: block; color: var(--text); font-size: 1.1em; margin-bottom: 6px; }

.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface); }

/* ---------- dialog / toast ---------- */
.dialog { border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: min(420px, 92vw); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(17, 24, 39, .45); }
.dialog h3 { font-size: 1.15em; margin-bottom: 4px; }
.dialog .field-label { margin: 14px 0 6px; }
.dialog .hint { margin-top: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: .9em;
  max-width: 90vw;
}
.toast.error { background: #b91c1c; }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .icon-btn { display: grid; place-items: center; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: min(320px, 85vw);
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(17, 24, 39, .35); }
  .msg { max-width: 92%; }
  .join-card { padding: 22px; }
  .join-head h1 { font-size: 36px; }
  .topbar { gap: 8px; padding: 10px 12px; }
  .brand { font-size: 17px; }
  .me-chip { padding: 4px; gap: 6px; }
  .me-chip .pseudo, .me-chip .badge { display: none; }
  .me-chip .avatar { width: 30px; height: 30px; border-radius: 8px; }
  #random-btn { padding: .5em .6em; }
  #random-btn .label { display: none; }
  #leave-btn { padding: .5em .7em; }
  .tab-header { padding: 8px 12px; }
  .tab-header .sub { display: none; }
  .messages { padding: 12px; }
  .composer { padding: 10px 12px; }
}

/* ---------- IA, classement, « écrit… » ---------- */
.avatar.ai { font-size: 1em; }
.tag-ai {
  display: inline-block; font-size: .68em; font-weight: 800; letter-spacing: .06em; padding: 0 .45em; border-radius: 5px;
  background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; line-height: 1.5;
}
.ai-note { margin-top: 16px; padding: 10px 14px; border-radius: 10px; background: #eef2ff; color: #312e81; font-size: .88em; }
.user-list .section { cursor: default; margin-top: 8px; padding: 6px 8px 2px; font-size: .74em; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.user-list .section:hover { background: transparent; }
.user-list .section .hint { text-transform: none; letter-spacing: 0; font-weight: 500; }
.panel h2 .more { margin-left: auto; font-size: .9em; text-transform: none; letter-spacing: 0; color: var(--bleu); text-decoration: none; font-weight: 600; }
.rankings { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.rankings .empty { color: var(--muted); font-size: .85em; }
.rank { display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 8px; font-size: .88em; }
.rank .pos { width: 18px; height: 18px; border-radius: 5px; background: var(--c); color: #fff; font-size: .75em; font-weight: 800; display: grid; place-items: center; }
.rank .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank .n { font-variant-numeric: tabular-nums; font-weight: 700; }
.rank .n small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.typing { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .85em; padding: 4px 0 0 44px; }
.typing .dots { display: inline-flex; gap: 3px; }
.typing .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing .dots i:nth-child(2) { animation-delay: .2s; }
.typing .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing .dots i { animation: none; } }

/* ---------- signalement ---------- */
.msg .report { opacity: 0; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: .95em; padding: 0 4px; line-height: 1; transition: opacity .12s, color .12s; }
.msg:hover .report, .msg .report:focus-visible { opacity: 1; }
.msg .report:hover { color: var(--rouge); }
@media (hover: none) { .msg .report { opacity: .55; } }
.quote { margin: 10px 0 0; padding: 8px 12px; border-left: 3px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: .9em; border-radius: 6px; max-height: 96px; overflow: auto; overflow-wrap: anywhere; }
