/* ==========================================================================
   CDVR Community — Registre Historique des Présences (Vue Paysage 16:9)
   ========================================================================== */

/* Conteneur principal plein écran */
.registry-view-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #ffffff;
  color: #0f172a;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] .registry-view-container {
  background: #0f172a;
  color: #f8fafc;
}

/* Forçage de l'orientation Paysage STRICTEMENT sur Mobile tactile tenu en Portrait */
@media (max-width: 900px) and (orientation: portrait) and (hover: none) and (pointer: coarse) {
  .registry-view-container.force-landscape {
    width: 100vh !important;
    width: 100dvh !important;
    height: 100vw !important;
    height: 100dvw !important;
    transform: rotate(90deg) translateY(-100%);
    transform-origin: top left;
  }
}

/* Rotation manuelle forcée (si l'utilisateur clique explicitement sur le bouton Rotation) */
.registry-view-container.manual-rotated {
  width: 100vh !important;
  width: 100dvh !important;
  height: 100vw !important;
  height: 100dvw !important;
  transform: rotate(90deg) translateY(-100%);
  transform-origin: top left;
}

/* Barre d'outils supérieure compacte */
.registry-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: #ffffff;
  border-bottom: 1px solid #cbd5e1;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  z-index: 30;
}

[data-theme="dark"] .registry-toolbar {
  background: #1e293b;
  border-bottom-color: #334155;
}

.registry-toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.registry-title-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(26, 99, 201, 0.1);
  color: var(--bleu_cdvr, #1a63c9);
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 800;
  font-size: 0.76rem;
  letter-spacing: 0.3px;
  border: 1px solid rgba(26, 99, 201, 0.25);
  white-space: nowrap;
}

[data-theme="dark"] .registry-title-badge {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.3);
}

.registry-select-group {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  font-size: 0.82rem;
  font-weight: 600;
  min-width: 220px;
  max-width: 340px;
  cursor: pointer;
  outline: none;
}

[data-theme="dark"] .registry-select-group {
  background: #0f172a;
  border-color: #334155;
  color: #f8fafc;
}

.registry-toolbar-center {
  display: flex;
  align-items: center;
  gap: 6px;
}

.registry-period-toggle {
  display: inline-flex;
  background: #e2e8f0;
  padding: 2px;
  border-radius: 6px;
}

[data-theme="dark"] .registry-period-toggle {
  background: #334155;
}

.registry-period-btn {
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: #64748b;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

[data-theme="dark"] .registry-period-btn {
  color: #94a3b8;
}

.registry-period-btn.active {
  background: #ffffff;
  color: var(--bleu_cdvr, #1a63c9);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  font-weight: 700;
}

[data-theme="dark"] .registry-period-btn.active {
  background: #2563eb;
  color: #ffffff;
}

.registry-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  cursor: pointer;
  font-size: 0.72rem;
}

[data-theme="dark"] .registry-nav-btn {
  background: #263650;
  border-color: rgba(203, 213, 225, 0.35);
  color: #f8fafc;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .registry-nav-btn:hover {
  background: #324564;
  border-color: rgba(203, 213, 225, 0.55);
}

.registry-period-label {
  font-weight: 700;
  font-size: 0.82rem;
  min-width: 95px;
  text-align: center;
  color: #0f172a;
}

[data-theme="dark"] .registry-period-label {
  color: #f8fafc;
}

.registry-toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.registry-btn-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  cursor: pointer;
  transition: background 0.15s;
}

[data-theme="dark"] .registry-btn-action {
  background: #263650;
  border-color: rgba(203, 213, 225, 0.35);
  color: #f8fafc;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.registry-btn-action:hover {
  background: #f1f5f9;
}

.registry-btn-action:active {
  transform: scale(0.96);
}

[data-theme="dark"] .registry-btn-action:hover {
  background: #324564;
  border-color: rgba(203, 213, 225, 0.55);
  color: #ffffff;
}

.registry-btn-close {
  background: #fee2e2 !important;
  color: #b91c1c !important;
  border-color: #fca5a5 !important;
  font-weight: 700 !important;
}

[data-theme="dark"] .registry-btn-close {
  background: #432635 !important;
  color: #FFE4E6 !important;
  border-color: rgba(251, 113, 133, 0.45) !important;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
}

