:root {
  --bg: #0b1220;
  --bg2: #131b30;
  --card: #172140;
  --text: #e8ecff;
  --muted: #8a94b8;
  --accent: #4ade80;
  --accent-alt: #60a5fa;
  --danger: #ef4444;
  --bd: #253055;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
.shell { max-width: 640px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(84px + env(safe-area-inset-bottom));
  min-height: 100vh; }

/* Auth page */
body.auth .shell { display: flex; align-items: center; padding-top: 40px; padding-bottom: 40px; }
.auth-box { width: 100%; max-width: 400px; margin: 0 auto; background: var(--card);
  padding: 32px 24px; border-radius: 20px; }
.auth-box h1 { text-align: center; font-size: 2rem; margin-bottom: 8px; }
.auth-box .lead { text-align: center; color: var(--muted); margin-bottom: 24px; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; padding: 4px 0; }
.topbar h1 { flex: 1; font-size: 1.15rem; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.back { display: inline-block; padding: 4px 8px; font-size: 1.2rem; color: var(--muted); }

.league-switcher { background: var(--bg2); color: var(--text); border: 1px solid var(--bd);
  padding: 6px 8px; border-radius: 8px; font-size: .9rem; }

/* Layout primitives */
.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; border: 1px solid var(--bd); }
.stack > * + * { margin-top: 10px; }
h2 { font-size: 1.05rem; margin-bottom: 6px; }
h3 { font-size: .95rem; margin-bottom: 6px; color: var(--muted); }
.small { font-size: .8rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 20px; }

/* Forms */
label { display: block; margin-bottom: 6px; font-size: .9rem; color: var(--muted); }
input, select, textarea { width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--bd); background: var(--bg2); color: var(--text);
  font-family: inherit; font-size: 1rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* Buttons */
.btn { display: inline-block; padding: 10px 18px; border-radius: 10px;
  background: var(--bg2); color: var(--text); border: 1px solid var(--bd);
  font-family: inherit; font-size: 1rem; cursor: pointer; text-align: center; }
.btn.primary { background: var(--accent); color: #0b1220; border: 0; font-weight: 700; }
.btn.big { padding: 14px 24px; font-size: 1.1rem; width: 100%; }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: #fff; border: 0; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; font-size: .95rem; }
.flash-ok { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.flash-err { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); }

/* KPI */
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--card); padding: 14px 8px; border-radius: 12px; text-align: center; border: 1px solid var(--bd); }
.kpi b { display: block; font-size: 1.6rem; color: var(--accent); }
.kpi b small { font-size: .8rem; }
.kpi span { font-size: .75rem; color: var(--muted); }

/* Match row */
.match-row { display: grid; grid-template-columns: auto 1fr auto 1fr auto auto; gap: 10px;
  align-items: center; padding: 10px 12px; background: var(--bg2); border-radius: 10px;
  color: var(--text); font-size: .95rem; }
.match-row.done { background: color-mix(in srgb, var(--accent) 8%, var(--bg2)); }
.team-tla { font-weight: 700; letter-spacing: 1px; min-width: 40px; text-align: center; }
.vs { text-align: center; }
.kickoff { min-width: 60px; text-align: right; }
.date-sep { color: var(--muted); font-size: .8rem; text-transform: uppercase;
  padding: 12px 4px 4px; letter-spacing: 1px; }

.stage-filter { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 4px; }
.chip { padding: 6px 12px; background: var(--bg2); border: 1px solid var(--bd);
  border-radius: 99px; color: var(--muted); font-size: .85rem; white-space: nowrap; flex-shrink: 0; }
