*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #004d98;
  --primary-l: #1565c0;
  --accent:    #a50044;
  --bg:        #f0f2f8;
  --surface:   #fff;
  --border:    #dce3ee;
  --text:      #1a1a1a;
  --muted:     #666;
  --radius:    10px;
  --shadow:    0 2px 10px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ===== HEADER ===== */
.header {
  background: var(--primary);
  color: #fff;
  padding: 1.25rem 1rem .75rem;
  text-align: center;
}
.header h1 { font-size: 1.4rem; font-weight: 700; }
.header p  { font-size: .85rem; opacity: .8; margin-top: .2rem; }

.header-tournoi {
  position: relative;
  padding-top: 1rem;
  padding-bottom: .75rem;
}
.btn-back {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,.18);
  border: none;
  color: #fff;
  padding: .35rem .7rem;
  border-radius: 6px;
  font-size: .82rem;
  cursor: pointer;
  white-space: nowrap;
}

/* ===== ACCUEIL TOURNOIS ===== */
.home-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}
.home-section-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .85rem;
  padding: 0 .1rem;
}
.home-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  font-size: .95rem;
}

.tournoi-card {
  background: #fff;
  border-radius: 12px;
  border-left: 5px solid #ddd;
  box-shadow: 0 2px 12px rgba(0,0,0,.07);
  padding: 1rem 1.1rem;
  margin-bottom: .9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s, box-shadow .1s;
}
.tournoi-card.actif { border-left-color: var(--primary); }
.tournoi-card:active { transform: scale(.985); box-shadow: 0 1px 6px rgba(0,0,0,.08); }

