/* === Variables === */
:root {
  --blue-dark: #1B3A6B;
  --blue: #2E6DB4;
  --blue-light: #EBF2FC;
  --white: #FFFFFF;
  --bg: #F4F6FB;
  --text: #1A1A2E;
  --text-muted: #6B7280;
  --border: #D1D9E6;
  --green: #16A34A;
  --red: #DC2626;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(27,58,107,0.10);
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; }
img { max-width: 100%; display: block; }

/* === Layout === */
.container { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 16px; }

/* === Header === */
.app-header {
  background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue) 100%);
  color: var(--white);
  padding: 20px 0 18px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-logos {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  min-height: 56px;
}
.header-logos img {
  height: 90px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  background: white;
  border-radius: 8px;
  padding: 6px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.logo-slot {
  width: 120px;
  height: 90px;
  border: 2px dashed rgba(255,255,255,0.3);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.35);
  font-size: 10px;
  text-align: center;
  padding: 4px;
}
.app-title {
  font-size: clamp(1.3rem, 5vw, 2rem);
  font-weight: 900;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.app-subtitle {
  font-size: 0.8rem;
  opacity: 0.75;
  margin-top: 3px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* === Card === */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  margin: 14px 0;
}
.card-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--blue-dark);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 2px solid var(--blue-light);
  padding-bottom: 8px;
  margin-bottom: 16px;
}

/* === Form Grid === */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .form-grid { grid-template-columns: 1fr 1fr 1fr; } }
.form-grid .col-full { grid-column: 1 / -1; }
@media (min-width: 640px) { .form-grid .col-2 { grid-column: span 2; } }

/* === Form Controls === */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-group label .required { color: var(--red); margin-left: 2px; }

input[type=text],
input[type=email],
input[type=tel],
input[type=password],
input[type=search],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.18s, box-shadow 0.18s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46,109,180,0.15);
}
input.error, select.error { border-color: var(--red); }
::placeholder { color: #A0AEC0; }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 34px;
  cursor: pointer;
}

