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

:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --bg-main: #F8FAFC;
  --card-bg: #FFFFFF;
  --text-main: #1E293B;
  --text-muted: #64748B;
  --border-color: #E2E8F0;
  --radius-lg: 12px;
  --radius-md: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
}

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}


body {
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Nav */
.navbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 0.8rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.navbar-brand {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  list-style: none;
}

.nav-link {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  transition: color 0.2s;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-md);
}

.nav-link:hover, .nav-link.active {
  color: var(--primary);
  background-color: #EEF2FF;
}

.user-badge {
  background: #F1F5F9;
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.btn-logout {
  color: #EF4444;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn-logout:hover {
  text-decoration: underline;
}

/* Container */
.container {
  max-width: 1400px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  width: 100%;
  flex: 1;
}

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-main);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

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

.btn-secondary {
  background-color: #F1F5F9;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: #E2E8F0;
}

.btn-danger {
  background-color: #FEE2E2;
  color: #DC2626;
}

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

/* Alerts / Flash */
.flash-messages {
  margin-bottom: 1rem;
}

.alert {
  padding: 0.9rem 1.2rem;
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.95rem;
}

.alert-success { background: #DCFCE7; color: #166534; border: 1px solid #BBF7D0; }
.alert-danger { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-warning { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.alert-info { background: #E0F2FE; color: #075985; border: 1px solid #BAE6FD; }

/* Dashboard Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* Sidebar Totaux Matières Accordéon */
.accordion-card {
  padding: 1rem !important;
}

.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.accordion-chevron {
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: transform 0.25s ease;
}

.accordion-card.collapsed .accordion-chevron {
  transform: rotate(-90deg);
}

.accordion-card.collapsed .accordion-content {
  display: none;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.matiere-stat-item {
  margin-bottom: 0.9rem;
  padding: 0.6rem 0.8rem;
  background: #F8FAFC;
  border-radius: var(--radius-md);
  border-left: 4px solid #CBD5E1;
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.progress-bar-bg {
  height: 6px;
  background: #E2E8F0;
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* Timetable Toolbar Header */
.timetable-header-toolbar {
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
}

.hebdo-toolbar-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.week-picker-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.week-picker-input {
  width: auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.88rem;
}

.period-template-toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-left: 1px solid var(--border-color);
  padding-left: 1rem;
}

.period-select-input {
  width: auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.88rem;
}

.toolbar-period-btns {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.toolbar-print-container {
  margin-left: auto;
  display: flex;
  align-items: center;
}



/* Timetable Grid CSS */
.timetable-wrapper {
  overflow-x: auto;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.timetable-header-toolbar {
  padding: 1rem;
  background: #F8FAFC;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.timetable-grid {
  display: grid;
  border-collapse: collapse;
  position: relative;
  user-select: none;
}

.grid-cell-header {
  background: #F1F5F9;
  font-weight: 700;
  text-align: center;
  padding: 0.6rem;
  font-size: 0.9rem;
  border-right: 1px solid var(--border-color);
  border-bottom: 2px solid var(--border-color);
  color: #475569;
}

.grid-time-label {
  background: #F8FAFC;
  font-size: 0.75rem;
  color: #64748B;
  font-weight: 600;
  text-align: center;
  padding: 0.2rem 0.4rem;
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid #F1F5F9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-cell-slot {
  position: relative;
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid #F1F5F9;
  height: 28px;
  cursor: pointer;
  transition: background 0.15s;
}

.grid-cell-slot:hover {
  background-color: #EEF2FF;
}

.grid-cell-slot.selected {
  background-color: #C7D2FE !important;
  border: 1px dashed var(--primary);
}

/* Merged Event Cards */
.merged-event-card {
  position: absolute;
  top: 2px;
  left: 2px;
  right: 2px;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  color: #ffffff;
  font-size: 0.82rem;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0,0,0,0.12);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 10;
}


.merged-event-card:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  z-index: 20;
}

.event-title {
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.2;
}

.event-subtitle {
  font-size: 0.75rem;
  opacity: 0.9;
}

.event-time {
  font-size: 0.7rem;
  opacity: 0.85;
  margin-top: 0.2rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  width: 90%;
  max-width: 480px;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(-20px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.3rem;
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.nav-brand-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

@media (min-width: 769px) {
  .nav-brand-container {
    width: auto;
  }
}

.nav-user-compact {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Responsive Mobile Styles (<768px) */
@media (max-width: 768px) {
  .navbar {
    padding: 0.5rem 0.8rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .nav-links {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 0.2rem;
    gap: 0.3rem;
    white-space: nowrap;
    justify-content: space-between;
  }

  .nav-link {
    font-size: 0.82rem;
    padding: 0.3rem 0.5rem;
  }

  .user-badge {
    font-size: 0.78rem;
    padding: 0.25rem 0.5rem;
  }

  .user-name-short {
    max-width: 70px;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }

  .container {
    padding: 0 0.5rem;
    margin: 0.75rem auto;
  }

  .dashboard-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }


  .timetable-header-toolbar {
    padding: 0.75rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .hebdo-toolbar-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    width: 100%;
  }

  .week-picker-container {
    justify-content: space-between;
    width: 100%;
  }

  .week-picker-input {
    flex: 1;
    max-width: 100%;
  }

  .period-template-toolbar-group {
    border-left: none;
    padding-left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    width: 100%;
  }

  .period-select-input {
    max-width: 100%;
    width: 100%;
  }

  .toolbar-period-btns {
    width: 100%;
    display: flex;
    gap: 0.4rem;
  }

  .toolbar-period-btns .btn {
    flex: 1;
    justify-content: center;
    padding: 0.5rem;
    font-size: 0.82rem;
  }

  .toolbar-print-container {
    margin-left: 0;
    width: 100%;
  }

  .toolbar-print-btn {
    width: 100%;
    justify-content: center;
    font-size: 0.85rem;
  }

  .timetable-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }


  .timetable-grid {
    min-width: 600px; /* Assure que la grille reste lisible en mode swipe horizontal */
  }

  .timetable-grid.mobile-single-day {
    min-width: 100% !important; /* Mode 1 jour unique sur mobile */
  }

  .mobile-day-tabs {
    display: flex !important;
    overflow-x: auto;
    background: #F1F5F9;
    padding: 0.4rem;
    border-bottom: 1px solid var(--border-color);
    gap: 0.4rem;
  }

  .mobile-day-tab {
    flex: 1;
    min-width: 44px;
    padding: 0.4rem 0.6rem;
    text-align: center;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    background: #ffffff;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    cursor: pointer;
  }

  .mobile-day-tab.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
  }

  .modal-card {
    width: 95% !important;
    padding: 1.2rem !important;
    max-height: 90vh;
    overflow-y: auto;
  }

  .btn {
    padding: 0.5rem 0.9rem;
    font-size: 0.88rem;
  }
}

/* Print CSS */
@media print {
  .navbar, .timetable-header-toolbar, .dashboard-sidebar, .btn, .no-print, .mobile-day-tabs {
    display: none !important;
  }
  .dashboard-grid {
    display: block !important;
  }
  .container {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .timetable-wrapper {
    border: none !important;
    box-shadow: none !important;
  }
  @page {
    size: A4 landscape;
    margin: 10mm;
  }
}

