/* ============================================================
   BASE
   ============================================================ */
html {
  scroll-behavior: smooth;
}

/* ============================================================
   PLANNING GRID
   ============================================================ */
.grid-container {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 230px);
  position: relative;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  -webkit-overflow-scrolling: touch; /* smooth scroll on iOS */
}

/* Sticky header row — stays visible on vertical scroll */
table.planning thead th {
  position: sticky;
  top: 0;
  z-index: 15;
}

/* Sticky first column — stays visible on horizontal scroll */
table.planning th:first-child,
table.planning td:first-child {
  position: sticky;
  left: 0;
  z-index: 10;
  background: white;
  min-width: 100px;
  max-width: 140px;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.08);
}

/* Corner cell: sticky both top AND left — highest z-index */
table.planning thead th:first-child {
  z-index: 25;
  background: #f9fafb;
  top: 0;
  left: 0;
}

/* Column header highlight when search result */
.col-highlight th {
  outline: 3px solid #f59e0b !important;
  outline-offset: -2px;
  animation: col-flash 1.5s ease-out;
}

@keyframes col-flash {
  0%   { background-color: #fef3c7; }
  100% { background-color: inherit; }
}

/* ============================================================
   CELL STATES
   ============================================================ */
.cell-checked {
  background-color: #4ade80 !important;
}

.cell-unchecked {
  background-color: #e5e7eb !important;
}

/* Own row */
.own-row td:first-child {
  background-color: #fefce8 !important;
}

.own-row {
  background-color: #fefce8;
}

/* ============================================================
   COLUMN HEADERS (type)
   ============================================================ */
.header-vendredi {
  background-color: #3b82f6;
  color: white;
}

.header-dimanche {
  background-color: #f97316;
  color: white;
}

.header-autre {
  background-color: #2E7D6B;
  color: white;
}

/* ============================================================
   TOTALS ROW
   ============================================================ */
.totals-row {
  position: sticky;
  bottom: 0;
  background: white;
  font-weight: bold;
  border-top: 2px solid #374151;
  z-index: 15;
}

.totals-row td:first-child {
  background: white !important;
  z-index: 20;
}

/* ============================================================
   TABLE BASE
   ============================================================ */
table.planning {
  border-collapse: collapse;
  white-space: nowrap;
}

table.planning th {
  padding: 0.5rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid #e5e7eb;
}

table.planning td {
  padding: 0.2rem 0.35rem;
  border-bottom: 1px solid #f3f4f6;
}

/* Cells: min 44px for touch targets */
.presence-cell {
  cursor: pointer;
  transition: background-color 0.15s ease;
  min-width: 44px;
  height: 40px;
  text-align: center;
  vertical-align: middle;
}

.presence-cell:hover .cell-unchecked,
.presence-cell:hover .cell-checked {
  opacity: 0.8;
}

.cell-readonly {
  cursor: default;
}

/* ============================================================
   SESSION NOTE in header
   ============================================================ */
.session-note {
  font-style: italic;
  font-size: 0.6rem;
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.9;
  max-width: 70px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  margin-top: 1px;
}

.note-icon {
  cursor: help;
  font-style: normal;
  font-size: 0.75rem;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.page-btn {
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  background: white;
  color: #374151;
  transition: background-color 0.15s;
  min-width: 32px;
  text-align: center;
}

.page-btn:hover:not(:disabled) {
  background: #f3f4f6;
}

.page-btn.active {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
  font-weight: 600;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ============================================================
   PIN INPUT
   ============================================================ */
.pin-input {
  font-size: 2rem;
  letter-spacing: 0.5rem;
  text-align: center;
  width: 8rem;
  border: 2px solid #d1d5db;
  border-radius: 0.5rem;
  padding: 0.5rem;
}

.pin-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* ============================================================
   SPINNER
   ============================================================ */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   SAVE INDICATOR
   ============================================================ */
.save-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: #6b7280;
  transition: opacity 0.3s;
}

/* ============================================================
   MONTH NAV
   ============================================================ */
.month-nav-btn {
  background: none;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: #374151;
  transition: background-color 0.15s;
}

.month-nav-btn:hover {
  background-color: #f3f4f6;
}

/* ============================================================
   SEARCH BAR (planning)
   ============================================================ */
.search-bar {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  background: white;
  border-bottom: 1px solid #e5e7eb;
}

.search-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  min-width: 140px;
  max-width: 280px;
}

.search-input {
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
}

.search-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* ============================================================
   RESPONSIVE — 375px (iPhone SE) → 768px (tablet)
   ============================================================ */
@media (max-width: 640px) {
  .search-bar {
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
  }

  .search-field-group {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .search-input {
    font-size: 1rem; /* évite le zoom auto iOS à 16px */
  }

  table.planning th:first-child,
  table.planning td:first-child {
    min-width: 72px;
    max-width: 90px;
    font-size: 0.7rem;
  }

  table.planning th {
    padding: 0.35rem 0.3rem;
    font-size: 0.6rem;
  }

  table.planning td {
    padding: 0.15rem 0.25rem;
  }

  .presence-cell {
    min-width: 44px; /* keep 44px touch target */
    height: 36px;
  }

  .pin-input {
    font-size: 1.5rem;
    width: 7rem;
  }

  .grid-container {
    max-height: calc(100vh - 260px);
  }

  .session-note {
    display: none; /* hide text note on very small screens, show icon only */
  }

  .note-icon {
    display: inline !important;
  }
}

@media (min-width: 641px) {
  .note-icon-only {
    display: none;
  }
}

/* ============================================================
   MANAGER DU SOIR ROW
   ============================================================ */
.manager-row {
  background-color: #6B3FA0 !important;
  color: white;
}

.manager-row td:first-child {
  background-color: #6B3FA0 !important;
  color: white;
  font-weight: 700;
  z-index: 12;
}

.manager-cell {
  cursor: pointer;
  min-width: 44px;
  height: 40px;
  text-align: center;
  vertical-align: middle;
  transition: background-color 0.15s;
}

.manager-cell:hover {
  background-color: rgba(255,255,255,0.15) !important;
}

.manager-cell-locked {
  cursor: not-allowed;
  opacity: 0.75;
}

.manager-cell-readonly {
  cursor: default;
}

/* ============================================================
   COLUMN HEADER — clickable
   ============================================================ */
table.planning thead th[data-session-id] {
  cursor: pointer;
  transition: opacity 0.15s;
}

table.planning thead th[data-session-id]:hover {
  opacity: 0.85;
}

/* ============================================================
   SESSION POPUP
   ============================================================ */
.session-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.session-popup-box {
  background: white;
  border-radius: 1rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 90%;
  max-width: 440px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 9999;
}

/* ============================================================
   ADMIN TABLE IMPROVEMENTS
   ============================================================ */
.admin-search {
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
  width: 100%;
  max-width: 320px;
}

.admin-search:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
