/* Ma·Trading — ma-minute : la porte unique vers Ma (09/10).
   Une minuterie quasi transparente en bas à droite ; cliquée, elle ouvre une
   vitre translucide à deux fils (Mademoiselle Ma / ma-minute). Règle d'or :
   ne JAMAIS cacher le marché — la pastille est discrète, la vitre laisse lire
   les bougies à travers, et un clic hors d'elle la replie.
   Feuille séparée (CSP 'self', pas de <style> inline), chargée par index.html. */

/* ---------- fermée : la minuterie ---------- */

/* Monogramme Ma’ cerclé d'une aiguille qui fait le tour en 60 s. Presque
   invisible au repos, opaque à l'approche — et plus discrète du tout quand
   une réponse attend (.a-du-nouveau). */
#mm-pastille {
  position: fixed; right: 16px; bottom: 16px; z-index: 80;
  width: 50px; height: 50px; border-radius: 50%;
  display: grid; place-items: center; padding: 0;
  background: rgba(17, 14, 11, .8); border: none; cursor: pointer;
  opacity: .3; transition: opacity .3s var(--ease), transform .3s var(--ease);
}
#mm-pastille:hover, #mm-pastille:focus-visible { opacity: 1; transform: scale(1.08); }
#mm-pastille .mono {
  position: absolute; font: italic 500 17px/1 "Fraunces", Georgia, serif;
  color: var(--orange); letter-spacing: -.02em; padding-bottom: 2px;
}
#mm-pastille svg { position: absolute; inset: 0; width: 50px; height: 50px; transform: rotate(-90deg); }
#mm-pastille .cadran { fill: none; stroke: rgba(255, 255, 255, .14); stroke-width: 2; }
#mm-pastille .aiguille {
  fill: none; stroke: var(--orange); stroke-width: 2; stroke-linecap: round;
  stroke-dasharray: 144.5; /* 2π·23 */
  animation: mm-tour 60s linear infinite;
}
@keyframes mm-tour { from { stroke-dashoffset: 144.5; } to { stroke-dashoffset: 0; } }
#mm-pastille .ma-badge { top: -3px; right: -3px; } /* l'habit .ma-badge, ancré par le fixed */
#mm-pastille.a-du-nouveau {
  opacity: 1;
  box-shadow: 0 0 0 1px rgba(243, 112, 33, .16), 0 0 26px var(--glow);
}

/* ---------- ouverte : la vitre ---------- */

#mm {
  position: fixed; right: 16px; bottom: 16px; z-index: 80;
  width: 440px; max-width: calc(100vw - 32px);
  height: min(700px, calc(100vh - 78px));
  display: flex; flex-direction: column; border-radius: 18px; overflow: hidden;
  background: rgba(17, 14, 11, .74);
  backdrop-filter: blur(14px) saturate(1.1); -webkit-backdrop-filter: blur(14px) saturate(1.1);
  border: 1px solid rgba(243, 112, 33, .16);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 30px 70px -24px rgba(0, 0, 0, .9);
  transform-origin: 100% 100%;
  animation: mm-surgir .22s var(--ease);
}
@keyframes mm-surgir { from { opacity: 0; transform: scale(.94) translateY(10px); } }

/* l'aube du panneau : une lueur golden hour derrière l'en-tête */
#mm header {
  flex: none; position: relative; padding: 14px 16px 10px;
  display: flex; align-items: baseline; gap: 9px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  background: radial-gradient(130% 150% at 85% -40%, rgba(243, 112, 33, .22), transparent 60%);
}
#mm header h1 { font: 500 calc(22px + var(--fs)) / 1 "Fraunces", Georgia, serif; letter-spacing: -.02em; margin: 0; }
#mm header h1 i { color: var(--orange); font-style: italic; }
.mm-sous { font: italic 500 calc(13px + var(--fs)) / 1 "Fraunces", Georgia, serif; color: var(--orange-soft); }
.mm-sous.sobre {
  font-family: "Schibsted Grotesk", system-ui, sans-serif; font-style: normal;
  font-weight: 500; font-size: calc(11.5px + var(--fs)); line-height: 1.2; color: var(--muted);
}
.mm-fermer {
  margin-left: auto; align-self: center; background: none; border: none;
  color: var(--muted); width: 30px; height: 30px; border-radius: 8px;
  font-size: 20px; line-height: 1; cursor: pointer;
}
.mm-fermer:hover { color: var(--txt); background: rgba(255, 255, 255, .06); }

