/* ============================================
   SCHOOL SYSTEM MANAGEMENT - Styles globaux
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Scrollbar personnalisée */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Gradient header pour les pages de login */
.login-gradient {
  background: linear-gradient(135deg, #102a43 0%, #243b53 50%, #0f766e 100%);
}

/* Card hover effect */
.card-hover {
  transition: all 0.2s ease-in-out;
}

.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

/* Boutons */
.btn-primary {
  background-color: #243b53;
  color: white;
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-weight: 500;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  cursor: pointer;
}

.btn-primary:hover {
  background-color: #102a43;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background-color: white;
  color: #334e68;
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-weight: 500;
  border: 1px solid #cbd5e1;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.btn-secondary:hover {
  background-color: #f8fafc;
  border-color: #94a3b8;
}

.btn-danger {
  background-color: #dc2626;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 500;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  cursor: pointer;
}

.btn-danger:hover {
  background-color: #b91c1c;
}

.btn-success {
  background-color: #059669;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 500;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  cursor: pointer;
}

.btn-success:hover {
  background-color: #047857;
}

/* Input fields */
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  font-size: 0.9375rem;
  background-color: white;
  transition: all 0.15s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: #0f766e;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334e68;
  margin-bottom: 0.375rem;
}

.form-label .required {
  color: #dc2626;
  margin-left: 0.125rem;
}

/* Table styles */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background-color: #f1f5f9;
}

.data-table th {
  padding: 0.875rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #e2e8f0;
}

.data-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9375rem;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-success {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-danger {
  background-color: #fee2e2;
  color: #991b1b;
}

.badge-warning {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-info {
  background-color: #dbeafe;
  color: #1e40af;
}

.badge-neutral {
  background-color: #f1f5f9;
  color: #475569;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.modal-content {
  background-color: white;
  border-radius: 0.75rem;
  width: 100%;
  max-width: 42rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  margin: auto;
}

.modal-content.modal-lg {
  max-width: 56rem;
}

.modal-content.modal-xl {
  max-width: 84rem;
}

/* Fiche de cotation - table compacte */
.grading-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}
.grading-table th, .grading-table td {
  border: 1px solid #94a3b8;
  padding: 4px 6px;
  text-align: center;
  vertical-align: middle;
}
.grading-table thead th {
  background-color: #f1f5f9;
  font-weight: 700;
  color: #0f172a;
}
.grading-table .col-name {
  text-align: left;
  min-width: 180px;
}
.grading-table .row-maxima {
  background-color: #fef3c7;
  font-weight: 700;
}
.grading-table .row-maxima td {
  background-color: #fef3c7;
}
.grading-table .col-sem {
  background-color: #e0f2fe;
  font-weight: 600;
}
.grading-table .col-tg {
  background-color: #dcfce7;
  font-weight: 700;
}
.grading-table input.note-input {
  width: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-family: inherit;
  font-size: inherit;
  padding: 2px;
}
.grading-table input.note-input:disabled {
  color: #94a3b8;
  cursor: not-allowed;
}
/* Input éditable (période ouverte) : fond très légèrement vert + texte foncé + focus visible */
.grading-table input.note-input:not(:disabled) {
  background-color: #f0fdf4;
  color: #0f172a;
  font-weight: 600;
  cursor: text;
  border-radius: 3px;
  transition: box-shadow 0.15s, background-color 0.15s, border-color 0.15s;
}
.grading-table input.note-input:not(:disabled):hover {
  background-color: #dcfce7;
}
.grading-table input.note-input:not(:disabled):focus {
  outline: none;
  box-shadow: 0 0 0 2px #10b981;
  background-color: #ffffff;
}
/* Feedback enregistrement */
.grading-table input.note-input.note-saved {
  box-shadow: 0 0 0 2px #10b981 inset;
  background-color: #d1fae5 !important;
}
.grading-table input.note-input.note-error {
  box-shadow: 0 0 0 2px #ef4444 inset;
  background-color: #fee2e2 !important;
  color: #991b1b !important;
}

.grading-table .col-locked {
  background-color: #f8fafc;
  position: relative;
}
.grading-table .col-locked input.note-input {
  background-color: #f1f5f9;
  color: #cbd5e1;
}
.grading-table th.col-locked {
  color: #64748b;
  font-style: italic;
}
.grading-table th.col-open {
  background-color: #dcfce7 !important;
  color: #166534;
}
.period-status-icon {
  display: inline-block;
  font-size: 9px;
  margin-left: 2px;
  vertical-align: super;
}

/* Sidebar */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  border-radius: 0.5rem;
  color: #d9e2ec;
  font-weight: 500;
  font-size: 0.9375rem;
  transition: all 0.15s ease;
  cursor: pointer;
  text-decoration: none;
}

.sidebar-link:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: white;
}

