/* === Reset & Global Dark Theme === */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  background: #121212;
  color: #e0e0e0;
  display: flex;
  font-size: 16px; 
  line-height: 1.6;
}

a {
  color: #40A9E0;
  text-decoration: none;
  transition: color 0.2s ease-in-out;
}

a:hover {
  text-decoration: underline;
  color: #6abef3;
}

/* === Header === */
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 1000;
  border-bottom: 1px solid #27293d;
}

header .brand-logo {
  display: flex;
  align-items: center;
}

header .brand-logo img {
  height: 38px;
  width: auto;
}

header .brand-logo .app-name {
  margin-left: 0.8rem;
  font-size: 1.2rem;
  font-weight: 600;
  color: #e0e0e0;
}

header .btn-logout {
  background: transparent;
  border: 1px solid #4a4a60;
  padding: 0.5em 0.9em;
  border-radius: 5px;
  color: #e0e0e0;
  cursor: pointer;
  transition: background 0.2s ease-in-out, border-color 0.2s ease-in-out;
  display: flex;
  align-items: center;
}
header .btn-logout i {
  margin-right: 0.5em;
}

header .btn-logout:hover,
header .btn-logout:focus {
  background: rgba(224, 224, 224, 0.1);
  border-color: #6abef3;
  outline: none;
}


/* === Login page ======================================================= */
.login-container{
  position:fixed;          /* occupe tout l’écran, au-dessus de tout */
  inset:0;                 /* équivalent de top:0; right:0; bottom:0; left:0 */
  display:flex;
  flex-direction:column;   /* au cas où d’autres éléments s’ajoutent */
  align-items:center;
  justify-content:center;  /* *** centre vraiment verticalement *** */
  background:#121212;
}

.login-card{
  background:#1f1f2e;
  width:100%;
  max-width:380px;             /* largeur fixe mais responsive */
  padding:2.5rem 2rem;
  border-radius:8px;
  box-shadow:0 4px 12px rgba(0,0,0,.55);
  text-align:center;
}

/* titres, champs et bouton conservent l’UX du dark-theme  */
.login-card h2{
  margin-bottom:1.5rem;
  font-size:1.6rem;
  font-weight:600;
  color:#40A9E0;
}

.login-card label{
  display:block;
  text-align:left;
  margin-top:1rem;
  font-weight:500;
  color:#ccc;
}

.login-card input{
  width:100%;
  padding:.65em .9em;
  margin-top:.35em;
  border:1px solid #333;
  border-radius:4px;
  background:#292936;
  color:#e0e0e0;
}

.login-card button{
  width:100%;
  margin-top:1.8rem;
  padding:.85em 1.2em;
  background:#40A9E0;
  color:#121212;
  border:none;
  border-radius:4px;
  font-size:1rem;
  font-weight:600;
  cursor:pointer;
  transition:background .2s;
}
.login-card button:hover{background:#38a0ca;}


/* === Loading Overlay & Spinner === */
#loadingOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(18, 18, 18, 0.85);
  justify-content: center;
  align-items: center;
  z-index: 3000;
  pointer-events: all;
}

#loadingOverlay.active {
  display: flex;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 6px solid #292936;
  border-top: 6px solid #40A9E0;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* === Sidebar === */
.sidebar {
  position: fixed;
  top: 60px;
  left: 0;
  width: 230px;
  bottom: 0;
  background: #1f1f2e;
  padding-top: 1.5rem;
  overflow-y: auto;
  border-right: 1px solid #27293d;
}

.sidebar__menu {
  list-style: none;
}

.sidebar__item {
  padding: 0.85rem 1.5rem;
  color: #c0c0d0;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background 0.2s ease-in-out, color 0.2s ease-in-out;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
}

