/* ============================================================
   tournament.css — Styles partagés
   Le Mée Sports Handball — Tournoi
   ============================================================ */

/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #1a4fa0;
  --dark:      #163d7d;
  --light:     #2563c4;
  --bg:        #f5f7fb;
  --card:      #ffffff;
  --border:    #dde3ef;
  --text:      #1e2a3a;
  --text-muted:#6b7a99;
  --danger:    #dc2626;
  --danger-hover:#b91c1c;
  --success:   #16a34a;
  --radius:    12px;
  --shadow:    0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
}

html { font-size: 16px; }

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

/* ── Header ────────────────────────────────────────────── */
.site-header {
  background: var(--primary);
  color: #fff;
  padding: 0 1.5rem;
  box-shadow: 0 2px 12px rgba(26,79,160,0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 68px;
}

.header-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
}

.header-logo-fallback {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.header-titles { flex: 1; }

.header-title {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
}

.header-subtitle {
  font-size: 0.82rem;
  opacity: 0.82;
  margin-top: 1px;
}

.header-nav {
  display: flex;
  gap: 0.25rem;
}

.header-nav a {
  color: rgba(255,255,255,0.88);
  text-decoration: none;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.header-nav a:hover,
.header-nav a.active {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

/* ── Layout principal ──────────────────────────────────── */
.main-content {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.25rem;
}

/* ── Section titles ────────────────────────────────────── */
.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s, box-shadow 0.15s;
  text-decoration: none;
  line-height: 1.4;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--dark); }

.btn-secondary {
  background: #e8edf5;
  color: var(--primary);
}
.btn-secondary:hover { background: #d5ddf0; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover { background: #15803d; }

.btn-sm {
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* ── Forms ──────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,79,160,0.12);
}

input[type="file"] {
  font-size: 0.85rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap { overflow-x: hidden; }

/* Classement des poules : table compacte à largeur fixe */
.standings-table {
  table-layout: fixed;
  width: 100%;
}
.standings-table th,
.standings-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Colonne Équipe prend tout l'espace restant */
.standings-table .col-team  { width: auto; }
.standings-table .col-rank  { width: 28px; }
.standings-table .col-num   { width: 26px; text-align: center; }
.standings-table .col-pts   { width: 30px; text-align: center; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 0.4rem 0.4rem;
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.4rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(26,79,160,0.03); }

.rank-cell {
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  width: 32px;
}

.rank-1 { color: #f59e0b; }
.rank-2 { color: #94a3b8; }
.rank-3 { color: #cd7c2b; }

.team-cell {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
}

.team-avatar {
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
}

.team-logo {
  flex-shrink: 0;
}

.pts-cell {
  font-weight: 700;
  color: var(--primary);
  text-align: center;
}

.num-cell { text-align: center; }

/* ── Matches list (public) ──────────────────────────────── */
.match-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  min-width: 0; /* allow flex children to shrink */
}

.match-row:last-child { border-bottom: none; }

.match-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 38px;
  flex-shrink: 0;
  font-weight: 600;
  text-align: center;
}

.match-team {
  flex: 1;
  min-width: 0; /* critical for ellipsis */
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.match-team.home {
  justify-content: flex-end;
  text-align: right;
}

.match-team.away {
  justify-content: flex-start;
}

/* Nom d'équipe tronqué avec ellipsis */
.match-team-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.match-score {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.15rem 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  min-width: 60px;
  max-width: 60px;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.match-score.played {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Knockout bracket (public) ──────────────────────────── */
.knockout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.ko-match {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.ko-match-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 0.7rem;
}

.ko-match.final { border-color: var(--primary); }
.ko-match.final .ko-match-label { color: var(--primary); }

.ko-team-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0;
  gap: 0.5rem;
}

.ko-team-row + .ko-team-row {
  border-top: 1px solid var(--border);
}

.ko-team-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  font-size: 0.9rem;
  flex: 1;
}

.ko-team-name.tbd { color: var(--text-muted); font-style: italic; font-weight: 400; }

.ko-score {
  font-weight: 700;
  font-size: 1rem;
  color: var(--primary);
  min-width: 24px;
  text-align: center;
}

.winner-badge {
  background: #fef3c7;
  color: #92400e;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.95rem;
}

/* ── Buvette grid ───────────────────────────────────────── */
.buvette-section { margin-bottom: 2rem; }

.buvette-section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--border);
}

.buvette-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
}

.buvette-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  text-align: center;
  transition: box-shadow 0.15s, transform 0.12s;
}

