/*
 * Study Helper chat layout
 *
 * The existing helper controls keep their original IDs and behaviour. The
 * companion script moves them into this layout so the UI can feel like one
 * continuous chat without changing the study APIs.
 */

:root {
    --study-chat-panel: var(--agenda-surface, #373532);
    --study-chat-panel-raised: var(--agenda-surface-strong, #312f2d);
    --study-chat-line: var(--agenda-soft-line, rgba(226, 220, 210, 0.11));
    --study-chat-line-soft: color-mix(in srgb, var(--agenda-soft-line, rgba(226, 220, 210, 0.11)) 72%, transparent);
    --study-chat-muted: var(--text-secondary, #aaa69d);
}

body.light-mode {
    --study-chat-panel: var(--agenda-surface, #fffdf8);
    --study-chat-panel-raised: var(--agenda-surface-strong, #f1ede5);
    --study-chat-line: var(--agenda-soft-line, rgba(63, 57, 48, 0.11));
    --study-chat-line-soft: color-mix(in srgb, var(--agenda-soft-line, rgba(63, 57, 48, 0.11)) 72%, transparent);
    --study-chat-muted: var(--text-secondary, #6f6a61);
}

/* Only the active module is promoted to a flex column. This is important
   because inactive views still carry their old inline display:none state. */
body.study-chat-ui-active[data-study-module="quiz"] #quizView,
body.study-chat-ui-active[data-study-module="notes"] #noteView,
body.study-chat-ui-active[data-study-module="mindmap"] #mindMapView,
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView {
    display: flex !important;
    flex: 1 1 0 !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 20px clamp(18px, 3.4vw, 54px) 26px !important;
    box-sizing: border-box !important;
}

body.study-chat-ui-active .study-chat-shell {
    display: flex !important;
    flex: 1 1 0 !important;
    flex-direction: column !important;
    min-height: 0 !important;
    width: 100% !important;
    max-width: none !important;
    height: 100% !important;
    margin: 0 auto !important;
    box-sizing: border-box !important;
}

/* The nested legacy wrappers should not create a second viewport or a second
   block of padding after the header has been promoted into the chat shell. */
body.study-chat-ui-active .study-chat-shell > .interrog-shell {
    display: contents !important;
}

body.study-chat-ui-active .study-chat-shell > .new-mm-container,
body.study-chat-ui-active .study-chat-shell > #newMmFormContainer:not([style*="display: none"]) {
    display: contents !important;
}

body.study-chat-ui-active .study-chat-setup:not(.study-chat-shell):not([style*="display: none"]) {
    display: contents !important;
}

body.study-chat-ui-active .study-chat-settings {
    position: relative;
    z-index: 3;
    display: none !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: start !important;
    gap: 22px;
    flex: 0 0 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 0 14px !important;
    padding: 18px 20px 17px !important;
    border: 1px solid var(--study-chat-line) !important;
    border-radius: 18px !important;
    background: var(--study-chat-panel) !important;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.10) !important;
    box-sizing: border-box !important;
}

body.study-chat-ui-active .study-chat-settings .header-left {
    display: flex !important;
    align-items: flex-start !important;
    min-width: 0 !important;
    gap: 13px !important;
}

body.study-chat-ui-active .study-chat-settings .header-icon-badge {
    flex: 0 0 40px;
    width: 40px !important;
    height: 40px !important;
    margin-top: 1px;
    border-radius: 12px !important;
    background: color-mix(in srgb, var(--study-accent) 12%, transparent) !important;
    border-color: color-mix(in srgb, var(--study-accent) 26%, var(--study-chat-line)) !important;
}

body.study-chat-ui-active .study-chat-settings .header-info {
    display: flex !important;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0 !important;
    gap: 4px !important;
}

body.study-chat-ui-active .study-chat-settings .header-title {
    font-size: 23px !important;
    line-height: 1.16 !important;
    letter-spacing: -0.025em;
}

body.study-chat-ui-active .study-chat-settings .header-subtitle {
    max-width: 700px;
    margin: 0 !important;
    color: var(--study-chat-muted) !important;
    font-size: 13px !important;
}

/* Keep module options immediately above the prompt, wrapping instead of
   creating another horizontal scroll area on narrower screens. */
body.study-chat-ui-active .study-chat-options {
    display: block;
    width: 100%;
    min-width: 0;
    overflow: visible;
    max-width: 800px;
    margin-inline: auto;
    margin-bottom: 8px;
    padding: 0 0 8px;
    border-bottom: 1px solid var(--study-chat-line-soft);
    box-sizing: border-box;
}

body.study-chat-ui-active .study-chat-options-row {
    display: flex !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    width: 100%;
    min-width: 0;
    gap: 10px 16px !important;
    margin: 0 !important;
}

body.study-chat-ui-active .study-chat-options-row > div {
    display: inline-flex !important;
    flex: 0 0 auto;
    align-items: center !important;
    white-space: nowrap;
    gap: 7px !important;
}

body.study-chat-ui-active .study-chat-options .size-label {
    color: var(--study-chat-muted) !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

body.study-chat-ui-active .study-chat-settings .header-right-mode {
    grid-column: 2;
    grid-row: 1;
    align-self: start !important;
    justify-self: end;
    width: auto !important;
    min-width: 148px;
    padding-top: 1px !important;
}

body.study-chat-ui-active .study-chat-settings .clean-segmented-switch {
    box-shadow: none !important;
}

body.study-chat-ui-active .study-chat-settings .clean-segmented-switch.size-segmented-switch {
    width: 220px !important;
}

body.study-chat-ui-active .study-chat-options .clean-segmented-switch {
    box-shadow: none !important;
}

body.study-chat-ui-active .study-chat-settings .clean-segmented-switch.control-segmented-switch {
    width: 148px !important;
}

body.study-chat-ui-active .study-chat-settings .clean-segmented-switch.format-switch {
    width: 254px !important;
}

body.study-chat-ui-active .study-chat-options .study-dropdown-toggle-btn,
body.study-chat-ui-active .study-chat-options .study-page-count-input {
    min-height: 34px !important;
    border: 1px solid var(--study-chat-line) !important;
    border-radius: 9px !important;
    background: var(--study-chat-panel-raised) !important;
}

/* Put the active Study/Balance control beside the module tabs at the top. */
body.study-workspace-active #studyHelperTabBar.browser-tabs-container {
    flex-direction: row !important;
    align-items: center !important;
    gap: 12px !important;
}

body.study-workspace-active .study-browser-tab-strip {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    width: auto !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
}

.study-helper-mode-slot {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-end;
    margin-left: auto;
}

.study-helper-mode-slot .header-right-mode {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    width: auto !important;
    min-width: 148px !important;
    margin: 0 !important;
    padding: 0 !important;
}

.study-helper-mode-slot .clean-segmented-switch.control-segmented-switch {
    width: 148px !important;
    margin: 0 !important;
}

/* Conversation area: the helper speaks in messages, while generated legacy
   result panels simply appear as the assistant's rich response below them. */
body.study-chat-ui-active .study-chat-scroll {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: stretch;
    min-height: 120px;
    overflow-x: hidden;
    overflow-y: visible;
    padding: 14px clamp(4px, 1.5vw, 22px) 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--study-chat-line) transparent;
}

body.study-chat-ui-active .study-chat-scroll::-webkit-scrollbar { width: 7px; }
body.study-chat-ui-active .study-chat-scroll::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: var(--study-chat-line);
}

.study-chat-welcome {
    display: none !important;
}

.study-chat-avatar {
    display: grid;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--study-accent) 28%, var(--study-chat-line));
    border-radius: 10px;
    background: color-mix(in srgb, var(--study-accent) 11%, var(--study-chat-panel));
    color: var(--study-accent);
}