.sidebar__item i {
  margin-right: 1rem;
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.sidebar__item:hover {
  background: #27293d;
  color: #fff;
  border-left-color: #40A9E0;
}

.sidebar__item.active {
  background: #2a2c44;
  color: #fff;
  font-weight: 600;
  border-left-color: #40A9E0;
}

.sidebar__submenu {
  list-style: none;
  padding-left: 2rem;
  margin-top: 0.5rem;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}
.sidebar__item.open > .sidebar__submenu {
    max-height: 500px;
}

.sidebar__subitem {
  padding: 0.5rem 0 0.5rem 1.5rem;
  color: #a0a0b8;
  cursor: pointer;
  transition: color 0.2s ease-in-out;
  font-size: 0.9rem;
  position: relative;
}
.sidebar__subitem::before {
  content: "";
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  background-color: #5c5e7d;
  border-radius: 50%;
}

.sidebar__subitem:hover,
.sidebar__subitem.active {
  color: #fff;
}
.sidebar__subitem:hover::before {
  background-color: #40A9E0;
}

/* === Main container === */
.container {
  margin-top: 60px;
  margin-left: 230px;
  padding: 2.5rem;
  width: calc(100% - 230px);
  overflow-x: hidden;
}

/* === Flash Messages === */
.flash {
  padding: 1em 1.25em;
  border-radius: 6px;
  margin-bottom: 1.5em;
  font-weight: 500;
  color: #fff;
  display: flex;
  align-items: center;
  opacity: 1;
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}
.flash i {
  margin-right: 0.8em;
}

.flash.success {
  background: #2f855a;
}

.flash.error {
  background: #c53030;
}
.flash.disappearing {
  opacity: 0;
  transform: translateY(-20px);
}

/* === Cards (Général) === */
.form-card, 
.table-card {
  background: #1f1f2e;
  border-radius: 8px;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  border: 1px solid #27293d;
}

.form-card.import-trigger {
  padding: 0; 
  background: transparent;
  border: none;
  box-shadow: none;
}

/* === DataTables Dark Styling === */
table.dataTable {
  width: 100% !important;
  border-collapse: separate !important;
  border-spacing: 0;
  border: 1px solid #2c2e43;
  border-radius: 6px;
  overflow: hidden;
}

table.dataTable thead th {
  background: #27293d;
  color: #e0e0e0;
  font-weight: 600;
  border-bottom: 2px solid #3a3c53;
  padding: 0.9em 1em;
  text-align: left;
}
table.dataTable thead th.dt-center,
table.dataTable thead th.no-sort {
    text-align: center;
}

table.dataTable tbody tr {
  background: #1f1f2e;
  transition: background-color 0.15s ease-in-out;
}

table.dataTable tbody tr:nth-child(even) {
  background: #232334;
}

table.dataTable tbody tr:hover {
  background: #303045;
}

table.dataTable tbody td {
  padding: 0.8em 1em;
  border-bottom: 1px solid #2c2e43;
  color: #c0c0d0;
}
table.dataTable tbody tr:last-child td {
  border-bottom: none;
}
table.dataTable tbody td.dt-center {
    text-align: center;
}

/* DataTables Controls */
.dataTables_wrapper {
  margin-top: 1.5rem;
}
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
  margin-bottom: 1.5rem;
}

.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label {
  color: #bbb;
  font-weight: 500;
}

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
  background: #292936;
  color: #e0e0e0;
  border: 1px solid #38384a;
  border-radius: 5px;
  padding: 0.5em 0.8em;
  margin-left: 0.5em;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.dataTables_wrapper .dataTables_length select:focus,
.dataTables_wrapper .dataTables_filter input:focus {
  outline: none;
  border-color: #40A9E0;
  box-shadow: 0 0 0 2px rgba(64, 169, 224, 0.3);
}

