/* styles.css — thème clair (fond blanc) / sombre via [data-theme] */

:root {
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --card: #ffffff;
  --card-head: #f0f2f5;
  --text: #1a1d21;
  --text-soft: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --live: #e11d48;        /* rouge "match en cours" */
  --live-bg: #fff1f3;
  --warn: #ea580c;        /* orange "joue dans <24h" */
  --warn-bg: #fff7ed;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
}

[data-theme="dark"] {
  --bg: #0f1115;
  --bg-soft: #161922;
  --card: #1a1e27;
  --card-head: #222734;
  --text: #e8eaed;
  --text-soft: #9aa3b2;
  --border: #2a3040;
  --accent: #60a5fa;
  --live: #fb7185;
  --live-bg: #2a1419;
  --warn: #fb923c;
  --warn-bg: #2a1c10;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden; /* le scroll se fait via le pan/zoom du canvas */
}

/* --- Barre du haut --- */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}
.title { font-size: 18px; margin: 0; font-weight: 700; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.status-pill {
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
}

.icon-btn {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { border-color: var(--accent); }

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 360px;
  max-width: 90vw;
  background: var(--card);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(-100%);
  transition: transform .25s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.sidebar.open { transform: translateX(0); }

.sidebar-head {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-head input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
}
.sidebar-body { overflow-y: auto; padding: 8px; flex: 1; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  z-index: 40;
}

/* Liste d'équipes dans la sidebar */
.team-list { list-style: none; margin: 0; padding: 0; }
.team-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.team-item:hover { background: var(--bg-soft); }
.team-item img { width: 26px; height: auto; border-radius: 3px; }
.team-item .team-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fav-btn {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 2px 4px;
  color: var(--text-soft);
}
.fav-btn:hover { color: #f5b301; }
.fav-btn.on { color: #f5b301; }

.list-header {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); padding: 10px 10px 4px; font-weight: 700;
}

/* Détail d'une équipe */
.team-detail h2 { display: flex; align-items: center; gap: 10px; margin: 6px 4px 12px; font-size: 20px; }
.team-detail h2 img { width: 38px; border-radius: 4px; }
.back-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 13px; padding: 4px; margin-bottom: 4px;
}
.summary {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 0 4px 14px;
}
.summary .chip {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}
.detail-subtitle {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-soft); margin: 14px 4px 8px;
}
.scorer-list { list-style: none; margin: 0 4px 6px; padding: 0; }
.scorer-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 8px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.scorer-item:last-child { border-bottom: none; }
.scorer-goals { color: var(--text-soft); font-variant-numeric: tabular-nums; }

.match-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin: 0 4px 8px;
  background: var(--bg);
}
.match-row.soon { border-color: var(--warn); background: var(--warn-bg); }
.match-row.live { border-color: var(--live); background: var(--live-bg); }
.match-meta { font-size: 11px; color: var(--text-soft); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; }
.match-teams { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.match-teams .side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.match-teams .side img { width: 22px; border-radius: 3px; }
.match-teams .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.match-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.match-score .vs { color: var(--text-soft); font-weight: 400; }
.scorers { margin-top: 8px; font-size: 12px; color: var(--text-soft); }
.scorers div { display: flex; gap: 6px; }
.badge-live { color: var(--live); font-weight: 700; }

/* --- Scène / zoom-pan --- */
.stage { position: relative; height: calc(100vh - 56px); overflow: hidden; }
.viewport {
  position: absolute; inset: 0; overflow: hidden; cursor: grab;
  user-select: none;        /* évite la sélection de texte pendant le pan */
  -webkit-user-select: none;
  touch-action: none;       /* le pan/pinch agit sur le canvas, pas sur la page */
}
.viewport img { -webkit-user-drag: none; user-drag: none; }
.viewport.grabbing { cursor: grabbing; }
.canvas {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  padding: 40px;
  display: flex;
  flex-direction: row;        /* paysage : poules et phase finale côte à côte */
  align-items: flex-start;
  gap: 70px;
  width: max-content;
}
.canvas.portrait {
  flex-direction: column;     /* portrait : phase finale sous les poules */
  gap: 50px;
}

/* --- Poules --- */
.section-title { font-size: 22px; font-weight: 800; margin: 0 0 16px; }
.groups-grid {
  display: grid;
  grid-template-columns: repeat(4, 320px);
  gap: 20px;
}
.group-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.group-card h3 {
  margin: 0;
  padding: 10px 14px;
  background: var(--card-head);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.standings { width: 100%; border-collapse: collapse; font-size: 13px; }
.standings th, .standings td { padding: 7px 8px; text-align: center; }
.standings th { color: var(--text-soft); font-weight: 600; font-size: 11px; }
.standings td.team-cell, .standings th.team-cell { text-align: left; }
.standings tbody tr { border-top: 1px solid var(--border); }
.standings tbody tr.qualif td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.standings .team-cell { display: flex; align-items: center; gap: 8px; }
.standings .team-cell img { width: 22px; border-radius: 3px; cursor: pointer; }
.standings .team-cell .clickable { cursor: pointer; }
.standings .team-cell .clickable:hover { color: var(--accent); }
.standings td.pts { font-weight: 700; }

/* matchs d'une poule (sous le classement) */
.group-fixtures { padding: 8px 10px 12px; border-top: 1px dashed var(--border); }
.gf-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: 12px; padding: 4px 6px; border-radius: 6px;
}
/* poules : couleur de police selon l'état (orange <24h, rouge en cours) */
.gf-row.soon, .gf-row.soon .gf-when { color: var(--warn); font-weight: 600; }
.gf-row.live, .gf-row.live .gf-when { color: var(--live); font-weight: 600; }
.gf-row .gf-teams { display: flex; align-items: center; gap: 6px; min-width: 0; }
.gf-row img { width: 16px; border-radius: 2px; cursor: pointer; }
.gf-row .gf-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.gf-row .gf-when { color: var(--text-soft); font-size: 11px; }

/* --- Bracket / phase finale --- */
/* hauteur définie en JS sur .bracket ; chaque colonne se centre via space-around */
.bracket {
  display: flex;
  gap: 44px;
  align-items: stretch;
  position: relative; /* repère pour l'overlay des traits */
}
.bracket-lines {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}
.bracket-line {
  fill: none;
  stroke: var(--text-soft);
  stroke-opacity: .7;
  /* stroke-width est fixé par JS pour compenser le zoom */
}
.bracket-col {
  display: flex;
  flex-direction: column;
  min-width: 300px;
  position: relative;
  z-index: 1; /* colonnes au-dessus des traits */
}
.bracket-col-label {
  flex: 0 0 auto;
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 700;
  text-align: center;
}
/* la zone des matchs : même hauteur partout, répartition régulière
   => un match d'un tour s'aligne au milieu de ses deux nourriciers */
.bracket-col-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

.tie { display: flex; flex-direction: column; }
.tie-date {
  font-size: 11px;
  color: var(--text-soft);
  margin: 0 6px 4px;
}
.tie-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;        /* coins arrondis comme le modèle */
  box-shadow: var(--shadow);
  padding: 9px 16px;
}
.tie.soon .tie-box { border-color: var(--warn); background: var(--warn-bg); }
.tie.live .tie-box { border-color: var(--live); background: var(--live-bg); }
.tie-side { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.tie-side.right { justify-content: flex-end; }
.tie-side img { width: 26px; height: auto; border-radius: 3px; cursor: pointer; }
.tie-side .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.tie-side .placeholder { color: var(--text-soft); font-style: italic; }
.tie-side.winner .name { font-weight: 800; }
.tie-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 15px;
}
.tie-score .vs { color: var(--text-soft); font-weight: 400; font-size: 13px; }

