/* NESSA — Styles communs mutualisés
   Chargé via ae_head_meta.html sur toutes les pages.
   Variables, transitions globales, utilitaires, et composants réutilisables. */

:root {
  /* Couleurs — thème bleu (défaut) */
  --bg: #071e2f;
  --bg-alt: #0b2236;
  --card: #0f2a43;
  --card-hover: #163b5e;
  --stroke: #1a3a5c;
  --ink: #eaf2ff;
  --ink-dim: rgba(234,242,255,.7);
  --ink-mute: rgba(234,242,255,.55);
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --ok: #4ade80;
  --warn: #facc15;
  --err: #f87171;
  --info: #60a5fa;

  /* Rayons (cohérents iOS-like) */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  /* Espacement (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Ombres (iOS-inspired : plus douces, moins tranchées) */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.12);
  --shadow-sm: 0 2px 6px rgba(0,0,0,.15);
  --shadow-md: 0 8px 24px rgba(0,0,0,.25);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.35);

  /* Typographie (échelle 1.25) */
  --font: -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Menlo', 'Monaco', monospace;
  --fz-xs: 12px;
  --fz-sm: 13px;
  --fz-md: 14px;
  --fz-lg: 16px;
  --fz-xl: 20px;
  --fz-2xl: 24px;
  --fz-3xl: 32px;
  --lh: 1.5;

  /* Transitions (plus douces, iOS-style) */
  --transition: .2s cubic-bezier(.4,0,.2,1);
  --transition-fast: .15s cubic-bezier(.4,0,.2,1);
  --transition-slow: .35s cubic-bezier(.4,0,.2,1);

  /* Logo (uniforme partout) */
  --logo-height: 32px;

  /* Z-index (pile claire) */
  --z-base: 1;
  --z-sticky: 100;
  --z-modal: 1000;
  --z-tour: 10000;
  --z-toast: 99999;
}

/* Thème CLAIR (jour) */
html[data-theme="clair"] {
  --bg: #f4f7fb;
  --bg-alt: #ffffff;
  --card: #ffffff;
  --card-hover: #f0f5fb;
  --stroke: #dbe4ef;
  --ink: #0b2236;
  --ink-dim: rgba(11,34,54,.7);
  --ink-mute: rgba(11,34,54,.5);
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --shadow-xs: 0 1px 2px rgba(13,50,90,.08);
  --shadow-sm: 0 2px 6px rgba(13,50,90,.10);
  --shadow-md: 0 8px 24px rgba(13,50,90,.14);
  --shadow-lg: 0 20px 48px rgba(13,50,90,.18);
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* Transitions fluides globales */
a, button, input, select, textarea, .btn, .card, .tuile {
  transition: all var(--transition);
}

a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Boutons */
.nessa-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.nessa-btn:hover {
  background: var(--card-hover);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(-1px);
}
.nessa-btn:active {
  transform: translateY(0);
}

/* Cards / Tuiles */
.nessa-card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 16px;
}
.nessa-card:hover {
  border-color: rgba(56,189,248,.3);
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
}

/* Scrollbar personnalisée */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.22); }

/* Animations d'entrée réutilisables */
@keyframes nessa-fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes nessa-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.nessa-animate-in {
  animation: nessa-fade-in .35s ease both;
}

