/* Page « Assistant d'étude » (pages/assistant.php, assets/js/assistant.js) */
/* La page elle-même ne défile jamais (ordinateur, tablette, téléphone) : seul le fil de la discussion défile. */
html:has(body.page-assistant) { overflow: hidden; overscroll-behavior: none; }
body.page-assistant { height: 100vh; height: 100dvh; overflow: hidden; }
body.page-assistant .app-layout { min-height: 0; }
body.page-assistant .main-content { padding: 0.75rem 1rem 0.75rem; height: calc(100vh - var(--header-height, 64px)); height: calc(100dvh - var(--header-height, 64px)); overflow: hidden; }
.as-app { --as-green: #146040; --as-green2: #1d7a50; --as-ink: #1c2b42; --as-soft: #f3efe3; --as-line: #e3dcc8;
  max-width: 1180px; margin: 0 auto; color: var(--as-ink);
  height: calc(100vh - var(--header-height, 64px) - 1.6rem); height: calc(100dvh - var(--header-height, 64px) - 1.6rem); min-height: 420px; }
.as-app *, .as-app *::before, .as-app *::after { box-sizing: border-box; }

/* ---- états sans conversation (désactivé, visiteur) */
.as-state { padding: 1rem; color: #4a5668; }
.as-card { max-width: 560px; margin: 4vh auto 0; padding: 2rem 1.5rem; text-align: center; background: #fff; border: 1px solid var(--as-line); border-radius: 20px; box-shadow: 0 10px 30px rgba(28, 43, 66, 0.08); }
.as-card h1 { margin: 0.2rem 0 0.6rem; font-size: 1.5rem; color: var(--as-green); }
.as-big { font-size: 3.2rem; line-height: 1; }
.as-points { list-style: none; margin: 1rem 0; padding: 0; display: grid; gap: 0.4rem; text-align: left; max-width: 340px; margin-inline: auto; }
.as-points li { padding: 0.5rem 0.8rem 0.5rem 2rem; border-radius: 12px; background: var(--as-soft); position: relative; font-size: 0.92rem; }
.as-points li::before { content: "✓"; position: absolute; left: 0.8rem; color: var(--as-green2); font-weight: 800; }
.as-cta { display: inline-block; padding: 0.8rem 1.4rem; border-radius: 14px; background: linear-gradient(160deg, var(--as-green2), var(--as-green)); color: #fff; font-weight: 800; text-decoration: none; box-shadow: 0 6px 16px rgba(20, 96, 64, 0.32); }

/* ---- disposition de la conversation */
.as-chat { position: relative; display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 0.9rem; height: 100%; }
.as-chat[hidden] { display: none; }
.as-side { display: flex; flex-direction: column; min-height: 0; padding: 0.9rem; background: #fff; border: 1px solid var(--as-line); border-radius: 18px; }
.as-side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.as-side-close { display: none; }
.as-new { padding: 0.65rem 0.8rem; border: 2px dashed var(--as-green2); border-radius: 12px; background: #f0f8f3; color: var(--as-green); font: inherit; font-weight: 800; cursor: pointer; }
.as-new:hover { background: #e2f2e8; }
.as-conv-list { list-style: none; margin: 0.7rem 0; padding: 0; overflow-y: auto; flex: 1; display: grid; gap: 0.3rem; align-content: start; }
.as-conv { display: flex; align-items: stretch; border-radius: 10px; }
.as-conv.is-active { background: #e2f2e8; }
.as-conv:hover { background: var(--as-soft); }
.as-conv.is-active:hover { background: #d6ecde; }
.as-conv-open { flex: 1; min-width: 0; text-align: left; padding: 0.5rem 0.6rem; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; display: grid; gap: 0.1rem; }
.as-conv-open span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; font-weight: 600; }
.as-conv-open small, .as-conv-empty { color: #7a8494; font-size: 0.75rem; }
.as-conv-del { border: 0; background: none; cursor: pointer; padding: 0 0.5rem; opacity: 0; font-size: 0.9rem; }
.as-conv:hover .as-conv-del, .as-conv-del:focus-visible { opacity: 0.8; }
.as-side-note { margin: 0; font-size: 0.72rem; color: #7a8494; line-height: 1.35; }

.as-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #fff; border: 1px solid var(--as-line); border-radius: 18px; overflow: hidden; }
.as-head { display: flex; align-items: center; gap: 0.7rem; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--as-line); background: linear-gradient(180deg, #f7f4ea, #fff); }
.as-title { display: flex; align-items: center; gap: 0.6rem; flex: 1; min-width: 0; }
.as-title-ico { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #e2f2e8; font-size: 1.4rem; flex-shrink: 0; }
.as-title strong { display: block; font-size: 1rem; }
.as-title small { display: block; color: #6b7686; font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-hist-btn { display: none; }
.as-icon-btn { width: 40px; height: 40px; border: 1px solid var(--as-line); border-radius: 12px; background: #fff; font-size: 1.15rem; cursor: pointer; flex-shrink: 0; }
.as-icon-btn:hover { background: var(--as-soft); }
.as-usage { width: 150px; flex-shrink: 0; text-align: right; }
.as-usage-bar { display: block; height: 7px; border-radius: 999px; background: #e8e2d0; overflow: hidden; }
.as-usage-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--as-green2), #7cc79b); border-radius: 999px; transition: width 0.4s ease; }
.as-usage.is-low .as-usage-bar i { background: linear-gradient(90deg, #e08a1e, #d64545); }
.as-usage small { display: block; margin-top: 0.2rem; font-size: 0.72rem; color: #6b7686; }

/* ---- fil de la discussion */
.as-log { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.8rem; scroll-behavior: smooth; background: #fcfbf7; }
.as-welcome { margin: auto; max-width: 560px; text-align: center; padding: 1rem 0; }
.as-welcome[hidden] { display: none; }
.as-welcome-bot { font-size: 3rem; line-height: 1; }
.as-welcome h1 { margin: 0.4rem 0; font-size: 1.5rem; color: var(--as-green); }
.as-welcome p { color: #4a5668; margin: 0.4rem 0; }
.as-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin: 1rem 0; }
.as-chips button { padding: 0.55rem 0.9rem; border: 1px solid var(--as-line); border-radius: 999px; background: #fff; font: inherit; font-size: 0.88rem; font-weight: 600; cursor: pointer; color: var(--as-ink); }
.as-chips button:hover { background: #e2f2e8; border-color: var(--as-green2); }
.as-tip { font-size: 0.8rem; color: #7a8494 !important; }

.as-msg { display: flex; gap: 0.5rem; max-width: 100%; }
.as-user { justify-content: flex-end; }
.as-av { width: 32px; height: 32px; border-radius: 50%; background: #e2f2e8; display: grid; place-items: center; font-size: 1.05rem; flex-shrink: 0; margin-top: 2px; }
.as-bubble { max-width: min(760px, 86%); padding: 0.65rem 0.9rem; border-radius: 16px; line-height: 1.5; font-size: 0.96rem; overflow-wrap: anywhere; }
.as-user .as-bubble { background: linear-gradient(160deg, var(--as-green2), var(--as-green)); color: #fff; border-bottom-right-radius: 5px; }
.as-assistant .as-bubble { background: #fff; border: 1px solid var(--as-line); border-bottom-left-radius: 5px; }
.as-err .as-bubble { background: #fdf0e6; border-color: #f0c9a4; color: #7a3d00; }
.as-bubble p { margin: 0 0 0.55rem; }
.as-bubble p:last-child, .as-bubble ul:last-child, .as-bubble ol:last-child { margin-bottom: 0; }
.as-bubble ol, .as-bubble ul { margin: 0.2rem 0 0.55rem; padding-left: 1.3rem; }
.as-bubble li { margin: 0.2rem 0; }
.as-bubble .as-h { font-weight: 800; color: var(--as-green); margin-top: 0.4rem; }
.as-bubble code { background: #f1ede0; padding: 0.05rem 0.35rem; border-radius: 6px; font-size: 0.88em; }
.as-bubble pre { background: #1c2b42; color: #f3efe3; padding: 0.7rem 0.9rem; border-radius: 10px; overflow-x: auto; margin: 0.4rem 0; }
.as-bubble pre code { background: none; padding: 0; color: inherit; }
.as-bubble .as-math, .as-bubble mjx-container[display="true"] { overflow-x: auto; max-width: 100%; }
.as-bubble hr { border: 0; border-top: 1px solid var(--as-line); margin: 0.6rem 0; }
.as-photo-tag { display: inline-block; margin-bottom: 0.3rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: rgba(255, 255, 255, 0.22); font-size: 0.78rem; font-weight: 700; }
.as-typing .as-bubble { display: flex; gap: 5px; align-items: center; padding: 0.9rem 1rem; }
.as-typing i { width: 8px; height: 8px; border-radius: 50%; background: #9aa5b5; animation: as-bounce 1.1s infinite ease-in-out; }
.as-typing i:nth-child(2) { animation-delay: 0.15s; } .as-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes as-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-5px); opacity: 1; } }
.as-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- zone de saisie */
.as-composer { padding: 0.6rem 0.8rem 0.5rem; border-top: 1px solid var(--as-line); background: #fff; }
.as-trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.as-previews { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.as-previews[hidden], .as-limit[hidden] { display: none; }
.as-prev { position: relative; }
.as-prev img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--as-line); display: block; }
.as-prev button { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: #16233a; color: #fff; cursor: pointer; line-height: 1; }
.as-limit { margin-bottom: 0.5rem; padding: 0.55rem 0.8rem; border-radius: 12px; background: #fdecc8; color: #5b3a00; font-size: 0.86rem; }
.as-limit a { color: #5b3a00; font-weight: 800; }
.as-row { display: flex; align-items: flex-end; gap: 0.5rem; }
.as-row textarea { flex: 1; min-width: 0; resize: none; max-height: 160px; padding: 0.65rem 0.85rem; border: 1px solid #cfc7af; border-radius: 14px; font: inherit; font-size: 1rem; line-height: 1.4; background: #fcfbf7; color: var(--as-ink); }
.as-row textarea:focus { outline: 2px solid var(--as-green2); outline-offset: 1px; background: #fff; }
.as-attach { align-self: flex-end; }
.as-send { width: 46px; height: 46px; border: 0; border-radius: 14px; background: linear-gradient(160deg, var(--as-green2), var(--as-green)); color: #fff; font-size: 1.2rem; cursor: pointer; flex-shrink: 0; box-shadow: 0 4px 12px rgba(20, 96, 64, 0.3); }
.as-send:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.as-foot { margin: 0.4rem 0 0; font-size: 0.7rem; color: #8a93a0; text-align: center; }
.as-backdrop { display: none; }

/* ---- téléphone : la liste des discussions devient un tiroir, la saisie reste au-dessus de la barre d'onglets */
@media (max-width: 860px) {
  .as-chat { grid-template-columns: minmax(0, 1fr); }
  .as-hist-btn { display: inline-block; }
  .as-side { position: fixed; z-index: 400; top: 0; bottom: 0; left: 0; width: min(86vw, 320px); border-radius: 0 18px 18px 0; transform: translateX(-105%); transition: transform 0.22s ease; padding-top: calc(0.9rem + env(safe-area-inset-top, 0px)); }
  .as-side.is-open { transform: none; box-shadow: 8px 0 30px rgba(10, 20, 36, 0.35); }
  .as-side-close { display: block; border: 0; background: none; font-size: 1.6rem; cursor: pointer; }
  .as-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 390; background: rgba(10, 20, 36, 0.5); }
  .as-usage { width: 110px; }
}
@media (max-width: 767px) {
  body.page-assistant .main-content { padding: 0; }   /* la barre d'onglets du bas est fixe : sa hauteur est retirée de .as-app */
  .as-app { height: calc(100vh - var(--header-height, 56px) - var(--tabbar-height, 60px) - env(safe-area-inset-bottom, 0px));
            height: calc(100dvh - var(--header-height, 56px) - var(--tabbar-height, 60px) - env(safe-area-inset-bottom, 0px)); min-height: 0; }
  .as-main { border-radius: 0; border-left: 0; border-right: 0; }
  .as-bubble { max-width: 90%; font-size: 0.95rem; }
  .as-title small { display: none; }
  .as-foot { display: none; }
  .as-card { margin: 1rem; padding: 1.4rem 1rem; }
}
@media (prefers-reduced-motion: reduce) { .as-log { scroll-behavior: auto; } .as-typing i { animation: none; } .as-side { transition: none; } }

/* ------------------------------------------------------------ achat de jetons (PayTech) */
.as-buy-btn { flex-shrink: 0; border: 0; border-radius: 999px; padding: 0.4rem 0.8rem; font-weight: 800; font-size: 0.8rem; color: #fff; cursor: pointer; background: linear-gradient(160deg, #e0a526, #c98a0f); box-shadow: 0 3px 10px rgba(201, 138, 15, 0.35); }
.as-buy-btn[hidden], .as-modal[hidden], .as-banner[hidden] { display: none; }
.as-link-btn { border: 0; background: none; padding: 0; color: #5b3a00; font: inherit; font-weight: 800; text-decoration: underline; cursor: pointer; }
.as-modal { position: fixed; inset: 0; z-index: 600; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(15, 30, 24, 0.55); }
.as-modal-card { position: relative; width: min(460px, 100%); max-height: calc(100dvh - 2rem); overflow-y: auto; background: #fff; border-radius: 18px; padding: 1.2rem 1.1rem 1.1rem; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3); }
.as-modal-card h2 { margin: 0 2rem 0.5rem 0; font-size: 1.15rem; }
.as-modal-close { position: absolute; top: 0.5rem; right: 0.5rem; }
.as-buy-intro, .as-buy-note { font-size: 0.86rem; line-height: 1.45; color: #46515f; margin: 0 0 0.7rem; }
.as-buy-note { margin: 0.7rem 0 0; font-size: 0.78rem; color: #6b7686; }
.as-buy-warn { margin: 0 0 0.6rem; padding: 0.55rem 0.7rem; border-radius: 12px; background: #fdecc8; color: #5b3a00; font-size: 0.85rem; }
.as-buy-err { margin: 0 0 0.6rem; padding: 0.5rem 0.7rem; border-radius: 12px; background: #fde2e2; color: #8a1f1f; font-size: 0.85rem; }
.as-buy-err[hidden] { display: none; }
.as-buy-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.as-pack { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; text-align: left; padding: 0.7rem 0.9rem; border: 1.5px solid #cfe3d6; border-radius: 14px; background: #f5fbf7; cursor: pointer; font: inherit; color: #12382a; }
.as-pack:hover:not(:disabled) { border-color: #1f8f5f; background: #eaf7ef; }
.as-pack:disabled { opacity: 0.6; cursor: wait; }
.as-pack.is-wait { border-color: #1f8f5f; }
.as-pack-main { display: grid; font-weight: 800; }
.as-pack-main small, .as-buy-list--ro small { font-weight: 500; font-size: 0.75rem; color: #5d6b78; }
.as-pack b, .as-buy-list--ro b { font-size: 1.05rem; white-space: nowrap; }
.as-buy-list--ro li { display: flex; justify-content: space-between; gap: 0.8rem; padding: 0.55rem 0.8rem; border: 1px solid #e3e8e5; border-radius: 12px; align-items: center; }
.as-buy-list--ro li span { display: grid; font-weight: 700; }
.as-buy-link { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; }
.as-buy-link input { flex: 1; min-width: 0; padding: 0.5rem 0.6rem; border: 1px solid #cdd5d0; border-radius: 10px; font-size: 0.8rem; }
.as-buy-copy { flex-shrink: 0; border: 0; border-radius: 10px; padding: 0 0.8rem; background: #146040; color: #fff; font-weight: 700; cursor: pointer; }
.as-buy-actions { margin-bottom: 0.8rem; }
.as-buy-actions .as-cta { display: block; text-align: center; font-size: 0.9rem; padding: 0.65rem 1rem; }
.as-banner { display: flex; align-items: center; gap: 0.5rem; padding: 0.55rem 0.9rem; font-size: 0.86rem; font-weight: 700; background: #eef3f0; color: #24423a; border-bottom: 1px solid #d5e1da; flex-shrink: 0; }
.as-banner.is-ok { background: #dff5e8; color: #0f5a37; }
.as-banner.is-warn { background: #fdecc8; color: #5b3a00; }
.as-banner-x { margin-left: auto; border: 0; background: none; font-size: 1.1rem; cursor: pointer; color: inherit; }
@media (max-width: 767px) { .as-buy-btn { padding: 0.35rem 0.6rem; } }

/* ------------------------------------------------------------ « Refaire avec l'assistant avancé » */
.as-escalate { display: inline-block; margin-top: 0.6rem; padding: 0.4rem 0.8rem; border: 1.5px solid #146040; border-radius: 999px; background: #fff; color: #146040; font: inherit; font-size: 0.8rem; font-weight: 700; cursor: pointer; }
.as-escalate:hover:not(:disabled) { background: #eaf7ef; }
.as-escalate:disabled { opacity: 0.6; cursor: wait; }

/* ------------------------------------------------------------ graphiques et courbes tracés par l'assistant */
.as-chart { margin: .7rem 0; max-width: 100%; }
.sc-fig { margin: 0; padding: .55rem .6rem; border: 1px solid #dfe5e2; border-radius: 12px; background: #fff; color: #26302c; }
.sc-fig figcaption { font-weight: 700; font-size: .88rem; margin-bottom: .25rem; }
.sc-svg { width: 100%; height: auto; display: block; }
.as-chart-err { margin: 0; padding: .5rem .7rem; border-radius: 10px; background: #fdecc8; color: #5b3a00; font-size: .85rem; }

/* tableaux de valeurs de l'assistant */
.sc-table-wrap { overflow-x: auto; }
.sc-table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.sc-table th, .sc-table td { border: 1px solid #cfd8d3; padding: .3rem .5rem; text-align: center; }
.sc-table thead th { background: #e8f1ec; }
.sc-table tbody th { background: #f3f6f4; text-align: left; }

/* Sous-titre du nom de l'assistante (écran d'accueil de l'assistant) */
.as-card .as-sub { margin: -0.3rem 0 0.8rem; color: var(--color-text-muted, #5b6b7b); font-weight: 600; }
