/* ==========================================================================
   Olidarts — Base / chrome partagé (reset, header, nav, footer, composants)
   Dépend de tokens.css.
   ========================================================================== */

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { color: #fff; line-height: 1.2; }
img { display: block; }

/* ---- Utilitaires ---- */
.container { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 0 2rem; }
.mono  { font-family: var(--font-mono); }
.muted { color: var(--text-muted); }
.gold  { color: var(--primary); }
main   { flex: 1; }

/* ---- Titre de page partagé (classements, tournois, parties, stats, compte…) ---- */
.page-title-section { padding: 2.5rem 0 1.5rem; border-bottom: 1px solid var(--border); margin-bottom: 2rem; }
.page-title {
  font-size: clamp(2rem, 4vw, 3rem); font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.08em; color: #fff; line-height: 1;
}

/* ---- Accessibilité (§J3) ---- */
/* Contenu réservé aux lecteurs d'écran (masqué visuellement). */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
/* Anneau de focus visible au clavier uniquement (pas au clic souris). */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 3px;
}
:focus:not(:focus-visible) { outline: none; }
/* Lien d'évitement : caché jusqu'au focus clavier. */
.skip-link {
  position: fixed; top: 0; left: 0; z-index: var(--z-skip);
  transform: translateY(-120%);
  background: var(--primary); color: #000; font-weight: 700;
  padding: 0.6rem 1rem; border-radius: 0 0 var(--radius-sm) 0;
  transition: transform 0.15s;
}
.skip-link:focus { transform: translateY(0); }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---- Header ---- */
.site-header {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--content-max); margin: 0 auto;
  height: var(--header-h); padding: 0 2rem;
  display: flex; align-items: center; gap: 2rem;
}
.logo { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.logo img { height: 32px; width: 32px; object-fit: contain; }
.logo-name { font-size: 1.2rem; font-weight: 700; color: var(--primary); letter-spacing: 0.02em; }

.main-nav { display: flex; gap: 0.25rem; flex: 1; }
.main-nav a {
  color: var(--text-muted); font-size: 0.875rem; font-weight: 500;
  padding: 0.4rem 0.75rem; border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.main-nav a:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.05); }
.main-nav a.active { color: var(--primary); }

.header-actions { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; }

/* ---- Bouton menu burger (mobile) ---- */
/* Masqué en desktop ; révélé en <=768px par le bloc responsif. */
.nav-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 40px; height: 40px; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-primary); cursor: pointer;
}
.nav-toggle:hover { background: rgba(255, 255, 255, 0.1); }
/* Trois barres : la barre centrale est l'élément, les deux autres ses pseudo-éléments. */
.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: ''; display: block;
  width: 18px; height: 2px; border-radius: 2px;
  background: currentColor;
  transition: transform 0.25s ease, background 0.2s ease;
}
.nav-toggle-bars { position: relative; }
.nav-toggle-bars::before { position: absolute; top: -6px; left: 0; }
.nav-toggle-bars::after  { position: absolute; top:  6px; left: 0; }
/* Ouvert : la barre centrale disparaît, les deux autres forment une croix. */
.site-header.nav-open .nav-toggle-bars { background: transparent; }
.site-header.nav-open .nav-toggle-bars::before { transform: translateY(6px)  rotate(45deg); }
.site-header.nav-open .nav-toggle-bars::after  { transform: translateY(-6px) rotate(-45deg); }

.search-box {
  position: relative;
  display: flex; align-items: center; gap: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  transition: border-color 0.15s;
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-dim); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  background: none; border: none; outline: none;
  color: var(--text-primary); font-family: inherit; font-size: 0.875rem; width: 160px;
}
.search-box input::placeholder { color: var(--text-sub); }
.search-box input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ---- Résultats de recherche (§F3) ---- */
.search-results { position: absolute; top: calc(100% + 6px); right: 0; z-index: var(--z-dropdown); }
/* Masquer le menu quand la barre n'a pas le focus (survol conservé pour cliquer). */
.search-box:not(:focus-within) .search-results:not(:hover) { display: none; }
.search-menu {
  min-width: 260px; max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-glow, 0 10px 40px rgba(0,0,0,0.5));
  padding: 0.35rem;
}
.search-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.5rem 0.6rem; border-radius: var(--radius-sm);
  transition: background 0.12s;
}
.search-item:hover { background: var(--surface-2); }
.search-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  font-size: 0.66rem; font-weight: 700; color: #000;
}
.search-item-main { display: flex; flex-direction: column; min-width: 0; }
.search-item-name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.search-item-sub { font-size: 0.72rem; color: var(--text-muted); }
.search-empty { padding: 0.75rem 0.6rem; font-size: 0.82rem; color: var(--text-sub); text-align: center; }

