/* ---- ai: tutor widget ---- */
.aitutor-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.aitutor-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 900;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 18px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--ink, #0E1B2A); color: #fff; font: 600 15px/1 var(--body, system-ui, sans-serif);
  box-shadow: 0 10px 28px rgba(14, 27, 42, 0.28), 0 2px 6px rgba(14, 27, 42, 0.18);
  transition: transform .15s ease, background .15s ease;
}
.aitutor-fab:hover { background: var(--accent, #0B6E5A); transform: translateY(-1px); }
.aitutor-fab:focus-visible, .aitutor-icon:focus-visible, .aitutor-form textarea:focus-visible { outline: 3px solid var(--yellow, #FFD23F); outline-offset: 2px; }
body:has(.cms-fab) .aitutor-fab { bottom: 84px; }
.aitutor.is-open .aitutor-fab { display: none; }

.aitutor-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 901;
  width: min(420px, calc(100vw - 40px)); height: min(640px, calc(100vh - 40px));
  display: flex; flex-direction: column;
  background: var(--white, #fff); color: var(--ink, #0E1B2A);
  border: 1px solid var(--line, #D5DEDB); border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(14, 27, 42, 0.28);
  font-family: var(--body, system-ui, sans-serif); font-size: 16px; line-height: 1.5;
}
.aitutor-panel[hidden] { display: none; }
.aitutor-head { display: flex; align-items: center; gap: 6px; padding: 14px 12px 12px 18px; background: var(--ink, #0E1B2A); color: var(--on-dark, #E8EEF2); }
.aitutor-head > div { flex: 1; min-width: 0; }
.aitutor-head h2 { font-size: 18px; line-height: 1.2; color: #fff; }
.aitutor-sub { font-size: 13px; color: var(--on-dark-muted, #C3CFD8); margin-top: 2px; }
.aitutor-icon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; }
.aitutor-icon:hover { background: rgba(255, 255, 255, 0.12); }

.aitutor-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--ground, #F5F8F7); overscroll-behavior: contain; }
.aitutor-msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.aitutor-msg p + p, .aitutor-msg p + ol, .aitutor-msg p + ul, .aitutor-msg ol + p, .aitutor-msg ul + p { margin-top: 8px; }
.aitutor-msg ol, .aitutor-msg ul { margin: 0; padding-left: 22px; }
.aitutor-msg code { font-family: var(--mono, monospace); font-size: 14px; background: rgba(14, 27, 42, 0.06); padding: 1px 4px; border-radius: 4px; }
.aitutor-msg .katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; }
.aitutor-msg.assistant { align-self: flex-start; background: var(--white, #fff); border: 1px solid var(--line, #D5DEDB); border-bottom-left-radius: 4px; }
.aitutor-msg.user { align-self: flex-end; background: var(--accent, #0B6E5A); color: #fff; border-bottom-right-radius: 4px; }
.aitutor-msg.user code { background: rgba(255, 255, 255, 0.18); }
.aitutor-msg.error { align-self: stretch; max-width: none; background: #FBEAEA; color: var(--error, #A12622); border: 1px solid #F0C9C7; font-size: 15px; }
.aitutor-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.aitutor-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted, #4A5966); opacity: .35; animation: aitutor-dot 1s infinite; }
.aitutor-typing i:nth-child(2) { animation-delay: .15s; }
.aitutor-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes aitutor-dot { 50% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .aitutor-typing i { animation: none; opacity: .7; } .aitutor-fab { transition: none; } }

.aitutor-form { display: flex; gap: 8px; align-items: flex-end; padding: 12px 12px 6px; border-top: 1px solid var(--line, #D5DEDB); background: var(--white, #fff); }
.aitutor-form textarea { flex: 1; min-width: 0; resize: none; max-height: 140px; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid #7B8C97; border-radius: 12px; color: var(--ink, #0E1B2A); background: #fff; }
.aitutor-form .btn { flex: none; }
.aitutor-form .btn[disabled] { opacity: .6; cursor: wait; }
.aitutor-note { font-size: 12.5px; color: var(--muted, #4A5966); padding: 0 14px 10px; background: var(--white, #fff); }
.aitutor-body { padding: 20px 18px; display: flex; flex-direction: column; gap: 12px; color: var(--text, #33424F); }
.aitutor-body .actions { margin-top: 6px; }

@media (max-width: 600px) {
  .aitutor-fab { right: 14px; bottom: 14px; padding: 12px 16px; }
  .aitutor-panel { inset: 0; right: 0; bottom: 0; width: 100%; height: 100%; height: 100dvh; border-radius: 0; border: 0; }
  body.aitutor-locked { overflow: hidden; }
}
