/* ==========================================
   STYLES GÉNÉRAUX & RESET
   ========================================== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #f8fafc;
  color: #1e293b;
}

/* LA CLASSE HIDDEN DOIT TOUJOURS ÊTRE PRIORITAIRE ABSOLUE */
.hidden {
  display: none !important;
}

/* ==========================================
   BARRE SUPÉRIEURE (TOP BAR) DESKTOP
   ========================================== */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 55px;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #ffffff;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  border-bottom: 3px solid #b91c1c;
  z-index: 1000;
  box-sizing: border-box;
}

/* ==========================================
   BOUTON MENU MOBILE (TOGGLE)
   ========================================== */
#mobileMenuToggle {
  display: none;
}

/* ==========================================
   STRUCTURE PRINCIPALE & MENU LATÉRAL DESKTOP
   ========================================== */
#appSection {
  display: flex;
  min-height: calc(100vh - 55px);
  margin-top: 55px;
  position: relative;
}

/* Conteneur de la barre latérale sur Desktop */
#mainSidebarTabs.main-tabs, 
.main-tabs {
  position: fixed;
  top: 55px;
  left: 0;
  width: 250px;
  height: calc(100vh - 55px);
  background-color: #0f172a;
  overflow-y: auto;
  z-index: 900;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 2px solid #1e293b;
  margin: 0;
  padding: 0;
  transition: transform 0.3s ease-in-out;
}

/* Zone du contenu principal à droite du menu */
#appSection > div:not(.main-tabs) {
  margin-left: 250px;
  padding: 20px;
  flex: 1;
  box-sizing: border-box;
  width: calc(100% - 250px);
  transition: all 0.3s ease;
}

/* Style des boutons du menu latéral */
.main-tab-btn {
  display: block;
  width: 100%;
  background: transparent;
  color: #94a3b8;
  border: none;
  border-left: 4px solid transparent;
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  box-sizing: border-box;
  border-radius: 0;
}

.main-tab-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.main-tab-btn.active {
  background-color: #1e293b;
  color: #ffffff;
  border-left-color: #b91c1c;
  font-weight: bold;
}

/* ==========================================
   ALIGNEMENT ET GESTION DES FILTRES
   ========================================== */
.filter-single-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
}

.filter-single-line > div {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.filter-single-line select,
.filter-single-line input[type="text"],
.filter-single-line input[type="date"] {
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background-color: #fff;
  box-sizing: border-box;
}

/* ==========================================
   CHARTE GRAPHIQUE DES BADGES DE STATUT
   ========================================== */
.badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  display: inline-block;
  text-align: center;
}

.badge-pending {
  background-color: #fef08a;
  color: #854d0e;
}

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

.badge-approved2 {
  background-color: #dcfce7;
  color: #166534;
}

/* ==========================================
   ANIMATION PULSATION / CLIGNOTEMENT BROUILLONS
   ========================================== */
@keyframes pulseRedYellow {
  0% {
    background-color: #b91c1c;
    color: #ffffff;
    box-shadow: 0 0 0 0 rgba(185, 28, 28, 0.7);
  }
  50% {
    background-color: #eab308;
    color: #000000;
    box-shadow: 0 0 0 6px rgba(234, 179, 8, 0.3);
  }
  100% {
    background-color: #b91c1c;
    color: #ffffff;
    box-shadow: 0 0 0 0 rgba(185, 28, 28, 0);
  }
}

.badge-pulse,
.pulsing-badge,
.report-draft-pulse,
.draft-active-pulse,
.badge-active-drafts,
.tab-active-drafts,
#draftCountBadge.has-drafts,
#presenceDraftCountBadge.has-drafts {
  animation: pulseRedYellow 1.6s infinite ease-in-out !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 2px 8px;
  font-weight: bold;
}

/* ==========================================
   CARTES, FORMULAIRES ET BOUTONS STANDARD
   ========================================== */
.card {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 20px;
  margin-bottom: 20px;
}

#loginSection {
  margin-top: 90px;
  max-width: 450px;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

/* Tableaux */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  margin-bottom: 15px;
  background: #ffffff;
}

th, td {
  border: 1px solid #e2e8f0;
  padding: 8px 10px;
  text-align: left;
  font-size: 13px;
}

th {
  background-color: #f1f5f9;
  color: #334155;
  font-weight: bold;
}

/* Champs de saisie */
input[type="text"], 
input[type="date"], 
input[type="number"], 
input[type="password"], 
select, 
textarea {
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 13px;
  background-color: #ffffff;
  color: #1e293b;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #0284c7;
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.15);
}

