/* KAO Planning — Styles de base et tokens de design */

:root {
  /* Thème clair « papier » (direction D) */
  --color-background: #F5F2EA;
  --color-surface: #FBF9F4;
  --color-surface-hover: #EFEBE1;
  --color-border: #E2DCCD;
  --color-foreground: #1A1A1A;
  --color-muted: #7D7668;
  --color-primary: #1A1A1A;
  --color-primary-hover: #3A3A3A;
  --color-on-primary: #F5F2EA;
  --color-success-bg: #E3EBDD; --color-success-fg: #3D5A2E;
  --color-warning-bg: #F6E6D2; --color-warning-fg: #8A4A14;
  --color-danger-bg: #F6DEDA; --color-danger-fg: #9B2C1E; --color-danger-border: #D9A49B;
  --shadow: 0 1px 2px rgba(26, 26, 26, 0.06);

  /* Étiquettes d'équipe, réservées */
  --color-team-red: #A8322A; --color-team-red-bg: #F4E1DE;
  --color-team-blue: #2B5797; --color-team-blue-bg: #E1E8F3;

  /* Carte de chaleur : encre de plus en plus dense */
  --no5v5: repeating-linear-gradient(45deg, #ECE7DB, #ECE7DB 6px, #E4DECF 6px, #E4DECF 12px);
  --no5v5-fg: #A69F90;
  --heat-1: rgba(26, 26, 26, 0.10);
  --heat-2: rgba(26, 26, 26, 0.20);
  --heat-3: rgba(26, 26, 26, 0.32);
  --heat-4: rgba(26, 26, 26, 0.46);
  --heat-fg: #1A1A1A;

  /* Types d'événement */
  --ev-scrim-bg: #1A1A1A; --ev-scrim-fg: #F5F2EA;
  --ev-ranked-bg: #B3471D; --ev-ranked-fg: #FBF3EC;
  --ev-tournoi-bg: #4D6B3C; --ev-tournoi-fg: #F1F5EC;
  --ev-autre-bg: #5B6470; --ev-autre-fg: #F2F4F7;

  /* Typographie : titres en serif, texte en sans-serif système */
  --font-heading: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --touch-target-min: 44px;
  color-scheme: light;
}

/* Sombre : préférence du système, sauf choix explicite du clair ; ou choix explicite du sombre */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Thème sombre « ardoise » (direction F) */
    --color-background: #111827;
    --color-surface: #1F2937;
    --color-surface-hover: #273244;
    --color-border: #2B3646;
    --color-foreground: #E5E7EB;
    --color-muted: #9CA3AF;
    --color-primary: #2DD4BF;
    --color-primary-hover: #5EEAD4;
    --color-on-primary: #042F2E;
    --color-success-bg: #123A33; --color-success-fg: #5EEAD4;
    --color-warning-bg: #3A2A12; --color-warning-fg: #FCD34D;
    --color-danger-bg: #3B1518; --color-danger-fg: #FCA5A5; --color-danger-border: #7F1D1D;
    --shadow: none;

    --color-team-red: #F87171; --color-team-red-bg: #3B1518;
    --color-team-blue: #60A5FA; --color-team-blue-bg: #172A46;

    --no5v5: repeating-linear-gradient(45deg, #172030, #172030 6px, #1B2536 6px, #1B2536 12px);
    --no5v5-fg: #4B5563;
    --heat-1: rgba(45, 212, 191, 0.16);
    --heat-2: rgba(45, 212, 191, 0.30);
    --heat-3: rgba(45, 212, 191, 0.46);
    --heat-4: rgba(45, 212, 191, 0.64);
    --heat-fg: #ECFEFF;

    --ev-scrim-bg: #F9FAFB; --ev-scrim-fg: #111827;
    --ev-ranked-bg: #FDA4AF; --ev-ranked-fg: #4C0519;
    --ev-tournoi-bg: #FCD34D; --ev-tournoi-fg: #422006;
    --ev-autre-bg: #A5B4FC; --ev-autre-fg: #1E1B4B;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  /* Thème sombre « ardoise » (direction F) */
  --color-background: #111827;
  --color-surface: #1F2937;
  --color-surface-hover: #273244;
  --color-border: #2B3646;
  --color-foreground: #E5E7EB;
  --color-muted: #9CA3AF;
  --color-primary: #2DD4BF;
  --color-primary-hover: #5EEAD4;
  --color-on-primary: #042F2E;
  --color-success-bg: #123A33; --color-success-fg: #5EEAD4;
  --color-warning-bg: #3A2A12; --color-warning-fg: #FCD34D;
  --color-danger-bg: #3B1518; --color-danger-fg: #FCA5A5; --color-danger-border: #7F1D1D;
  --shadow: none;

  --color-team-red: #F87171; --color-team-red-bg: #3B1518;
  --color-team-blue: #60A5FA; --color-team-blue-bg: #172A46;

  --no5v5: repeating-linear-gradient(45deg, #172030, #172030 6px, #1B2536 6px, #1B2536 12px);
  --no5v5-fg: #4B5563;
  --heat-1: rgba(45, 212, 191, 0.16);
  --heat-2: rgba(45, 212, 191, 0.30);
  --heat-3: rgba(45, 212, 191, 0.46);
  --heat-4: rgba(45, 212, 191, 0.64);
  --heat-fg: #ECFEFF;

  --ev-scrim-bg: #F9FAFB; --ev-scrim-fg: #111827;
  --ev-ranked-bg: #FDA4AF; --ev-ranked-fg: #4C0519;
  --ev-tournoi-bg: #FCD34D; --ev-tournoi-fg: #422006;
  --ev-autre-bg: #A5B4FC; --ev-autre-fg: #1E1B4B;
  color-scheme: dark;
}

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

html, body {
  background-color: var(--color-background);
  color: var(--color-foreground);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Header & Navigation mobile-first */
.app-header {
  background-color: var(--color-background);
  border-bottom: 1px solid var(--color-border);
  padding: 0.5rem 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.brand {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--color-foreground);
  display: flex;
  align-items: center;
  min-height: var(--touch-target-min);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
  flex-wrap: wrap;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
  color: var(--color-muted);
  transition: background-color 150ms ease, color 150ms ease;
  cursor: pointer;
}

.nav-link:hover, .nav-link:focus-visible {
  color: var(--color-foreground);
  background-color: var(--color-surface-hover);
}

.nav-link.active {
  color: var(--color-foreground);
  background-color: var(--color-surface-hover);
  font-weight: 600;
}

/* Conteneur principal */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

/* Boutons accessibles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  padding: 0.625rem 1.25rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.btn-primary {
  background-color: var(--color-primary);
  color: var(--color-on-primary);
}

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

/* Badges d'équipe */
.badge-team-red {
  background-color: var(--color-team-red-bg);
  color: var(--color-team-red);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-team-blue {
  background-color: var(--color-team-blue-bg);
  color: var(--color-team-blue);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Heatmap & créneaux */
.slot {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  border: 1px solid var(--color-border);
  cursor: pointer;
}

.slot.no5v5 {
  background: var(--no5v5);
}

.slot.heat-1 { background-color: var(--heat-1); }
.slot.heat-2 { background-color: var(--heat-2); }
.slot.heat-3 { background-color: var(--heat-3); }
.slot.heat-4 { background-color: var(--heat-4); }

/* Navigation par semaine (dispos, plannings) */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.week-nav-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  font-size: 1.25rem;
  border-radius: 6px;
  background: transparent;
  color: var(--color-foreground);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: background-color 150ms ease;
}

.nav-arrow:hover {
  background-color: var(--color-surface-hover);
}

/* Screens de games (page événement, staff) */
.games {
  border-top: 1px solid var(--color-border);
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.games-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  margin: 0;
}

.games-empty {
  color: var(--color-muted);
  margin: 0;
}

.game {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.75rem;
}

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.game-screens {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.game-screens img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
}

.game-add {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}

.game-add label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-muted);
}

.btn-small {
  min-height: var(--touch-target-min);
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--color-border);
}

/* Champs de formulaire communs */
.form-control,
input[type="text"],
input[type="date"],
select,
textarea {
  font: inherit;
  font-size: 1rem;
  color: var(--color-foreground);
  background-color: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  min-height: var(--touch-target-min);
  max-width: 100%;
}

textarea,
textarea.form-control {
  width: 100%;
  min-height: 6rem;
  resize: vertical;
  line-height: 1.5;
}

.form-control:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

input[type="checkbox"],
input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--color-primary);
}

