/* =========================
   Philomène I.A. – styles.css (fix mobile)
   ========================= */
:root{
  --bg:#0b0b10;
  --panel:#141420;
  --panel-2:#181828;
  --text:#EAEAF2;
  --text-dim:#A9A9C0;
  --accent:#7A4DFF;
  --accent-2:#9F7BFF;
  --ok:#6CF29A;
  --shadow: 0 10px 30px rgba(122,77,255,.25),
            inset 0 0 0 1px rgba(255,255,255,.05);
  --radius:16px;

  /* échelle mobile */
  --pad:12px;
  --h-topbar:56px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  color:var(--text);
  background:var(--bg);
  font:16px/1.45 system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;
  display:flex; flex-direction:column;
  /* safe area iOS */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ============ Topbar ============ */
#topbar{
  position:sticky; top:0; z-index:50;
  display:flex; align-items:center; justify-content:space-between;
  gap:10px; height:var(--h-topbar);
  padding:0 var(--pad);
  background:linear-gradient(180deg, rgba(10,10,15,.95), rgba(10,10,15,.75));
  backdrop-filter: blur(6px);
  border-bottom:1px solid rgba(255,255,255,.06);
}
.topbar__left,.topbar__right{display:flex; align-items:center; gap:10px; flex-wrap:nowrap}
.chip{
  background:var(--panel);
  border:1px solid rgba(255,255,255,.08);
  color:var(--text);
  padding:9px 12px;
  border-radius:12px;
  cursor:pointer;
  white-space:nowrap;
  font-size:14px;
  line-height:18px;
}
.chip.icon{ width:42px; height:42px; display:grid; place-items:center; padding:0 }

/* 💎 compteur */
.gem{
  display:flex; align-items:center; gap:8px;
  padding:8px 12px; border-radius:14px;
  background:linear-gradient(180deg, rgba(122,77,255,.14), rgba(122,77,255,.08));
  border:1px solid rgba(122,77,255,.25);
  box-shadow: var(--shadow);
  min-width: 120px;
  justify-content:center;
}
.gem__icon{filter:drop-shadow(0 0 6px rgba(122,77,255,.6))}
#tokenCount{font-variant-numeric: tabular-nums}

/* ============ Menu déroulant ============ */
.dropdown{
  position:absolute; right:var(--pad); top:calc(var(--h-topbar) + 6px);
  width:220px;
  background:var(--panel-2);
  border:1px solid rgba(255,255,255,.08);
  border-radius:14px; overflow:hidden;
  box-shadow:0 20px 40px rgba(0,0,0,.55);
  z-index:60;
}
.dropdown__item{
  display:block; width:100%; text-align:left;
  background:transparent; color:var(--text);
  padding:12px 14px; border:0; cursor:pointer; font-size:15px;
}
.dropdown__item + .dropdown__item{ border-top:1px solid rgba(255,255,255,.06)}

/* ============ Ligne version ============ */
#versionLine{
  display:flex; align-items:center; gap:10px;
  padding:10px 16px; color:var(--text-dim);
  border-bottom:1px solid rgba(255,255,255,.06);
}
.dot{width:10px;height:10px;border-radius:50%}
.dot--on{background:radial-gradient(circle at 50% 50%, var(--ok), #2e7f55 60%)}

/* ============ Chat ============ */
#chat{
  flex:1; overflow:auto;
  padding:18px var(--pad) 128px;   /* place pour le composer */
}
.bubble{
  max-width:min(720px, 92%);
  margin:12px 8px;
  background:var(--panel);
  border-radius:18px;
  border:1px solid rgba(255,255,255,.08);
  box-shadow: var(--shadow);
}
.bubble.bot{ margin-left:8px }
.bubble.user{
  margin-left:auto;
  background:linear-gradient(180deg, rgba(122,77,255,.18), rgba(122,77,255,.12));
  border-color:rgba(122,77,255,.35)
}
.bubble__content{ padding:14px 16px; }

/* ============ Composer ============ */
#composer{
  position:sticky; bottom:0; z-index:55;
  padding:10px var(--pad);
  background:linear-gradient(180deg, transparent, rgba(10,10,15,.92));
  display:flex; align-items:center; gap:10px;
}
.fab{
  width:46px; height:46px; border-radius:14px;
  background:var(--panel); color:var(--text);
  border:1px solid rgba(255,255,255,.08); cursor:pointer;
}
.inputWrap{
  flex:1; display:flex; align-items:center; gap:8px;
  background:var(--panel-2);
  border:1px solid rgba(255,255,255,.1);
  border-radius:16px;
  padding:8px 10px 8px 12px;
  box-shadow: var(--shadow);
  min-height:46px;
}
#userInput{
  flex:1; background:transparent; border:0; color:var(--text);
  outline:none; font-size:16px;
}
.iconBtn{
  width:42px; height:42px; border-radius:12px;
  border:1px solid rgba(255,255,255,.08); background:var(--panel);
  cursor:pointer;
}
.sendBtn{
  width:54px; height:54px; border-radius:17px; border:0; cursor:pointer;
  color:#fff; background:linear-gradient(180deg, var(--accent), var(--accent-2));
  box-shadow:0 10px 26px rgba(122,77,255,.45);
}