/* ---------- les onglets des deux fils ---------- */

.mm-onglets {
  flex: none; display: flex; gap: 6px; padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.mm-onglets button {
  flex: 1; position: relative; padding: 7px 10px; border-radius: 999px;
  background: none; border: 1px solid transparent; cursor: pointer;
  font-size: calc(12.5px + var(--fs)); font-weight: 600; color: var(--muted);
}
.mm-onglets button:hover { color: var(--txt); }
.mm-onglets button.active {
  color: var(--orange); border-color: rgba(243, 112, 33, .5);
  background: rgba(243, 112, 33, .08);
}
.mm-onglets .point {
  position: absolute; top: 4px; right: 10px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--orange); box-shadow: 0 0 6px var(--glow);
}

/* ---------- l'aiguillage du premier message ---------- */

#mm-choix { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 24px 18px; justify-content: center; overflow-y: auto; }
#mm-choix h3 { font: 500 calc(19px + var(--fs)) / 1.2 "Fraunces", Georgia, serif; text-align: center; margin: 0 0 4px; }
.mm-carte-choix {
  text-align: left; padding: 14px 16px; border-radius: 14px; cursor: pointer;
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .1);
  color: var(--txt); font: inherit;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.mm-carte-choix:hover { border-color: rgba(243, 112, 33, .5); background: rgba(243, 112, 33, .09); }
.mm-carte-choix b { display: block; font-size: calc(15px + var(--fs)); margin-bottom: 3px; }
.mm-carte-choix span { font-size: calc(12.5px + var(--fs)); color: var(--muted); line-height: 1.45; }
.mm-choix-note { text-align: center; font-size: calc(11.5px + var(--fs)); color: var(--muted); margin: 0; }

/* ---------- le fil ---------- */

.mm-fil { flex: 1; overflow-y: auto; padding: 14px 14px 6px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .14) transparent; }

.mm-rang { display: flex; gap: 9px; margin: 0 0 9px; align-items: flex-end; }
.mm-rang.moi { justify-content: flex-end; }
.mm-rang.annonce { justify-content: center; }
.mm-avatar {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, rgba(243, 112, 33, .28), rgba(243, 112, 33, .1));
  border: 1px solid rgba(243, 112, 33, .3);
  font: italic 500 13px/1 "Fraunces", Georgia, serif; color: var(--orange);
}
.mm-rang.suite .mm-avatar { visibility: hidden; }
.mm-bulle {
  max-width: 82%; padding: 9px 13px; border-radius: 15px;
  font-size: calc(14px + var(--fs)); line-height: 1.5;
  white-space: pre-line; overflow-wrap: break-word;
}
.mm-rang:not(.moi):not(.annonce) .mm-bulle {
  background: linear-gradient(180deg, rgba(243, 112, 33, .14), rgba(243, 112, 33, .08));
  border: 1px solid rgba(243, 112, 33, .18);
  border-bottom-left-radius: 5px;
}
.mm-rang.moi .mm-bulle {
  background: rgba(255, 255, 255, .09); border: 1px solid rgba(255, 255, 255, .1);
  border-bottom-right-radius: 5px;
}
.mm-bulle img { display: block; max-width: 100%; border-radius: 9px; margin-top: 8px; border: 1px solid var(--line); }
.mm-bulle .mm-quand { display: block; margin-top: 4px; font-size: calc(10.5px + var(--fs)); color: var(--muted); }
.mm-bulle .mm-chip {
  display: inline-block; margin-top: 6px; padding: 1px 8px; border-radius: 999px;
  font-size: calc(10.5px + var(--fs)); color: var(--orange-soft);
  background: rgba(243, 112, 33, .1); border: 1px solid rgba(243, 112, 33, .22);
}
.mm-bulle.annonce {
  max-width: 94%; text-align: center; font-size: calc(12.5px + var(--fs)); color: var(--orange-soft);
  background: rgba(255, 255, 255, .04); border: 1px dashed rgba(243, 112, 33, .32);
}
.mm-bulle.attente { color: var(--muted); font-style: italic; background: none; border: 1px dashed var(--line); }