[data-theme="dark"] .registry-btn-close:hover {
  background: #5b283d !important;
  border-color: rgba(251, 113, 133, 0.65) !important;
  color: #ffffff !important;
}

/* Zone du tableau défilable */
.registry-table-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #ffffff;
  -webkit-overflow-scrolling: touch;
}

[data-theme="dark"] .registry-table-wrapper {
  background: #0f172a;
}

/* Tableau quadrillé compact rappelant le registre papier */
.registry-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  font-size: 0.8rem;
  text-align: center;
  background: #ffffff;
  color: #0f172a;
}

[data-theme="dark"] .registry-table {
  background: #0f172a;
  color: #f8fafc;
}

/* Bordures & Quadrillage */
.registry-table th,
.registry-table td {
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  padding: 4px 6px;
  box-sizing: border-box;
  color: #0f172a;
}

[data-theme="dark"] .registry-table th,
[data-theme="dark"] .registry-table td {
  border-right: 1px solid #334155;
  border-bottom: 1px solid #334155;
  color: #f8fafc;
}

/* En-têtes figés en haut */
.registry-table thead tr:first-child th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f1f5f9;
  color: #0f172a !important;
  font-weight: 700;
  font-size: 0.76rem;
  height: 32px;
}

.registry-table thead tr:nth-child(2) th {
  position: sticky;
  top: 32px;
  z-index: 20;
  background: #e2e8f0;
  color: #0f172a !important;
  font-weight: 800;
  font-size: 0.78rem;
  height: 25px;
}

[data-theme="dark"] .registry-table thead tr:first-child th {
  background: #1e293b;
  color: #f8fafc !important;
}

[data-theme="dark"] .registry-table thead tr:nth-child(2) th {
  background: #334155;
  color: #f8fafc !important;
}

/* Colonne 1 : Index (#) — Largeur ultra compacte */
.registry-col-index {
  position: sticky;
  left: 0;
  z-index: 10;
  background: #f8fafc;
  width: 26px;
  min-width: 26px;
  max-width: 26px;
  font-weight: 700;
  color: #64748b !important;
  text-align: center;
  padding: 4px 2px !important;
}

/* Colonne 2 : Élèves — Largeur confortable pour noms complets et composés */
.registry-col-student {
  position: sticky;
  left: 26px;
  z-index: 10;
  background: #ffffff;
  width: 190px;
  min-width: 180px;
  max-width: 230px;
  text-align: left !important;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 8px !important;
  padding-right: 6px !important;
  color: #0f172a !important;
}

.registry-student-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 215px;
  color: #0f172a;
}

[data-theme="dark"] .registry-student-name {
  color: #f8fafc;
}

/* Colonne 3 : Jours / Âge (reproduit le registre papier : 10,6 ME, VE) */
.registry-col-days {
  position: sticky;
  left: 216px;
  z-index: 10;
  background: #f8fafc;
  width: 62px;
  min-width: 58px;
  max-width: 70px;
  text-align: center;
  font-weight: 700;
  padding: 2px 2px !important;
}

.registry-days-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.registry-age-label {
  font-size: 0.67rem;
  font-weight: 700;
  color: #64748b;
  line-height: 1;
}

[data-theme="dark"] .registry-age-label {
  color: #94a3b8;
}

.registry-pills-row {
  display: flex;
  gap: 2px;
  justify-content: center;
  flex-wrap: nowrap;
}

.registry-day-pill {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 800;
  padding: 1px 3px;
  border-radius: 3px;
  background: #e0f2fe;
  color: #0369a1;
  line-height: 1.1;
  letter-spacing: -0.2px;
}

[data-theme="dark"] .registry-day-pill {
  background: #075985;
  color: #e0f2fe;
}

/* Colonne 4 : SOLDE (SOLD / Total) — Compacte */
.registry-col-sold {
  position: sticky;
  left: 278px;
  z-index: 10;
  background: #f8fafc;
  width: 48px;
  min-width: 48px;
  max-width: 48px;
  text-align: center;
  font-weight: 800;
  padding: 4px 2px !important;
}

[data-theme="dark"] .registry-col-index {
  background: #1e293b;
  color: #94a3b8 !important;
}

[data-theme="dark"] .registry-col-student {
  background: #0f172a;
  color: #f8fafc !important;
}