.chip.on { background: var(--accent); color: #0b1220; border-color: transparent; font-weight: 700; }

.pts-pill { display: inline-block; padding: 2px 8px; border-radius: 99px;
  background: var(--accent); color: #0b1220; font-weight: 700; font-size: .8rem; margin-left: 4px; }
.pts-pill.zero { background: var(--bg2); color: var(--muted); }
.pts-pill.big { font-size: 1.1rem; padding: 6px 14px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--bg2);
  color: var(--muted); font-size: .7rem; letter-spacing: .5px; text-transform: uppercase; }
.tag.warn { background: color-mix(in srgb, orange 30%, transparent); color: orange; }
.tag.err { background: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.tag.ok { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--accent); }

/* Match detail */
.match-detail { padding: 24px 14px; }
.match-header { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; }
.team-block { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.crest { width: 64px; height: 64px; object-fit: contain; }
.team-name { font-weight: 700; font-size: .95rem; }
.match-vs { text-align: center; }
.match-vs .vs { font-size: 1.5rem; font-weight: 700; color: var(--muted); }
.final-score { font-size: 2.4rem; font-weight: 800; text-align: center; color: var(--accent); }

.score-input { display: flex; align-items: center; justify-content: center; gap: 10px; }
.score-input label { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 0; }
.score-input input { width: 70px; height: 70px; text-align: center; font-size: 2.4rem;
  font-weight: 700; padding: 0; border-radius: 14px; }
.score-input .dash { font-size: 2rem; color: var(--muted); }

/* Leaderboard */
.lb-row { display: grid; grid-template-columns: 30px 30px 1fr auto auto; gap: 10px;
  align-items: center; padding: 10px 12px; background: var(--bg2); border-radius: 10px; }
.lb-row.me { background: color-mix(in srgb, var(--accent) 15%, var(--bg2)); }
.lb-rank { font-weight: 700; color: var(--muted); }
.lb-avatar { font-size: 1.3rem; }
.lb-name { font-weight: 500; }
.lb-detail { text-align: right; }
.lb-total { font-weight: 700; font-size: 1.1rem; min-width: 40px; text-align: right; }

/* Tabbar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--bg) 90%, #000); backdrop-filter: blur(10px);
  border-top: 1px solid var(--bd); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 10; }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px;
  color: var(--muted); flex: 1; font-size: .7rem; text-align: center; }
.tabbar a.on { color: var(--accent); }
.tabbar .ic { font-size: 1.3rem; }

/* Admin */
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; background: var(--bg2); border-radius: 8px; color: var(--text); }
.inline-form { display: inline-flex; gap: 6px; }
.outsider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.outsider-check { display: flex; align-items: center; gap: 6px; background: var(--bg2);
  padding: 6px 10px; border-radius: 8px; font-size: .85rem; cursor: pointer; margin: 0; color: var(--text); }
.outsider-check input { width: auto; margin: 0; }

fieldset { border: 1px solid var(--bd); padding: 12px; border-radius: 10px; }
legend { padding: 0 8px; font-size: .85rem; color: var(--muted); }

details summary { list-style: none; cursor: pointer; }
details summary::-webkit-details-marker { display: none; }
code { background: var(--bg2); padding: 2px 6px; border-radius: 4px; font-family: monospace; }

/* ---- Chat WinnerUP+ ---- */
.section-title { font-size: .85rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 4px; }
.chat-row { display: flex; gap: 10px; align-items: center; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--bd); border-radius: 12px; text-decoration: none;
  color: var(--text); transition: transform .1s, border-color .1s; }
