:root {
  --as-ai-bg: #071f16;
  --as-ai-panel: #0d2f23;
  --as-ai-soft: #123c2d;
  --as-ai-gold: #f3d27a;
  --as-ai-text: #f8f7ed;
  --as-ai-muted: #d8ccb0;
  --as-ai-danger: #ffb4a9;
  --as-ai-shadow: 0 20px 60px rgba(0,0,0,.35);
}

.as-ai-button {
  position: fixed;
  z-index: 99998;
  left: 18px;
  right: auto;
  bottom: 18px;
  border: 1px solid rgba(243,210,122,.6);
  background: linear-gradient(135deg, #0d3a2b, #123f31);
  color: var(--as-ai-text);
  border-radius: 999px;
  padding: 13px 18px;
  font-weight: 800;
  box-shadow: var(--as-ai-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.as-ai-button:hover { transform: translateY(-1px); }

.as-ai-panel {
  position: fixed;
  z-index: 99999;
  left: 18px;
  right: auto;
  bottom: 76px;
  width: min(440px, calc(100vw - 24px));
  max-height: min(720px, calc(100vh - 96px));
  background: linear-gradient(180deg, var(--as-ai-panel), #081d15);
  color: var(--as-ai-text);
  border: 1px solid rgba(243,210,122,.32);
  border-radius: 22px;
  box-shadow: var(--as-ai-shadow);
  overflow: hidden;
  display: none;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.as-ai-panel.open { display: flex; flex-direction: column; }

.as-ai-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(0,0,0,.18);
  border-bottom: 1px solid rgba(243,210,122,.22);
}

.as-ai-header strong { color: var(--as-ai-gold); font-size: 1rem; }
.as-ai-header small { display: block; color: var(--as-ai-muted); margin-top: 2px; }
.as-ai-close {
  border: none;
  background: transparent;
  color: var(--as-ai-text);
  font-size: 24px;
  cursor: pointer;
}

.as-ai-body {
  overflow: auto;
  padding: 14px;
}

.as-ai-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.as-ai-chip,
.as-ai-send,
.as-ai-correct,
.as-ai-tts,
.as-ai-quiz-btn {
  border: 1px solid rgba(243,210,122,.22);
  background: rgba(255,255,255,.06);
  color: var(--as-ai-text);
  border-radius: 12px;
  padding: 9px 10px;
  cursor: pointer;
  font-weight: 700;
}

.as-ai-chip:hover,
.as-ai-send:hover,
.as-ai-correct:hover,
.as-ai-tts:hover,
.as-ai-quiz-btn:hover {
  background: rgba(243,210,122,.12);
}

.as-ai-textarea,
.as-ai-input,
.as-ai-select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(243,210,122,.24);
  background: rgba(0,0,0,.24);
  color: var(--as-ai-text);
  border-radius: 14px;
  padding: 12px;
  outline: none;
  font: inherit;
}

.as-ai-textarea { min-height: 96px; resize: vertical; }

.as-ai-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.as-ai-send {
  background: linear-gradient(135deg, #f3d27a, #c9993f);
  color: #102117;
}

.as-ai-correct {
  background: rgba(243,210,122,.10);
  color: var(--as-ai-text);
}

.as-ai-response {
  margin-top: 12px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(243,210,122,.18);
  border-radius: 16px;
  padding: 12px;
  min-height: 80px;
  white-space: pre-wrap;
  line-height: 1.55;
}

.as-ai-response[dir="rtl"] { text-align: right; font-size: 1.2rem; }
.as-ai-error { color: var(--as-ai-danger); }
.as-ai-muted { color: var(--as-ai-muted); }

.as-ai-quiz {
  margin-top: 12px;
  border-top: 1px solid rgba(243,210,122,.18);
  padding-top: 12px;
}

.as-ai-quiz-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.as-ai-question-card {
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.16);
  border-radius: 14px;
  padding: 11px;
  margin-top: 10px;
}

.as-ai-choice {
  width: 100%;
  text-align: left;
  margin: 5px 0;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.06);
  color: var(--as-ai-text);
  padding: 9px;
  border-radius: 10px;
  cursor: pointer;
}

.as-ai-choice.good { background: rgba(95, 201, 126, .28); }
.as-ai-choice.bad { background: rgba(255, 99, 99, .25); }

@media (max-width: 620px) {
  .as-ai-panel { left: 12px; right: auto; bottom: 72px; }
  .as-ai-button { left: 12px; right: auto; bottom: 12px; }
  .as-ai-tools, .as-ai-quiz-grid, .as-ai-actions { grid-template-columns: 1fr; }
}


.as-canvas-result-box {
  width: min(980px, calc(100% - 24px));
  margin: 18px auto;
  padding: 18px;
  border-radius: 18px;
  border: 2px solid rgba(189, 143, 55, .55);
  background: linear-gradient(135deg, rgba(7,31,22,.96), rgba(18,60,45,.94));
  color: #f8f7ed;
  box-shadow: 0 14px 40px rgba(0,0,0,.25);
  direction: ltr;
  text-align: left;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.as-canvas-result-box h3 {
  margin: 0 0 12px;
  color: #f3d27a;
  font-size: clamp(18px, 3vw, 24px);
}

.as-canvas-line,
.as-canvas-correction {
  white-space: pre-wrap;
  line-height: 1.65;
  border-radius: 14px;
  padding: 14px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(243,210,122,.2);
  margin-top: 10px;
}

.as-canvas-line {
  font-weight: 800;
  color: #fffbe8;
}

.as-canvas-correction {
  color: #f8f7ed;
}

.as-canvas-result-ready {
  animation: asCanvasPulse 1.1s ease-out 1;
}

@keyframes asCanvasPulse {
  0% { box-shadow: 0 0 0 0 rgba(243,210,122,.55); }
  100% { box-shadow: 0 14px 40px rgba(0,0,0,.25); }
}


.as-home-button {
  position: fixed;
  z-index: 99997;
  left: 16px;
  top: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 15px;
  border-radius: 999px;
  border: 1px solid rgba(243,210,122,.72);
  background: linear-gradient(135deg, #0d3a2b, #123f31);
  color: #f8f7ed !important;
  text-decoration: none !important;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 12px 36px rgba(0,0,0,.25);
  cursor: pointer;
}

.as-home-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #123f31, #18513f);
}

@media (max-width: 620px) {
  .as-home-button {
    top: 10px;
    left: 10px;
    min-height: 38px;
    padding: 9px 12px;
    font-size: 14px;
  }
}


/* Indicateur discret de suivi établissement */
.as-db-sync-pill{position:fixed;left:14px;bottom:88px;z-index:9998;border:1px solid rgba(243,210,122,.35);background:rgba(6,24,18,.86);color:#f3d27a;border-radius:999px;padding:8px 11px;font-weight:800;font-size:.82rem;display:none;box-shadow:0 10px 30px rgba(0,0,0,.25)}
.as-db-sync-pill.show{display:block}
@media(max-width:640px){.as-db-sync-pill{bottom:76px;font-size:.78rem}}

/* v29 - résultat ArabicSchool visible directement dans la page */
.as-page-ai-result {
  width: min(1100px, calc(100% - 24px));
  margin: 18px auto 22px;
  padding: 18px;
  border-radius: 22px;
  border: 2px solid rgba(243,210,122,.38);
  background: linear-gradient(180deg, rgba(7,31,22,.97), rgba(16,56,40,.95));
  color: #fffaf0;
  box-shadow: 0 18px 52px rgba(0,0,0,.28);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  direction: ltr;
  text-align: left;
}
.as-page-ai-hidden { display: none !important; }
.as-page-ai-result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid rgba(243,210,122,.20);
  padding-bottom: 12px;
  margin-bottom: 12px;
}
.as-page-ai-result-kicker {
  display: inline-block;
  color: #ffe6a3;
  font-weight: 900;
  font-size: .92rem;
  letter-spacing: .02em;
  margin-bottom: 4px;
}
.as-page-ai-result h2 {
  margin: 0;
  color: #f3d27a;
  font-size: clamp(1.25rem, 2.6vw, 2rem);
}
.as-page-ai-result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.as-page-ai-result-btn {
  border: 1px solid rgba(243,210,122,.34);
  border-radius: 999px;
  background: linear-gradient(135deg, #f3d27a, #c9993f);
  color: #071f16;
  padding: 9px 13px;
  font-weight: 950;
  cursor: pointer;
}
.as-page-ai-result-btn.secondary {
  background: rgba(255,255,255,.10);
  color: #fffaf0;
}
.as-page-ai-result-content {
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: clamp(1rem, 2.4vw, 1.18rem);
  border-radius: 18px;
  border: 1px solid rgba(243,210,122,.18);
  background: rgba(255,255,255,.07);
  padding: 16px;
  max-height: 70vh;
  overflow: auto;
}
.as-page-ai-ready {
  animation: asPageResultPulse 1s ease-out 1;
}
.as-page-ai-copy-helper {
  position: fixed;
  left: -9999px;
  top: -9999px;
}
@keyframes asPageResultPulse {
  0% { box-shadow: 0 0 0 0 rgba(243,210,122,.55); }
  100% { box-shadow: 0 18px 52px rgba(0,0,0,.28); }
}
@media(max-width: 720px) {
  .as-page-ai-result { width: calc(100% - 16px); padding: 14px; border-radius: 18px; }
  .as-page-ai-result-header { display: grid; }
  .as-page-ai-result-actions { justify-content: stretch; }
  .as-page-ai-result-btn { flex: 1 1 auto; }
  .as-page-ai-result-content { max-height: 60vh; }
}
@media print {
  .as-page-ai-result-actions { display: none !important; }
  .as-page-ai-result { box-shadow: none; background: white; color: #111; border: 1px solid #ddd; }
  .as-page-ai-result h2 { color: #064e3b; }
  .as-page-ai-result-kicker { color: #8a6a17; }
  .as-page-ai-result-content { color: #111; background: #fafafa; border: 1px solid #ddd; max-height: none; }
}