.study-chat-avatar svg,
.study-chat-avatar img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.study-chat-copy { min-width: 0; }

.study-chat-label {
    margin: 1px 0 6px;
    color: var(--study-chat-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.study-chat-bubble {
    width: fit-content;
    max-width: min(680px, 100%);
    padding: 12px 15px;
    border: 1px solid var(--study-chat-line-soft);
    border-radius: 5px 16px 16px 16px;
    background: var(--study-chat-panel);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.55;
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.07);
}

.study-chat-message {
    display: flex;
    justify-content: flex-end;
    margin: 4px 0 14px;
}

.study-chat-message.user .study-chat-bubble {
    max-width: min(760px, 86%);
    border: none !important;
    border-radius: 16px 5px 16px 16px;
    background: var(--accent-color) !important;
    color: var(--accent-text) !important;
    box-shadow: none !important;
}

.study-chat-message.assistant {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    gap: 11px;
    margin: 4px 0 16px;
}

.study-chat-message.assistant .study-chat-bubble { color: var(--study-chat-muted); }

.study-chat-message.assistant.is-pending .study-chat-bubble::after {
    display: inline-block;
    width: 5px;
    height: 5px;
    margin-left: 5px;
    border-radius: 50%;
    background: var(--study-accent);
    content: '';
    animation: studyChatPulse 1.1s ease-in-out infinite;
}

/* The thread keeps its inline generation message while the shared foreground
   layer provides the same progress at the top of the whole workspace. */
.study-chat-message.assistant.is-generation .study-chat-bubble::after { display: none; }

.study-generation-inline {
    width: min(460px, 100%);
    min-width: min(320px, 100%);
    padding: 13px 14px 12px;
    border-radius: 5px 16px 16px 16px;
}

.study-generation-inline-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 9px;
    color: var(--study-chat-muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.study-generation-inline-state {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    letter-spacing: .025em;
    text-transform: uppercase;
}

.study-generation-inline-state i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--study-accent);
    animation: studyGenerationPresence 1.4s ease-in-out infinite;
}