.dataTables_wrapper .dataTables_paginate {
  padding-top: 1rem;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
  background: #292936;
  color: #e0e0e0 !important;
  border: 1px solid #38384a;
  padding: 0.5em 0.9em;
  margin: 0 0.2em;
  border-radius: 5px;
  transition: background 0.2s ease-in-out, border-color 0.2s ease-in-out;
  cursor: pointer;
  text-decoration: none !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: #353546;
  border-color: #40A9E0;
  color: #fff !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: #40A9E0;
  color: #121212 !important;
  border-color: #40A9E0;
  font-weight: 600;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
  background: #292936;
  color: #666 !important;
  border-color: #38384a;
  cursor: default;
}
.dataTables_info {
  color: #bbb;
  padding-top: 0.8em !important;
  font-size: 0.9rem;
}
.dataTables_processing {
  background: rgba(31, 31, 46, 0.9) !important;
  color: #e0e0e0 !important;
  border-radius: 6px;
  padding: 1em;
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
}
  
/* === Action Buttons in Table === */
.btn-preview,
.btn-download,
.btn-print {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.4em;
  color: #8699ad;
  transition: color 0.2s ease-in-out, transform 0.1s ease;
  margin: 0 0.2em;
}
.btn-preview i,
.btn-download i,
.btn-print i {
    width: 18px;
    height: 18px;
}

.btn-preview:hover, .btn-preview:focus {
  color: #40A9E0;
  transform: scale(1.1);
  outline: none;
}
.btn-download:hover, .btn-download:focus {
  color: #f5a623;
  transform: scale(1.1);
  outline: none;
}



.btn-print:hover , .btn-print:focus{         /* NEW */
  color:#f5a623;
  transform: scale(1.1);
  outline: none;
}
  
/* === Feather icons general fix === */
.feather {
  stroke: currentColor;
  width: 1em; 
  height: 1em; 
  vertical-align: -0.125em;
  stroke-width: 2;
}

/* === MODALS (Import & PDF Preview) === */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(18, 18, 18, 0.85);
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: 1rem;
}
.modal.active {
  display: flex;
}

.modal-content {
  background: #1f1f2e;
  border-radius: 8px;  
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex; /* Essentiel pour la structure interne flex */
  flex-direction: column; /* Header, form/content, footer s'empilent */
  border: 1px solid #2c2e43;
  overflow: hidden; 
}

/* Styles spécifiques pour le modal d'import */
.modal-content.import {
  width: 90vw;
  max-width: 700px; 
  min-height: 450px; /* Hauteur minimale du modal pour que la dropzone ait de la place */
  max-height: 85vh; /* Limite la hauteur maximale du modal */
}

/* Header du modal d'import (enfant de .modal-content.import) */
.modal-content.import header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #2c2e43;
  display: flex;
  justify-content: space-between; 
  align-items: center;
  position: relative; 
  flex-shrink: 0; /* Empêche le header de rétrécir si le contenu est grand */
}
.modal-content.import header h3 {
  margin: 0;
  color: #e0e0e0; 
  font-size: 1.25rem;
  font-weight: 600;
}

/* Formulaire à l'intérieur du modal d'import (enfant de .modal-content.import, après son header) */
.modal-content.import form#importForm {
  display: flex;
  flex-direction: column; /* La dropzone et le footer du form s'empilent */
  flex-grow: 1; /* Très important: le formulaire prend tout l'espace vertical restant dans .modal-content.import */
  min-height: 0; /* Recommandé pour les conteneurs flex enfants qui doivent grandir */
                 /* Cela évite que la taille intrinsèque du contenu (dropzone) n'empêche le form de s'adapter correctement */
}

/* Dropzone à l'intérieur du formulaire (enfant de form#importForm) */
.dropzone {
  flex-grow: 1; /* Très important: la dropzone prend tout l'espace vertical restant dans le formulaire (avant le footer du formulaire) */
  border: 2px dashed #38384a; 
  margin: 1.5rem; 
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column; 
  color: #888; 
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  padding: 1rem; 
  min-height: 150px; /* Hauteur minimale pour que la zone de drop soit toujours un peu visible et cliquable */
}
.dropzone:hover,
.dropzone.dragover { 
  background: rgba(64, 169, 224, 0.05); 
  border-color: #40A9E0; 
}
.dropzone.selected {
  border-style: solid; 
  border-color: #40A9E0; 
  color: #e0e0e0; 
}
.dropzone .file-selected-info { 
  display: flex;
  flex-direction: column; 
  align-items: center;
  gap: 0.8rem; 
}
.dropzone .file-selected-info i.feather { 
  width: 48px; 
  height: 48px;
  stroke-width: 1.5;
  color: #40A9E0; 
}
.dropzone .file-selected-info span { 
  font-size: 0.95rem;
  word-break: break-all; 
  padding: 0 0.5rem; 
}

