/* =========================================================
   QHSEfrance — Theme Toggle / France Tech
   Componente global: mismo aspecto en todas las páginas.
   No depende de los colores de QHSEproTools ni FIREproTools.
   ========================================================= */

.theme-toggle {
  /* Identidad propia del control QHSEfrance */
  --tt-night: #071426;
  --tt-surface: #0d2138;
  --tt-france: #164b9b;
  --tt-tech: #2f73ff;
  --tt-red: #e63946;
  --tt-white: #ffffff;

  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 99999;

  min-width: 154px;
  height: 46px;
  padding: 0 16px;

  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;

  /* 1ª capa = scan; 2ª capa = vidrio tecnológico */
  background:
    linear-gradient(
      105deg,
      transparent 0%,
      transparent 43%,
      rgba(255, 255, 255, 0.00) 46%,
      rgba(255, 255, 255, 0.26) 50%,
      rgba(255, 255, 255, 0.00) 54%,
      transparent 57%,
      transparent 100%
    ) -190px 0 / 92px 100% no-repeat,
    linear-gradient(
      135deg,
      rgba(7, 20, 38, 0.96) 0%,
      rgba(13, 33, 56, 0.94) 100%
    );

  color: var(--tt-white) !important;
  -webkit-text-fill-color: var(--tt-white) !important;

  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.10);

  backdrop-filter: blur(14px) saturate(1.12);
  -webkit-backdrop-filter: blur(14px) saturate(1.12);

  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;

  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: 0.01em;

  isolation: isolate;

  transition:
    transform 0.20s ease,
    box-shadow 0.28s ease,
    border-color 0.28s ease,
    background-position 0.75s cubic-bezier(.22,.61,.36,1);
}

/* Borde energético azul France → bleu tech → rouge.
   Se mueve lentamente incluso en reposo. */
.theme-toggle::before {
  content: "";
  position: absolute;
  inset: -2px;
  z-index: -1;

  padding: 1.5px;
  border-radius: inherit;

  background:
    linear-gradient(
      110deg,
      var(--tt-france) 0%,
      var(--tt-tech) 32%,
      #f7f9fc 50%,
      var(--tt-red) 68%,
      var(--tt-france) 100%
    );
  background-size: 240% 100%;

  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;

  opacity: 0.78;
  filter:
    drop-shadow(0 0 5px rgba(47, 115, 255, 0.34))
    drop-shadow(0 0 4px rgba(230, 57, 70, 0.18));

  pointer-events: none;
  animation: qf-tech-border-flow 7s linear infinite;
}

/* Firma tricolor mínima: no convierte el botón en una bandera,
   pero refuerza discretamente la identidad France Tech. */
.theme-toggle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 46px;
  height: 2px;
  transform: translateX(-50%);
  border-radius: 99px;
  background: linear-gradient(
    90deg,
    var(--tt-france) 0 33.333%,
    #f7f9fc 33.333% 66.666%,
    var(--tt-red) 66.666% 100%
  );
  opacity: 0.48;
  pointer-events: none;
  box-shadow: 0 0 6px rgba(47, 115, 255, 0.18);
}

.theme-toggle:hover {
  transform: translateY(-2px);
  border-color: rgba(143, 176, 255, 0.42);

  /* El scan cruza el control una sola vez con el hover */
  background-position:
    calc(100% + 190px) 0,
    0 0;

  box-shadow:
    0 16px 38px rgba(0, 0, 0, 0.34),
    0 0 18px rgba(47, 115, 255, 0.16),
    0 0 14px rgba(230, 57, 70, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.theme-toggle:hover::before {
  opacity: 1;
  filter:
    drop-shadow(0 0 7px rgba(47, 115, 255, 0.46))
    drop-shadow(0 0 5px rgba(230, 57, 70, 0.26));
}

.theme-toggle:active {
  transform: translateY(0) scale(0.985);
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.28),
    0 0 16px rgba(47, 115, 255, 0.18);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.30),
    0 0 0 3px rgba(47, 115, 255, 0.32),
    0 0 20px rgba(47, 115, 255, 0.18);
}

/* ========================= NÚCLEO ========================= */

.theme-toggle__icons {
  position: relative;
  width: 29px;
  height: 29px;
  border-radius: 999px;

  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.34), transparent 28%),
    linear-gradient(
      135deg,
      var(--tt-france) 0%,
      var(--tt-tech) 48%,
      var(--tt-red) 100%
    );

  color: var(--tt-white) !important;
  -webkit-text-fill-color: var(--tt-white) !important;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;

  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.18),
    0 0 10px rgba(47, 115, 255, 0.34),
    inset 0 1px 2px rgba(255, 255, 255, 0.18);

  transition:
    transform 0.38s cubic-bezier(.2,.8,.2,1),
    box-shadow 0.28s ease;
}

.theme-toggle:hover .theme-toggle__icons {
  transform: rotate(10deg) scale(1.05);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.24),
    0 0 14px rgba(47, 115, 255, 0.48),
    0 0 9px rgba(230, 57, 70, 0.20),
    inset 0 1px 2px rgba(255, 255, 255, 0.22);
}

.theme-toggle__icon {
  width: 16px;
  height: 16px;
  display: none;
  color: var(--tt-white) !important;
  fill: currentColor;
  stroke: currentColor;
}

/* La aparición del nuevo icono actúa como microanimación del cambio de theme */
body[data-theme="light"] .theme-toggle__icon--sun,
body[data-theme="dark"] .theme-toggle__icon--moon {
  display: block;
  animation: qf-theme-icon-in 0.46s cubic-bezier(.2,.8,.2,1);
}