.study-generation-inline-title {
    display: block;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.4;
}

.study-generation-inline--mindmap .study-generation-inline-title {
    margin-top: 5px;
}

.study-mindmap-loader {
    display: inline-block;
    box-sizing: border-box;
    width: 16px;
    height: 16px;
    margin: 2px 6px 0 0;
    border: 2px solid color-mix(in srgb, currentColor 24%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;
    color: var(--study-accent);
    vertical-align: -3px;
    animation: studyMindmapSpinner .8s linear infinite;
}

.study-mindmap-loader i {
    display: none;
}

@keyframes studyMindmapSpinner {
    to { transform: rotate(360deg); }
}

.study-generation-inline-stage {
    min-height: 20px;
    margin: 3px 0 11px;
    color: var(--study-chat-muted);
    font-size: 13px;
    line-height: 1.5;
}

.study-generation-inline-progress {
    position: relative;
    height: 3px;
    overflow: hidden;
    border-radius: 99px;
    background: color-mix(in srgb, var(--study-accent) 15%, var(--study-chat-line));
}

.study-generation-inline-progress i {
    position: absolute;
    inset: 0 auto 0 0;
    width: 34%;
    border-radius: inherit;
    background: var(--study-accent);
    animation: studyGenerationProgress 1.25s cubic-bezier(.45, 0, .55, 1) infinite;
}

.study-generation-inline-progress.is-determinate i {
    width: 100%;
    animation: none;
    transform: scaleX(var(--study-generation-progress, 0));
    transform-origin: left center;
    transition: transform 240ms ease;
}

.study-chat-message.assistant.is-generation:not(.is-pending) .study-generation-inline-state i {
    animation: none;
    background: #5fbf86;
}

@keyframes studyGenerationPresence {
    0%, 100% { opacity: .38; transform: scale(.8); }
    50% { opacity: 1; transform: scale(1); }
}

@keyframes studyGenerationProgress {
    from { transform: translateX(-115%); }
    to { transform: translateX(300%); }
}

@keyframes studyChatPulse {
    0%, 100% { opacity: .25; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-2px); }
}