/* Footer du formulaire (enfant de form#importForm, après la dropzone) */
.modal-content.import form#importForm footer {
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: flex-end; 
  gap: 0.75rem; 
  border-top: 1px solid #2c2e43;
  background-color: #1a1a2e; 
  flex-shrink: 0; /* Empêche le footer de rétrécir */
}


/* Styles spécifiques pour le modal PDF */
.modal-content.pdf {
  width: 90vw;
  max-width: 1000px;
  max-height: 90vh;  
}
.modal-content.pdf h3 { 
  color: #e0e0e0;
  font-size: 1.25rem;
  font-weight: 600;
  padding: 1rem 1.5rem 0.5rem; 
  margin:0;
  text-align: center;
  flex-shrink: 0; /* Empêche le titre de rétrécir */
}
.modal-content.pdf canvas#pdfViewer {
  width: 100%;
  height: auto; 
  max-height: calc(90vh - 7rem); /* Ajusté pour prendre en compte le titre et le padding du modal */
  margin-top: 0.5rem; 
  border-radius: 4px; 
  flex-grow: 1; /* Permet au canvas de prendre l'espace vertical restant si besoin */
  min-height: 0; /* Important pour que flex-grow fonctionne bien */
}

/* Bouton de fermeture commun aux modals */
.modal-content .close-btn { 
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  background: rgba(255,255,255,0.08);
  border: none;
  color: #aaa; 
  font-size: 1.6rem; 
  font-weight: 400;
  line-height: 1;
  padding: 0.2em 0.4em;
  border-radius: 50%; 
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s;
  z-index: 10; 
}
.modal-content .close-btn:hover {
  color: #f5a623; 
  background-color: rgba(245, 166, 35, 0.15); 
}

/* === Styles des boutons primaires et secondaires === */
.btn-primary, .btn-secondary { 
  border: none;
  padding: 0.6em 1.2em;
  border-radius: 5px; 
  cursor: pointer;
  display: inline-flex; 
  align-items: center;
  gap: 0.6em; 
  font-weight: 500;
  font-size: 0.9rem;
  transition: background-color 0.2s, transform 0.1s;
}
.btn-primary:hover, .btn-secondary:hover {
  transform: translateY(-1px); 
}
.btn-primary:active, .btn-secondary:active {
  transform: translateY(0);
}

.btn-primary {
  background-color: #f5a623; 
  color: #121212; 
}
.btn-primary:hover {
  background-color: #d48806; 
}
.btn-primary:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.4);
}

.btn-secondary {
  background-color: #38384a; 
  color: #e0e0e0; 
  border: 1px solid #4a4a60; 
}
.btn-secondary:hover {
  background-color: #4a4a60; 
}
.btn-secondary:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(74, 74, 96, 0.5);
}

/* === Responsive Adjustments === */
@media (max-width: 992px) {
  .sidebar {
    width: 200px;
  }
  .container {
    margin-left: 200px;
    width: calc(100% - 200px);
    padding: 1.5rem;
  }
  header .brand-logo .app-name {
    display: none;
  }
}

