/* ── Variables ──────────────────────────────────────────────────── */
:root {
  --primary:      #1e4620;
  --primary-dark: #122b13;
  --accent:       #d4780a;
  --surface:      #f5f7f4;
  --surface2:     #e8ece6;
  --surface3:     #dde3da;
  --border:       #c0cbbe;
  --text:         #111;
  --text-muted:   #556052;
  --danger:       #b83232;
  --success:      #1e7e40;
  --warn:         #8a5f00;
  --warn-bg:      #fff8e1;
  --radius:       10px;
  --touch:        52px;
  --max-w:        720px;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

/* ── Layout — corps rigide, seul #main défile ───────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--surface);
  color: var(--text);
  height: 100dvh;        /* hauteur exacte du viewport, jamais plus */
  overflow: hidden;      /* le body ne défile PAS */
  display: flex;
  flex-direction: column;
}

/* Header : flex-item fixe, fond pleine largeur, contenu centré */
#header {
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  width: 100%;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 12px;
  max-width: var(--max-w);
  margin: 0 auto;
}
.header-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-back {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  min-width: var(--touch);
  min-height: var(--touch);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
/* ── Sync indicator ─────────────────────────────────────────────── */
.sync-status {
  font-size: 0.68rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 99px; flex-shrink: 0;
  min-width: 26px; text-align: center;
}
.sync-ok      { background: rgba(255,255,255,.25); color: #fff; }
.sync-pending { background: #fef9c3; color: #854d0e; }
.sync-offline { background: rgba(255,255,255,.15); color: rgba(255,255,255,.7); }

/* ── Lecture seule participant ───────────────────────────────────── */
.emarg-readonly { font-size: 0.9rem; color: var(--text-muted); min-width: 24px; text-align: center; }
.emarg-readonly.emarged { color: #16a34a; font-weight: 700; }
.readonly-note {
  margin: 16px 16px 8px; padding: 10px 12px;
  background: color-mix(in srgb, var(--border) 40%, transparent);
  border-radius: 8px; font-size: 0.78rem; color: var(--text-muted); text-align: center;
}

.btn-text-sm {
  color: #fff;
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
  padding: 8px 4px;
  opacity: 0.9;
  min-height: var(--touch);
  display: flex;
  align-items: center;
}

/* Zone de défilement — flex: 1 + min-height: 0 est obligatoire */
#main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ── Tabs — collants dans #main (top:0 = haut du conteneur scrollable) */
.tab-nav {
  position: sticky;
  top: 0;                /* haut de #main, pas du viewport */
  z-index: 90;
  background: var(--primary-dark);
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  padding: 14px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab.active { color: #fff; border-bottom-color: var(--accent); }

.tab-content {
  padding: 16px;
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
}

/* ── Centrage desktop ───────────────────────────────────────────── */
.home, .form-page, .recap-page, .saison-page, .recap-actions {
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
}
@media (min-width: 720px) {
  .tab-nav { justify-content: center; }
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-text, .btn-danger {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  gap: 6px;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:active  { filter: brightness(0.85); }
.btn-secondary { background: var(--surface2); color: var(--primary); border: 1.5px solid var(--border); }
.btn-secondary:active { background: var(--surface3); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-text     { background: none; color: var(--primary); }
.btn-text:active { opacity: 0.6; }
.btn-full { width: 100%; }
.btn-lg { font-size: 1.05rem; min-height: 56px; }
.btn-add { margin-top: 16px; }
.btn-file {
  display: flex; align-items: center; justify-content: center;
  min-height: var(--touch); padding: 12px 20px;
  border-radius: var(--radius); font-size: 1rem; font-weight: 600;
  cursor: pointer; background: var(--surface2); color: var(--primary);
  border: 1.5px solid var(--border); margin-top: 8px; width: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ── Forms ──────────────────────────────────────────────────────── */
.form-page { display: flex; flex-direction: column; gap: 16px; padding: 16px; }
.tab-content .form-page { padding: 0; }   /* tab-content déjà padded */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 1rem; font-family: inherit; background: #fff; color: var(--text);
  -webkit-appearance: none; appearance: none;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }

.radio-group { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-chip {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px;
  background: #fff; border: 1.5px solid var(--border); border-radius: 100px;
  font-size: 0.9rem; cursor: pointer; min-height: 44px;
}
.radio-chip input { accent-color: var(--primary); }
.radio-chip:has(input:checked) { background: var(--primary); color: #fff; border-color: var(--primary); }

.espece-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.espece-btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 56px; padding: 10px; background: #fff;
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 600; cursor: pointer; text-align: center;
}
.espece-btn:has(input:checked) { background: var(--primary); color: #fff; border-color: var(--primary); }
.espece-btn input { display: none; }

/* ── Home ───────────────────────────────────────────────────────── */
.home { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.season-badge {
  display: inline-block; background: var(--surface2); color: var(--text-muted);
  font-size: 0.8rem; font-weight: 700; padding: 4px 10px; border-radius: 100px;
  letter-spacing: 0.05em; align-self: flex-start;
}
.section-title {
  font-size: 0.78rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.battue-list { display: flex; flex-direction: column; gap: 8px; }
.battue-card {
  display: block; background: #fff; border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit;
}
.battue-card:active { background: var(--surface2); }
.battue-card-date { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.battue-card-lieu { font-size: 1rem; font-weight: 700; margin: 2px 0; }
.battue-card-meta { font-size: 0.85rem; color: var(--text-muted); }

/* Backup warning */
.backup-warning {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
  background: var(--warn-bg); border: 1.5px solid #f0c040; border-radius: var(--radius);
}
.backup-warning-icon { font-size: 1.2rem; flex-shrink: 0; }
.backup-warning-body { flex: 1; }
.backup-warning-title { font-weight: 700; color: var(--warn); font-size: 0.9rem; }
.backup-warning-sub   { font-size: 0.82rem; color: var(--warn); margin-top: 2px; }

.backup-row { display: flex; gap: 8px; }
.backup-row > * { flex: 1; }
.last-backup { font-size: 0.78rem; color: var(--text-muted); text-align: center; }

/* ── Install prompt ─────────────────────────────────────────────── */
.install-prompt {
  margin: 0 16px 0;
  background: #e8f5e9; border: 1.5px solid #81c784; border-radius: var(--radius);
  padding: 14px 16px;
}
.install-prompt h3 { font-size: 0.95rem; color: var(--primary); margin-bottom: 6px; }
.install-prompt p  { font-size: 0.85rem; color: #2e5e30; margin-bottom: 10px; line-height: 1.4; }
.install-steps { list-style: none; font-size: 0.85rem; color: #2e5e30; display: flex; flex-direction: column; gap: 4px; }
.install-steps li::before { content: '→ '; }
.install-dismiss { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }

/* ── Participants ───────────────────────────────────────────────── */
.participant-list { display: flex; flex-direction: column; gap: 8px; }
.participant-row {
  display: flex; align-items: center; gap: 12px; background: #fff;
  border: 1.5px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  min-height: var(--touch);
}
.participant-poste {
  min-width: 38px; height: 38px; background: var(--surface2); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.9rem; color: var(--primary); flex-shrink: 0;
}
.participant-info { flex: 1; min-width: 0; }
.participant-nom { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.participant-permis { font-size: 0.8rem; color: var(--text-muted); }
.btn-emarg {
  min-width: 48px; min-height: 48px; border-radius: 8px; border: 2px solid var(--border);
  background: #fff; font-size: 1.2rem; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.btn-emarg.emarged { background: var(--success); border-color: var(--success); color: #fff; }

/* ── Prélèvements ───────────────────────────────────────────────── */
.prelevement-list { display: flex; flex-direction: column; gap: 8px; }
.prelevement-row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 12px; background: #fff; border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.prelevement-espece {
  font-weight: 800; font-size: 0.85rem; padding: 4px 8px;
  border-radius: 6px; background: var(--surface2); color: var(--primary); white-space: nowrap;
}
.prelevement-info { display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; min-width: 0; }
.bracelet { color: var(--text-muted); font-size: 0.78rem; }
.tireur { color: var(--primary); font-weight: 600; }
.prelevement-heure { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }

/* ── Empty states ───────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 32px 24px; color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 10px; }
.empty-state-title { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-state-sub { font-size: 0.875rem; line-height: 1.4; }
.empty { color: var(--text-muted); font-size: 0.9rem; padding: 20px 0; text-align: center; }

/* ── Share / QR ─────────────────────────────────────────────────── */
.share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.share-section { margin-bottom: 20px; }
.share-section h3 { font-size: 0.95rem; margin-bottom: 6px; }
.share-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 12px; line-height: 1.4; }
.qr-container {
  display: flex; justify-content: center; margin: 12px 0; padding: 16px;
  background: #fff; border-radius: var(--radius); border: 1.5px solid var(--border);
}
.qr-container canvas, .qr-container img { max-width: 100%; height: auto; }
.qr-toobig {
  padding: 16px; background: var(--surface2); border-radius: var(--radius);
  font-size: 0.85rem; color: var(--text-muted); text-align: center;
  margin-bottom: 12px; line-height: 1.4;
}
hr { border: none; border-top: 1.5px solid var(--border); margin: 20px 0; }

#scanner-container { background: #000; border-radius: var(--radius); overflow: hidden; margin: 12px 0; }
#scanner-video { width: 100%; display: block; max-height: 60vh; object-fit: cover; }

/* Import summary */
.import-summary {
  padding: 12px 14px; background: #e8f5e9; border: 1.5px solid #81c784;
  border-radius: var(--radius); font-size: 0.875rem; margin-top: 12px;
}
.import-summary strong { color: var(--primary); }

/* ── Dialogs ────────────────────────────────────────────────────── */
dialog {
  border: none; border-radius: var(--radius); padding: 20px;
  width: min(400px, calc(100vw - 32px)); max-height: 90dvh;
  overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.22);
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog h2 { font-size: 1.1rem; margin-bottom: 16px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 20px; }
.dialog-actions .btn-text { flex: 1; }
.dialog-actions .btn-primary { flex: 2; }

/* ── Saison ─────────────────────────────────────────────────────── */
.saison-page { padding: 16px; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.stat { background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-n { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-l { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }

/* ── Tables ─────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.recap-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin: 10px 0; min-width: 320px; }
.recap-table th {
  background: var(--surface2); text-align: left; padding: 8px 10px;
  font-size: 0.78rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.recap-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.recap-table tr:last-child td { border-bottom: none; }

/* ── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 10px 20px; border-radius: 100px;
  font-size: 0.9rem; font-weight: 500; opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none; z-index: 9999; white-space: nowrap; max-width: 90vw;
  text-align: center;
}
.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Misc ───────────────────────────────────────────────────────── */
h2 { font-size: 1rem; margin: 16px 0 8px; }
h3 { font-size: 0.9rem; margin: 12px 0 6px; }
.unknown-battue {
  padding: 40px 24px; text-align: center; color: var(--text-muted);
  display: flex; flex-direction: column; gap: 16px; align-items: center;
}
.unknown-battue h2 { color: var(--text); }

/* ── Recap ──────────────────────────────────────────────────────── */
.recap-page { padding: 16px; }
.recap-header { margin-bottom: 20px; }
.recap-header h1 { font-size: 1.2rem; color: var(--primary); margin-bottom: 12px; }
.recap-meta-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-size: 0.85rem;
}
/* ── Banners battue ─────────────────────────────────────────────── */
.participant-banner {
  display: flex; flex-direction: column; gap: 10px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border-left: 3px solid var(--primary);
  padding: 12px 14px; margin: 0;
}
.participant-banner-text { font-size: 0.85rem; line-height: 1.4; }
.participant-banner-btn  { align-self: stretch; }
.reception-banner {
  background: color-mix(in srgb, #22c55e 12%, transparent);
  border-left: 3px solid #22c55e;
  padding: 10px 14px; font-size: 0.85rem; font-weight: 600;
  color: color-mix(in srgb, #166534 80%, var(--text));
}

/* ── Direction badges (onglet Partager) ─────────────────────────── */
.share-dir-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.dir-badge { font-size: 0.7rem; font-weight: 700; letter-spacing: .03em;
             padding: 2px 8px; border-radius: 99px; }
.dir-resp  { background: color-mix(in srgb, var(--primary) 15%, transparent);
             color: var(--primary); border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent); }
.dir-team  { background: color-mix(in srgb, #f59e0b 15%, transparent);
             color: #92400e; border: 1px solid color-mix(in srgb, #f59e0b 40%, transparent); }
.dir-arrow { font-size: 0.9rem; color: var(--text-muted); }
.sync-note  { color: #166534; font-weight: 500; }
.fallback-details { margin-top: 8px; }
.fallback-details summary {
  font-size: 0.8rem; color: var(--text-muted); cursor: pointer;
  padding: 6px 0; user-select: none;
}
.fallback-details summary:hover { color: var(--text); }

.recap-footer { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 0.85rem; }
.signature-block { margin-top: 24px; border-top: 1.5px solid var(--border); padding-top: 16px; page-break-inside: avoid; }
.sig-name  { font-weight: 700; font-size: 1rem; }
.sig-role  { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 20px; }
.sig-area  { height: 56px; border-bottom: 1.5px solid var(--text); }
.sig-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Masquer N° Permis sur les petits écrans ; visible en impression */
@media (max-width: 540px) { .col-permis { display: none; } }

.recap-actions { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.no-print {}

/* ── Print ──────────────────────────────────────────────────────── */
@media print {
  @page { margin: 2cm; }
  #header, .tab-nav, .recap-actions, .no-print { display: none !important; }
  body { background: #fff; font-size: 11pt; height: auto; overflow: visible; }
  #main { overflow: visible; height: auto; }
  .recap-page { padding: 0; max-width: none; }
  .recap-header h1 { font-size: 14pt; }
  .recap-table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .recap-table td, .recap-table th { page-break-inside: avoid; }
  tr { page-break-inside: avoid; }
  thead { display: table-header-group; }
  .col-permis { display: table-cell !important; }
  .recap-meta-grid { grid-template-columns: 1fr 1fr 1fr; }
  .table-wrap { overflow: visible; }
}