.tc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .55rem;
}
.tc-status {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .75rem;
  font-weight: 700;
}
.tc-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tc-dot-live { background: #43a047; animation: blink .9s infinite alternate; }
.tc-dot-end  { background: #bbb; }
.tc-dot-live + span { color: var(--primary); }
.tc-dot-end  + span { color: #aaa; }
@keyframes blink { from { opacity: 1; } to { opacity: .3; } }

.tc-date { font-size: .78rem; color: var(--muted); }
.tc-nom  { font-size: 1.1rem; font-weight: 700; color: var(--text); line-height: 1.25; margin-bottom: .5rem; }
.tc-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tc-meta { font-size: .82rem; color: var(--muted); }
.tc-cta  { font-size: .85rem; font-weight: 700; color: var(--primary); white-space: nowrap; }

/* ===== PLAN TERRAINS ===== */
.terrains-plan {
  padding: 1.25rem 1rem 2rem;
  max-width: 680px;
  margin: 0 auto;
}
.terrain-section { margin-bottom: 1.75rem; }
.terrain-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
  padding: .5rem 1.4rem .45rem;
  border-radius: 8px;
  margin-bottom: .65rem;
  text-align: center;
}
.terrain-header strong { font-size: .95rem; font-weight: 800; letter-spacing: .08em; }
.terrain-header em     { font-size: .78rem; font-weight: 400; opacity: .85; margin-top: .1rem; }
.terrain-h  { background: #002b6b; }
.terrain-k  { background: #1a5e20; }
.terrain-svg {
  width: 100%;
  display: block;
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(0,0,0,.18);
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  background: var(--primary-l);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab {
  flex: 1;
  padding: .75rem .5rem;
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: .2s;
}
.tab.active {
  color: #fff;
  border-bottom-color: var(--accent);
}

/* ===== ADMIN TABS ===== */
.admin-tabs {
  display: flex;
  background: #fff;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
}
.admin-tab {
  padding: .75rem 1.25rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
  margin-bottom: -2px;
}
.admin-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ===== PANELS ===== */
.tab-panel { padding: 1rem; }

/* ===== STANDINGS ===== */
.groupe-block { margin-bottom: 1.5rem; }
.groupe-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: .5rem;
}
.standings-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: .88rem;
}
.standings-table th {
  background: var(--primary);
  color: #fff;
  padding: .5rem .6rem;
  text-align: center;
  font-weight: 600;
}
.standings-table th:first-child { text-align: left; padding-left: .75rem; }
.standings-table td {
  padding: .55rem .6rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.standings-table td:first-child { text-align: left; padding-left: .75rem; font-weight: 600; }
.standings-table tr:last-child td { border-bottom: none; }
.standings-table tr.qualifie td:first-child { border-left: 3px solid var(--accent); }
.pts-col { font-weight: 700; color: var(--primary); }

/* ===== MATCH CARDS ===== */
.phase-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 1rem 0 .5rem;
}
.match-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .75rem 1rem;
  margin-bottom: .65rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .5rem;
}
.match-card.en-cours { border-left: 4px solid var(--accent); }
.match-card.termine  { border-left: 4px solid var(--primary); }
.match-card.planifie { border-left: 4px solid #ccc; }

.team-name { font-weight: 600; font-size: .95rem; }
.team-name.right { text-align: right; }

.score-box {
  text-align: center;
  min-width: 60px;
}
.score-val {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: .05em;
}
.score-meta {
  font-size: .72rem;
  color: var(--muted);
  margin-top: .1rem;
}
.badge-phase {
  font-size: .7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e8f5e9;
  color: var(--primary);
  display: inline-block;
  margin-top: .25rem;
}
.badge-en-cours { background: #fff0f3; color: var(--accent); }

/* ===== ADMIN FORMS ===== */
.page-section {
  max-width: 700px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--primary);
}
.form-group { margin-bottom: .9rem; }
.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .3rem;
  color: #444;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
  background: #fff;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .6rem 1.25rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary:hover { background: var(--primary-l); }
.btn-secondary {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  padding: .55rem 1rem;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-danger {
  background: #fff;
  color: #c62828;
  border: 1.5px solid #e57373;
  border-radius: 8px;
  padding: .4rem .75rem;
  font-size: .85rem;
  cursor: pointer;
  font-family: inherit;
}
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }

/* ===== LISTS ===== */
.item-list { margin-top: .75rem; }
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .9rem;
  margin-bottom: .4rem;
  gap: .5rem;
}
.item-label { font-weight: 600; }
.item-sub   { font-size: .8rem; color: var(--muted); }
.item-actions { display: flex; gap: .4rem; flex-shrink: 0; }

/* ===== SCORE EDITOR ===== */
.score-editor {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.score-editor input[type=number] {
  width: 52px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  padding: .3rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
}
.score-sep { font-weight: 700; color: var(--muted); }

/* ===== QR ===== */
.qr-section { text-align: center; padding: 1.5rem 1rem; }
.qr-section canvas { margin: 1rem auto; display: block; }
.qr-url {
  font-size: .8rem;
  color: var(--muted);
  word-break: break-all;
  margin: .5rem 0 1rem;
}

/* ===== LOGIN ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 380px;
}
.login-card h2 { color: var(--primary); margin-bottom: 1.25rem; font-size: 1.2rem; }

/* ===== ADMIN TOPBAR ===== */
.admin-topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
}
.admin-topbar h1 { font-size: 1rem; font-weight: 700; }
.admin-topbar button {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  padding: .4rem .8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
}

/* ===== ALERTS ===== */
.alert { padding: .6rem .9rem; border-radius: 8px; font-size: .88rem; margin: .5rem 0; }
.alert-success { background: #e8f5e9; color: #2e7d32; }
.alert-error   { background: #ffebee; color: #c62828; }

/* ===== EMPTY STATE ===== */
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: .9rem; }

/* ===== MATCH EDIT CARD ===== */
.match-edit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: .6rem;
  box-shadow: var(--shadow);
}
.match-edit-teams {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .25rem;
  margin-bottom: .6rem;
  font-size: .95rem;
}
.match-edit-fields {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}
@media (max-width: 500px) {
  .match-edit-fields { gap: .4rem; }
  .match-edit-fields input[type=time],
  .match-edit-fields select { font-size: .8rem; }
  .admin-tabs { font-size: .8rem; }
  .admin-tab  { padding: .6rem .75rem; }
  .page-section { padding: .75rem .75rem; }
  .gen-block { padding: .75rem; background: #f0f2f8; border-radius: var(--radius); border: 1px solid var(--border); }
}

/* ===== TOURNOI ACTIF ===== */
.item-row-actif {
  background: #e3eeff;
  border-color: var(--primary);
  border-left: 4px solid var(--primary);
}
.item-row-actif .item-label { color: var(--primary); font-weight: 700; }
.badge-actif {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  padding: .25rem .65rem;
  border-radius: 20px;
}

/* ===== STATUS BADGE ===== */
.status-badge {
  font-size: .72rem;
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 600;
}
.status-planifie  { background: #f5f5f5; color: #666; }
.status-en_cours  { background: #fff0f3; color: var(--accent); }
.status-termine   { background: #e3eeff; color: var(--primary); }

/* ===== BRACKET PHASES FINALES ===== */
.bracket-phase { margin-bottom: 1.5rem; }
.bracket-phase-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent);
  margin: 1rem .25rem .5rem;
}
.bracket-match {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .5rem;
  padding: .75rem .9rem;
  margin-bottom: .5rem;
  border-left: 4px solid #ddd;
}
.bracket-match.termine   { border-left-color: var(--primary); }
.bracket-match.en_cours  { border-left-color: var(--accent); }
.bm-team { font-weight: 600; font-size: .95rem; color: var(--muted); }
.bm-team.bm-winner { color: var(--primary); font-weight: 700; }
.bm-team.right { text-align: right; }
.bm-score { text-align: center; min-width: 56px; }
.bm-score-val { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.bm-meta { font-size: .7rem; color: var(--muted); margin-top: .15rem; }
.bracket-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.bracket-empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.bracket-empty p { margin-bottom: .35rem; font-size: .9rem; }
.bracket-sub { font-size: .82rem !important; color: #aaa !important; }

/* ===== BONUS FILLES ===== */
.bonus-wrap {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  color: var(--accent);
  font-weight: 600;
}
.bonus-select {
  padding: .25rem .4rem;
  border: 1.5px solid #f5c6d5;
  border-radius: 6px;
  font-size: .82rem;
  color: var(--accent);
  background: #fff0f5;
  font-weight: 700;
  cursor: pointer;
}