/* L'attribut hidden doit toujours masquer, même si un composant fixe display */
[hidden] { display: none !important; }

/* Liste des événements sous le calendrier coach */
.week-events {
  margin-top: 1rem;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.week-events-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.week-events-empty {
  color: var(--color-muted);
  margin: 0;
}

.week-events-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.week-events-list a {
  display: grid;
  grid-template-columns: 9rem 8rem 1fr auto;
  gap: 0.75rem;
  align-items: center;
  min-height: var(--touch-target-min);
  padding: 0 0.5rem;
  border-radius: 6px;
  color: var(--color-foreground);
  text-decoration: none;
}

.week-events-list a:hover,
.week-events-list a:focus-visible {
  background-color: var(--color-surface-hover);
}

.we-time,
.we-count {
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.we-type {
  font-weight: 600;
}

/* Titres en serif (thème papier comme ardoise) */
h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 600;
}

/* Couleur par type d'événement (blocs du calendrier, cartes de planning) */
.event-type-scrim { --ev-bg: var(--ev-scrim-bg); --ev-fg: var(--ev-scrim-fg); }
.event-type-ranked { --ev-bg: var(--ev-ranked-bg); --ev-fg: var(--ev-ranked-fg); }
.event-type-tournoi { --ev-bg: var(--ev-tournoi-bg); --ev-fg: var(--ev-tournoi-fg); }
.event-type-autre { --ev-bg: var(--ev-autre-bg); --ev-fg: var(--ev-autre-fg); }

/* Bascule clair / sombre */
.theme-toggle {
  background: none;
  border: none;
  color: var(--color-muted);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