[data-theme="dark"] .registry-col-days {
  background: #1e293b;
  color: #f8fafc !important;
}

[data-theme="dark"] .registry-col-sold {
  background: #1e293b;
  color: #f8fafc !important;
}

/* Croisement colonnes figées + en-tête figé (Coin supérieur gauche) */
.registry-table thead tr:first-child th.registry-col-index,
.registry-table thead tr:first-child th.registry-col-student,
.registry-table thead tr:first-child th.registry-col-days,
.registry-table thead tr:first-child th.registry-col-sold {
  z-index: 25;
  background: #e2e8f0;
}

.registry-table thead tr:nth-child(2) th.registry-col-index,
.registry-table thead tr:nth-child(2) th.registry-col-student,
.registry-table thead tr:nth-child(2) th.registry-col-days,
.registry-table thead tr:nth-child(2) th.registry-col-sold {
  z-index: 25;
  background: #cbd5e1;
}

[data-theme="dark"] .registry-table thead tr:first-child th.registry-col-index,
[data-theme="dark"] .registry-table thead tr:first-child th.registry-col-student,
[data-theme="dark"] .registry-table thead tr:first-child th.registry-col-days,
[data-theme="dark"] .registry-table thead tr:first-child th.registry-col-sold {
  background: #334155;
}

[data-theme="dark"] .registry-table thead tr:nth-child(2) th.registry-col-index,
[data-theme="dark"] .registry-table thead tr:nth-child(2) th.registry-col-student,
[data-theme="dark"] .registry-table thead tr:nth-child(2) th.registry-col-days,
[data-theme="dark"] .registry-table thead tr:nth-child(2) th.registry-col-sold {
  background: #475569;
}

/* Zébrures du tableau (1 ligne sur 2 avec fond grisé pour faciliter le suivi) */
.registry-table tbody tr.registry-row-even td {
  background-color: #f1f5f9;
}
.registry-table tbody tr.registry-row-even td.registry-col-index {
  background-color: #e2e8f0;
}
.registry-table tbody tr.registry-row-even td.registry-col-student {
  background-color: #f1f5f9;
}
.registry-table tbody tr.registry-row-even td.registry-col-days {
  background-color: #e8eef5;
}
.registry-table tbody tr.registry-row-even td.registry-col-sold {
  background-color: #f1f5f9;
}

[data-theme="dark"] .registry-table tbody tr.registry-row-even td {
  background-color: #172033;
}
[data-theme="dark"] .registry-table tbody tr.registry-row-even td.registry-col-index {
  background-color: #111827;
}
[data-theme="dark"] .registry-table tbody tr.registry-row-even td.registry-col-student {
  background-color: #172033;
}
[data-theme="dark"] .registry-table tbody tr.registry-row-even td.registry-col-days {
  background-color: #111827;
}
[data-theme="dark"] .registry-table tbody tr.registry-row-even td.registry-col-sold {
  background-color: #172033;
}

/* Case barrée / noircie pour les jours où l'élève n'est pas inscrit */
.registry-cell-not-enrolled {
  background: repeating-linear-gradient(
    -45deg,
    #cbd5e1,
    #cbd5e1 2.5px,
    #e2e8f0 2.5px,
    #e2e8f0 7px
  ) !important;
  cursor: not-allowed;
  user-select: none;
}

[data-theme="dark"] .registry-cell-not-enrolled {
  background: repeating-linear-gradient(
    -45deg,
    #334155,
    #334155 2.5px,
    #1e293b 2.5px,
    #1e293b 7px
  ) !important;
}

/* Colonnes des dates réelles — Optimisées pour laisser entrer tout un trimestre */
.registry-col-date {
  width: 46px;
  min-width: 44px;
  max-width: 50px;
  text-align: center;
  padding: 4px 2px !important;
}

.registry-date-header {
  font-size: 0.74rem;
  letter-spacing: -0.4px;
  white-space: nowrap;
  font-weight: 700;
}

.registry-date-day {
  font-size: 0.65rem;
  font-weight: 800;
  color: #2563eb;
  line-height: 1;
  margin-bottom: 2px;
  text-transform: uppercase;
}

[data-theme="dark"] .registry-date-day {
  color: #60a5fa;
}

.registry-date-num {
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
}