/* ========================= TEXTO ========================= */

.theme-toggle__label,
body[data-theme="light"] .theme-toggle__label,
body[data-theme="dark"] .theme-toggle__label,
body[data-theme="light"] .theme-toggle span,
body[data-theme="dark"] .theme-toggle span {
  color: var(--tt-white) !important;
  -webkit-text-fill-color: var(--tt-white) !important;
}

.theme-toggle__label {
  position: relative;
  white-space: nowrap;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.28);
}

/* SVG/iconos: blindaje contra overrides globales del theme light */
.theme-toggle svg,
.theme-toggle svg *,
body[data-theme="light"] .theme-toggle svg,
body[data-theme="light"] .theme-toggle svg * {
  color: var(--tt-white) !important;
  fill: currentColor;
  stroke: currentColor;
}

/* ========================= ANIMACIONES ========================= */

@keyframes qf-tech-border-flow {
  0%   { background-position: 0% 50%; }
  100% { background-position: 240% 50%; }
}

@keyframes qf-theme-icon-in {
  0% {
    opacity: 0;
    transform: rotate(-160deg) scale(0.62);
    filter: blur(2px);
  }
  65% {
    opacity: 1;
    transform: rotate(12deg) scale(1.10);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: rotate(0deg) scale(1);
    filter: blur(0);
  }
}

/* ========================= RESPONSIVE ========================= */

@media (max-width: 600px) {
  .theme-toggle {
    right: 12px;
    bottom: 12px;
    min-width: 132px;
    height: 42px;
    padding: 0 12px;
    gap: 8px;
    font-size: 0.84rem;
  }

  .theme-toggle__icons {
    width: 26px;
    height: 26px;
  }

  .theme-toggle__icon {
    width: 15px;
    height: 15px;
  }

  .theme-toggle::after {
    width: 38px;
  }
}

/* Respeta las preferencias de accesibilidad.
   El diseño visual permanece, sólo se detienen movimientos. */
@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-toggle__icons {
    transition: none;
  }

  .theme-toggle::before,
  body[data-theme="light"] .theme-toggle__icon--sun,
  body[data-theme="dark"] .theme-toggle__icon--moon {
    animation: none;
  }

  .theme-toggle:hover {
    background-position:
      -190px 0,
      0 0;
  }
}


/* =========================================================
   INTEGRACIÓN VISUAL CON LA BARRA QHSEfrance
   Shell = mismos grises de navegación.
   El núcleo France Tech sigue aportando azul/rojo.
   ========================================================= */

/* DARK / por defecto: mismo graphite que la navbar */
.theme-toggle,
body[data-theme="dark"] .theme-toggle {
  background:
    linear-gradient(
      105deg,
      transparent 0%,
      transparent 43%,
      rgba(255, 255, 255, 0.00) 46%,
      rgba(255, 255, 255, 0.22) 50%,
      rgba(255, 255, 255, 0.00) 54%,
      transparent 57%,
      transparent 100%
    ) -190px 0 / 92px 100% no-repeat,
    linear-gradient(135deg, #151e28 0%, #111820 58%, #0d141c 100%) !important;

  border-color: rgba(255, 255, 255, 0.13) !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

/* LIGHT: mismo gris acero claro que la navbar */
body[data-theme="light"] .theme-toggle {
  background:
    linear-gradient(
      105deg,
      transparent 0%,
      transparent 43%,
      rgba(255, 255, 255, 0.00) 46%,
      rgba(255, 255, 255, 0.82) 50%,
      rgba(255, 255, 255, 0.00) 54%,
      transparent 57%,
      transparent 100%
    ) -190px 0 / 92px 100% no-repeat,
    linear-gradient(135deg, #edf1f5 0%, #e3e8ef 58%, #d8dfe7 100%) !important;

  border-color: rgba(20, 32, 51, 0.13) !important;
  box-shadow:
    0 12px 28px rgba(20, 32, 51, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.82) !important;
}

/* Conservamos el requisito anterior:
   icono y texto visibles en blanco también en light.
   El label recibe una cápsula graphite interna. */
body[data-theme="light"] .theme-toggle__label {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #18222d 0%, #111820 100%);
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  box-shadow:
    0 4px 12px rgba(20, 32, 51, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* En dark la cápsula se funde con el shell para que no parezca doble botón */
body[data-theme="dark"] .theme-toggle__label,
body:not([data-theme]) .theme-toggle__label {
  padding: 0;
  background: transparent;
  box-shadow: none;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

/* Núcleo coherente con France Tech: azul Francia → bleu tech → rouge */
.theme-toggle__icons {
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.34), transparent 28%),
    linear-gradient(135deg, #164b9b 0%, #2f73ff 50%, #e63946 100%) !important;
}

/* Hover integrado */
body[data-theme="light"] .theme-toggle:hover {
  border-color: rgba(22, 75, 155, 0.28) !important;
  box-shadow:
    0 15px 34px rgba(20, 32, 51, 0.16),
    0 0 16px rgba(47, 115, 255, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.88) !important;
}

body[data-theme="dark"] .theme-toggle:hover,
body:not([data-theme]) .theme-toggle:hover {
  border-color: rgba(47, 115, 255, 0.34) !important;
}

/* Blindaje final contra light_override.css */
body[data-theme="light"] .theme-toggle span,
body[data-theme="light"] .theme-toggle__label,
body[data-theme="light"] .theme-toggle__icons,
body[data-theme="light"] .theme-toggle svg,
body[data-theme="light"] .theme-toggle svg * {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}
