/* ═══════════════════════════════════════════════════════════════════ */
/* RESPONSIVE DESIGN AMÉLIORÉ - COMPÉTITIONS SUR MOBILE             */
/* ═══════════════════════════════════════════════════════════════════ */

/* Breakpoints:
   - Desktop: > 1024px (aucun changement)
   - Tablet: 768px - 1024px (légères adaptations)
   - Mobile: 480px - 768px (adaptations majeures)
   - Small Mobile: < 480px (ultra-mobile friendly)
*/

/* ─────────────────────────────────────────────────────────────────── */
/* ANTI-ZOOM MOBILE - Assurer pas de débordement horizontal           */
/* ─────────────────────────────────────────────────────────────────── */

/* S'assurer que TOUT le contenu rentre dans la viewport sans débordement
   Le navigateur ne doit pas zoomer automatiquement */

@media (max-width: 768px) {
  html, body {
    max-width: 100vw;
    overflow-x: hidden;
  }

  body {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* Assurer que les balises sont lisibles */
  h1, h2, h3, h4, h5, h6 {
    font-size: inherit;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* S'assurer que le texte input ne force pas le zoom */
  input, select, textarea {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* Empêcher débordement horizontal sur tous les éléments */
  * {
    max-width: 100%;
  }

  /* Assurer que les images ne débordent pas */
  img {
    max-width: 100%;
    height: auto;
    display: block;
  }

  /* Les conteneurs doivent rester dans les limites */
  .comp-detail-container,
  .comp-detail-header,
  .poule-section,
  .tireurs-grid,
  main,
  article,
  section,
  aside,
  div {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Assurer que les tableaux ne débordent pas */
  table, thead, tbody, tfoot, tr, td, th {
    max-width: 100%;
    word-break: break-word;
  }
}

/* ─────────────────────────────────────────────────────────────────── */
/* TABLETTE (768px - 1024px) */
/* ─────────────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .comp-detail-container {
    padding: 1.25rem;
  }

  .poule-section {
    padding: 1.25rem;
  }

  .poule-results-table {
    font-size: 0.85rem;
  }

  .poule-results-table th,
  .poule-results-table td {
    padding: 0.6rem 0.5rem;
  }
}

/* ─────────────────────────────────────────────────────────────────── */
/* MOBILE STANDARD (480px - 768px) */
/* ─────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  /* ─── Poules - Tableau sur mobile en cartes ─── */
  .poule-results-table {
    display: block;
    font-size: 0.8rem;
    overflow: visible;
    margin-bottom: 1rem;
  }

  .poule-results-table thead {
    display: none;
  }

  .poule-results-table tbody {
    display: block;
  }

  .poule-results-table tr {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    align-content: start;
  }

  .poule-results-table td {
    display: contents;
  }

  .poule-results-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    grid-column: 1;
  }

  .poule-results-table td {
    grid-column: 2;
    padding: 0;
    border: none;
    margin-bottom: 0.5rem;
  }

  /* Rang - First cell */
  .rank-cell {
    grid-column: 1 / -1;
    background: var(--primary-color);
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    text-align: center;
    font-weight: 700;
    margin-bottom: 0.5rem;
  }

  .rank-cell::before {
    content: "Classement";
  }

  .tireur-name-cell {
    font-weight: 600;
    grid-column: 1 / -1;
  }

  .tireur-name-cell::before {
    content: "Tireur";
  }

  .stat-cell {
    text-align: right;
  }

  .index-cell {
    background: var(--secondary-bg);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
  }

  /* ─── Matchs layout on mobile ─── */
  .match-item {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    align-items: stretch;
  }

  .match-player {
    width: 100%;
  }

  .match-score {
    background: var(--secondary-bg);
    padding: 0.5rem;
    border-radius: 4px;
  }

  /* ─── Poule timing stack ─── */
  .poule-timing {
    flex-direction: column;
    gap: 0.5rem;
  }

  .poule-timing-item {
    flex-direction: column;
    gap: 0;
  }

  /* ─── Tableau pagination/scrolling ─── */
  .competitions-table {
    font-size: 0.8rem;
  }

  .competitions-table th,
  .competitions-table td {
    padding: 0.5rem 0.75rem;
  }

  .table-title {
    min-width: 150px;
  }

  .table-actions {
    flex-direction: column;
    gap: 0.25rem;
  }

  .table-actions .btn-small {
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    width: 100%;
  }
}

/* ─────────────────────────────────────────────────────────────────── */
/* PETIT MOBILE (< 480px) */
/* ─────────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  /* ─── Layout général ─── */
  .comp-detail-container {
    padding: 0.75rem;
  }

  .poule-section {
    padding: 0.75rem;
    border-radius: 6px;
  }

  /* ─── En-têête plus compact ─── */
  .comp-detail-header h1 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
  }

  .comp-detail-meta {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .meta-item label {
    font-size: 0.7rem;
  }

  .meta-item value {
    font-size: 0.95rem;
  }

  /* ─── Tabs - Stack verticalement si nécessaire ─── */
  .comp-tabs-nav {
    gap: 0;
    margin-bottom: 0.75rem;
    -webkit-overflow-scrolling: touch;
  }

  .comp-tabs-nav button {
    padding: 0.65rem 0.75rem;
    font-size: 0.75rem;
    flex-shrink: 0;
  }

  /* ─── Tireurs grid - 1 colonne ─── */
  .tireurs-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .tireur-card {
    padding: 0.75rem;
    border-radius: 6px;
  }

  .tireur-card-name {
    font-size: 0.9rem;
  }

  .tireur-card-licence {
    font-size: 0.65rem;
    padding: 0.3rem 0.5rem;
  }

  .tireur-category {
    font-size: 0.8rem;
    padding: 0.5rem;
  }

  .tireur-country {
    font-size: 2rem;
  }

  /* ─── Poules - Layout ultra-compact ─── */
  .poule-header {
    grid-template-columns: 35px 1fr;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
  }

  .poule-number {
    width: 35px;
    height: 35px;
    font-size: 0.8rem;
    flex-shrink: 0;
  }

  .poule-info h3 {
    font-size: 0.85rem;
    margin-bottom: 0.15rem;
  }

  .poule-info p {
    font-size: 0.7rem;
  }

  .poule-timing {
    grid-column: 1 / -1;
    gap: 0.5rem;
    font-size: 0.7rem;
    margin-top: 0.5rem;
  }

  .poule-timing-item {
    gap: 0.25rem;
  }

  /* ─── Tableau results - Cartes compactes ─── */
  .poule-results-table {
    font-size: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .poule-results-table tr {
    grid-template-columns: 35px 1fr;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 5px;
  }

  .rank-cell {
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    grid-column: 1;
    grid-row: 1 / 3;
  }

  .tireur-name-cell {
    grid-column: 2;
    font-size: 0.8rem;
  }

  .tireur-name-cell::before {
    content: none;
  }

  .stat-cell,
  .index-cell {
    font-size: 0.7rem;
    padding: 0.2rem 0.3rem;
  }

  /* ─── Matchs - Cartes empilées ─── */
  .match-item {
    grid-template-columns: 1fr;
    gap: 0.4rem;
    padding: 0.5rem;
    font-size: 0.7rem;
  }

  .match-player {
    padding: 0.5rem;
    font-size: 0.7rem;
  }

  .match-score {
    font-size: 0.85rem;
    padding: 0.4rem;
  }

  .match-detail {
    font-size: 0.65rem;
  }

  /* ─── Section générale compacts ─── */
  .poules-container {
    gap: 1rem;
  }

  .comp-tab-content {
    padding: 0;
  }

  /* ─── Classement scissions - Ultra compact ─── */
  .classement-container-double {
    gap: 1rem;
  }

  .classement-tableau-header {
    padding: 0.75rem 1rem;
  }

  .classement-tableau-header h3 {
    font-size: 0.95rem;
    gap: 0.25rem;
  }

  .classement-table-scission th,
  .classement-table-scission td {
    padding: 0.4rem 0.35rem;
    font-size: 0.7rem;
  }

  .classement-rank-scission {
    width: 30px;
    font-size: 0.7rem;
  }

  .classement-rank-scission.gold,
  .classement-rank-scission.silver,
  .classement-rank-scission.bronze {
    font-size: 1rem;
  }

  .classement-tireur-name-scission {
    font-size: 0.75rem;
  }

  .classement-tireur-club-scission {
    font-size: 0.65rem;
  }

  .classement-tireur-category-scission {
    font-size: 0.65rem;
  }

  /* ─── Tournoi bracket - Scroll horizontal ─── */
  .bracket-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-height: auto;
  }

  .bracket-round {
    min-width: 150px;
  }

  .bracket-match {
    font-size: 0.7rem;
  }

  .bracket-player-name {
    font-size: 0.65rem;
  }

  .bracket-score {
    font-size: 0.75rem;
    padding: 0.2rem 0.4rem;
  }

  /* ─── Responsive text ─── */
  .poule-results-table td::before {
    font-size: 0.65rem;
  }

  /* ─── Boutons - Full width sur mobile ─── */
  .btn-small {
    width: 100%;
    display: block;
    margin-bottom: 0.25rem;
  }

  .btn-small:last-child {
    margin-bottom: 0;
  }
}

/* ─────────────────────────────────────────────────────────────────── */
/* OPTIMISATIONS POUR LES INDEX/LISTES DE COMPÉTITIONS */
/* ─────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .competition-folder {
    margin-bottom: 1rem;
  }

  .folder-header {
    padding: 1.25rem;
  }

  .folder-info {
    padding: 1.25rem;
  }

  .folder-footer {
    flex-direction: column;
    gap: 0.5rem;
  }

  .competitions-list.card-view {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
  }

  .competition-card header {
    padding: 1rem;
  }

  .competition-card h3 {
    gap: 0.5rem;
  }

  .competition-info {
    padding: 1rem;
  }

  .info-row {
    grid-template-columns: 100px 1fr;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
  }

  .competition-footer {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) {
  /* Page index compétitions */
  .search-controls {
    flex-direction: column;
    gap: 0.75rem;
  }

  .search-bar {
    max-width: 100%;
  }

  .search-bar input {
    font-size: 1rem;
    padding: 0.65rem 1rem;
  }

  .view-toggle {
    width: 100%;
    justify-content: stretch;
  }

  .view-toggle-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }

  .filters {
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
  }

  .filter-btn {
    width: 100%;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
  }

  /* Modal sur mobile */
  .modal-overlay.active {
    padding-top: 0;
    align-items: flex-start;
  }

  .modal-content {
    max-width: 100%;
    width: 100%;
    max-height: 100vh;
    border-radius: 12px 12px 0 0;
    margin-top: 60px;
  }

  .modal-header {
    padding: 1rem;
    gap: 0.5rem;
  }

  .modal-header h2 {
    font-size: 1.1rem;
  }

  .modal-close-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .competitions-in-folder {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .competition-folder {
    margin-bottom: 0.75rem;
  }

  .folder-header {
    padding: 1rem;
  }

  .folder-title {
    font-size: 1rem;
    gap: 0.5rem;
  }

  .folder-count-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.6rem;
  }

  .folder-info {
    padding: 1rem;
  }

  .info-row {
    grid-template-columns: 80px 1fr;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
  }

  .folder-footer {
    padding: 0.75rem 1rem;
  }

  .btn-small {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    flex: 1;
  }

  .table-actions {
    flex-direction: column;
    gap: 0.25rem;
  }

  .table-actions .btn-small {
    width: 100%;
  }

  /* Tableau - conversion en scroll horizontal */
  .competitions-list.list-view {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .competitions-table {
    font-size: 0.75rem;
    min-width: 650px;
  }

  .competitions-table th,
  .competitions-table td {
    padding: 0.4rem 0.5rem;
    white-space: nowrap;
  }

  .table-title {
    min-width: 120px;
  }

  .status-badge,
  .competition-status {
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
  }
}