@media (max-width: 768px) {
  .sidebar {
    left: -200px;
    transition: left 0.3s ease-in-out;
    z-index: 1100;
  }
  .sidebar.open {
      left: 0;
  }
  .container {
    margin-left: 0;
    width: 100%;
    padding: 1rem;
  }
  header .brand-logo .app-name {
    display: inline-block;
  }

  .form-card, .table-card {
    padding: 1.5rem;
  }
  .modal-content.import {
      min-height: 350px; 
      max-height: 90vh;
  }
   .dropzone {
      margin: 1rem; 
      min-height: 120px; /* Réduire la hauteur min de la dropzone sur mobile */
  }
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    float: none;
    text-align: left;
    width: 100%;
  }
  .dataTables_wrapper .dataTables_length select,
  .dataTables_wrapper .dataTables_filter input {
    width: auto; 
    min-width: 150px; 
    margin-left: 0.5em;
  }
  .dataTables_wrapper .dataTables_paginate {
    text-align: center;
  }
  .dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.4em 0.6em;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }
  header {
    padding: 0 1rem;
  }
  header .brand-logo img {
      height: 32px;
  }
  .container {
    padding: 1rem 0.8rem;
  }
  .form-card, .table-card {
    padding: 1rem;
  }
  .btn-primary, .btn-secondary {
    padding: 0.7em 1em;
    font-size: 0.85rem;
  }
  .modal-content { 
      width: 95vw;
      max-height: 95vh;
  }
  .modal-content.import header h3 {
      font-size: 1.1rem;
  }
  .modal-content.import {
      min-height: 300px; 
  }
  .dropzone {
      margin: 0.8rem;
      min-height: 100px; /* Encore plus petit sur très petits écrans */
  }
  .modal-content.import form#importForm footer {
      padding: 0.75rem 1rem;
      gap: 0.5rem;
  }
   .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
      font-size: 0.9em; 
  }
  .dataTables_wrapper .dataTables_length select,
  .dataTables_wrapper .dataTables_filter input {
      padding: 0.4em 0.6em;
      font-size: 0.9em;
  }
}


/*==========  MODAL “CRÉATION UNITAIRE” ==========*/
.modal-content.single{                     /* plus soigné */
  display:flex; flex-direction:column;
  width:90vw; max-width:700px; max-height:90vh;
  background:#1f1f2e; border-radius:10px;
  box-shadow:0 8px 24px rgba(0,0,0,.6);
  overflow:hidden;
}
.modal-content.single header{
  display:flex; justify-content:space-between; align-items:center;
  padding:1rem 1.5rem; border-bottom:1px solid #333;
}
.modal-content.single header h3{margin:0;font-size:1.1rem;color:#40A9E0;}
.modal-content.single .close-btn{
  font-size:1.8rem; color:#e0e0e0; background:none;border:none;cursor:pointer;
}
.modal-content.single .close-btn:hover{color:#f5a623;}

.single-body{flex:1 1 auto; overflow-y:auto; padding:1.5rem;}
.single-body .two-cols{
  display:grid; grid-template-columns:1fr 1fr; gap:1.2rem 2rem;
}
.single-body label{display:flex;flex-direction:column;font-size:.85rem;color:#ccc;font-weight:500;}
.single-body input,.single-body select{
  margin-top:.35rem; padding:.55em .7em;
  border:1px solid #3a3c53; border-radius:6px;
  background:#292936; color:#e0e0e0; font-size:.9rem;
}
.single-body input:focus,.single-body select:focus{
  outline:none; border-color:#40A9E0;
  box-shadow:0 0 0 2px rgba(64,169,224,.35);
}

/* footer hérite du style import → juste centrer le contenu */
.modal-content.single footer{
  padding:1rem 1.5rem; border-top:1px solid #333;
  display:flex; justify-content:flex-end; gap:.8rem;
}

@media(max-width:600px){
  .single-body .two-cols{grid-template-columns:1fr;}
}




/* === DataTables custom toolbar === */
.dt-toolbar{
  display:flex;gap:.8rem;flex-wrap:wrap;margin-bottom:1rem;
}
.dt-toolbar .btn-secondary,
.dt-toolbar .btn-primary{
  padding:.45em 1em;font-size:.88rem;font-weight:500;display:inline-flex;align-items:center;gap:.5em;
}
table.dataTable tbody td.select-checkbox:before{
  content:'☐';font-size:1rem;color:#6c6c8a;
}
table.dataTable tr.selected td.select-checkbox:before{
  content:'☑';color:#40A9E0;
}
