.ai-page { max-width: 1100px; }
.ai-mobile-tabs { display: none; }
.ai-page-intro { display: flex; align-items: end; justify-content: space-between; gap: 30px; padding: 52px 0 30px; }
.ai-page-intro h1 { margin-bottom: 12px; }
.ai-connection { display: inline-flex; align-items: center; gap: 9px; padding-bottom: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.ai-connection .status-dot.warning { background: var(--gold-deep); box-shadow: 0 0 0 3px rgba(155, 108, 23, .12); }
.ai-chat-panel { overflow: hidden; }
.ai-chat-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 21px 24px; border-bottom: 1px solid var(--line); }
.ai-identity { display: flex; align-items: center; gap: 11px; min-width: 0; }
.ai-identity > span:last-child { display: block; min-width: 0; }
.ai-identity strong, .ai-identity small { display: block; }
.ai-identity strong { font-size: 14px; }
.ai-identity small { color: var(--muted); margin-top: 3px; font-size: 10px; }
.ai-avatar { width: 37px; height: 37px; display: grid; place-items: center; border-radius: 11px; color: var(--gold-deep); background: #f2ead7; }
.ai-avatar svg { width: 20px; height: 20px; }
.ai-messages { display: grid; gap: 13px; min-height: 520px; max-height: 68vh; overflow-y: auto; padding: 25px; background: #fbfbf8; }
.ai-message { width: 100%; padding: 13px 4px; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.ai-message.user { justify-self: end; width: min(78%, 680px); padding: 13px 15px; border: 1px solid #dfe2e7; border-radius: 18px 18px 5px 18px; color: var(--ink); background: #eef0f3; box-shadow: 0 5px 14px rgba(20, 21, 18, .04); }
.ai-message.error { width: 100%; padding: 8px 4px; border-left: 2px solid var(--error); border-radius: 0; background: transparent; color: var(--error); }
.ai-message-label { margin-bottom: 5px; color: var(--muted); font: 500 10px Calibri, "Segoe UI", system-ui, sans-serif; letter-spacing: .04em; }
.ai-message.user .ai-message-label { color: var(--muted); }
.ai-message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.6; }
.ai-message p mjx-container { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
.ai-message p mjx-container[display="true"] { margin: .7em 0; padding: .15em 0; }
.ai-message.pending .ai-thinking { display: inline-flex; align-items: center; min-height: 1.6em; }
.ai-thinking-dots { position: relative; display: inline-block; width: 25px; height: 22px; color: var(--gold-deep); vertical-align: middle; animation: ai-thinking-cycle 6s linear infinite; animation-play-state: running; will-change: transform; }
.ai-thinking-dots > span { position: absolute; left: 0; top: 0; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation-duration: 6s; animation-timing-function: ease-in-out; animation-iteration-count: infinite; animation-play-state: running; will-change: transform; }
.ai-thinking-dots > span:nth-child(1) { animation-name: ai-thinking-dot-one; }
.ai-thinking-dots > span:nth-child(2) { animation-name: ai-thinking-dot-two; }
.ai-thinking-dots > span:nth-child(3) { animation-name: ai-thinking-dot-three; }
.ai-composer { display: flex; align-items: end; gap: 11px; padding: 18px 24px 10px; border-top: 1px solid var(--line); background: var(--surface); }
.ai-composer textarea { min-height: 44px; max-height: 150px; flex: 1; resize: none; overflow-y: auto; border: 1px solid #cfd0c7; border-radius: 10px; outline: 0; padding: 11px 13px; color: var(--ink); background: #fff; line-height: 1.4; transition: border .2s ease, box-shadow .2s ease; }
.ai-composer textarea:focus { border-color: var(--gold-deep); box-shadow: 0 0 0 3px rgba(155, 108, 23, .12); }
.ai-composer textarea::placeholder { color: #aeb0a7; }
.ai-composer .button { flex: 0 0 auto; min-width: 87px; }
.ai-quota-box { display: flex; align-items: center; gap: 10px; margin: 14px 24px 0; padding: 9px 12px; border: 1px solid #dedfd6; border-radius: 10px; color: var(--muted); background: #fbfbf8; font-size: 11px; }
.ai-quota-label { color: var(--ink); font-weight: 700; letter-spacing: .02em; }
.ai-quota-box strong { min-width: 42px; padding: 4px 7px; border-radius: 6px; color: var(--gold-deep); background: #f2ead7; font: 700 11px/1 Calibri, "Segoe UI", system-ui, sans-serif; text-align: center; }
.ai-quota-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-quota-purchase { flex: 0 0 auto; min-height: 30px; margin-left: auto; padding: 0 10px; border: 1px solid var(--ink); border-radius: 8px; color: #fff; background: var(--ink); font: 700 10px/1 Calibri, "Segoe UI", system-ui, sans-serif; white-space: nowrap; }
.ai-quota-purchase:hover { color: #fff; background: #2b2d27; }
.ai-quota-purchase:disabled { color: #d8d9d2; border-color: #73756d; background: #73756d; cursor: not-allowed; }
.ai-quota-box.is-depleted { border-color: #e6c5c0; color: var(--error); background: #fff8f6; }
.ai-quota-box.is-depleted .ai-quota-label { color: var(--error); }
.ai-quota-box.is-depleted strong { color: #fff; background: var(--error); }
.ai-form-hint { margin: 0; padding: 0 24px 20px; color: #999b91; font: 10px Calibri, "Segoe UI", system-ui, sans-serif; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@keyframes ai-thinking-cycle {
  0%, 30% { transform: rotate(0deg); }
  70%, 100% { transform: rotate(1800deg); }
}
@keyframes ai-thinking-dot-one {
  0%, 18% { transform: translate(1px, 8px); }
  6% { transform: translate(1px, 5px); }
  12% { transform: translate(1px, 6px); }
  30%, 70% { transform: translate(10px, 2px); }
  82%, 100% { transform: translate(1px, 8px); }
  88% { transform: translate(1px, 5px); }
  94% { transform: translate(1px, 6px); }
}
@keyframes ai-thinking-dot-two {
  0%, 18% { transform: translate(10px, 8px); }
  6% { transform: translate(10px, 6px); }
  12% { transform: translate(10px, 5px); }
  30%, 70% { transform: translate(5px, 12px); }
  82%, 100% { transform: translate(10px, 8px); }
  88% { transform: translate(10px, 6px); }
  94% { transform: translate(10px, 5px); }
}
@keyframes ai-thinking-dot-three {
  0%, 18% { transform: translate(19px, 8px); }
  6% { transform: translate(19px, 4px); }
  12% { transform: translate(19px, 6px); }
  30%, 70% { transform: translate(15px, 12px); }
  82%, 100% { transform: translate(19px, 8px); }
  88% { transform: translate(19px, 4px); }
  94% { transform: translate(19px, 6px); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-thinking-dots, .ai-thinking-dots > span { animation: none; }
  .ai-thinking-dots > span:nth-child(1) { transform: translate(1px, 8px); }
  .ai-thinking-dots > span:nth-child(2) { transform: translate(10px, 8px); }
  .ai-thinking-dots > span:nth-child(3) { transform: translate(19px, 8px); }
}

@media (max-width: 780px) {
  .ai-mobile-tabs { display: flex; gap: 5px; margin: 11px 0 0; padding: 4px; overflow-x: auto; border: 1px solid #dedfd6; border-radius: 12px; background: #f4f4ee; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .ai-mobile-tabs::-webkit-scrollbar { display: none; }
  .ai-mobile-tab { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; min-height: 35px; padding: 0 12px; border: 1px solid transparent; border-radius: 9px; color: var(--muted); background: transparent; font: 600 10px/1 Calibri, "Segoe UI", system-ui, sans-serif; text-decoration: none; white-space: nowrap; transition: color .2s ease, background .2s ease, box-shadow .2s ease; }
  .ai-mobile-tab:hover { color: var(--ink); }
  .ai-mobile-tab.active { color: var(--ink); background: #fff; box-shadow: 0 2px 8px rgba(20, 21, 18, .09); }
  .ai-mobile-tab:focus-visible { outline: 3px solid rgba(155, 108, 23, .28); outline-offset: 2px; }
  .ai-page-intro { display: block; padding: 22px 0 18px; }
  .ai-page-intro h1 { margin-bottom: 9px; font-size: clamp(29px, 8vw, 35px); line-height: 1.05; }
  .ai-page-intro .intro-copy { max-width: 560px; font-size: 12px; line-height: 1.5; }
  .ai-connection { margin-top: 13px; padding-bottom: 0; white-space: normal; font-size: 10px; }
  .ai-chat-header { align-items: flex-start; flex-direction: column; gap: 13px; padding: 15px; }
  .ai-identity { width: 100%; }
  .ai-identity strong { font-size: 13px; }
  .ai-identity small { font-size: 9px; }
  .ai-avatar { width: 34px; height: 34px; border-radius: 10px; }
  .ai-messages { min-height: clamp(360px, 56vh, 520px); max-height: 64vh; padding: 14px; gap: 10px; }
  .ai-message { width: 100%; padding: 11px 4px; }
  .ai-message.user { width: 92%; padding: 11px 12px; border-radius: 16px 16px 4px 16px; }
  .ai-message.error { width: 100%; padding: 8px 4px; }
  .ai-message p { font-size: 12.5px; line-height: 1.55; }
  .ai-quota-box { margin-inline: 14px; gap: 8px; padding: 8px 10px; font-size: 10px; }
  .ai-quota-box strong { min-width: 38px; font-size: 10px; }
  .ai-quota-purchase { min-height: 28px; padding-inline: 7px; border-radius: 7px; font-size: 9px; }
  .ai-composer { align-items: flex-end; flex-direction: row; gap: 7px; padding: 11px 14px 8px; }
  .ai-composer textarea { min-height: 42px; padding: 10px; font-size: 12px; }
  .ai-composer .button { width: auto; min-width: 68px; min-height: 42px; height: 42px; padding-inline: 12px; }
  .ai-form-hint { padding: 0 14px 14px; font-size: 9px; line-height: 1.4; }
}

@media (max-width: 390px) {
  .ai-mobile-tab { padding-inline: 10px; font-size: 9px; }
  .ai-chat-header { padding-inline: 13px; }
  .ai-messages { padding-inline: 11px; }
  .ai-composer { padding-inline: 11px; }
  .ai-composer .button { min-width: 62px; padding-inline: 9px; }
}