.buvette-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.buvette-emoji {
  font-size: 2.4rem;
  margin-bottom: 0.5rem;
  display: block;
}

.buvette-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.buvette-price {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary);
}

/* ── Admin Tabs ─────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.75rem;
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.75rem 1.25rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color 0.15s;
}

.tab-btn:hover { color: var(--primary); }

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Admin team list ────────────────────────────────────── */
.team-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.team-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
}

.team-item-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.92rem;
}

/* ── Admin score inputs ─────────────────────────────────── */
.match-score-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.match-score-row:last-of-type { border-bottom: none; }

.match-score-team {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 80px;
}

.match-score-team.home { text-align: right; }

.score-input {
  width: 56px !important;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.35rem 0.4rem !important;
}

.score-sep {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-muted);
}

.time-input {
  width: 80px !important;
  font-size: 0.82rem !important;
  padding: 0.35rem 0.5rem !important;
}

/* ── Poule label badge ──────────────────────────────────── */
.pool-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  letter-spacing: 0.3px;
}

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

.alert-info  { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warn  { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-success { background: #f0fdf4; color: #14532d; border: 1px solid #bbf7d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Misc helpers ───────────────────────────────────────── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-gap { gap: 0.75rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }

/* ── Layout résultats (poules + programme côte à côte) ──── */
.results-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.results-main {
  flex: 1;
  min-width: 0;
}

.results-aside {
  width: 300px;
  flex-shrink: 0;
  position: sticky;
  top: 80px; /* sous le header sticky */
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

/* ── Pools grid ─────────────────────────────────────────── */
.pools-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

/* ── Programme des matchs ────────────────────────────────── */
.programme-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.programme-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  padding: 0.85rem 1rem 0.7rem;
  border-bottom: 1px solid var(--border);
}

.programme-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.programme-item:last-child { border-bottom: none; }

.programme-time {
  font-weight: 700;
  color: var(--text-muted);
  min-width: 38px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.programme-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 20px;
  color: #fff;
  white-space: nowrap;
  flex-shrink: 0;
}

.programme-matchup {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 500;
}

.programme-score {
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 0.82rem;
}

/* ── Section classement final (KO) ──────────────────────── */
.ko-classification-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 1rem 0 0.6rem;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (min-width: 640px) {
  .buvette-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .buvette-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 900px) {
  .results-layout {
    flex-direction: column;
  }
  .results-aside {
    width: 100%;
    position: static;
    max-height: none;
  }
  .pools-grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile : programme en premier, puis poules, puis phase finale */
@media (max-width: 767px) {
  .results-aside { order: -1; }
  .results-main  { order:  0; }
}

@media (max-width: 600px) {
  .header-inner { height: auto; padding: 0.75rem 0; flex-wrap: wrap; }
  .header-nav { width: 100%; border-top: 1px solid rgba(255,255,255,0.2); padding-top: 0.5rem; }
  .form-row { grid-template-columns: 1fr; }
  .knockout-grid { grid-template-columns: 1fr; }
  .tabs { -webkit-overflow-scrolling: touch; }
  .tab-btn { padding: 0.65rem 0.9rem; font-size: 0.85rem; }
}

/* ── Print / public clean ───────────────────────────────── */
@media print {
  .site-header { position: static; }
  .btn { display: none; }
}