.chat-row:hover { border-color: var(--accent); transform: translateY(-1px); }
.chat-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--bg2);
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0; }
.chat-body { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chat-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.chat-badge { display: inline-block; min-width: 20px; height: 20px; line-height: 20px;
  padding: 0 6px; background: var(--danger); color: #fff; border-radius: 99px;
  font-size: .75rem; font-weight: 700; text-align: center; }
.chat-row.contact { opacity: .8; }
.chat-row.contact:hover { opacity: 1; }

/* Page conversation : pleine hauteur, composer sticky en bas */
body.chat-page .shell { padding-top: 0; padding-bottom: 0; height: 100dvh;
  display: flex; flex-direction: column; overflow: hidden; }
body.chat-page .topbar { padding: calc(10px + env(safe-area-inset-top)) 4px 8px;
  margin: 0; flex-shrink: 0; }
.chat-window { flex: 1 1 auto; display: flex; flex-direction: column; gap: 6px;
  padding: 12px; overflow-y: auto; background: var(--bg2); border-radius: 12px 12px 0 0;
  min-height: 0; -webkit-overflow-scrolling: touch; }
.chat-msg { display: flex; flex-direction: column; max-width: 80%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.his { align-self: flex-start; align-items: flex-start; }
.chat-author { padding: 6px 4px 2px; }
.chat-bubble-wrap { position: relative; display: inline-block; max-width: 100%; }
.chat-bubble { padding: 8px 12px; border-radius: 14px; word-break: break-word; line-height: 1.35; }
.chat-msg.mine .chat-bubble { background: var(--accent); color: #0b1220; border-bottom-right-radius: 4px; }
.chat-msg.his .chat-bubble { background: var(--card); color: var(--text);
  border-bottom-left-radius: 4px; border: 1px solid var(--bd); }
.chat-bubble.deleted { opacity: .55; font-style: italic; background: var(--bg2) !important;
  color: var(--muted) !important; border: 1px dashed var(--bd) !important; }
.chat-bubble[data-toggle-meta] { cursor: pointer; }
.chat-edited { font-size: .7rem; opacity: .7; font-style: italic; }
.chat-meta[hidden] { display: none; }
.chat-del-x, .chat-edit-x { position: absolute; top: -8px; margin: 0; padding: 0;
  z-index: 2; line-height: 1; text-decoration: none; }
.chat-del-x { right: -8px; }
.chat-edit-x { left: -8px; }
.chat-del-x button, .chat-edit-x {
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--bd);
  background: var(--bg2); color: var(--muted); font-size: 14px; cursor: pointer;
  padding: 0; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.25); text-decoration: none;
  opacity: .6; transition: opacity .15s, transform .15s;
}
.chat-msg:hover .chat-del-x button, .chat-msg:hover .chat-edit-x { opacity: 1; }
.chat-del-x button:hover { color: var(--danger); border-color: var(--danger); transform: scale(1.15); }
.chat-edit-x:hover { color: var(--accent); border-color: var(--accent); transform: scale(1.15); }
@media (hover: none) { .chat-msg.mine .chat-del-x button, .chat-msg.mine .chat-edit-x { opacity: .85; } }

.chat-edit-form { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.chat-edit-form textarea { width: 100%; min-height: 60px; padding: 8px 12px;
  border-radius: 14px; border: 1px solid var(--accent); background: var(--bg2);
  color: var(--text); font: inherit; font-size: 1rem; resize: vertical; }
.chat-edit-actions { display: flex; gap: 6px; justify-content: flex-end; }

.chat-composer { flex-shrink: 0; background: var(--bg);
  padding: 8px 12px calc(84px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--bd); box-shadow: 0 -6px 14px rgba(0,0,0,.15); }
.chat-composer-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.chat-composer textarea[name=body] {
  width: 100%; min-height: 42px; max-height: 110px;
  padding: 10px 12px; font-family: inherit; font-size: 1rem; line-height: 1.35;
  border-radius: 18px; border: 1px solid var(--bd); background: var(--bg2); color: var(--text);
  resize: none; overflow-y: auto; -webkit-appearance: none; appearance: none;
  box-sizing: border-box; margin: 0; display: block;
}
.chat-send { width: 44px; height: 44px; padding: 0; border-radius: 50%;
  font-size: 1.2rem; line-height: 1; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; }

/* Aide PWA */
.stepped { list-style: none; counter-reset: st; padding: 0; }
.stepped li { counter-increment: st; padding: 8px 0 8px 36px; position: relative;
  border-bottom: 1px solid var(--bd); }
.stepped li:last-child { border-bottom: 0; }
.stepped li::before { content: counter(st); position: absolute; left: 0; top: 8px;
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  color: #0b1220; font-weight: 700; display: flex; align-items: center;
  justify-content: center; font-size: .85rem; }
details summary { padding: 6px 0; }

/* ---- Onglets login/signup ---- */
.auth-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--bg2);
  border-radius: 10px; padding: 4px; }
.auth-tabs a { flex: 1; text-align: center; padding: 10px; border-radius: 8px;
  color: var(--muted); font-weight: 600; }
.auth-tabs a.on { background: var(--card); color: var(--text); }
