/* ============================================
   RESPONSIVE & PWA STYLES - Epoint SR
   ============================================ */

/* Variables CSS pour thème cohérent */
:root {
  --primary-color: #4F46E5;
  --primary-dark: #4338CA;
  --secondary-color: #7C3AED;
  --success-color: #10B981;
  --warning-color: #F59E0B;
  --danger-color: #EF4444;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-600: #4B5563;
  --gray-800: #1F2937;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

/* ============================================
   BOUTONS RESPONSIVE GLOBAUX
   ============================================ */

.btn-responsive {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border-radius: .5rem;
  font-weight: 600;
  transition: background .2s, opacity .2s, transform .1s;
}

.btn-responsive i { width: 1.25rem; text-align: center; }

@media (max-width: 768px) {
  .btn-responsive { width: 100%; }
  /* Cibler les boutons/ancre de contenu (éviter navbar) */
  main a.inline-flex,
  main button.inline-flex,
  main a.btn,
  main button.btn {
    width: 100% !important;
    justify-content: center !important;
  }
}

.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--secondary-color); color: #fff; }
.btn-secondary:hover { filter: brightness(0.95); }

.btn-outline { background: transparent; color: var(--primary-color); border: 2px solid var(--primary-color); }
.btn-outline:hover { background: rgba(79,70,229,.1); }

.btn-danger { background: var(--danger-color); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }

.btn-sm { padding: .375rem .625rem; font-size: .875rem; }
.btn-md { padding: .5rem .875rem; font-size: .95rem; }
.btn-lg { padding: .75rem 1rem; font-size: 1rem; }

/* Reset et base responsive */
* {
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Safe area pour iPhone X+ */
@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ============================================
   TABLE TO CARD VIEW - RESPONSIVE
   ============================================ */

@media (max-width: 1024px) {
  /* Cacher les tables standards sur mobile/tablette */
  .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 768px) {
  /* Table to Card transformation */
  .table-card-view {
    display: block !important;
    border: none !important;
  }

  .table-card-view thead {
    display: none;
  }

  .table-card-view tbody {
    display: block;
  }

  .table-card-view tr {
    display: block;
    margin-bottom: 1rem;
    background: white;
    border-radius: 0.75rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-200);
    padding: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
  }

  .table-card-view tr:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }

  .table-card-view td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0 !important;
    border: none !important;
    border-bottom: 1px solid var(--gray-100);
    text-align: right !important;
  }

  .table-card-view td:last-child {
    border-bottom: none;
  }

  .table-card-view td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    flex: 0 0 45%;
    text-align: left;
  }

  /* Boutons d'action en bas de carte */
  .table-card-view td.actions-cell {
    margin-top: 0.5rem;
    padding-top: 1rem !important;
    border-top: 2px solid var(--gray-100) !important;
    border-bottom: none !important;
    justify-content: center;
    gap: 0.5rem;
  }

  .table-card-view td.actions-cell::before {
    display: none;
  }

  /* Badges et statuts en cards */
  .table-card-view .badge,
  .table-card-view .inline-flex {
    font-size: 0.8rem;
  }
}

