.ai-hidden { display: none !important; }

.ai-launcher {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  gap: 9px;
  align-items: center;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 999px;
  color: #fffdf8;
  background: #263d42;
  box-shadow: 0 14px 32px rgba(38, 61, 66, .28);
  font: 750 14px/1 ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
}

.ai-launcher::before { content: "✦"; color: #f1c77f; font-size: 17px; }
.ai-launcher:hover { background: #315c68; }

.ai-drawer {
  position: fixed;
  top: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 50;
  width: min(470px, calc(100vw - 28px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #c8d5d4;
  border-radius: 22px;
  background: #fffdf8;
  box-shadow: 0 24px 70px rgba(35, 33, 30, .26);
  font-family: ui-sans-serif, system-ui, "PingFang SC", sans-serif;
  transform: translateX(calc(100% + 32px));
  transition: transform .22s ease;
}

.ai-drawer.is-open { transform: translateX(0); }
.ai-drawer-header { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 18px 20px 14px; color: #fffdf8; background: #263d42; }
.ai-drawer-header strong { display: block; font-size: 17px; }
.ai-drawer-header small { display: block; margin-top: 4px; color: #cbdad7; font-size: 12px; }
.ai-header-actions { display: flex; gap: 7px; align-items: center; }
.ai-settings-button { display: none; min-height: 34px; padding: 0 10px; border: 1px solid rgba(255, 255, 255, .24); border-radius: 999px; color: #fff; background: rgba(255, 255, 255, .08); font: 750 11px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.ai-icon-button { width: 36px; height: 36px; border: 1px solid rgba(255, 255, 255, .24); border-radius: 50%; color: #fff; background: transparent; font-size: 21px; cursor: pointer; }

.ai-account { display: flex; gap: 8px; align-items: center; padding: 10px 16px; border-bottom: 1px solid #e1e7e4; background: #f4f8f6; font-size: 12px; }
.ai-account strong { color: #176b53; }
.ai-account .ai-spacer { flex: 1; }
.ai-text-button { padding: 6px 9px; border: 1px solid #c5d1cc; border-radius: 8px; color: #315c68; background: #fff; text-decoration: none; white-space: nowrap; font: 700 12px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }

.ai-settings-panel { flex: 0 0 auto; }
.ai-controls { display: grid; grid-template-columns: 1.25fr .75fr; gap: 10px; padding: 12px 16px; border-bottom: 1px solid #e1e7e4; }
.ai-controls label { display: grid; gap: 5px; color: #66756e; font-size: 11px; font-weight: 700; }
.ai-controls select { width: 100%; min-height: 38px; border: 1px solid #ccd7d1; border-radius: 8px; padding: 0 9px; color: #17211d; background: #fff; font: 650 12px/1 ui-sans-serif, system-ui, sans-serif; }
.ai-context-row { grid-column: 1 / -1; }

.ai-modes { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px; border-bottom: 1px solid #e1e7e4; scrollbar-width: none; }
.ai-modes::-webkit-scrollbar { display: none; }
.ai-mode { flex: 0 0 auto; padding: 7px 10px; border: 1px solid #ccd7d1; border-radius: 999px; color: #596a62; background: #fff; font: 750 11px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.ai-mode.is-active { color: #fff; border-color: #315c68; background: #315c68; }

.ai-messages { flex: 1 1 180px; min-height: 120px; overflow-y: auto; overscroll-behavior: contain; padding: 16px; background: #f7f3ea; }
.ai-message { max-width: 92%; margin: 0 0 12px; padding: 11px 13px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.65; }
.ai-message.assistant { border: 1px solid #d8cbb9; border-bottom-left-radius: 4px; background: #fffdf8; }
.ai-message.user { margin-left: auto; border-bottom-right-radius: 4px; color: #fff; background: #315c68; }
.ai-message.is-status { color: #66756e; font-style: italic; }
.ai-message-meta { display: block; margin-top: 7px; color: #7b8983; font-size: 10px; }
.ai-analysis-details { margin: 0 0 12px; overflow: hidden; border: 1px solid #d8cbb9; border-radius: 11px; background: #f7f1e7; }
.ai-analysis-details summary { position: relative; padding: 9px 34px 9px 11px; color: #765348; list-style: none; font-size: 12px; font-weight: 800; cursor: pointer; }
.ai-analysis-details summary::-webkit-details-marker { display: none; }
.ai-analysis-details summary::after { position: absolute; top: 50%; right: 12px; content: "+"; color: #9c4038; font-size: 17px; transform: translateY(-50%); }
.ai-analysis-details[open] summary::after { content: "−"; }
.ai-analysis-path { padding: 10px 11px 12px; border-top: 1px solid #e2d6c5; color: #5f594f; white-space: pre-wrap; font-size: 12px; line-height: 1.65; }
.ai-answer-body { white-space: pre-wrap; }

.ai-inspiration { flex: 0 0 auto; border-top: 1px solid #e1e7e4; background: #fff; }
.ai-inspiration-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px 0; color: #765348; font-size: 11px; }
.ai-inspiration-head button { border: 0; color: #315c68; background: transparent; font: 750 11px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.ai-inspiration-head button::after { content: " ↻"; color: #9c4038; }
.ai-suggestions { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px 10px; background: #fff; scrollbar-width: none; }
.ai-suggestions::-webkit-scrollbar { display: none; }
.ai-suggestions button { flex: 0 0 auto; padding: 7px 10px; border: 1px solid #d8cbb9; border-radius: 999px; color: #765348; background: #fffaf1; font: 700 11px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.ai-composer { display: grid; grid-template-columns: 1fr auto; gap: 9px; align-items: end; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid #e1e7e4; background: #fff; }
.ai-composer textarea { width: 100%; max-height: 130px; min-height: 44px; resize: vertical; border: 1px solid #c5d1cc; border-radius: 10px; padding: 10px 11px; font: 14px/1.5 ui-sans-serif, system-ui, sans-serif; }
.ai-send { min-width: 66px; min-height: 44px; border: 0; border-radius: 10px; color: #fff; background: #9c4038; font-weight: 800; cursor: pointer; }
.ai-send:disabled { cursor: not-allowed; opacity: .52; }

.ai-lesson-action { display: flex; justify-content: flex-end; margin: -8px 0 16px; }
.ai-lesson-action button { padding: 8px 12px; border: 1px solid #b9cecf; border-radius: 999px; color: #315c68; background: #edf5f4; font: 750 12px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.ai-lesson-action button::before { content: "✦ "; color: #9c4038; }

@media (max-width: 640px) {
  .ai-launcher { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .ai-drawer { inset: 0; width: 100%; height: 100dvh; border: 0; border-radius: 0; }
  .ai-drawer-header { flex: 0 0 auto; min-height: 58px; padding: calc(9px + env(safe-area-inset-top)) 12px 9px; }
  .ai-drawer-header strong { font-size: 15px; }
  .ai-drawer-header small { max-width: 210px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
  .ai-settings-button { display: block; }
  .ai-icon-button { width: 34px; height: 34px; font-size: 19px; }
  .ai-account { flex: 0 0 auto; gap: 6px; min-height: 40px; padding: 7px 12px; font-size: 11px; }
  .ai-text-button { padding: 7px 8px; font-size: 11px; }
  .ai-settings-panel { display: none; max-height: 44dvh; overflow-y: auto; background: #fff; }
  .ai-settings-panel.is-open { display: block; }
  .ai-controls { grid-template-columns: minmax(0, 1.25fr) minmax(0, .75fr); gap: 7px; padding: 9px 12px; }
  .ai-controls label { gap: 3px; font-size: 10px; }
  .ai-controls select { min-height: 34px; padding: 0 7px; font-size: 11px; }
  .ai-modes { padding: 8px 12px; }
  .ai-mode { padding: 7px 9px; font-size: 10px; }
  .ai-messages { flex: 1 1 auto; min-height: 0; padding: 12px; }
  .ai-message { max-width: 94%; margin-bottom: 9px; padding: 9px 11px; font-size: 13px; line-height: 1.58; }
  .ai-analysis-details { margin-bottom: 9px; }
  .ai-analysis-details summary { padding: 8px 32px 8px 10px; font-size: 11px; }
  .ai-analysis-path { padding: 9px 10px 10px; font-size: 11px; }
  .ai-inspiration-head { padding: 7px 12px 0; }
  .ai-suggestions { padding: 7px 12px 8px; }
  .ai-suggestions button { padding: 7px 9px; font-size: 10px; }
  .ai-composer { flex: 0 0 auto; gap: 7px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .ai-composer textarea { min-height: 42px; max-height: 92px; padding: 9px 10px; font-size: 13px; resize: none; }
  .ai-send { min-width: 60px; min-height: 42px; }
}