/* Toast / Notifications */
.nessa-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  animation: nessa-slide-up .3s ease both;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
.nessa-toast-ok   { background: rgba(17,47,77,.95); border: 1px solid rgba(74,222,128,.4); color: #bbf7d0; }
.nessa-toast-err  { background: rgba(47,17,17,.95); border: 1px solid rgba(248,113,113,.5); color: #fecaca; }
.nessa-toast-warn { background: rgba(47,35,17,.95); border: 1px solid rgba(251,191,36,.5); color: #fef3c7; }

/* Responsive utilitaires */
@media (max-width: 600px) {
  .nessa-hide-mobile { display: none !important; }
}
@media (min-width: 601px) {
  .nessa-hide-desktop { display: none !important; }
}

/* Responsive global (smartphone) */
@media (max-width: 768px) {
  /* Navigation */
  .ae-nav {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    margin-top: 8px;
    border-radius: 8px;
  }
  .ae-nav .links { gap: 6px; margin-left: 0; font-size: 13px; }
  .ae-nav .right { margin-left: 0; width: 100%; justify-content: space-between; font-size: 12px; }
  .ae-switch { padding: 6px 10px; font-size: 12px; }

  /* Containers globaux */
  body > div, main, .container, [style*="max-width:1200px"],
  [style*="max-width: 1200px"], [style*="max-width:1100px"],
  [style*="max-width: 1100px"] {
    max-width: 100% !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  /* Grilles et flex wrapping */
  .grid, [style*="grid-template-columns"], [style*="display:grid"],
  [style*="display: grid"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Tables responsives */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; font-size: 13px; }
  th, td { padding: 8px 10px !important; white-space: nowrap; }

  /* Forms */
  input[type="text"], input[type="search"], input[type="email"],
  input[type="password"], input[type="url"], input[type="number"],
  select, textarea {
    font-size: 16px !important;
    max-width: 100% !important;
  }

  /* Cards, tuiles et boutons */
  .nessa-card { padding: 12px; }
  .nessa-btn { padding: 10px 14px; font-size: 13px; width: 100%; justify-content: center; }

  /* Fix scrolling iOS */
  html { -webkit-text-size-adjust: 100%; }

  /* Flex containers */
  [style*="display:flex"][style*="gap:2"], [style*="display: flex"][style*="gap:2"],
  [style*="display:flex"][style*="gap:3"], [style*="display: flex"][style*="gap:3"] {
    flex-wrap: wrap !important;
  }

  /* Images */
  img { max-width: 100%; height: auto; }

  /* Large headings */
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  h3 { font-size: 1.1rem !important; }

  /* Toasts */
  .nessa-toast { left: 12px; right: 12px; bottom: 12px; }

  /* Profile menu overlay */
  .profil-menu-panel { width: 100vw !important; max-width: 100vw !important; right: 0 !important; border-radius: 0 !important; }
}

@media (max-width: 480px) {
  .ae-nav .links a { font-size: 12px; }
  .ae-nav > a { font-size: 14px; }
  body { font-size: 14px; }
}

/* Skeleton loading */
.nessa-skeleton {
  background: linear-gradient(90deg, var(--card) 25%, rgba(255,255,255,.06) 50%, var(--card) 75%);
  background-size: 200% 100%;
  animation: nessa-shimmer 1.5s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes nessa-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Utilitaires de texte */
.nessa-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Page transitions (pour un chargement fluide) */
body {
  animation: nessa-page-in .3s ease both;
}
@keyframes nessa-page-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Animations avatar / compagnon */
@keyframes ae-avatar-breathe {
  0%, 100% { transform: translateY(0) scale(1) rotate(0deg); }
  25%      { transform: translateY(-3px) scale(1.015) rotate(.5deg); }
  50%      { transform: translateY(-5px) scale(1.03) rotate(0deg); }
  75%      { transform: translateY(-3px) scale(1.015) rotate(-.5deg); }
}
@keyframes ae-avatar-blink {
  0%, 90%, 100% { clip-path: inset(0 0 0 0); }
  94%            { clip-path: inset(30% 5% 30% 5%); }
}
@keyframes ae-avatar-speak-bounce {
  0%   { transform: translateY(20px) scale(.6); opacity: 0; }
  18%  { transform: translateY(-18px) scale(1.1); opacity: 1; }
  30%  { transform: translateY(3px) scale(.96); }
  42%  { transform: translateY(-12px) scale(1.07); }
  54%  { transform: translateY(2px) scale(.98); }
  66%  { transform: translateY(-7px) scale(1.04); }
  78%  { transform: translateY(0) scale(1); }
  88%  { transform: translateY(-3px) scale(1.02); }
  100% { transform: translateY(0) scale(1); }
}
@keyframes ae-avatar-entrance {
  0%   { transform: translateY(30px) scale(.6); opacity: 0; }
  40%  { transform: translateY(-12px) scale(1.08); opacity: 1; }
  60%  { transform: translateY(4px) scale(.97); }
  80%  { transform: translateY(-3px) scale(1.02); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.ae-notif-bulle-avatar img,
.ae-companion-avatar img,
.ae-loading-avatar img,
.ae-bye-avatar img,
.ae-msg1-avatar img,
.ae-demande-avatar img,
.ae-welcome-avatar img {
  animation:
    ae-avatar-entrance .7s cubic-bezier(.34,1.56,.64,1) both,
    ae-avatar-breathe 3.5s ease-in-out infinite .7s,
    ae-avatar-blink 5s ease infinite 1s;
  transform-origin: center bottom;
}

/* Phase « parle » : entrée + rebond amplifié */
.ae-avatar-speaking img,
.ae-notif-bulle-avatar.speaking img,
.ae-loading-avatar.speaking img,
.ae-bye-avatar.speaking img,
.ae-msg1-avatar.speaking img,
.ae-demande-avatar.speaking img,
.ae-welcome-avatar.speaking img {
  animation: ae-avatar-speak-bounce 1.2s cubic-bezier(.22,1,.36,1) both,
    ae-avatar-breathe 3.5s ease-in-out infinite 1.2s,
    ae-avatar-blink 5s ease infinite 1.5s;
  transform-origin: center bottom;
}

/* Après parole : juste respiration + clignotement, SANS rejouer l'entrée */
.ae-notif-bulle-avatar.ae-entered img,
.ae-companion-avatar.ae-entered img,
.ae-loading-avatar.ae-entered img,
.ae-bye-avatar.ae-entered img,
.ae-msg1-avatar.ae-entered img,
.ae-demande-avatar.ae-entered img,
.ae-welcome-avatar.ae-entered img {
  animation:
    ae-avatar-breathe 3.5s ease-in-out infinite,
    ae-avatar-blink 5s ease infinite;
  transform-origin: center bottom;
}

@keyframes ae-bulle-pop {
  0%   { opacity: 0; transform: scale(.85) translateY(6px); }
  60%  { opacity: 1; transform: scale(1.03) translateY(-2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.ae-notif-bulle-wrapper .ae-notif-bulle,
.ae-bye-bulle,
.ae-loading-bulle,
.ae-msg1-bulle {
  animation: ae-bulle-pop .4s cubic-bezier(.34,1.56,.64,1) both;
}

/* Focus-visible global (nav clavier claire, iOS/macOS-like). */
a:focus-visible, button:focus-visible,
[role="button"]:focus-visible, [tabindex]:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible,
.nessa-btn:focus-visible, .tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* Toast unifié : remplace les alert(), console + zone aria-live pour les
   lecteurs d'écran. Usage JS : NessaToast.ok("Sauvegardé"), .err("Oups"),
   .warn("Attention"). */
#nessa-toast-region {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 14px;
  z-index: var(--z-toast);
  pointer-events: none;
}
#nessa-toast-region .nessa-toast-wrap {
  display: flex; align-items: flex-end; gap: 10px;
  pointer-events: auto;
  animation: nessa-toast-in .35s cubic-bezier(.22,1.61,.36,1) both;
}
#nessa-toast-region .nessa-toast-avatar {
  width: 56px; height: 56px; flex-shrink: 0;
  display: flex; align-items: flex-end; justify-content: center;
}
#nessa-toast-region .nessa-toast-avatar img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  transform-origin: center bottom;
  animation: nessa-companion-bounce 1.1s cubic-bezier(.28,.84,.42,1) 2;
}
@keyframes nessa-companion-bounce {
  0%   { transform: translateY(0)     scaleY(1); }
  25%  { transform: translateY(-12px) scaleY(1.05); }
  45%  { transform: translateY(0)     scaleY(.92); }
  55%  { transform: translateY(0)     scaleY(1.04); }
  70%  { transform: translateY(-5px)  scaleY(1.02); }
  100% { transform: translateY(0)     scaleY(1); }
}
@keyframes nessa-toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
#nessa-toast-region .nessa-toast-wrap.nessa-toast--leaving {
  animation: nessa-slide-down .2s ease both;
}
#nessa-toast-region .nessa-toast {
  position: static;
  pointer-events: auto;
  min-width: 220px;
  max-width: 380px;
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  font-size: var(--fz-md);
  line-height: 1.4;
  animation: nessa-slide-up .28s cubic-bezier(.4,0,.2,1) both;
}
#nessa-toast-region .nessa-toast.nessa-toast--leaving {
  animation: nessa-slide-down .2s ease both;
}
@keyframes nessa-slide-down {
  to { opacity: 0; transform: translateY(10px); }
}
@media (max-width: 600px) {
  #nessa-toast-region { left: 12px; right: 12px; bottom: 12px; }
  #nessa-toast-region .nessa-toast { max-width: none; }
}

/* Logo : taille uniforme dans la nav et le header. */
.nessa-logo-img {
  height: var(--logo-height);
  width: auto;
  display: inline-block;
  vertical-align: middle;
}

/* Bouton primaire unique : inspiration iOS, couleur pleine et radius doux. */
.nessa-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #062032;
  font-weight: 700;
  font-size: var(--fz-md);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: transform var(--transition-fast), box-shadow var(--transition);
}
.nessa-btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.nessa-btn-primary:active { transform: translateY(0); }
.nessa-btn-primary:disabled { opacity: .5; cursor: not-allowed; }

/* Impression : export PDF d'une note via Cmd/Ctrl + P. */
@media print {
  body { background: #fff !important; color: #000 !important; }
  .ae-nav, .ae-toolbar, .tox-toolbar, .tox-statusbar,
  #ae-tour-backdrop, #ae-tour-hole, .ae-tour-card,
  #ae-quiz-overlay, .ae-msg-bubble, .nessa-noprint,
  #nessa-toast-region {
    display: none !important;
  }
  #note-titre, .note-titre, h1, h2, h3 { color: #000 !important; }
  #note-contenu, .mce-content-body, .prose, article.note {
    color: #000 !important;
    background: #fff !important;
    max-width: 100% !important;
    padding: 0 !important;
    box-shadow: none !important;
  }
  @page { margin: 18mm 16mm; }
}