/* ---- Barre de chargement globale (§F4) ---- */
html.htmx-loading::after {
  content: ''; position: fixed; top: 0; left: 0; z-index: var(--z-loading);
  height: 2px; width: 100%;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: load-slide 0.9s ease-in-out infinite;
}
@keyframes load-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ---- Toasts (§F4) ---- */
.toast-box {
  position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: 0.5rem; max-width: min(90vw, 360px);
}
.toast {
  padding: 0.7rem 1rem; border-radius: var(--radius);
  font-size: 0.85rem; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 8px 30px rgba(0,0,0,0.45);
  opacity: 0; transform: translateY(8px); transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }

.btn-login {
  color: var(--primary); border: 1px solid var(--primary-border);
  padding: 0.35rem 0.9rem; border-radius: var(--radius-sm);
  font-size: 0.85rem; font-weight: 600;
}
.btn-login:hover { background: var(--primary-dim); }

/* ---- Sélecteur de langue (§J2) ---- */
.lang-switch { display: flex; gap: 2px; flex-shrink: 0; }
.lang-opt {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  color: var(--text-sub); padding: 0.25rem 0.45rem; border-radius: var(--radius-sm);
  transition: color 0.12s, background 0.12s;
}
.lang-opt:hover { color: var(--text-primary); background: var(--surface-2); }
.lang-opt.active { color: #000; background: var(--primary); }

.user-chip { display: flex; align-items: center; gap: 0.5rem; }
.user-chip .name { font-size: 0.85rem; font-weight: 600; }

/* ---- Avatar ---- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  font-family: var(--font-sans); font-size: 0.72rem; font-weight: 700;
  color: #000; flex-shrink: 0;
}

/* ---- Boutons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  cursor: pointer; border: none; border-radius: var(--radius-sm);
  padding: 0.55rem 1rem; font-family: var(--font-sans);
  font-size: 0.85rem; font-weight: 600;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.btn-primary   { background: var(--primary); color: #000; }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 85%, white); transform: translateY(-1px); }
.btn-secondary { background: var(--surface-2); color: var(--text-primary); }
.btn-ghost     { background: transparent; border: 1px solid var(--primary-border); color: var(--primary); }
.btn-ghost:hover { background: var(--primary-dim); }
.btn-danger    { background: var(--danger); color: #fff; }

/* ---- Badges / chips ---- */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.6rem; border-radius: var(--radius-sm);
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
}
.badge-live     { background: color-mix(in srgb, var(--danger) 15%, transparent);   color: var(--danger); }
.badge-upcoming { background: color-mix(in srgb, var(--player-b) 15%, transparent); color: var(--player-b); }
.badge-done     { background: rgba(255, 255, 255, 0.06); color: var(--text-muted); }
/* Créneau d'un match (planification) : accord acquis / réponse attendue / rien d'engagé.
   Même palette que les statuts ci-dessus, pour que la page ne gagne pas un code couleur. */
.badge-confirmed { background: color-mix(in srgb, var(--primary) 15%, transparent); color: var(--primary); }
.badge-proposed  { background: color-mix(in srgb, var(--player-b) 15%, transparent); color: var(--player-b); }
.badge-none      { background: rgba(255, 255, 255, 0.06); color: var(--text-muted); }
.level-chip {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: var(--radius-sm);
  background: var(--surface-2); font-family: var(--font-mono);
  font-size: 0.72rem; color: var(--text-muted);
}

/* ---- Cartes ---- */
.card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.5rem;
}
.card-glass {
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-color: var(--primary-border);
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}
.card-glass:hover { box-shadow: var(--shadow-glow); transform: translateY(-2px); }

