/**
 * Glass Button Component - Version Améliorée
 * Bouton glassmorphique réutilisable avec support dark/light mode
 * Taille: 28px × 28px (fixe)
 */

/* ========================================
   VARIABLES CSS - Angles d'animation
   ======================================== */

@property --angle-1 {
  syntax: "<angle>";
  inherits: false;
  initial-value: -75deg;
}

@property --angle-2 {
  syntax: "<angle>";
  inherits: false;
  initial-value: -45deg;
}

/* ========================================
   CONTENEUR PRINCIPAL
   ======================================== */

.glass-button-wrap {
  position: relative;
  z-index: 2;
  width: 28px;
  height: 28px;
  margin-left: 0;
  background: transparent;
  border-radius: 50%;
  pointer-events: none;
  transition: all 400ms cubic-bezier(0.25, 1, 0.5, 1);
}

/* Aligner avec les autres icônes quand la sidebar est ouverte */
body.sidebar-open .glass-button-wrap {
  margin-left: 0;
}

/* ========================================
   OMBRE PORTÉE DU BOUTON
   ======================================== */

.glass-button-shadow {
  --shadow-cuttoff-fix: 2em;
  position: absolute;
  width: calc(100% + var(--shadow-cuttoff-fix));
  height: calc(100% + var(--shadow-cuttoff-fix));
  top: calc(0% - var(--shadow-cuttoff-fix) / 2);
  left: calc(0% - var(--shadow-cuttoff-fix) / 2);
  filter: blur(8px);
  pointer-events: none;
  overflow: visible;
}

.glass-button-shadow::after {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 0;
  width: calc(100% - var(--shadow-cuttoff-fix) - 0.25em);
  height: calc(100% - var(--shadow-cuttoff-fix) - 0.25em);
  top: calc(var(--shadow-cuttoff-fix) - 0.5em);
  left: calc(var(--shadow-cuttoff-fix) - 0.875em);
  padding: 0.125em;
  box-sizing: border-box;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.08));
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  opacity: 1;
  overflow: visible;
  transition: all 400ms cubic-bezier(0.25, 1, 0.5, 1);
}

/* ========================================
   BOUTON PRINCIPAL
   ======================================== */

.glass-button {
  --border-width: 1.5px;
  all: unset;
  cursor: pointer;
  position: relative;
  pointer-events: auto;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: all 400ms cubic-bezier(0.25, 1, 0.5, 1);

  /* Light Mode - Background & Effects */
  background: linear-gradient(
    -75deg,
    rgba(255, 255, 255, 0.05),
    rgba(255, 255, 255, 0.2),
    rgba(255, 255, 255, 0.05)
  );
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);

  /* Light Mode - Multi-layer Box Shadow */
  box-shadow:
    inset 0 2px 2px rgba(0, 0, 0, 0.05),
    inset 0 -2px 2px rgba(255, 255, 255, 0.5),
    0 4px 2px -2px rgba(0, 0, 0, 0.2),
    0 0 1.6px 4px inset rgba(255, 255, 255, 0.2),
    0 0 0 0 rgba(255, 255, 255, 1);
}

.glass-button:disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* ========================================
   CONTENU DU BOUTON (icône +)
   ======================================== */

.glass-button-content {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1;
  color: var(--text-secondary);
  text-shadow: 0 0.05em 0.05em rgba(0, 0, 0, 0.05);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: all 400ms cubic-bezier(0.25, 1, 0.5, 1);
  /* Correction visuelle pour centrer parfaitement le "+" */
  transform: translate(0, -1px);
}

/* ========================================
   EFFET DE BRILLANCE INTERNE (::before)
   ======================================== */