.field-error { font-size: 0.75rem; color: var(--red); display: none; margin-top: 2px; }
.field-error.visible { display: block; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.18s;
  font-family: inherit;
  text-decoration: none;
}
.btn-primary { background: var(--blue-dark); color: var(--white); }
.btn-primary:hover { background: var(--blue); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(27,58,107,0.25); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary { background: var(--bg); color: var(--blue-dark); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #B91C1C; }
.btn-success { background: var(--green); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; border-radius: 6px; }
.btn-full { width: 100%; }

/* === Stage Table === */
.stages-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .stages-grid { grid-template-columns: 1fr; } }

.stages-column {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.stages-column-header {
  background: var(--blue-dark);
  color: white;
  padding: 7px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.stage-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
}
.stage-row:last-child { border-bottom: none; }
.stage-row:nth-child(even) { background: #FAFBFD; }
.stage-num {
  padding: 7px 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  font-size: 0.875rem;
  color: var(--blue-dark);
}
.stage-verify-cell {
  padding: 5px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--border);
}
.stage-btn {
  width: 100%;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--white);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.stage-btn:hover { border-color: var(--blue); }
.stage-btn.ok { background: #DCFCE7; border-color: var(--green); color: var(--green); }
.stage-btn.ko { background: #FEE2E2; border-color: var(--red); color: var(--red); }

/* === Stage Popover === */
.stage-popover {
  position: fixed;
  z-index: 1000;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 8px;
  display: flex;
  gap: 6px;
}
.stage-popover button {
  padding: 7px 10px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.8rem;
  font-family: inherit;
  transition: opacity 0.15s;
}
.stage-popover button:hover { opacity: 0.85; }
.stage-popover .pop-ok { background: #DCFCE7; color: var(--green); }
.stage-popover .pop-ko { background: #FEE2E2; color: var(--red); }
.stage-popover .pop-clear { background: var(--bg); color: var(--text-muted); }

/* === Alerts === */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin: 10px 0;
  font-size: 0.9rem;
  line-height: 1.4;
}
.alert-success { background: #DCFCE7; color: #15803D; border: 1px solid #BBF7D0; }
.alert-error { background: #FEE2E2; color: #B91C1C; border: 1px solid #FECACA; }
.alert-info { background: var(--blue-light); color: var(--blue-dark); border: 1px solid #BFDBFE; }

/* === Version Badge === */
.version-badge {
  position: fixed;
  bottom: 10px;
  right: 12px;
  font-size: 0.68rem;
  color: var(--text-muted);
  background: rgba(255,255,255,0.9);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  z-index: 999;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

/* === Admin Tabs === */
.tab-nav {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color 0.15s;
  font-family: inherit;
}
.tab-btn:hover { color: var(--blue); }
.tab-btn.active { color: var(--blue-dark); border-bottom-color: var(--blue-dark); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* === Admin Table === */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
  background: var(--blue-light);
  color: var(--blue-dark);
  padding: 10px 12px;
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.table-responsive { overflow-x: auto; border-radius: 8px; border: 1.5px solid var(--border); }

/* === List Editor === */
.list-editor { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; gap: 8px; align-items: center; }
.list-item input { flex: 1; }

/* === Image Upload Slots === */
.image-slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 640px) { .image-slots { grid-template-columns: repeat(4, 1fr); } }

.image-slot {
  border: 2px dashed var(--border);
  border-radius: 8px;
  aspect-ratio: 4 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}
.image-slot:hover { border-color: var(--blue); background: var(--blue-light); }
.image-slot img { width: 100%; height: 100%; object-fit: contain; }
.image-slot .slot-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  pointer-events: none;
}
.image-slot .slot-icon { font-size: 1.5rem; margin-bottom: 4px; pointer-events: none; }
.image-slot input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* === Spinner === */
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Belt / Ceinture === */
.belt-pcc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px 14px;
  background: var(--blue-light);
  border-radius: 8px;
  border: 1.5px solid var(--border);
}
.belt-pcc-row input[type=checkbox] {
  width: 18px; height: 18px; flex-shrink: 0;
  cursor: pointer; accent-color: var(--blue-dark);
}
.belt-pcc-row label { font-size: 0.9rem; cursor: pointer; }
.belt-pcc-info {
  font-size: 0.8rem; color: var(--blue-dark);
  background: var(--blue-light); border-radius: 6px;
  padding: 7px 12px; margin-bottom: 12px;
  border-left: 3px solid var(--blue);
}

.belt-palette {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.belt-palette-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 8px;
  border: 2px dashed var(--border); background: var(--white);
  cursor: grab; font-weight: 600; font-size: 0.875rem;
  user-select: none; touch-action: none;
  transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}
.belt-palette-item:hover { border-color: var(--blue); background: var(--blue-light); }
.belt-palette-item.disabled { opacity: 0.3; pointer-events: none; }
.belt-palette-badge {
  width: 26px; height: 26px; border-radius: 5px; display: flex;
  align-items: center; justify-content: center;
  font-weight: 900; font-size: 0.8rem; border: 2px solid;
}
.holster-badge { background: #EBF2FC; border-color: var(--blue-dark); color: var(--blue-dark); }
.pouch-badge   { background: #DCFCE7; border-color: var(--green); color: var(--green); }
.magnet-badge  { background: #FEE2E2; border-color: var(--red); color: var(--red); }

.belt-zone {
  position: relative; width: 100%; height: 300px;
  background: #F8FAFF; border: 2px dashed var(--border);
  border-radius: 10px; overflow: hidden; touch-action: none;
}
.belt-zone.drag-over { border-color: var(--blue); background: var(--blue-light); }

.belt-oval {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 52%; height: 90%;
  border: 2.5px solid var(--blue-dark); border-radius: 50%;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 10px;
  pointer-events: none;
}
.belt-oval-label {
  font-size: 0.72rem; color: var(--blue-dark); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
}
/* Mobile : la zone est étroite mais haute -> l'ovale (width 52% / height 90%)
   devenait trop allongé verticalement. On le dimensionne à partir de la
   HAUTEUR (fixe) avec le même ratio large que sur web/tablette, plus petit,
   et on plafonne la largeur : la forme reste identique et ne déborde jamais
   du cadre quelle que soit la largeur de l'écran. */
@media (max-width: 639px) {
  .belt-zone { height: 220px; }
  .belt-oval {
    height: 72%; width: auto;
    aspect-ratio: 1.6 / 1;
    max-width: 90%;
  }
}

.belt-el {
  position: absolute; width: 40px; height: 40px;
  border-radius: 7px; border: 2px solid;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 0.9rem;
  cursor: grab; user-select: none; touch-action: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: box-shadow 0.12s;
}
.belt-el:active { cursor: grabbing; box-shadow: 0 5px 16px rgba(0,0,0,0.25); }
.belt-el[data-type=holster] { background: #EBF2FC; border-color: var(--blue-dark); color: var(--blue-dark); }
.belt-el[data-type=pouch]   { background: #DCFCE7; border-color: var(--green);    color: var(--green); }
.belt-el[data-type=magnet]  { background: #FEE2E2; border-color: var(--red);      color: var(--red); }

.belt-el-remove {
  position: absolute; top: -8px; right: -8px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #374151; color: white; border: none;
  font-size: 0.65rem; font-weight: 900; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1; padding: 0;
}
.belt-el-remove:hover { background: var(--red); }

.belt-ghost {
  position: fixed; width: 40px; height: 40px; border-radius: 7px;
  border: 2px solid; display: flex; align-items: center;
  justify-content: center; font-weight: 900; font-size: 0.9rem;
  pointer-events: none; opacity: 0.75; z-index: 9999;
  transform: translate(-50%, -50%);
}
.belt-ghost[data-type=holster] { background: #EBF2FC; border-color: var(--blue-dark); color: var(--blue-dark); }
.belt-ghost[data-type=pouch]   { background: #DCFCE7; border-color: var(--green);    color: var(--green); }
.belt-ghost[data-type=magnet]  { background: #FEE2E2; border-color: var(--red);      color: var(--red); }

.belt-hint { font-size: 0.75rem; color: var(--text-muted); text-align: center; margin-top: 8px; }

/* === PDF Preview (hidden, A4 proportions) === */
#pdf-preview {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 794px;
  min-height: 1123px;
  background: white;
  padding: 32px;
  font-family: system-ui, sans-serif;
  color: #1A1A2E;
  font-size: 12px;
  line-height: 1.4;
}

/* === Utility === */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* === QR Code flottant === */
.qr-float-btn {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--blue-dark);
  color: var(--white);
  border: none;
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(27,58,107,0.35);
  z-index: 100;
  transition: background 0.15s;
}
.qr-float-btn:hover { background: var(--blue); }

@media (min-width: 768px) {
  .qr-float-btn { display: flex; }
}

.qr-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.qr-modal.active { display: flex; }

.qr-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.qr-card {
  position: relative;
  background: var(--white);
  border-radius: 16px;
  padding: 28px 24px 24px;
  text-align: center;
  z-index: 201;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
  max-width: 300px;
  width: 90%;
}

.qr-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}
.qr-close:hover { color: var(--text); }

.qr-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

#qr-code-container {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 8px;
}

#qr-code-container img,
#qr-code-container canvas { display: block; }

.qr-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--blue-dark);
  margin-bottom: 4px;
}

.qr-url {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* === Check-in Feature === */

/* Admin table check-in button — not checked */
.btn-checkin {
  background: #e9ecef;
  color: #6c757d;
  border: 1px solid #ced4da;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

/* Admin table check-in button — checked */
.btn-checkin.checked {
  background: #27AE60;
  color: white;
  border-color: #27AE60;
}

/* One competitor row */
.checkin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  background: white;
  margin-bottom: 8px;
}

/* Row when competitor is checked in */
.checkin-row.checked {
  background: #f0fff4;
  border-color: #27AE60;
}

/* Competitor name */
.checkin-name {
  font-weight: 600;
  font-size: 15px;
}

/* Division / squad info below name */
.checkin-meta {
  font-size: 13px;
  color: #6c757d;
  margin-top: 2px;
}

/* Mobile check-in toggle button — not checked */
.btn-checkin-mobile {
  min-height: 44px;
  min-width: 44px;
  background: #e9ecef;
  color: #6c757d;
  border: 1px solid #ced4da;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Mobile check-in toggle button — checked */
.btn-checkin-mobile.checked {
  background: #27AE60;
  color: white;
  border-color: #27AE60;
}