/* --- Panneau flottant : prochains matchs --- */
.next-panel {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 300px;
  max-width: 42vw;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 20;
}
.next-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--card-head);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.next-title { font-size: 13px; font-weight: 700; }
.next-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text); font-size: 14px; line-height: 1; padding: 2px 4px;
}
.next-panel.collapsed .next-head { border-bottom: none; }
.next-panel.collapsed .next-body { display: none; }
.next-body { max-height: 320px; overflow-y: auto; padding: 4px; }
.next-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px; font-size: 13px;
}
.next-row + .next-row { border-top: 1px solid var(--border); }
.next-time {
  flex: 0 0 auto; width: 40px;
  font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text-soft);
}
.next-teams { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; }
.next-teams img { width: 20px; height: auto; border-radius: 3px; cursor: pointer; }
.next-teams .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.next-teams .placeholder { color: var(--text-soft); font-style: italic; }
.next-vs { color: var(--text-soft); flex: 0 0 auto; }
.next-empty { padding: 12px; color: var(--text-soft); font-size: 13px; }
/* états : orange <24h, rouge en cours */
.next-row.soon, .next-row.soon .next-time { color: var(--warn); font-weight: 600; }
.next-row.live, .next-row.live .next-time { color: var(--live); font-weight: 600; }

/* --- Contrôles zoom --- */
.zoom-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
}
.zoom-level { font-size: 11px; color: var(--text-soft); }

/* --- Loader --- */
.loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-soft);
  font-size: 15px;
  z-index: 10;
}
.loader.hidden { display: none; }
.loader.error { color: var(--live); }

/* --- Mobile --- */
@media (max-width: 640px) {
  /* la sidebar occupe toute la largeur de l'écran */
  .sidebar { width: 100vw; max-width: 100vw; border-right: none; }

  /* panneaux flottants moins envahissants sur petit écran */
  .next-panel { width: auto; left: 12px; right: 12px; max-width: none; }

  /* zoom au doigt (pinch) sur mobile : on masque les boutons */
  .zoom-controls { display: none; }
}