.glass-button::before {
  content: "";
  position: absolute;
  z-index: 1;
  width: calc(100% - var(--border-width));
  height: calc(100% - var(--border-width));
  top: calc(var(--border-width) / 2);
  left: calc(var(--border-width) / 2);
  box-sizing: border-box;
  border-radius: 50%;
  background: linear-gradient(
    var(--angle-2),
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.4) 40% 50%,
    rgba(255, 255, 255, 0) 55%
  );
  background-size: 200% 200%;
  background-position: 0% 50%;
  background-repeat: no-repeat;
  mix-blend-mode: overlay;
  pointer-events: none;
  overflow: clip;
  transition: background-position 500ms cubic-bezier(0.25, 1, 0.5, 1);
}

/* ========================================
   BORDURE AVEC DÉGRADÉ CONIQUE (::after)
   ======================================== */

.glass-button::after {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 0;
  width: calc(100% + var(--border-width));
  height: calc(100% + var(--border-width));
  top: calc(0% - var(--border-width) / 2);
  left: calc(0% - var(--border-width) / 2);
  padding: var(--border-width);
  box-sizing: border-box;
  border-radius: 50%;
  background: conic-gradient(
      from var(--angle-1) at 50% 50%,
      rgba(255, 255, 255, 0.4),
      rgba(255, 255, 255, 0.85) 5% 40%,
      rgba(255, 255, 255, 0.4) 50%,
      rgba(255, 255, 255, 0.85) 60% 95%,
      rgba(255, 255, 255, 0.4)
    ),
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.85));
  box-shadow: inset 0 0 0 calc(var(--border-width) / 2) rgba(255, 255, 255, 0.95);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  transition: all 400ms cubic-bezier(0.25, 1, 0.5, 1);
}

/* ========================================
   ÉTAT HOVER
   ======================================== */

.glass-button:hover {
  transform: scale(0.975);
  background: linear-gradient(
    -75deg,
    rgba(255, 255, 255, 0.05),
    rgba(255, 255, 255, 0.2),
    rgba(255, 255, 255, 0.05)
  );
  backdrop-filter: blur(0.16px);
  -webkit-backdrop-filter: blur(0.16px);
  box-shadow:
    inset 0 2px 2px rgba(0, 0, 0, 0.05),
    inset 0 -2px 2px rgba(255, 255, 255, 0.5),
    0 2.4px 0.8px -1.6px rgba(0, 0, 0, 0.25),
    0 0 0.8px 1.6px inset rgba(255, 255, 255, 0.5),
    0 0 0 0 rgba(255, 255, 255, 1);
}

.glass-button:hover::before {
  background-position: 25% 50%;
}

.glass-button:hover::after {
  --angle-1: -125deg;
}

.glass-button:hover .glass-button-content {
  text-shadow: 0.025em 0.025em 0.025em rgba(0, 0, 0, 0.06);
}

/* ========================================
   ÉTAT ACTIVE (Pressé)
   ======================================== */

.glass-button-wrap:has(.glass-button:active) {
  transform: rotate3d(1, 0, 0, 25deg);
}

.glass-button:active {
  box-shadow:
    inset 0 2px 2px rgba(0, 0, 0, 0.05),
    inset 0 -2px 2px rgba(255, 255, 255, 0.5),
    0 2px 2px -2px rgba(0, 0, 0, 0.2),
    0 0 1.6px 4px inset rgba(255, 255, 255, 0.2),
    0 3.6px 0.8px 0 rgba(0, 0, 0, 0.05),
    0 4px 0 0 rgba(255, 255, 255, 0.75),
    inset 0 4px 0.8px 0 rgba(0, 0, 0, 0.15);
}

.glass-button:active::before {
  --angle-2: -15deg;
  background-position: 50% 15%;
}

.glass-button:active::after {
  --angle-1: -75deg;
}

.glass-button-wrap:has(.glass-button:active) .glass-button-content {
  text-shadow: 0.025em 0.25em 0.05em rgba(0, 0, 0, 0.12);
}

/* ========================================
   OMBRE - ÉTATS HOVER & ACTIVE
   ======================================== */

.glass-button-wrap:has(.glass-button:hover) .glass-button-shadow {
  filter: blur(4px);
  -webkit-filter: blur(4px);
  transition: filter 400ms cubic-bezier(0.25, 1, 0.5, 1);
}