.sidebar-link.active {
  background-color: rgba(15, 118, 110, 0.3);
  color: white;
  border-left: 3px solid #14b8a6;
}

.sidebar-link i {
  width: 1.25rem;
  text-align: center;
}

/* Stat cards */
.stat-card {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  border: 1px solid #e2e8f0;
  transition: all 0.2s ease;
}

.stat-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid #cbd5e1;
  border-top-color: #0f766e;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Animation fade in */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

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

/* Toast notification */
.toast {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
  background: white;
  border-left: 4px solid #0f766e;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 18rem;
  max-width: 24rem;
  animation: slideIn 0.3s ease-out;
}

.toast.toast-error {
  border-left-color: #dc2626;
}

.toast.toast-success {
  border-left-color: #059669;
}

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

/* Section title */
.section-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #102a43;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.section-subtitle {
  color: #627d98;
  font-size: 0.9375rem;
  margin-top: 0.25rem;
}

/* Empty state */
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: #627d98;
}

.empty-state i {
  font-size: 3rem;
  color: #cbd5e1;
  margin-bottom: 1rem;
}

/* ============================================
   RESPONSIVE MOBILE PROFESSIONNEL
   ============================================ */

/* --- Sidebar : drawer sur mobile, fixe sur desktop --- */
.app-sidebar {
  transition: transform 0.28s ease;
  /* Ancrage top/bottom (au lieu de height:100vh/100dvh) : la sidebar est
     TOUJOURS bornee a la zone reellement visible, meme quand la barre du
     navigateur mobile est affichee. Le nav interne scrolle (flex-1 +
     overflow-y-auto) et le bouton Deconnexion reste epingle en bas. */
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  height: auto;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 1023.98px) {
  /* Cachee hors ecran par defaut sur mobile/tablette */
  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  /* Ouverte via le hamburger */
  .app-sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  }
}

@media (min-width: 1024px) {
  /* Toujours visible sur desktop */
  .app-sidebar {
    transform: none !important;
  }
}

/* --- Zones tactiles confortables sur mobile --- */
@media (max-width: 767.98px) {
  .sidebar-link {
    padding: 0.875rem 1rem;
    font-size: 1rem;
  }

  .section-title {
    font-size: 1.25rem;
  }

  .btn-primary,
  .btn-secondary,
  .btn-danger,
  .btn-success {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    min-height: 2.75rem; /* cible tactile 44px */
  }

  /* Les groupes de boutons d'action passent a la ligne proprement */
  .stat-card {
    padding: 1rem;
  }

  /* Toasts : pleine largeur en bas sur mobile (plus naturel au pouce) */
  .toast {
    top: auto;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    min-width: 0;
    max-width: none;
  }

  /* Modals : plein ecran confortable sur mobile */
  .modal-overlay {
    padding: 0.5rem;
    align-items: flex-end;
  }

  .modal-content,
  .modal-content.modal-lg,
  .modal-content.modal-xl {
    max-width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: 0.75rem 0.75rem 0 0;
  }

  /* Tables de donnees : padding reduit pour voir plus de contenu */
  .data-table th,
  .data-table td {
    padding: 0.625rem 0.625rem;
    font-size: 0.8125rem;
    white-space: nowrap;
  }
}

/* --- Conteneurs scrollables avec inertie tactile --- */
.overflow-x-auto {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* Indice visuel de scroll horizontal sur mobile (degrade a droite) */
@media (max-width: 767.98px) {
  .table-scroll-hint {
    position: relative;
  }
  .table-scroll-hint::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to left, rgba(255, 255, 255, 0.95), transparent);
    pointer-events: none;
  }
}

/* --- Fiche de cotation sur mobile : colonne noms fixe (sticky) --- */
@media (max-width: 1023.98px) {
  .grading-table .col-name {
    min-width: 130px;
    max-width: 160px;
    position: sticky;
    left: 0;
    background: #ffffff;
    z-index: 2;
    box-shadow: 2px 0 4px -2px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .grading-table thead .col-name {
    background: #f1f5f9;
    z-index: 3;
  }
  .grading-table .row-maxima .col-name {
    background: #fef3c7;
  }
  /* Cellules de saisie assez larges pour le doigt */
  .grading-table input.note-input {
    min-width: 44px;
    min-height: 36px;
    font-size: 16px; /* empeche le zoom automatique iOS */
  }
  .grading-table th,
  .grading-table td {
    padding: 6px 4px;
  }
}

/* --- Bulletins consultes sur mobile : scroll horizontal naturel ---
   La page bulletin fait 210mm de large ; sur petit ecran on permet
   le defilement horizontal + pincement pour zoomer. --- */
@media (max-width: 767.98px) {
  .bulletin-mobile-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* --- Grilles KPI : 1 colonne sur tres petit ecran --- */
@media (max-width: 479.98px) {
  .grid.grid-cols-2 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
}
