/* ============================================================
   Materia OS — Base : reset, typo, composants M3 partagés
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--on-surface);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

h1, h2, h3, p { margin: 0; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  color: inherit;
}

.material-symbols-rounded {
  font-variation-settings: 'opsz' 24, 'wght' 400, 'FILL' 0, 'GRAD' 0;
  user-select: none;
}
.material-symbols-rounded.fill { font-variation-settings: 'opsz' 24, 'wght' 400, 'FILL' 1; }

/* --- Boutons Material 3 --- */
.m3-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 20px;
  border-radius: var(--r-full);
  font-weight: 550;
  font-size: 14px;
  letter-spacing: .1px;
  transition: box-shadow var(--dur-s) var(--ease), background var(--dur-s) var(--ease),
              transform var(--dur-s) var(--ease);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}
.m3-btn:active { transform: scale(.97); }
.m3-btn .material-symbols-rounded { font-size: 19px; }

.m3-btn.filled { background: var(--primary); color: var(--on-primary); }
.m3-btn.filled:hover { box-shadow: var(--shadow-1); filter: brightness(1.06); }

.m3-btn.tonal { background: var(--secondary-container); color: var(--on-secondary-container); }
.m3-btn.tonal:hover { box-shadow: var(--shadow-1); filter: brightness(1.03); }

.m3-btn.text { background: transparent; color: var(--primary); padding: 0 14px; }
.m3-btn.text:hover { background: color-mix(in srgb, var(--primary) 10%, transparent); }

.m3-btn.outlined {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--outline-variant);
}
.m3-btn.outlined:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }

.m3-btn.danger { background: var(--error-container); color: var(--on-error-container); }

.m3-btn:disabled { opacity: .4; pointer-events: none; }

/* Bouton icône rond */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  color: var(--on-surface-variant);
  transition: background var(--dur-s) var(--ease), color var(--dur-s) var(--ease);
  position: relative;
  overflow: hidden;
  flex: none;
}
.icon-btn:hover { background: color-mix(in srgb, var(--on-surface) 9%, transparent); }
.icon-btn.active { background: var(--secondary-container); color: var(--on-secondary-container); }
.icon-btn .material-symbols-rounded { font-size: 22px; }

/* --- Champs --- */
.m3-field {
  height: 44px;
  padding: 0 16px;
  border-radius: var(--r-full);
  border: none;
  outline: none;
  background: var(--surface-container-high);
  color: var(--on-surface);
  font-size: 14px;
  transition: box-shadow var(--dur-s) var(--ease);
}
.m3-field:focus { box-shadow: 0 0 0 2px var(--primary) inset; }
.m3-field::placeholder { color: var(--on-surface-variant); }

/* --- Sliders M3 --- */
input[type="range"].m3-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
}
input[type="range"].m3-slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: var(--r-full);
  background: linear-gradient(to right,
      var(--primary) 0%,
      var(--primary) var(--fill, 50%),
      var(--surface-container-highest) var(--fill, 50%));
}
input[type="range"].m3-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 4px;
  height: 26px;
  border-radius: 4px;
  background: var(--primary);
  margin-top: -8px;
  box-shadow: 0 0 0 5px var(--surface-container);
}

/* --- Switch M3 --- */
.m3-switch {
  position: relative;
  width: 52px;
  height: 32px;
  border-radius: var(--r-full);
  background: var(--surface-container-highest);
  border: 2px solid var(--outline);
  transition: background var(--dur-m) var(--ease), border-color var(--dur-m) var(--ease);
  flex: none;
}
.m3-switch::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--outline);
  transform: translateY(-50%);
  transition: all var(--dur-m) var(--ease);
}
.m3-switch.on { background: var(--primary); border-color: var(--primary); }
.m3-switch.on::after {
  left: 26px;
  width: 22px;
  height: 22px;
  background: var(--on-primary);
}

/* --- Effet ripple (encre Material) --- */
.ripple { position: relative; overflow: hidden; }
.ripple-ink {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: .16;
  transform: scale(0);
  animation: ripple-grow .5s var(--ease-out) forwards;
  pointer-events: none;
}
@keyframes ripple-grow {
  to { transform: scale(2.6); opacity: 0; }
}

/* --- Scrollbars --- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--outline-variant);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--outline); background-clip: content-box; }

/* --- Focus clavier --- */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* --- Menu contextuel --- */
#ctxmenu {
  position: fixed;
  z-index: 9000;
  min-width: 220px;
  padding: 8px;
  border-radius: var(--r-m);
  background: var(--surface-container);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--outline-variant);
  animation: ctx-in var(--dur-s) var(--ease-out);
  transform-origin: top left;
}
@keyframes ctx-in {
  from { opacity: 0; transform: scale(.92); }
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--r-s);
  font-size: 13.5px;
  color: var(--on-surface);
  text-align: left;
}
.ctx-item:hover { background: var(--secondary-container); color: var(--on-secondary-container); }
.ctx-item .material-symbols-rounded { font-size: 20px; color: var(--on-surface-variant); }
.ctx-item:hover .material-symbols-rounded { color: inherit; }
.ctx-item.danger { color: var(--error); }
.ctx-item.danger .material-symbols-rounded { color: var(--error); }
.ctx-sep { height: 1px; margin: 6px 10px; background: var(--outline-variant); }

/* --- Toasts / notifications --- */
#toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9500;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 360px;
  pointer-events: none;
}
.toast {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: var(--r-l);
  background: var(--surface-container);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--outline-variant);
  pointer-events: auto;
  animation: toast-in var(--dur-m) var(--ease-out);
  transition: opacity var(--dur-m) var(--ease), transform var(--dur-m) var(--ease);
}
.toast.out { opacity: 0; transform: translateX(40px); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(60px) scale(.95); }
}
.toast-ico {
  width: 40px;
  height: 40px;
  border-radius: var(--r-s);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-container);
  color: var(--on-primary-container);
  flex: none;
}
.toast-ico .material-symbols-rounded { font-size: 22px; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; font-size: 13.5px; }
.toast-msg { color: var(--on-surface-variant); font-size: 12.5px; margin-top: 2px; line-height: 1.4; }
.toast-close { margin: -4px -6px 0 0; width: 28px; height: 28px; }
.toast-close .material-symbols-rounded { font-size: 17px; }

/* --- Voile de luminosité --- */
#brightness-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity var(--dur-m) var(--ease);
}

/* --- Animations réduites --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