.glass-button-wrap:has(.glass-button:hover) .glass-button-shadow::after {
  top: calc(var(--shadow-cuttoff-fix) - 0.875em);
  opacity: 1;
}

.glass-button-wrap:has(.glass-button:active) .glass-button-shadow {
  filter: blur(8px);
  -webkit-filter: blur(8px);
}

.glass-button-wrap:has(.glass-button:active) .glass-button-shadow::after {
  top: calc(var(--shadow-cuttoff-fix) - 0.5em);
  opacity: 0.75;
}

/* ========================================
   DARK MODE - Adaptation pour thème sombre
   ======================================== */

[data-theme="dark"] .glass-button {
  background: linear-gradient(
    -75deg,
    rgba(0, 0, 0, 0.45),
    rgba(0, 0, 0, 0.25),
    rgba(0, 0, 0, 0.45)
  );
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.08),
    inset 0 -2px 2px rgba(0, 0, 0, 0.5),
    0 4px 2px -2px rgba(0, 0, 0, 0.4),
    0 0 1.6px 4px inset rgba(255, 255, 255, 0.1),
    0 0 0 0 rgba(255, 255, 255, 1);
}

[data-theme="dark"] .glass-button-content {
  color: var(--text-secondary);
  text-shadow: 0 0.05em 0.05em rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] .glass-button::before {
  opacity: 0.3;
}

[data-theme="dark"] .glass-button::after {
  background: conic-gradient(
      from var(--angle-1) at 50% 50%,
      rgba(0, 0, 0, 0.5),
      rgba(0, 0, 0, 0) 5% 40%,
      rgba(0, 0, 0, 0.5) 50%,
      rgba(0, 0, 0, 0) 60% 95%,
      rgba(0, 0, 0, 0.5)
    ),
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5));
  box-shadow: inset 0 0 0 calc(var(--border-width) / 2) rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .glass-button-shadow::after {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.25));
}

/* Dark Mode - Hover */
[data-theme="dark"] .glass-button:hover {
  background: linear-gradient(
    -75deg,
    rgba(0, 0, 0, 0.5),
    rgba(0, 0, 0, 0.3),
    rgba(0, 0, 0, 0.5)
  );
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.08),
    inset 0 -2px 2px rgba(0, 0, 0, 0.5),
    0 2.4px 0.8px -1.6px rgba(0, 0, 0, 0.5),
    0 0 0.8px 1.6px inset rgba(255, 255, 255, 0.15),
    0 0 0 0 rgba(255, 255, 255, 1);
}

[data-theme="dark"] .glass-button:hover .glass-button-content {
  text-shadow: 0.025em 0.025em 0.025em rgba(0, 0, 0, 0.4);
}

/* Dark Mode - Active */
[data-theme="dark"] .glass-button:active {
  box-shadow:
    inset 0 2px 2px rgba(0, 0, 0, 0.4),
    inset 0 -2px 2px rgba(255, 255, 255, 0.1),
    0 2px 2px -2px rgba(0, 0, 0, 0.4),
    0 0 1.6px 4px inset rgba(255, 255, 255, 0.1),
    0 3.6px 0.8px 0 rgba(0, 0, 0, 0.15),
    0 4px 0 0 rgba(255, 255, 255, 0.1),
    inset 0 4px 0.8px 0 rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] .glass-button-wrap:has(.glass-button:active) .glass-button-content {
  text-shadow: 0.025em 0.25em 0.05em rgba(0, 0, 0, 0.6);
}

/* ========================================
   RESPONSIVE - Appareils tactiles
   ======================================== */

@media (hover: none) and (pointer: coarse) {
  .glass-button::before,
  .glass-button:active::before {
    --angle-2: -45deg;
  }

  .glass-button::after,
  .glass-button:hover::after,
  .glass-button:active::after {
    --angle-1: -75deg;
  }
}