.study-chat-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    margin-top: 8px;
    padding: 6px 9px;
    overflow: hidden;
    border: 1px solid var(--study-chat-line);
    border-radius: 999px;
    color: var(--study-chat-muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.study-chat-attachment-chip svg { flex: 0 0 auto; width: 14px; height: 14px; }

/* Generated content inherits the conversation column and no longer gets
   rendered as a separate full-width settings page. */
body.study-chat-ui-active .study-chat-scroll > #quizStatusArea,
body.study-chat-ui-active .study-chat-scroll > #quizResultContainer,
body.study-chat-ui-active .study-chat-scroll > #noteResultContainer,
body.study-chat-ui-active .study-chat-scroll > #newMmProgress,
body.study-chat-ui-active .study-chat-scroll > #newMmResultArea,
body.study-chat-ui-active .study-chat-scroll > #interrogSession,
body.study-chat-ui-active .study-chat-scroll > #interrogFeedback {
    flex: 0 0 auto !important;
    width: calc(100% - 41px) !important;
    max-width: 800px !important;
    margin: 8px 0 18px 41px !important;
    box-sizing: border-box !important;
}

body.study-chat-ui-active[data-study-module="quiz"] #quizEditor,
body.study-chat-ui-active[data-study-module="notes"] #noteEditor,
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView > .interrog-shell,
body.study-chat-ui-active[data-study-module="mindmap"] #mindMapView > .new-mm-container {
    width: 100% !important;
    max-width: none !important;
    margin-inline: 0 !important;
}


/* The shared shell rule must not reveal a module that hideAllViews() marked
   hidden. The matching active-module selector below can still show it again. */
body.study-chat-ui-active .study-chat-shell[style*="display:none"],
body.study-chat-ui-active .study-chat-shell[style*="display: none"] {
    display: none !important;
}

body.study-chat-ui-active #newMmFormContainer[style*="display: none"] {
    display: none !important;
}

body.study-chat-ui-active .study-chat-scroll > #newMmResultArea {
    min-height: 360px;
    overflow: hidden;
    border: 1px solid var(--study-chat-line);
    border-radius: 16px;
    background: var(--study-chat-panel);
}

/* Mind map editor actions must stay in the scrollable conversation card.
   The canvas is intentionally compact so its labels remain readable at fit. */
body.study-chat-ui-active[data-study-module="mindmap"] .study-chat-scroll > #newMmResultArea {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    flex: 0 0 auto !important;
    gap: 10px;
}

body.study-chat-ui-active[data-study-module="mindmap"] #newMmResultArea .new-mm-canvas-wrap {
    flex: 0 0 auto !important;
    height: clamp(300px, 40vh, 430px) !important;
    min-height: 0 !important;
    border-radius: 14px;
}

body.study-chat-ui-active[data-study-module="mindmap"] #newMmResultArea #newMmCanvas {
    height: 100% !important;
    min-height: 0 !important;
}

body.study-chat-ui-active[data-study-module="mindmap"] #newMmResultArea .new-mm-editor-hint {
    margin: 0;
    font-size: 12px;
    line-height: 1.45;
}

body.study-chat-ui-active[data-study-module="mindmap"] #newMmResultArea .new-mm-controls {
    position: sticky;
    bottom: 0;
    z-index: 3;
    background: var(--study-chat-panel, #292825);
}

body.study-chat-ui-active[data-study-module="mindmap"] #newMmResultArea .new-mm-map-controls {
    gap: 8px;
}

@media (max-width: 680px) {
    body.study-chat-ui-active[data-study-module="mindmap"] #newMmResultArea .new-mm-canvas-wrap {
        height: 42vh !important;
        min-height: 260px !important;
    }
    body.study-chat-ui-active[data-study-module="mindmap"] #newMmResultArea .new-mm-controls {
        position: static;
        justify-content: flex-start;
    }
}

body.study-chat-ui-active .study-chat-scroll > #newMmProgress {
    padding: 5px 0;
}

/* Settings sit above a compact, standard chat composer. */
body.study-chat-ui-active .study-chat-composer-wrap {
    position: relative;
    z-index: 4;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    width: 100%;
    max-width: 800px;
    margin-inline: auto;
    padding: 8px 0 0;
    background: transparent;
}

/* The oral exam has its own transcript and automatic microphone flow. Keep
   the ordinary Study Helper composer and its setup bubbles out of live turns. */
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-composer-wrap,
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-scroll > .study-chat-welcome,
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-scroll > .study-chat-message.assistant {
    display: none !important;
}

.interrog-voice-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 16px;
    margin: 26px auto 0;
}

