/* Theme clair / sombre / auto — MedicAssist Pro.
 *
 * Deux responsabilites, et seulement deux :
 *   1. le socle sombre commun (color-scheme, fond du canevas) ;
 *   2. le selecteur de theme flottant.
 *
 * Les COULEURS des pages ne sont PAS ici : elles sont derivees du CSS de chaque
 * page par le serveur (src/services/darkThemeStylesheet.js) et injectees apres ce
 * fichier. Le nom porte sa version (-v1), meme convention que le logo. */

/* color-scheme fait passer en sombre les controles natifs (champs, listes,
   barres de defilement, cases a cocher) que le CSS des pages ne style pas. */
html[data-theme="dark"] {
  color-scheme: dark;
}

@media screen {
  /* :where() ramene la specificite a zero : ce sont des valeurs par defaut, une
     page qui pose son propre fond ou sa propre couleur les remplace. */
  :where(html[data-theme="dark"]) {
    background-color: #101614;
    color: #e6eaf1;
  }
}

/* ---- Selecteur ----------------------------------------------------------
   Les selecteurs du selecteur sont doubles (.ma-theme.ma-theme) a dessein : la
   feuille sombre derivee d'une page reprend ses regles generiques
   (`button { background: var(--accent) }`) sous un prefixe plus specifique que
   une simple classe, et transformerait la pastille en bouton d'action. */

.ma-theme {
  --ma-bg: #ffffff;
  --ma-border: #d8dee8;
  --ma-text: #172033;
  --ma-muted: #667085;
  --ma-hover: #f1f5f9;
  --ma-accent: #0f766e;
  --ma-accent-bg: #e8f7f4;
  --ma-shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
  position: fixed;
  inset-block-end: 16px;
  inset-inline-end: 16px;
  z-index: 9990;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.3;
}

html[data-theme="dark"] .ma-theme {
  --ma-bg: #1b2422;
  --ma-border: #33413d;
  --ma-text: #e6eaf1;
  --ma-muted: #9aa7a3;
  --ma-hover: #25302d;
  --ma-accent: #4fd1c5;
  --ma-accent-bg: rgba(79, 209, 197, 0.16);
  --ma-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}

.ma-theme.ma-theme .ma-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--ma-border);
  border-radius: 999px;
  background: var(--ma-bg);
  color: var(--ma-text);
  box-shadow: var(--ma-shadow);
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.ma-theme.ma-theme .ma-theme-toggle:hover,
.ma-theme.ma-theme .ma-theme-toggle[aria-expanded="true"] {
  opacity: 1;
}

.ma-theme.ma-theme .ma-theme-toggle:focus-visible,
.ma-theme.ma-theme .ma-theme-option:focus-visible {
  outline: 2px solid var(--ma-accent);
  outline-offset: 2px;
}

.ma-theme.ma-theme .ma-theme-toggle svg,
.ma-theme.ma-theme .ma-theme-option svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ma-theme.ma-theme .ma-theme-menu {
  position: absolute;
  inset-block-end: 48px;
  inset-inline-end: 0;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--ma-border);
  border-radius: 14px;
  background: var(--ma-bg);
  box-shadow: var(--ma-shadow);
}

.ma-theme.ma-theme .ma-theme-menu[hidden] {
  display: none;
}

.ma-theme.ma-theme .ma-theme-title {
  padding: 6px 10px 4px;
  color: var(--ma-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ma-theme.ma-theme .ma-theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ma-text);
  font: inherit;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  text-align: start;
  cursor: pointer;
}

.ma-theme.ma-theme .ma-theme-option:hover {
  background: var(--ma-hover);
}

.ma-theme.ma-theme .ma-theme-option[aria-checked="true"] {
  background: var(--ma-accent-bg);
  color: var(--ma-accent);
}

.ma-theme.ma-theme .ma-theme-option[aria-checked="true"]::after {
  content: "\2713";
  margin-inline-start: auto;
  font-weight: 800;
}

@media (max-width: 640px) {
  .ma-theme {
    inset-block-end: 12px;
    inset-inline-end: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ma-theme.ma-theme .ma-theme-toggle {
    transition: none;
  }
}

/* Le selecteur n'a rien a faire sur papier. */
@media print {
  .ma-theme {
    display: none !important;
  }
}
