:root {
  color-scheme: light;
  --surface-1:      #ffffff;
  --surface-2:      #eef1f5;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --border:         rgba(11,11,11,0.08);
  --series-blue:    #2a78d6;
  --series-pink:    #d6538f;
  --status-good:      #0ca30c;
  --status-warning:   #fab219;
  --status-serious:   #ec835a;
  --status-critical:  #d03b3b;
  --shadow-1: 0 1px 2px rgba(20,30,50,0.06), 0 3px 10px rgba(20,30,50,0.07);
  --shadow-2: 0 2px 6px rgba(20,30,50,0.08), 0 10px 28px rgba(20,30,50,0.12);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #201f1e;
    --surface-2:      #0a0b0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --border:         rgba(255,255,255,0.10);
    --series-blue:    #3987e5;
    --series-pink:    #e370a4;
    --status-good:      #0ca30c;
    --status-warning:   #fab219;
    --status-serious:   #ec835a;
    --status-critical:  #d03b3b;
    --shadow-1: 0 1px 2px rgba(0,0,0,0.3), 0 3px 10px rgba(0,0,0,0.3);
    --shadow-2: 0 2px 6px rgba(0,0,0,0.35), 0 10px 28px rgba(0,0,0,0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #201f1e;
  --surface-2:      #0a0b0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --border:         rgba(255,255,255,0.10);
  --series-blue:    #3987e5;
  --series-pink:    #e370a4;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.3), 0 3px 10px rgba(0,0,0,0.3);
  --shadow-2: 0 2px 6px rgba(0,0,0,0.35), 0 10px 28px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(140% 60% at 50% 0%, color-mix(in srgb, var(--series-blue) 6%, transparent) 0%, transparent 60%),
    var(--surface-2);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

/* Retour tactile générique : tout élément cliquable se tasse légèrement au toucher */
button, .club-card, .tile, select {
  transition: transform 0.12s ease, opacity 0.12s ease, background-color 0.15s ease;
}
button:active, .tab-btn:active, .mode-btn:active { transform: scale(0.96); }

/* ── Login ─────────────────────────────────────────────────────────── */

#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  background: radial-gradient(120% 100% at 50% 0%, color-mix(in srgb, var(--series-blue) 8%, var(--surface-2)) 0%, var(--surface-2) 55%);
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 26px;
  box-shadow: var(--shadow-2);
  text-align: center;
}
.login-icon {
  border-radius: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-1);
}
.login-card h1 {
  font-size: 21px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.login-card p.subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 22px;
}
.field { margin-bottom: 14px; text-align: left; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 16px; /* évite le zoom auto iOS */
}
.field input:focus {
  outline: none;
  border-color: var(--series-blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-blue) 20%, transparent);
}
/* ← Neutralise le fond jaune que Safari/Chrome imposent sur les champs
   autoremplis (identifiants enregistrés) — sans ça il ignore nos couleurs. */
.field input:-webkit-autofill,
.field input:-webkit-autofill:hover,
.field input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
  -webkit-text-fill-color: var(--text-primary);
  caret-color: var(--text-primary);
  transition: background-color 9999s ease-in-out 0s;
}
.forgot-link {
  display: block;
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--series-blue);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

button.primary {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  border: none;
  background: var(--series-blue);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--series-blue) 35%, transparent);
}
button.primary:active { transform: scale(0.98); }
button.primary:disabled { opacity: 0.6; cursor: default; box-shadow: none; }

.error-msg {
  background: color-mix(in srgb, var(--status-critical) 12%, transparent);
  color: var(--status-critical);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}
.info-msg {
  background: color-mix(in srgb, var(--status-good) 12%, transparent);
  color: var(--status-good);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}

/* ── Dashboard ─────────────────────────────────────────────────────── */

#dashboard-screen {
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-icon {
  border-radius: 7px;
  flex: 0 0 auto;
}
.topbar h1 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  flex: 1;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
button.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  padding: 8px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  cursor: pointer;
  line-height: 1;
}
button.icon-btn:active { background: var(--surface-2); }

select#club-select {
  width: 100%;
  margin-top: 8px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
}

/* ── Onglets Aperçu / Historique ──────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  padding: 6px 16px 0;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  /* ← Pas de position:sticky ici : le topbar est déjà sticky top:0,
     un deuxième élément sticky top:0 juste en dessous se superposerait
     dessus au défilement. Seul le topbar reste épinglé. */
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 4px;
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab-btn.active {
  color: var(--series-blue);
  border-bottom-color: var(--series-blue);
}

/* ── Historique : contrôles de période ────────────────────────────────── */

.hist-controls {
  margin: 14px 16px 0;
  padding: 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-1);
}
.hist-mode-toggle {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 12px;
}
.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
.mode-btn.active {
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: var(--shadow-1);
}
.hist-fields {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.hist-fields select,
.hist-fields input[type="date"] {
  flex: 1;
  min-width: 0;
  padding: 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 14px;
}
.hist-date-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hist-date-field span {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hist-date-field input { width: 100%; box-sizing: border-box; }
#hist-load-btn { width: 100%; }

.status-banner {
  margin: 14px 16px 0;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  box-shadow: var(--shadow-1);
}
.status-banner.stale {
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1));
  color: color-mix(in srgb, var(--status-warning) 55%, var(--text-primary));
  align-items: flex-start;
}
.status-banner .dot { font-size: 15px; line-height: 1; }
.stale-date { color: var(--status-critical); font-weight: 700; }
/* ← Une ligne par club (au lieu d'un paragraphe qui s'enchaîne) — plus lisible
   dès que plusieurs clubs sont listés avec leur propre date de retard. */