.interrog-voice-controls .interrog-voice-visualizer {
    flex: 0 0 120px;
    margin: 0;
}

.interrog-send-answer-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid var(--study-chat-line);
    border-radius: 999px;
    background: var(--study-chat-panel-raised);
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
    transition: opacity .15s ease, background .15s ease, transform .15s ease;
}

.interrog-send-answer-btn svg {
    width: 17px;
    height: 17px;
}

.interrog-send-answer-btn:not(:disabled) {
    border-color: color-mix(in srgb, var(--accent-color) 45%, var(--study-chat-line));
    background: color-mix(in srgb, var(--accent-color) 14%, var(--study-chat-panel-raised));
}

.interrog-send-answer-btn:disabled {
    cursor: not-allowed;
    opacity: .45;
}

.interrog-send-answer-btn:not(:disabled):hover {
    transform: translateY(-1px);
}

.interrog-answer-hint {
    margin: 12px auto 0;
    color: var(--study-chat-muted);
    font-size: 12px;
    line-height: 1.5;
}

.interrog-turn-listening {
    align-self: flex-start;
    padding: 8px 12px;
    border: 1px solid var(--study-chat-line-soft);
    border-radius: 12px;
    background: var(--study-chat-panel-raised);
    color: var(--study-chat-muted);
    font-size: 13px;
}

.interrog-turn-listening::after {
    content: '';
    display: inline-block;
    width: 18px;
    overflow: hidden;
    vertical-align: bottom;
    animation: interrog-listening-dots 1.2s steps(4, end) infinite;
}

@keyframes interrog-listening-dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75%, 100% { content: '...'; }
}

body.study-chat-ui-active .study-chat-composer {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: flex !important;
    align-items: flex-end !important;
    flex-wrap: nowrap !important;
    gap: 8px;
    width: 100%;
    max-width: none;
    height: auto;
    min-height: 48px;
    aspect-ratio: auto;
    padding: 6px 10px !important;
    box-sizing: border-box;
}

body.study-chat-ui-active .study-chat-composer > .study-chat-upload-btn,
body.study-chat-ui-active .study-chat-composer > .study-chat-voice,
body.study-chat-ui-active .study-chat-composer > .study-chat-send {
    position: relative;
    z-index: 2;
}

/* Study Helper has no live transcript row; the shared chat meter fills its single input row. */
body.study-chat-ui-active .study-chat-composer.is-study-voice-active {
    min-height: 48px;
}

body.study-chat-ui-active .study-chat-composer.is-study-voice-active .study-chat-input {
    height: 40px !important;
    min-height: 40px !important;
    max-height: 40px !important;
    color: transparent !important;
    caret-color: transparent !important;
    text-shadow: none !important;
}

body.study-chat-ui-active .study-chat-composer.is-study-voice-active .study-chat-input::placeholder {
    color: transparent !important;
}

body.study-chat-ui-active .study-chat-composer.voice-status-active > .study-chat-upload-btn {
    visibility: hidden !important;
    pointer-events: none !important;
}