/* Ligne des totaux sous les dates */
.registry-total-cell {
  font-size: 0.8rem;
  font-weight: 800;
  color: #0f172a !important;
}

[data-theme="dark"] .registry-total-cell {
  color: #38bdf8 !important;
}

.registry-total-cell.has-trial {
  color: #b45309 !important;
}

[data-theme="dark"] .registry-total-cell.has-trial {
  color: #fbbf24 !important;
}

/* Badges Solde (SOLD) */
.registry-sold-pill {
  display: inline-block;
  min-width: 28px;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

/* Alerte solde bas (rouge vif comme sur la photo) */
.registry-sold-alert {
  background: #dc2626 !important;
  color: #ffffff !important;
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.4);
}

.registry-sold-warning {
  background: #f59e0b !important;
  color: #ffffff !important;
}

.registry-sold-ok {
  background: #e2e8f0;
  color: #0f172a;
}

[data-theme="dark"] .registry-sold-ok {
  background: #334155;
  color: #f1f5f9;
}

/* Cellules de séances (Carnet & Forfait) */
.registry-cell-value {
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
}

.registry-cell-carnet {
  color: #0f172a !important;
  font-family: 'Caveat', cursive, sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
}

[data-theme="dark"] .registry-cell-carnet {
  color: #f8fafc !important;
}

/* Codes Danse au Forfait */
.registry-badge-P {
  display: inline-block;
  color: #16a34a !important;
  font-weight: 800;
}

.registry-badge-R {
  display: inline-block;
  color: #d97706 !important;
  font-weight: 800;
}

.registry-badge-A {
  display: inline-block;
  color: #dc2626 !important;
  font-weight: 800;
  opacity: 0.85;
}

.registry-badge-EX {
  display: inline-block;
  color: #64748b !important;
  font-weight: 700;
  font-size: 0.7rem;
}

/* Section ESSAIS EFFECTUÉS (Bandeau bleu comme sur le papier) */
.registry-section-row td {
  background: #e0f2fe !important;
  color: #0369a1 !important;
  font-weight: 800;
  text-align: left;
  letter-spacing: 0.5px;
  font-size: 0.78rem;
  padding: 5px 10px !important;
  border-top: 2px solid #38bdf8;
  border-bottom: 2px solid #38bdf8;
}

[data-theme="dark"] .registry-section-row td {
  background: rgba(14, 165, 233, 0.15) !important;
  color: #38bdf8 !important;
  border-color: rgba(14, 165, 233, 0.4);
}

.registry-try-row td {
  background: #f8fafc;
}

[data-theme="dark"] .registry-try-row td {
  background: rgba(15, 23, 42, 0.6);
}

.registry-try-badge {
  display: inline-block;
  font-weight: 800;
  color: #0284c7 !important;
  font-size: 1.05rem;
  font-family: 'Caveat', cursive, sans-serif;
}

[data-theme="dark"] .registry-try-badge {
  color: #38bdf8 !important;
}

/* Barre de pied de page synthétique */
.registry-footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 14px;
  background: #f8fafc;
  border-top: 1px solid #cbd5e1;
  font-size: 0.76rem;
  color: #64748b;
  flex-shrink: 0;
}

[data-theme="dark"] .registry-footer-bar {
  background: #0f172a;
  border-top-color: #334155;
  color: #94a3b8;
}

@media (max-width: 650px) {
  .hide-mobile {
    display: none !important;
  }
}

/* Impression A4 Paysage */
@media print {
  @page {
    size: landscape;
    margin: 6mm;
  }

  body * {
    visibility: hidden;
  }

  .registry-view-container,
  .registry-view-container * {
    visibility: visible;
  }

  .registry-view-container {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: auto;
    background: #ffffff !important;
    color: #000000 !important;
    transform: none !important;
  }

  .registry-toolbar,
  .registry-footer-bar {
    display: none !important;
  }

  .registry-table {
    border-collapse: collapse;
    width: 100% !important;
    font-size: 8pt;
  }

  .registry-table th,
  .registry-table td {
    border: 1px solid #000000 !important;
    padding: 3px 4px !important;
    color: #000000 !important;
  }

  .registry-sold-alert {
    background: #dddddd !important;
    color: #000000 !important;
    border: 1px solid #000000 !important;
  }
}
