/* Panneau principal */
.calendar-range-panel {
  position: fixed;
  z-index: 1002;
  background: linear-gradient(135deg, #23272f 0%, #2d3340 100%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  cursor: default;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  width: clamp(340px, 36vw, 420px);
  /* Position initiale via inset: top right bottom left (cohérent avec le panneau flottant) */
  inset: 200px auto auto 40px;
}

/* Assure la superposition du calendrier flatpickr au-dessus du panneau */
.flatpickr-calendar {
  z-index: 10050 !important;
}

/* Rendre cliquable toute la zone du wrapper pour ouvrir le calendrier */
.calendar-range-date-wrapper {
  cursor: text;
}
.calendar-range-date-wrapper:hover {
  box-shadow: 0 0 0 3px rgba(26, 42, 108, 0.08);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.calendar-range-panel.minimized {
  width: 340px;
}

.calendar-range-panel.analysis-success {
  animation: successPulse 0.6s ease-out;
}

@keyframes successPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

/* En-tête */
.calendar-range-header {
  background: linear-gradient(
    135deg,
    rgba(26, 42, 108, 0.97) 0%,
    rgba(26, 42, 108, 0.9) 50%,
    rgba(178, 31, 31, 0.93) 100%
  );
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.calendar-range-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: -80%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    120deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0.35) 50%,
    rgba(255, 255, 255, 0.08) 100%
  );
  filter: blur(4px);
  pointer-events: none;
  transition: left 0.5s cubic-bezier(0.4, 1.6, 0.6, 1);
  z-index: 2;
}

.calendar-range-header:hover::before {
  left: 110%;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.calendar-range-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c2c8e1;
}