body.study-chat-ui-active .study-chat-composer .study-chat-voice-status {
    position: absolute !important;
    z-index: 5 !important;
    top: auto !important;
    right: 106px !important;
    bottom: 6px !important;
    left: 12px !important;
    display: none;
    align-items: center;
    gap: 10px;
    width: auto;
    height: 38px;
    max-width: none !important;
    overflow: visible !important;
    padding: 0;
    color: var(--text-secondary, #b8b2a9);
    transform: none !important;
    pointer-events: none;
}

body.study-chat-ui-active .study-chat-composer.voice-status-active .study-chat-voice-status {
    display: flex !important;
}

body.study-chat-ui-active .study-chat-voice-status[aria-hidden="true"] {
    display: none !important;
}

body.study-chat-ui-active .study-chat-composer.voice-status-active .study-chat-voice-status .voice-activity-meter {
    min-width: 0;
}

body.study-chat-ui-active .study-chat-composer.voice-status-active .study-chat-voice {
    color: var(--text-primary) !important;
    background: rgba(255, 255, 255, .06) !important;
    border-color: transparent !important;
    border-radius: 50% !important;
    box-shadow: none !important;
}

body.light-mode.study-chat-ui-active .study-chat-composer.voice-status-active .study-chat-voice {
    background: rgba(0, 0, 0, .04) !important;
}

body.study-chat-ui-active .study-chat-composer.voice-status-active .study-chat-send svg {
    transform: rotate(-90deg) !important;
}

body.study-chat-ui-active .study-chat-composer.voice-status-active .study-chat-send {
    border: 0 !important;
    border-radius: 50% !important;
    background: var(--text-primary) !important;
    color: var(--codex-bg, var(--bg-dark)) !important;
    box-shadow: none !important;
}

.study-chat-upload-btn {
    display: inline-flex !important;
    flex: 0 0 38px !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    align-self: center !important;
}

.study-chat-upload-btn svg { width: 16px; height: 16px; }

body.study-chat-ui-active .study-chat-input {
    display: block;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: auto !important;
    height: 40px;
    min-height: 40px !important;
    max-height: 220px !important;
    margin: 0 !important;
    padding: 8px 10px !important;
    border: 0 !important;
    border-radius: 0 !important;
    outline: none !important;
    background: transparent !important;
    color: var(--text-primary) !important;
    font-size: 16px !important;
    line-height: 1.5 !important;
    resize: none !important;
    box-shadow: none !important;
}

body.study-chat-ui-active .study-chat-send:disabled {
    cursor: wait;
    opacity: .65;
}

body.study-chat-ui-active .study-chat-send span { display: none !important; }

.study-chat-meta {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 25px;
    padding: 4px 13px 0;
    color: var(--study-chat-muted);
    font-size: 11px;
}

.study-chat-attachments {
    display: flex;
    align-items: center;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 35%;
    min-height: 0;
    margin: 0;
}

body.study-chat-ui-active .study-chat-attachments .file-name-display {
    display: none;
    max-width: 100%;
    margin: 0;
    padding: 5px 8px;
    overflow: hidden;
    border: 1px solid var(--study-chat-line);
    border-radius: 999px;
    color: var(--study-chat-muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.study-chat-ui-active .study-chat-attachments .file-name-display:not(:empty) { display: block; }

body.study-chat-ui-active .study-library-picker-wrap { display: none !important; }

body.study-chat-ui-active .study-chat-legacy-inputs { display: none !important; }
body.study-chat-ui-active .study-chat-legacy-upload { display: none !important; }
body.study-chat-ui-active .study-chat-legacy-file-input { display: none !important; }

@media (max-width: 640px) {
    body.study-workspace-active #studyHelperTabBar.browser-tabs-container,
    body.media-workspace-active #mediaTabBar.browser-tabs-container {
        gap: 8px !important;
        padding-inline: 12px !important;
    }

    body.study-workspace-active .study-helper-mode-slot .header-right-mode,
    body.study-workspace-active .study-helper-mode-slot .clean-segmented-switch.control-segmented-switch {
        min-width: 132px !important;
        width: 132px !important;
    }
}

@media (max-width: 640px) {
    body.study-chat-ui-active[data-study-module="quiz"] #quizView,
body.study-chat-ui-active[data-study-module="notes"] #noteView,
body.study-chat-ui-active[data-study-module="mindmap"] #mindMapView,
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView {
        padding: 12px 12px max(18px, env(safe-area-inset-bottom)) !important;
    }

    body.study-chat-ui-active .study-chat-options { padding-bottom: 8px; }
    body.study-chat-ui-active .study-chat-options-row { align-items: center !important; gap: 8px 12px !important; }
    body.study-chat-ui-active .study-chat-options-row > div { flex: 0 0 auto; }
    body.study-chat-ui-active .study-chat-options .clean-segmented-switch.size-segmented-switch { width: 202px !important; }
    body.study-chat-ui-active .study-chat-options .clean-segmented-switch.format-switch { width: 238px !important; }

    body.study-chat-ui-active .study-chat-scroll { padding-inline: 0; }
    body.study-chat-ui-active .study-chat-scroll > #quizStatusArea,
body.study-chat-ui-active .study-chat-scroll > #quizResultContainer,
body.study-chat-ui-active .study-chat-scroll > #noteResultContainer,
body.study-chat-ui-active .study-chat-scroll > #newMmProgress,
body.study-chat-ui-active .study-chat-scroll > #newMmResultArea,
body.study-chat-ui-active .study-chat-scroll > #interrogSession,
body.study-chat-ui-active .study-chat-scroll > #interrogFeedback {
        width: calc(100% - 35px) !important;
        margin-left: 35px !important;
    }
    .study-chat-welcome { padding-top: 6px; }
    .study-chat-bubble { font-size: 13px; }
    .study-chat-message.user .study-chat-bubble { max-width: 92%; }
    body.study-chat-ui-active .study-chat-composer {
        min-height: 48px;
        padding: 6px 10px !important;
    }
    body.study-chat-ui-active .study-chat-input { height: 40px; min-height: 40px !important; }
    body.study-chat-ui-active .study-chat-send { width: 40px !important; min-width: 40px !important; max-width: 40px !important; height: 40px !important; min-height: 40px !important; }
    .study-chat-meta { padding-inline: 9px; }
}

@media (prefers-reduced-motion: reduce) {
    .study-chat-message.assistant.is-pending .study-chat-bubble::after,
    .study-generation-inline-state i,
    .study-generation-inline-progress i,
    .study-mindmap-loader,
    .study-mindmap-loader-trunk,
    .study-mindmap-loader-branch { animation: none; }
}

/* Oral exam: keep the submitted topic, controls, live voice surface, and
   transcript on the shared Study Helper workspace surface. */
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView {
    align-items: stretch !important;
}

body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView > .study-chat-exam-shell {
    flex: 1 1 0 !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 0 !important;
    height: 100% !important;
    margin: 0 !important;
    overflow: hidden !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}

body.study-chat-ui-active[data-study-module="interrogation"] .study-chat-exam-shell > .study-chat-scroll {
    width: 100%;
    min-height: 0;
    padding: 18px clamp(18px, 4vw, 48px) 22px;
    background: transparent;
}

body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-scroll > .study-chat-welcome,
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-scroll > .study-chat-message.assistant,
body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-composer-wrap {
    display: none !important;
}

body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-scroll > .study-chat-message.user {
    flex: 0 0 auto;
    width: 100%;
    max-width: 820px;
    margin: 0 auto 12px;
}

body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-scroll > #interrogSession.active {
    display: flex !important;
    flex: 1 0 auto !important;
    flex-direction: column;
    width: 100% !important;
    max-width: 900px !important;
    min-height: 0 !important;
    margin: 0 auto !important;
    padding: 0 !important;
    background: transparent;
    box-sizing: border-box;
}