/* ============ Sheet “Joindre…” ============ */
.sheet{
  position:fixed; left:var(--pad); right:var(--pad);
  bottom:calc(68px + env(safe-area-inset-bottom));
  background:var(--panel-2);
  border:1px solid rgba(255,255,255,.1);
  border-radius:18px;
  padding:12px;
  box-shadow:0 20px 36px rgba(0,0,0,.55);
  z-index:65;
}
.sheet__title{font-weight:700; margin:4px 6px 8px; color:var(--text)}
.sheet__row{ display:flex; flex-wrap:wrap; gap:10px }
.pill{
  padding:10px 14px; border-radius:999px; background:var(--panel); color:var(--text);
  border:1px solid rgba(255,255,255,.1); cursor:pointer;
}
.pill--ghost{ background:transparent }

/* ============ Modal (FAQ, etc.) ============ */
.modal::backdrop{ background:rgba(0,0,0,.55) }
.modal{ border:0; background:transparent; z-index:70 }
.modal__card{
  width:min(560px, 92vw); margin:auto;
  background:rgba(24,24,40,.98);
  border:1px solid rgba(255,255,255,.12);
  border-radius:18px; box-shadow:0 20px 40px rgba(0,0,0,.6);
  padding:16px;
}
.modal__title{ font-weight:800; margin-bottom:8px; color:#fff }
.modal__body{ color:var(--text); line-height:1.6 }
.modal__body .faq p{ margin:0 0 12px }
.modal__actions{ display:flex; justify-content:flex-end; gap:8px; margin-top:14px }

/* ============ Thème clair ============ */
body.theme-light{
  --bg:#F4F6FB; --panel:#FFFFFF; --panel-2:#FFFFFF;
  --text:#171923; --text-dim:#3F4153;
  --shadow: 0 10px 30px rgba(122,77,255,.15), inset 0 0 0 1px rgba(0,0,0,.06);
  background:#F2F3F8;
}
body.theme-light #topbar{
  background:linear-gradient(180deg, rgba(255,255,255,.92), rgba(255,255,255,.75));
  border-bottom:1px solid rgba(0,0,0,.06);
}
body.theme-light #versionLine{ border-bottom:1px solid rgba(0,0,0,.06) }

/* ============ Petites largeurs ============ */
@media (max-width: 390px){
  .chip{ padding:8px 10px; font-size:13px }
  .gem{ min-width:auto; padding:8px 10px }
  #tokenCount{ font-size:14px }
}
/* --- Micro-améliorations mobile --- */

/* 1) Chat plus fluide et stable (évite les sauts de scroll) */
#chat{
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
  /* garde un peu plus d'espace si le clavier remonte (iOS/Android) */
  padding-bottom: calc(128px + env(safe-area-inset-bottom));
}

/* 2) Clics plus faciles sur petits écrans */
.chip, .pill, .iconBtn, .sendBtn, .fab{
  touch-action: manipulation;
}

/* =========================
   PATCHS AJOUTÉS
   ========================= */

/* 1) PayPal: forcer la largeur à 100% dans la modale */
#paypal-buttons > div { width: 100% !important; }

/* 2) Bubbles: préserver les retours à la ligne et couper proprement */
.bubble__content {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* 3) Modales: scroll si contenu long sur petit écran */
.modal__card {
  max-height: 80vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* 4) Sécurité z-index (dropdown au-dessus du topbar et des iframes) */
.dropdown { z-index: 999; }
.modal { z-index: 1000; }