/* ─────────────────────────────────────────────────────────────────── */
/* UTILITAIRES POUR LES TRÈS PETITS ÉCRANS */
/* ─────────────────────────────────────────────────────────────────── */

@media (max-width: 360px) {
  body {
    font-size: 14px;
  }

  .comp-detail-container {
    padding: 0.5rem;
  }

  .comp-detail-header {
    padding: 1rem 0.75rem;
    margin-bottom: 0.75rem;
  }

  .comp-detail-header h1 {
    font-size: 1.1rem;
    margin-bottom: 0.4rem;
  }

  .comp-tabs-nav {
    margin-bottom: 0.5rem;
  }

  .comp-tabs-nav button {
    padding: 0.5rem 0.65rem;
    font-size: 0.7rem;
  }

  .poule-section {
    padding: 0.5rem;
  }

  .poule-number {
    width: 30px;
    height: 30px;
    font-size: 0.75rem;
  }

  .poule-info h3 {
    font-size: 0.8rem;
  }

  .tireur-card {
    padding: 0.65rem;
  }

  .tireur-card-name {
    font-size: 0.85rem;
  }

  .info-row {
    grid-template-columns: 70px 1fr;
    gap: 0.5rem;
  }

  .info-label,
  .info-value {
    font-size: 0.8rem;
  }
}