.stale-club-list { display: flex; flex-direction: column; gap: 3px; }

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 16px;
}
@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.tile:active { transform: scale(0.98); }
.tile .label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tile .value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: proportional-nums;
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.tile .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 0;
}

/* ← Recette correspondante affichée entre parenthèses dans la valeur d'une
   tuile (ex. tuiles séances uniques) — plus petite que le chiffre principal,
   en vert pour signaler que c'est un montant encaissé. */
.value-credit {
  font-size: 14px;
  font-weight: 600;
  color: var(--status-good);
}

/* ← Tuiles "crédit" (recette) : fond vert clair — et "débit" (dépenses) :
   fond rouge clair, juste en dessous — pour les distinguer d'un coup d'œil. */
.tile-credit {
  background: color-mix(in srgb, var(--status-good) 9%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-good) 30%, var(--border));
}
.tile-credit .value { color: var(--status-good); }

.tile-debit {
  background: color-mix(in srgb, var(--status-critical) 8%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-critical) 25%, var(--border));
}
.tile-debit .value { color: var(--status-critical); }

/* ── Solde : hero figure — LE chiffre que le patron regarde en premier ──── */

.solde-hero {
  margin: 16px 16px 0;
  padding: 24px 20px;
  border-radius: 20px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  position: relative;
  overflow: hidden;
}
.solde-hero.positif {
  background: linear-gradient(155deg, color-mix(in srgb, var(--status-good) 16%, var(--surface-1)) 0%, var(--surface-1) 65%);
  border-color: color-mix(in srgb, var(--status-good) 35%, var(--border));
}
.solde-hero.negatif {
  background: linear-gradient(155deg, color-mix(in srgb, var(--status-critical) 16%, var(--surface-1)) 0%, var(--surface-1) 65%);
  border-color: color-mix(in srgb, var(--status-critical) 35%, var(--border));
}
.solde-label {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.solde-value {
  margin: 0;
  font-size: 42px;
  font-weight: 800;
  font-variant-numeric: proportional-nums;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.solde-hero.positif .solde-value { color: var(--status-good); }
.solde-hero.negatif .solde-value { color: var(--status-critical); }
.solde-jour {
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 600;
}
.solde-jour.positif { color: var(--status-good); }
.solde-jour.negatif { color: var(--status-critical); }

/* ── Dépenses par catégorie ───────────────────────────────────────────── */

.section-title {
  margin: 22px 16px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cat-list {
  margin: 0 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 14px;
  box-shadow: var(--shadow-1);
}
.cat-row { padding: 11px 0; border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: none; }
.cat-row-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 7px;
}
.cat-name { color: var(--text-primary); font-weight: 500; }
.cat-montant { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.cat-bar-track {
  height: 6px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--series-blue) 15%, var(--surface-2));
  overflow: hidden;
}
.cat-bar-fill {
  height: 100%;
  background: var(--series-blue);
  border-radius: 3px;
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Histogramme horizontal : recette du jour, triée du plus grand au plus petit ── */

.bar-chart {
  margin: 0 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  box-shadow: var(--shadow-1);
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bar-code {
  flex: 0 0 32px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}
.bar-code-wide { flex-basis: 56px; }
.bar-track {
  flex: 1 1 auto;
  height: 16px;
  background: color-mix(in srgb, var(--series-blue) 12%, var(--surface-2));
  border-radius: 5px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  min-width: 3px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--series-blue) 80%, black 8%), var(--series-blue));
  border-radius: 0 5px 5px 0;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-value {
  flex: 0 0 auto;
  min-width: 62px;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Onglet "Par salle" : tableau salle × mois ─────────────────────────── */

.data-table-wrap {
  margin: 0 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px;
  box-shadow: var(--shadow-1);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.data-table th, .data-table td {
  padding: 9px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.data-table thead th {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table .data-table-rowhead {
  text-align: left;
  color: var(--text-primary);
  font-weight: 700;
  position: sticky;
  left: 0;
  background: var(--surface-1);
}
.data-table tbody td { color: var(--text-secondary); }
.data-table .data-table-total {
  font-weight: 700;
  color: var(--series-blue);
}
.data-table tfoot th, .data-table tfoot td {
  border-bottom: none;
  border-top: 2px solid var(--border);
  font-weight: 700;
  color: var(--text-primary);
}
.data-table tbody tr:last-child td, .data-table tbody tr:last-child th { border-bottom: none; }

.club-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 16px;
}
.club-card {
  background: linear-gradient(160deg, color-mix(in srgb, var(--series-blue) 14%, var(--surface-1)) 0%, var(--surface-1) 60%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.club-card.club-card-ladies {
  background: linear-gradient(160deg, color-mix(in srgb, var(--series-pink) 16%, var(--surface-1)) 0%, var(--surface-1) 60%);
  border-color: color-mix(in srgb, var(--series-pink) 25%, var(--border));
}
.club-card:active { transform: scale(0.99); }
.club-card-name {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.005em;
}
.club-card-when {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.club-card-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 8px;
}
.ccs-item { display: flex; flex-direction: column; }
.ccs-item-wide { grid-column: 1 / -1; }
.ccs-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ccs-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.club-card-solde {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.club-card-solde.positif { color: var(--status-good); }
.club-card-solde.negatif { color: var(--status-critical); }

.loading, .empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 16px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--series-blue) 20%, transparent);
  border-top-color: var(--series-blue);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Transition douce entre panneaux ─────────────────────────────────── */
#apercu-panel, #historique-panel {
  animation: fade-in 0.2s ease;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