/* Boutons d'action */
.btn-success { background-color: #16a34a; color: #ffffff; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-weight: 500; font-size: 13px; }
.btn-success:hover { background-color: #15803d; }

.btn-warning { background-color: #d97706; color: #ffffff; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-weight: 500; font-size: 13px; }
.btn-warning:hover { background-color: #b45309; }

.btn-danger { background-color: #dc2626; color: #ffffff; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-weight: 500; font-size: 13px; }
.btn-danger:hover { background-color: #b91c1c; }

.btn-secondary { background-color: #64748b; color: #ffffff; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-weight: 500; font-size: 13px; }
.btn-secondary:hover { background-color: #475569; }

/* Onglets d'administration & sous-onglets */
.admin-tabs {
  display: flex;
  gap: 5px;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 15px;
  flex-wrap: wrap;
}

.admin-tab-btn {
  background: #e2e8f0;
  border: none;
  padding: 8px 14px;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #475569;
}

.admin-tab-btn.active {
  background: #b91c1c;
  color: #ffffff;
  font-weight: bold;
}

.admin-pane, .report-sub-pane, .presence-sub-pane, .main-pane {
  display: none;
}

.admin-pane.active, .report-sub-pane.active, .presence-sub-pane.active, .main-pane.active {
  display: block;
}

/* Modales */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.modal-content {
  background: #ffffff;
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  max-width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-sizing: border-box;
}

/* Saisie des heures & colonnes spécifiques */
#timesheetTable input.hour-input,
.hour-input,
table input.km-day,
table input.repas-day {
  width: 55px !important;
  min-width: 55px !important;
  max-width: 65px !important;
  text-align: center !important;
  box-sizing: border-box;
  padding: 6px 2px !important;
}

/* ==========================================
   MODULE INSPECTION HEBDOMADAIRE (SOMBRE)
   ========================================== */
.inspection-card {
  background-color: #1e242d;
  border: 1px solid #323b48;
  border-radius: 8px;
  color: #e1e6ed;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  overflow: hidden;
}

.inspection-card .card-header {
  background-color: #171c24;
  border-bottom: 1px solid #323b48;
  font-weight: bold;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  color: #f59e0b;
}

/* Items à inspecter */
.inspection-item {
  padding: 8px 0;
  border-bottom: 1px solid #2a323d;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.inspection-item:last-child {
  border-bottom: none;
}

/* Groupe de boutons d'état */
.btn-status-group {
  display: inline-flex;
  gap: 4px;
}

.btn-status-group .btn {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #475569;
  background-color: #0f172a;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
}

.btn-status-group .btn:hover {
  background-color: #1e293b;
  color: #ffffff;
}

.btn-status-ok.active {
  background-color: #16a34a !important;
  color: #ffffff !important;
  border-color: #16a34a !important;
  box-shadow: 0 0 8px rgba(22, 163, 74, 0.4);
}

.btn-status-issue.active {
  background-color: #dc2626 !important;
  color: #ffffff !important;
  border-color: #dc2626 !important;
  box-shadow: 0 0 8px rgba(220, 38, 38, 0.4);
}

/* Schéma du camion / coffres */
.truck-diagram {
  background: #11151c;
  border-radius: 6px;
  padding: 12px;
  position: relative;
  text-align: center;
  border: 1px solid #2a323d;
  margin-bottom: 12px;
}

.truck-diagram img {
  max-width: 100%;
  height: auto;
  opacity: 0.85;
}

.coffre-badge {
  font-size: 0.7rem;
  padding: 3px 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  background-color: #1e293b;
  color: #f59e0b;
  border: 1px solid #f59e0b;
  border-radius: 4px;
}

.coffre-badge.active {
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
  background-color: #f59e0b;
  color: #0f172a;
  font-weight: bold;
}

/* ==========================================
   ADAPTATION RESPONSIVE (MOBILE < 900px)
   ========================================== */
@media (max-width: 900px) {

  .top-bar {
    padding: 6px 12px !important;
    height: 52px !important;
  }

  .user-status-container {
    gap: 6px !important;
    font-size: 11px !important;
    max-width: 65% !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #userRoleBadge {
    display: none !important;
  }

  #userInfo span {
    font-size: 12px !important;
  }

  .top-bar-actions {
    gap: 6px !important;
  }

  .top-bar-btn {
    padding: 6px 10px !important;
    font-size: 0 !important;
    height: 36px !important;
    width: 36px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 8px !important;
    position: relative !important;
  }

  #notifyBtn::before {
    content: "🔔";
    font-size: 16px;
  }

  .top-bar-btn[onclick*="refreshAppData"]::before {
    content: "🔄";
    font-size: 16px;
  }

  #notifyBadge {
    position: absolute !important;
    top: -4px !important;
    right: -4px !important;
    font-size: 10px !important;
    padding: 2px 5px !important;
    border: 2px solid #1e293b !important;
  }

  #appSection:not(.hidden) {
    display: block !important;
    margin-top: 52px !important;
  }

  #appSection:not(.hidden) #mobileMenuToggle {
    display: block !important;
    position: fixed !important;
    top: 58px !important;
    left: 10px !important;
    z-index: 2000 !important;
    background: #0f172a !important;
    color: #ffffff !important;
    border: 1px solid #334155 !important;
    padding: 8px 12px !important;
    border-radius: 6px !important;
    font-size: 12px !important;
    font-weight: bold !important;
    cursor: pointer !important;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3) !important;
    width: auto !important;
  }

  #loginSection {
    margin-top: 80px !important;
    padding: 15px !important;
    width: 92% !important;
  }

  #appSection > div:not(.main-tabs) {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 10px !important;
    padding-top: 50px !important;
  }

  #mainSidebarTabs.main-tabs, 
  .main-tabs {
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
    z-index: 1001 !important;
    width: 260px !important;
    padding-top: 45px !important;
  }

  #mainSidebarTabs.sidebar-open {
    transform: translateX(0) !important;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .modal-content {
    width: 95% !important;
    padding: 15px !important;
  }
}