/* Khung chat độc lập, không khóa trang và không phủ tối bài học. */
.study-chat-launcher { position: fixed; right: 20px; bottom: 20px; z-index: 180; border-radius: 28px; min-height: 46px; box-shadow: 0 4px 18px #17324d26; }
body:has(.study-chat-launcher:not([hidden])) .scroll-to-top { bottom: 80px; }
body:has(.study-chat:not([hidden])) .scroll-to-top { visibility: hidden; pointer-events: none; }
.study-chat { position: fixed; z-index: 181; right: 20px; bottom: 78px; width: min(440px, calc(100vw - 32px)); height: min(680px, calc(100dvh - 112px)); display: flex; flex-direction: column; box-sizing: border-box; border: 1px solid var(--line,#d6e2e8); border-radius: 14px; background: var(--surface,#fff); color: var(--text,#17324d); box-shadow: 0 8px 36px #17324d29; }
.study-chat [hidden], .study-chat[hidden], .study-chat-launcher[hidden] { display: none !important; }
.study-chat-header { padding: 16px 16px 10px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line,#d6e2e8); }
.study-chat h2 { margin: 0; font-size: 1rem; line-height: 1.45; }
.study-chat-header p { margin: 4px 0 0; font-size: .8rem; color: var(--text-2,#526679); }
.study-chat-header .button { padding: 8px; min-width: 36px; min-height: 36px; }
.study-chat-toolbar { display: flex; gap: 8px; padding: 8px 16px; }
.study-chat-toolbar .button { padding: 6px 9px; min-height: 34px; font-size: .8rem; }
.study-chat-body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 8px 16px 16px; scrollbar-gutter: stable; }
.study-chat-empty { color: var(--text-2,#526679); font-size: .9rem; line-height: 1.65; margin: 1rem 0; }
.study-chat-message { margin: 0 0 20px; font-size: .9rem; overflow-wrap: anywhere; }
.study-chat-message[data-role="user"] { margin-left: 28px; padding: 10px 12px; border-radius: 12px 12px 3px 12px; background: #edf6f5; }
.study-chat-message[data-role="user"] p { margin: 0; white-space: pre-wrap; }
.study-chat-message[data-role="assistant"] { padding: 0 2px; }
.study-chat-message-label { display: block; margin-bottom: 6px; font-size: .75rem; color: var(--text-2,#526679); }
.study-assistant-answer { line-height: 1.7; overflow-wrap: anywhere; }
.study-assistant-answer > :first-child { margin-top: 0; }
.study-assistant-answer h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
.study-assistant-answer p { margin: .65rem 0; }
.study-assistant-answer ul, .study-assistant-answer ol { padding-left: 1.25rem; margin: .6rem 0; }
.study-assistant-answer li { padding-left: .1rem; margin: .45rem 0; }
.study-assistant-answer blockquote { margin: .8rem 0; padding: .2rem .8rem; border-left: 3px solid var(--primary,#0d7776); background: #f2f8f7; }
.study-assistant-answer pre, .study-answer-table { overflow-x: auto; max-width: 100%; }
.study-assistant-answer pre { padding: .7rem; background: #f2f6f8; border-radius: 6px; }
.study-assistant-answer table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.study-assistant-answer td, .study-assistant-answer th { padding: .4rem .5rem; border: 1px solid #d6e2e8; text-align: left; }
.study-assistant-answer mjx-container { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
.study-chat-sources { display: grid; justify-items: start; gap: .4rem; margin-top: .8rem; }
.study-chat-sources:empty { display: none; }
.study-chat-sources a { max-width: 100%; white-space: normal; font-size: .85rem; }
.study-chat-source-link { color: var(--primary-dark,#0d7776); text-underline-offset: 3px; padding: .25rem 0; }
.study-chat-votes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.study-chat-votes button { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--text-2,#526679); min-height: 36px; padding: 6px; font: inherit; font-size: .75rem; }
.study-chat-votes button:hover, .study-chat-votes button[aria-pressed="true"] { background: #edf6f5; border-color: #bddbd7; color: #0d7776; }
.study-chat-votes button:focus-visible { outline: 2px solid var(--primary,#0d7776); outline-offset: 2px; }
.study-chat-history { display: grid; gap: 8px; }
.study-chat-history button { display: block; width: 100%; text-align: left; white-space: normal; font-weight: 500; }
.study-chat-history time { display: block; font-size: .75rem; font-weight: 400; color: var(--text-2,#526679); margin-top: 4px; }
.study-chat-older { font-size: .8rem; margin-bottom: 16px; }
.study-chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 6px; border-top: 1px solid var(--line,#d6e2e8); }
.study-chat textarea { flex: 1; min-width: 0; max-height: 140px; resize: vertical; box-sizing: border-box; border: 1px solid #bdcfd8; border-radius: 8px; padding: 9px; font: inherit; font-size: 16px; line-height: 1.5; }
.study-chat-form .button { flex-shrink: 0; min-width: 40px; min-height: 40px; padding: 8px; }
.study-chat-notice { padding: 2px 12px 10px; margin: 0; color: var(--text-2,#526679); font-size: .7rem; line-height: 1.5; }
.study-chat-status { margin: 0; padding: 0 16px; color: #9f2828; font-size: .8rem; }
.study-chat-status:empty { display: none; }
.study-chat-status:not(.is-error), .study-chat-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); }
.study-wait { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 8px; background: #f2f8f7; font-size: .85rem; }
.study-wait p { margin: 4px 0 0; color: var(--text-2,#526679); font-size: .8rem; }
.study-wait-dots { display: flex; flex-shrink: 0; gap: 4px; }
.study-wait-dots span { width: 5px; height: 5px; border-radius: 50%; background: #0d7776; animation: study-pulse 1.4s ease-in-out infinite; }
.study-wait-dots span:nth-child(2) { animation-delay: .15s; }
.study-wait-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes study-pulse { 0%,80%,100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (max-width: 480px) { .study-chat { right: 8px; bottom: 74px; width: calc(100vw - 16px); height: min(620px, calc(100dvh - 124px)); } .study-chat-launcher { right: 12px; bottom: 16px; } .study-chat-body { padding-left: 12px; padding-right: 12px; } }
@media (prefers-reduced-motion: reduce) { .study-wait-dots span { animation: none; opacity: .8; } }