/* ---- Tables ---- */
table.data { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data thead th {
  text-align: left; padding: 0.6rem 0.9rem;
  font-size: 0.65rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data tbody td { padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* ---- Footer ---- */
.site-footer { border-top: 1px solid var(--border); padding: 2rem; margin-top: 3rem; }
.footer-inner {
  max-width: var(--content-max); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem;
}
.footer-logo { display: flex; align-items: center; gap: 0.5rem; }
.footer-logo img { height: 22px; opacity: 0.6; }
.footer-logo span { color: var(--text-sub); font-size: 0.82rem; }
.footer-links { display: flex; gap: 1.5rem; }
.footer-links a { color: var(--text-sub); font-size: 0.8rem; }
.footer-links a:hover { color: var(--text-muted); }
.footer-copy { color: var(--text-sub); font-size: 0.8rem; font-family: var(--font-mono); }

/* ---- Page simple (accueil provisoire, 404/500) ---- */
.hello { max-width: 640px; margin: 12vh auto 0; padding: 2rem; text-align: center; }
.hello h1 { color: var(--primary); font-size: 2.4rem; margin-bottom: 0.5rem; }
.hello .tagline { color: var(--text-muted); margin-bottom: 2rem; }
.hello a { color: var(--primary); }
.hello a:hover { text-decoration: underline; }
.value { color: var(--primary); font-weight: 600; }

/* ---- Page de connexion (/auth) ---- */
.auth-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - var(--header-h) - 140px); padding: 2rem;
}
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card h1 { color: var(--primary); font-size: 1.6rem; margin-bottom: 0.5rem; }
.auth-card .sub { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.auth-card form { display: flex; flex-direction: column; gap: 0.9rem; }
.code-input {
  width: 100%; text-align: center; letter-spacing: 0.4em; text-transform: uppercase;
  font-family: var(--font-mono); font-size: 1.4rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary); padding: 0.8rem;
}
.code-input:focus { border-color: var(--primary); }
.code-input::placeholder { color: var(--text-sub); letter-spacing: 0.3em; }
.auth-error { color: var(--danger-text); font-size: 0.85rem; }
/* Erreur inline sous un champ (validation progressive, §RT3). min-height réserve
   la place pour éviter un saut de mise en page quand le message apparaît. */
.field-error { color: var(--danger-text); font-size: 0.8rem; min-height: 1.1em; margin-top: -0.3rem; }
.auth-hint { margin-top: 1.5rem; font-size: 0.8rem; color: var(--text-sub); }

/* Champs email / mot de passe (login + dashboard) */
.auth-field { display: flex; flex-direction: column; gap: 0.3rem; text-align: left; }
.auth-field > span { font-size: 0.8rem; color: var(--text-muted); }
.auth-field input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary);
  padding: 0.65rem 0.8rem; font-size: 1rem;
}
.auth-field input:focus { border-color: var(--primary); outline: none; }
/* Séparateur « ou » entre les deux méthodes de connexion */
.auth-sep {
  display: flex; align-items: center; gap: 0.75rem; margin: 0.4rem 0;
  color: var(--text-sub); font-size: 0.8rem; text-transform: uppercase;
}
.auth-sep::before, .auth-sep::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

/* Bandeau de retour + formulaire mot de passe du dashboard */
.dash-notice {
  padding: 0.75rem 1rem; border-radius: var(--radius);
  margin-bottom: 1rem; font-size: 0.9rem;
}
.dash-notice.ok  { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.dash-notice.err { background: var(--focus-bg); color: var(--danger); border: 1px solid var(--danger); }
.pw-form {
  display: flex; flex-direction: column; gap: 0.8rem;
  max-width: 420px; margin-top: 1rem;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .search-box { display: none; }
  .container { padding: 0 1rem; }        /* 2rem ronge trop l'espace sur petit écran */
  .header-inner { gap: 1rem; padding: 0 1rem; }
  .site-footer { padding: 1.5rem 1rem; }
  .header-actions { margin-left: auto; } /* pousse actions + burger à droite (la nav ne fait plus office de spacer) */
  .nav-toggle { display: inline-flex; }
  .footer-inner { flex-direction: column; text-align: center; }

  /* La nav devient un tiroir déroulant sous le header, ouvert par le burger. */
  .main-nav {
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 0.15rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    /* État fermé : masqué et légèrement remonté, pour une transition douce. */
    opacity: 0; visibility: hidden; transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  }
  .site-header.nav-open .main-nav {
    opacity: 1; visibility: visible; transform: translateY(0);
  }
  .main-nav a {
    padding: 0.85rem 1rem; font-size: 1rem;
    border-radius: var(--radius-sm);
  }
  .main-nav a.active { background: rgba(255, 255, 255, 0.05); }
}

/* Très petits écrans : logo en icône seule pour garantir que le header (logo +
   langue + connexion + burger) ne déborde jamais en scroll horizontal. */
@media (max-width: 400px) {
  .logo-name { display: none; }
  .header-actions { gap: 0.6rem; }
}

/* ---- Cibles tactiles (§adapt) ----
   Sur pointeur grossier (tactile / stylet), garantir des cibles ≥44px sans
   alourdir l'UI dense au pointeur fin (souris/trackpad). On ne détecte pas la
   taille d'écran mais la méthode de saisie : un portable tactile en profite. */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .lang-opt {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 44px; padding: 0.25rem 0.7rem;
  }
  .nav-toggle { width: 44px; height: 44px; }
  .btn-login { padding: 0.6rem 1rem; }
}