/* les conversations terminées, repliées derrière un lien discret */
.mm-archives-lien {
  display: block; width: 100%; margin: 0 0 10px; padding: 5px 0;
  background: none; border: none; border-bottom: 1px dashed var(--line);
  color: var(--muted); font: inherit; font-size: calc(11.5px + var(--fs)); cursor: pointer;
}
.mm-archives-lien:hover { color: var(--txt); }
.mm-rang.archive { opacity: .55; }

/* « elle écrit… » : trois points qui respirent */
.mm-tape { display: inline-flex; gap: 4px; padding: 4px 2px; }
.mm-tape i { width: 6px; height: 6px; border-radius: 50%; background: var(--orange-soft); animation: mm-respirer 1.1s ease-in-out infinite; }
.mm-tape i:nth-child(2) { animation-delay: .18s; }
.mm-tape i:nth-child(3) { animation-delay: .36s; }
@keyframes mm-respirer { 0%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- capture jointe + saisie ---------- */

.mm-apercu {
  flex: none; display: flex; gap: 10px; align-items: center;
  margin: 0 14px 8px; padding: 7px 10px; border-radius: 12px;
  background: rgba(255, 255, 255, .05); border: 1px dashed rgba(243, 112, 33, .35);
  font-size: calc(12px + var(--fs)); color: var(--muted);
}
.mm-apercu img { height: 40px; border-radius: 5px; border: 1px solid var(--line); }
.mm-apercu button { margin-left: auto; background: none; border: none; color: var(--muted); font: inherit; font-size: calc(13px + var(--fs)); padding: 3px 7px; border-radius: 7px; cursor: pointer; }
.mm-apercu button:hover { color: var(--txt); background: rgba(255, 255, 255, .07); }

.mm-saisie { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 0 14px 14px; }
.mm-saisie .champ {
  flex: 1; display: flex; align-items: flex-end; gap: 4px;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 21px; padding: 4px 6px 4px 8px;
  transition: border-color .2s var(--ease);
}
.mm-saisie .champ:focus-within { border-color: rgba(243, 112, 33, .5); }
#mm-photo {
  flex: none; width: 34px; height: 34px; border-radius: 50%; position: relative;
  display: grid; place-items: center; background: none; border: none; cursor: pointer;
  color: var(--orange-soft); font-size: 17px;
}
#mm-photo:hover { background: rgba(243, 112, 33, .14); }
#mm-photo.jointe::after {
  content: "✓"; position: absolute; top: -2px; right: -2px;
  width: 15px; height: 15px; border-radius: 50%; background: var(--orange);
  color: var(--bg); font: 700 10px/15px system-ui;
}
#mm-msg {
  flex: 1; resize: none; height: 34px; max-height: 96px; padding: 7px 6px;
  background: none; border: none; color: var(--txt); outline: none;
  font: inherit; font-size: calc(14px + var(--fs));
}
#mm-msg::placeholder { color: var(--muted); }
#mm-envoi {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
  display: grid; place-items: center;
  background: var(--orange); color: var(--bg); font-size: 17px;
  box-shadow: 0 8px 20px -8px var(--glow);
  transition: transform .15s var(--ease), filter .15s var(--ease);
}
#mm-envoi:hover { filter: brightness(1.12); transform: scale(1.05); }

/* ---------- où la minuterie n'a rien à faire ---------- */

/* les fenêtres détachées et la projection : pas d'assistance là. L'écran de
   Ma (formatrice), lui, garde la minuterie depuis le 10/10 — vitre réduite au
   fil minute : elle y signale les bugs, capture d'écran entière à l'appui. */
body.detached #mm-pastille, body.detached #mm,
body.projection #mm-pastille, body.projection #mm { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  #mm-pastille .aiguille, .mm-tape i { animation: none; }
  #mm { animation: none; }
}

/* ---------- mobile : au-dessus de la barre d'ordre, comme l'ancien rond Ma ---------- */
@media (max-width: 900px) {
  #mm-pastille { right: 12px; bottom: calc(104px + env(safe-area-inset-bottom)); }
  #mm {
    right: 8px; bottom: calc(66px + env(safe-area-inset-bottom));
    width: calc(100vw - 16px);
    height: min(640px, calc(100vh - 130px));
  }
  /* l'onglet Trade est déjà plein : on n'y superpose rien (comme avant) */
  #view-app.m-trade #mm-pastille, #view-app.m-trade #mm { display: none; }
}