/* ============================================
   NAVIGATION RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  /* Header mobile */
  .header-container {
    flex-direction: column;
    padding: 1rem;
  }

  .header-title {
    font-size: 1.25rem !important;
    margin-bottom: 0.75rem;
  }

  .header-actions {
    width: 100%;
    flex-direction: column;
    gap: 0.5rem;
  }

  .header-actions > * {
    width: 100%;
    justify-content: center;
  }

  /* Grilles responsive */
  .grid {
    grid-template-columns: 1fr !important;
  }

  .md\:grid-cols-2,
  .md\:grid-cols-3,
  .md\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }

  /* Stats cards mobile */
  .stats-card {
    margin-bottom: 1rem;
  }

  /* Formulaires mobile */
  .form-row {
    flex-direction: column;
  }

  .form-row > * {
    width: 100% !important;
    margin-bottom: 0.75rem;
  }

  /* Boutons pleine largeur sur mobile */
  .btn-mobile-full {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================
   CARDS SPÉCIFIQUES - POINTAGES
   ============================================ */

@media (max-width: 768px) {
  /* Card pointage avec statut visuel */
  .pointage-card {
    position: relative;
    overflow: hidden;
  }

  .pointage-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
  }

  .pointage-card.status-present::before {
    background: var(--success-color);
  }

  .pointage-card.status-absent::before {
    background: var(--danger-color);
  }

  .pointage-card.status-retard::before {
    background: var(--warning-color);
  }

  /* Date et jour en header de card */
  .card-header-date {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--gray-50);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    border-left: 4px solid var(--primary-color);
  }

  .card-header-date .date {
    font-weight: 700;
    font-size: 1rem;
    color: var(--gray-800);
  }

  .card-header-date .jour {
    font-size: 0.875rem;
    color: var(--gray-600);
  }
}

/* ============================================
   FILTRES & RECHERCHE MOBILE
   ============================================ */

@media (max-width: 768px) {
  .filter-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid var(--gray-200);
    padding: 1rem;
    box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1);
    z-index: 40;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }

  .filter-container.active {
    transform: translateY(0);
  }

  .filter-toggle {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
  }

  .filter-toggle:active {
    transform: scale(0.95);
  }

  .filter-toggle i {
    font-size: 1.5rem;
  }
}

/* ============================================
   MODALS & OVERLAYS MOBILE
   ============================================ */

@media (max-width: 768px) {
  .modal-content {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 1rem auto;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-header {
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
  }
}

/* ============================================
   TOUCH INTERACTIONS
   ============================================ */

.touchable {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.1s, opacity 0.1s;
}

.touchable:active {
  transform: scale(0.98);
  opacity: 0.8;
}

/* Swipe actions sur cards (optionnel) */
.swipeable {
  position: relative;
  transition: transform 0.3s ease;
}

.swipe-actions {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  background: var(--danger-color);
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.swipeable.swiped {
  transform: translateX(-120px);
}

.swipeable.swiped .swipe-actions {
  opacity: 1;
  pointer-events: all;
}

/* ============================================
   LOADING & SKELETON SCREENS
   ============================================ */

.skeleton {
  background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 0.375rem;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 1rem;
  margin: 0.5rem 0;
}

.skeleton-card {
  height: 150px;
  margin: 1rem 0;
}

/* ============================================
   ANIMATIONS & TRANSITIONS
   ============================================ */

@media (prefers-reduced-motion: no-preference) {
  .fade-in {
    animation: fadeIn 0.3s ease-in;
  }

  .slide-up {
    animation: slideUp 0.3s ease-out;
  }

  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  @keyframes slideUp {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* ============================================
   DARK MODE SUPPORT (optionnel)
   ============================================ */

@media (prefers-color-scheme: dark) {
  :root {
    --gray-50: #18181B;
    --gray-100: #27272A;
    --gray-200: #3F3F46;
    --gray-600: #D4D4D8;
    --gray-800: #F4F4F5;
  }

  body {
    background-color: var(--gray-50);
    color: var(--gray-800);
  }

  .table-card-view tr {
    background: var(--gray-100);
    border-color: var(--gray-200);
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .no-print {
    display: none !important;
  }

  .table-card-view tr {
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #000;
  }

  body {
    padding: 0;
  }
}

/* ============================================
   LANDSCAPE MODE MOBILE
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
  .stats-card-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .modal-content {
    max-height: 80vh;
  }
}

/* ============================================
   iOS SPECIFIC FIXES
   ============================================ */

@supports (-webkit-touch-callout: none) {
  /* Activer le scroll inertiel iOS, ne pas figer le body */
  html, body {
    height: 100%;
  }
  body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ios-scroll-fix {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }

  /* Fix pour les inputs sur iOS */
  input, textarea, select {
    font-size: 16px !important; /* Empêche le zoom sur focus */
  }
}