body.study-chat-ui-active[data-study-module="interrogation"] #interrogationView.interrogation-live-conversation .study-chat-scroll > #interrogFeedback.active {
    display: block !important;
    flex: 1 0 auto !important;
    width: 100% !important;
    max-width: 900px !important;
    margin: 0 auto !important;
    padding: 0 !important;
    background: transparent;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-session-header {
    align-items: center;
    gap: 12px;
    margin: 0 auto 12px;
    width: 100%;
    max-width: 820px;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-status-pill {
    max-width: min(58%, 360px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-main-hub {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: center;
    margin: 0 auto 16px;
    width: 100%;
    max-width: 820px;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-question-text {
    width: 100%;
    max-width: 760px;
    min-height: 1.4em;
    margin: 4px auto 0;
    font-size: clamp(18px, 2.3vw, 25px);
    line-height: 1.42;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-audio-stage {
    position: relative;
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: min(100%, 300px);
    height: 192px;
    margin: 7px auto 0;
    color: var(--text-primary);
}

body.study-chat-ui-active[data-study-module="interrogation"] #interrogAudioBlob {
    display: block;
    width: min(100%, 260px);
    height: 162px;
    overflow: visible;
    color: var(--text-primary);
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-mic-btn {
    position: absolute;
    right: 17px;
    bottom: 23px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--study-chat-line);
    border-radius: 50%;
    background: var(--study-chat-panel-raised);
    color: var(--text-primary);
    box-shadow: 0 5px 16px rgba(0, 0, 0, .15);
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-mic-btn.recording {
    border-color: rgba(239, 68, 68, .35);
    background: color-mix(in srgb, #ef4444 15%, var(--study-chat-panel-raised));
    color: #ef4444;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-audio-caption {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    color: var(--study-chat-muted);
    font-size: 12px;
    text-align: center;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-voice-controls {
    margin: 12px auto 0;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-transcript-container {
    flex: 1 0 auto;
    width: 100%;
    max-width: 820px;
    max-height: min(36vh, 330px);
    min-height: 96px;
    height: auto;
    margin: 0 auto 12px;
    padding: 14px 0 4px;
    overflow-y: auto;
    border: 0;
    border-top: 1px solid var(--study-chat-line-soft);
    border-radius: 0;
    background: transparent;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-transcript {
    gap: 10px;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-turn-examiner,
body.study-chat-ui-active[data-study-module="interrogation"] .interrog-turn-student {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: fit-content;
    max-width: min(82%, 680px);
    padding: 10px 14px;
    border: 1px solid var(--study-chat-line-soft);
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-turn-examiner {
    align-self: flex-start;
    background: var(--study-chat-panel-raised);
    color: var(--text-primary);
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-turn-student {
    align-self: flex-end;
    border-color: transparent;
    background: color-mix(in srgb, var(--accent-color) 14%, var(--study-chat-panel));
    color: var(--text-primary);
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-turn-speaker {
    color: var(--study-chat-muted);
    font-size: 10px;
    font-weight: 750;
    letter-spacing: .045em;
    text-transform: uppercase;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-turn-content {
    overflow-wrap: anywhere;
}

body.study-chat-ui-active[data-study-module="interrogation"] .interrog-finish-btn {
    width: auto;
    min-height: 38px;
    padding: 8px 14px;
}

@media (max-width: 640px) {
    body.study-chat-ui-active[data-study-module="interrogation"] .study-chat-scroll {
        padding: 12px 14px max(16px, env(safe-area-inset-bottom));
    }

    body.study-chat-ui-active[data-study-module="interrogation"] .interrog-session-header {
        align-items: flex-start;
        margin-bottom: 10px;
    }

    body.study-chat-ui-active[data-study-module="interrogation"] .interrog-status-pill {
        max-width: 58%;
        white-space: normal;
    }

    body.study-chat-ui-active[data-study-module="interrogation"] .interrog-audio-stage {
        height: 170px;
    }

    body.study-chat-ui-active[data-study-module="interrogation"] #interrogAudioBlob {
        height: 144px;
    }

    body.study-chat-ui-active[data-study-module="interrogation"] .interrog-transcript-container {
        max-height: 32vh;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.study-chat-ui-active[data-study-module="interrogation"] .interrog-audio-stage * {
        scroll-behavior: auto !important;
    }
}

/* Copy actions remain visible and keyboard accessible on every screen size. */
.study-chat-message.user {
    flex-direction: column;
    align-items: flex-end;
}

.study-chat-bubble { white-space: pre-wrap; }

.study-chat-copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 6px;
    padding: 6px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--study-chat-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.study-chat-copy-btn:hover,
.study-chat-copy-btn:focus-visible {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.study-chat-copy-btn:focus-visible { outline: 2px solid var(--study-accent); outline-offset: 2px; }
.study-chat-copy-btn:disabled { cursor: default; }

.study-chat-balanced-retry {
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    max-width: 100%;
    margin-top: 9px;
    padding: 8px 12px;
    border: 1px solid color-mix(in srgb, var(--accent-color) 70%, transparent);
    border-radius: 10px;
    background: var(--accent-color);
    color: var(--accent-text);
    font: inherit;
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
    transition: filter 150ms ease, opacity 150ms ease;
}

.study-chat-balanced-retry:hover:not(:disabled) { filter: brightness(1.08); }
.study-chat-balanced-retry:focus-visible { outline: 2px solid var(--study-accent); outline-offset: 2px; }
.study-chat-balanced-retry:disabled { cursor: default; opacity: .68; }

.study-chat-copy-btn svg { width: 16px; height: 16px; stroke-width: 2.5; }
.study-chat-copy-btn.copy-confirmed { color: var(--accent-color, #f59e0b); }