.drag-icon {
  font-size: 1.4rem;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.calendar-range-header:hover .drag-icon {
  opacity: 1;
}

.icon-calendar {
  fill: currentColor;
  opacity: 0.9;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.minimize-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: white;
}

.minimize-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.minimize-icon {
  font-size: 1.2rem;
  line-height: 1;
}

/* Corps du panneau */
.calendar-range-body {
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Réduction de la hauteur max pour éviter le scroll dans la plupart des cas */
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}

/* Scrollbar personnalisée */
.calendar-range-body::-webkit-scrollbar {
  width: 6px;
}

.calendar-range-body::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.calendar-range-body::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.calendar-range-body::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Section fichier */
.calendar-range-file {
  background: #23272f;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #323846;
}

.calendar-range-file label {
  font-size: 0.85rem;
  color: #c2c8e1;
  margin-bottom: 8px;
  display: block;
  font-weight: 500;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.icon-file {
  fill: #c2c8e1;
  flex-shrink: 0;
}

.calendar-range-filename {
  font-weight: 600;
  color: #c2c8e1;
  font-size: 0.95rem;
  word-break: break-word;
}

.file-stats {
  display: flex;
  gap: 12px;
  font-size: 0.85rem;
  color: #c2c8e1;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #dee2e6;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Raccourcis */
.date-shortcuts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.date-shortcuts label {
  font-size: 0.9rem;
  color: #c2c8e1;
  font-weight: 600;
}

.shortcuts-grid {
  display: grid;
  /* 3 colonnes pour réduire la hauteur verticale */
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.shortcut-btn {
  background: #e9ecef;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  padding: 10px 6px;
  font-size: 1.08rem;
  color: #495057;
  cursor: pointer;
  transition: all 0.2s;
  white-space: normal;
  word-break: break-word;
  text-align: center;
}

/* Boutons raccourcis : texte très visible, lisible et harmonisé */
.shortcut-btn {
  background: #23272f;
  border-color: #323846;
  color: #e9ecef;
  font-size: 0.9rem;
  font-weight: 600;
  text-shadow: 0 2px 6px #000;
  letter-spacing: 0.01em;
  text-transform: none;
  padding: 8px 4px;
  min-width: 0;
  min-height: 36px;
  line-height: 1.1;
  white-space: normal;
  overflow: visible;
  word-break: break-word;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shortcut-btn:hover {
  background: #323846;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.shortcut-btn.active {
  background: #1a2a6c;
  color: white;
  animation: buttonPulse 0.3s ease-out;
  text-shadow: 0 2px 6px rgba(26, 42, 108, 0.18);
  border-color: #1a2a6c;
}

@keyframes buttonPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.95);
  }
  100% {
    transform: scale(1);
  }
}

/* Sélection de dates */
.calendar-range-dates {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
  background: #23272f;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #323846;
}

.date-input-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.date-input-group label {
  font-size: 0.85rem;
  color: #c2c8e1;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

.icon-date {
  fill: currentColor;
  opacity: 0.7;
}

.calendar-range-date {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 8px;
  border: 2px solid #e9ecef;
  font-size: 0.95rem;
  transition: all 0.2s;
  background: white;
  color: #495057;
  cursor: pointer;
  display: block;
  min-width: 0;
}
.calendar-range-date {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 36px 10px 12px; /* padding right pour l’icône custom */
  border-radius: 8px;
  border: 2px solid #e9ecef;
  font-size: 0.95rem;
  transition: all 0.2s;
  background: white;
  color: #495057;
  cursor: pointer;
  display: block;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
}

/* Icône calendrier custom en pseudo-élément */
.calendar-range-date::-webkit-calendar-picker-indicator {
  opacity: 0;
  z-index: 2;
}
.calendar-range-date::-ms-input-placeholder {
  color: #adb5bd;
}
.calendar-range-date::placeholder {
  color: #adb5bd;
}

.calendar-range-date-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  background: linear-gradient(90deg, #ffe066 0%, #fffbe6 100%);
  border-radius: 8px;
  border: 2px solid #e9ecef;
  box-sizing: border-box;
  min-height: 42px;
  margin-bottom: 4px;
}
.calendar-range-date + .calendar-icon-custom {
  display: none;
}
.calendar-range-date-wrapper .calendar-icon-custom {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  pointer-events: none;
  z-index: 1;
  opacity: 0.7;
}

.calendar-range-date:hover,
.calendar-range-date:focus {
  outline: none;
  border-color: transparent;
  box-shadow: none;
}

/* Mettre en avant le wrapper au focus */
.calendar-range-date-wrapper:focus-within {
  border-color: #1a2a6c;
  box-shadow: 0 0 0 3px rgba(26, 42, 108, 0.1);
}

.date-separator {
  font-size: 1.2rem;
  color: #c2c8e1;
  margin-top: 20px;
  /* Ne force pas une grande largeur, reste compact même en wrap */
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  transition: transform 0.3s;
}

/* Le séparateur réduisait la largeur du premier champ lorsqu'il passait à la ligne.
   On le masque pour garantir l'uniformité des largeurs. */
.calendar-range-dates .date-separator {
  display: none !important;
}

/* Sur panneaux assez hauts et écrans non étroits, mettre les deux champs côte à côte */
@media (min-width: 480px) {
  .calendar-range-dates {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

@media (max-width: 480px) {
  .calendar-range-dates {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 6px;
  }
  .date-separator {
    display: none;
  }
  .date-input-group {
    min-width: 0;
    width: 100%;
  }
}

/* Prévisualisation */
.date-preview {
  background: #23272f;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #323846;
}

.preview-label {
  font-size: 0.85rem;
  color: #c2c8e1;
  margin-bottom: 8px;
  font-weight: 500;
}

.preview-text {
  font-size: 1rem;
  color: #e9ecef;
  font-weight: 600;
  margin-bottom: 6px;
}

.preview-placeholder {
  color: #adb5bd;
  font-weight: normal;
  font-style: italic;
}

.preview-dates {
  color: #c2c8e1;
}

.preview-duration {
  font-size: 0.85rem;
  color: #c2c8e1;
  display: flex;
  align-items: center;
  gap: 4px;
}

.duration-icon {
  font-size: 1rem;
}

/* Boutons d'action */
.action-buttons {
  display: flex;
  gap: 8px;
  /* S’adapte si l’espace horizontal est limité */
  flex-wrap: wrap;
}

.calendar-range-analyze-btn {
  /* Prend la largeur disponible mais autorise le passage à la ligne */
  flex: 1 1 220px;
  background: linear-gradient(
    135deg,
    rgba(26, 42, 108, 0.95) 0%,
    rgba(26, 42, 108, 0.85) 50%,
    rgba(178, 31, 31, 0.9) 100%
  );
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.calendar-range-analyze-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -75%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    120deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0.35) 50%,
    rgba(255, 255, 255, 0.08) 100%
  );
  pointer-events: none;
  transition: left 0.5s cubic-bezier(0.4, 1.6, 0.6, 1);
  z-index: 2;
  filter: blur(20px); /* Ajout du flou pour adoucir le reflet */
}

.calendar-range-analyze-btn:hover::before,
.calendar-range-analyze-btn:focus::before {
  left: 110%;
}

.calendar-range-analyze-btn:hover:not(:disabled),
.calendar-range-analyze-btn:focus:not(:disabled) {
  background: linear-gradient(
    135deg,
    rgba(26, 42, 108, 1) 0%,
    rgba(26, 42, 108, 0.92) 50%,
    rgba(178, 31, 31, 0.98) 100%
  );
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(26, 42, 108, 0.25);
}

.calendar-range-analyze-btn:active:not(:disabled) {
  transform: translateY(0);
}

.calendar-range-analyze-btn:disabled {
  background: #adb5bd;
  cursor: not-allowed;
  transform: none;
}

.calendar-range-analyze-btn.loading {
  background: #6c757d;
}

.icon-analyze {
  fill: currentColor;
}

.loading-spinner {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  stroke: currentColor;
}

.calendar-range-reset-btn {
  background: #23272f;
  border: 2px solid #323846;
  border-radius: 10px;
  width: 44px;
  height: 44px;
  /* Reste compact même si les boutons s’enroulent */
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: #e9ecef;
}

.calendar-range-reset-btn:hover {
  background: #323846;
  color: #fff;
  transform: scale(1.1);
}

.calendar-range-reset-btn svg {
  /* fill: currentColor; */
  fill: white;
}

/* Messages d'erreur */
.calendar-range-date {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 36px 10px 12px;
  border: none;
  outline: none;
  font-size: 0.95rem;
  background: transparent;
  color: #495057;
  cursor: pointer;
  display: block;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  z-index: 2;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Dernière analyse */
.last-analysis {
  background: #d4edda;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #c3e6cb;
  font-size: 0.85rem;
}

.last-analysis-label {
  font-weight: 600;
  margin-bottom: 4px;
}

.last-analysis-info {
  display: flex;
  justify-content: space-between;
}

.analysis-period {
  font-weight: 500;
}

.analysis-count {
  opacity: 0.8;
}

/* Responsive */
@media (max-width: 768px) {
  .calendar-range-panel {
    width: calc(100% - 40px);
    /* left: 20px;
    right: 20px; */
  }

  .shortcuts-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .calendar-range-dates {
    flex-direction: column;
  }

  .date-separator {
    transform: rotate(90deg);
    margin: 0;
  }
}

/* Animation pour panneau flottant */
.calendar-range-panel.floating-left-panel {
  animation: floatIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Effet de verre (glassmorphism) optionnel */
.calendar-range-panel.glass-effect {
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

/* Thème sombre (optionnel, harmonisé) */
@media (prefers-color-scheme: dark) {
  .calendar-range-header {
    /* background: linear-gradient(135deg, #2d3d7f 0%, #1a2a6c 100%); */
    background: linear-gradient(135deg, #1a2a6c, #b21f1f);
  }

  .calendar-range-date {
    /* Style de base du champ date effet or */
    background: linear-gradient(135deg, #f7e9b0 0%, #f9d423 50%, #ffef8e 100%);
    color: #7a5c00;
    border-color: #ffe066;
    box-shadow: 0 2px 8px rgba(249, 212, 35, 0.15),
      0 1.5px 6px rgba(255, 239, 142, 0.12);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1),
      box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
      border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
  }

  .calendar-range-date::before {
    /* Reflet glossy animé (effet brillant) */
    content: "";
    position: absolute;
    top: 0;
    left: -80%;
    width: 60%;
    height: 100%;
    background: linear-gradient(
      120deg,
      rgba(255, 255, 255, 0.1) 0%,
      rgba(255, 255, 255, 0.35) 50%,
      rgba(255, 255, 255, 0.08) 100%
    );
    filter: blur(4px);
    pointer-events: none;
    transition: left 0.5s cubic-bezier(0.4, 1.6, 0.6, 1);
    z-index: 2;
  }

  .calendar-range-date:hover::before,
  .calendar-range-date:focus::before {
    /* Animation du reflet glossy au survol */
    left: 110%;
  }

  .calendar-range-date-wrapper:focus-within {
    border-color: #1a2a6c;
    box-shadow: 0 0 0 3px rgba(26, 42, 108, 0.1);
  }

  /* 
  Explications :
  - Le premier box-shadow (0 4px 16px 2px rgba(249, 212, 35, 0.25)) donne une ombre dorée diffuse.
  - Le second (0 0 24px 4px #fffbe6) ajoute un halo lumineux blanc autour.
  - Modifiez ces valeurs pour ajuster la puissance, la couleur ou la diffusion de l'effet brillant au survol.
  */

  /* Harmonisation des messages et boutons */
  .calendar-range-error {
    background: #3a2323;
    border-color: #b21f1f;
    color: #ffb3b3;
  }

  .last-analysis {
    background: #23402a;
    border-color: #27ae60;
    color: #b6f7c1;
  }

  .calendar-range-analyze-btn {
    background: linear-gradient(
      135deg,
      rgba(26, 42, 108, 0.95) 0%,
      rgba(26, 42, 108, 0.85) 50%,
      rgba(178, 31, 31, 0.9) 100%
    );
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    color: #fff;
  }

  .calendar-range-analyze-btn:disabled {
    background: #444a5a;
    color: #bbb;
  }
}

/* Boutons raccourcis et actions : texte plus visible */
.shortcut-btn,
.calendar-range-analyze-btn,
.calendar-range-reset-btn {
  color: #222 !important;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.15);
}

/* Bouton principal : texte blanc sur fond dégradé */
.calendar-range-analyze-btn {
  color: #fff !important;
  font-size: 1.08rem;
  font-weight: 700;
  text-shadow: 0 2px 6px rgba(26, 42, 108, 0.18);
}

/* Bouton reset : texte foncé */
.calendar-range-reset-btn {
  color: #1a2a6c !important;
  font-size: 1rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.12);
}

/* Raccourcis : texte foncé sur fond clair */
.shortcut-btn {
  color: #ffffff !important;
  border: 1px solid #d0e3ff;
  font-size: 0.72rem;
  letter-spacing: 0.01em;
  text-transform: none;
  padding: 12px 8px;
  min-width: 0;
  min-height: 44px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: normal;
  display: flex;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  justify-content: center;
  text-shadow: 1px 1px 2px #000, 0 0 2px #000, 1px 1px 0 #000;
}

/* Raccourcis actifs : texte blanc sur fond bleu */
.shortcut-btn.active {
  color: #fff !important;
  background: #1a2a6c;
  text-shadow: 0 2px 6px rgba(26, 42, 108, 0.18);
  border-color: #1a2a6c;
}

/* Accessibilité : forcer la visibilité du texte même en mode sombre */

@media (max-width: 600px) {
  .calendar-range-panel {
    width: 98vw;
    min-width: 0;
    left: 1vw;
    right: 1vw;
  }
  .shortcuts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Optimisations pour le drag fluide */
.calendar-range-panel {
  will-change: transform;
  backface-visibility: hidden;
}

/* État pendant le drag */
.calendar-range-panel.dragging {
  opacity: 0.9;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  -webkit-user-select: none;
  user-select: none;
}

/* Désactiver les transitions pendant le drag */
.calendar-range-panel.dragging * {
  pointer-events: none;
}

/* Curseur pendant le drag (scopé au calendrier) */
.calendar-range-panel .drag-handle {
  touch-action: none; /* Important pour le tactile */
}
