/* Student AI assistant and the teacher review of that chat.
   Scoped so it does not restyle the case conversation.
   The chat window follows the ai-for-students chat: avatars, spacing,
   markdown, and a rounded composer. */

.assistant-chat {
    --assistant-blue: #0369a1;
    --assistant-blue-bg: #eff6ff;
    --assistant-text: #1e293b;
    --assistant-muted: #64748b;
    --assistant-hover: #f5f7fa;
    --assistant-line: #e2e8f0;
    --assistant-code: #1e293b;
    --assistant-page: #fafbfc;
}

#assistant-chat-open[hidden],
.chat-header-mark[hidden],
#assistant-chat-panel[hidden],
#assistant-chat-stop[hidden] {
    display: none !important;
}

#assistant-chat-open,
.chat-header-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.85rem;
    height: 1.85rem;
    padding: 0;
    flex-shrink: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #6b7280;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    cursor: pointer;
}

#header-ehr-open {
    width: auto;
    min-width: 1.85rem;
    padding: 0 0.35rem;
    font-size: 0.68rem;
}

#assistant-chat-open:hover,
#assistant-chat-open[aria-expanded="true"],
.chat-header-mark:hover {
    background: #f0f7ff;
    color: var(--assistant-blue, #0369a1);
}

#assistant-chat-panel.assistant-chat {
    position: fixed;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    width: min(440px, calc(100vw - 1rem));
    height: min(640px, calc(100vh - 1rem));
    min-width: 280px;
    min-height: 320px;
    max-width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
    resize: both;
    overflow: hidden;
    background: #fff;
    color: var(--assistant-text);
    border: 1px solid rgba(3, 105, 161, 0.18);
    border-radius: 12px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
}

.assistant-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 10px 8px 10px 16px;
    border-bottom: 1px solid var(--assistant-line);
    background: #fff;
    cursor: move;
    user-select: none;
    flex-shrink: 0;
}

.assistant-chat-title {
    color: var(--assistant-blue);
    font-weight: 600;
    font-size: 15px;
}

.assistant-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.assistant-chat-header-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--assistant-muted);
    cursor: pointer;
}

.assistant-chat-header-actions button:hover {
    background: var(--assistant-hover);
    color: var(--assistant-text);
}

#assistant-chat-maximize .assistant-icon-restore {
    display: none;
}

#assistant-chat-panel.is-maximized {
    resize: none;
}

#assistant-chat-panel.is-maximized #assistant-chat-maximize .assistant-icon-maximize {
    display: none;
}

#assistant-chat-panel.is-maximized #assistant-chat-maximize .assistant-icon-restore {
    display: block;
}

.assistant-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 24px;
    background: var(--assistant-page);
    font-size: 16px;
    line-height: 1.6;
}

.assistant-chat-messages::-webkit-scrollbar {
    width: 8px;
}

.assistant-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.assistant-chat-empty {
    margin: auto;
    max-width: 260px;
    text-align: center;
    color: var(--assistant-muted);
    font-size: 14px;
    line-height: 1.5;
}

.assistant-msg {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.assistant-msg.user {
    flex-direction: row-reverse;
}

.assistant-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #94a3b8;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.assistant-msg.user .assistant-msg-avatar {
    background: var(--assistant-blue);
}

.assistant-msg.thinking .assistant-msg-avatar {
    background: #cbd5e1;
    color: var(--assistant-muted);
}

.assistant-msg-body {
    min-width: 0;
    max-width: calc(100% - 48px);
    padding: 12px 16px;
    border-radius: 18px;
    background: #fff;
    color: var(--assistant-text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.assistant-msg.user .assistant-msg-body {
    background: var(--assistant-blue);
    color: #fff;
}

.assistant-msg-time {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--assistant-muted);
    text-align: right;
}

.assistant-msg.user .assistant-msg-time {
    color: rgba(255, 255, 255, 0.85);
}

.assistant-chat-thinking {
    color: var(--assistant-muted);
    font-size: 0.92rem;
    white-space: pre-wrap;
}

.assistant-msg-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--assistant-line);
}

.assistant-msg.user .assistant-msg-actions {
    border-top-color: rgba(255, 255, 255, 0.3);
}

.assistant-msg-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--assistant-muted);
    cursor: pointer;
}

.assistant-msg-actions button:hover {
    background: var(--assistant-hover);
    color: var(--assistant-text);
}

.assistant-msg.user .assistant-msg-actions button {
    color: rgba(255, 255, 255, 0.85);
}

.assistant-msg.user .assistant-msg-actions button:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

#assistant-chat-panel.is-busy .assistant-msg-actions {
    display: none;
}

.assistant-chat-composer {
    flex-shrink: 0;
    padding: 4px 16px 16px;
    background: var(--assistant-page);
}

.assistant-chat-prompt {
    display: flex;
    flex-direction: column;
    padding: 4px;
    border: 1px solid var(--assistant-line);
    border-radius: 28px;
    background: #fff;
}

.assistant-chat-prompt:focus-within {
    border-color: var(--assistant-blue);
    box-shadow: 0 0 0 3px rgba(3, 105, 161, 0.1);
}

.assistant-chat-prompt.drag-over {
    border: 2px dashed var(--assistant-blue);
    background: var(--assistant-hover);
}

.assistant-chat-files,
.assistant-chat-file-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.assistant-chat-files:not(:empty) {
    padding: 8px 12px 0;
}

.assistant-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.assistant-msg .assistant-files {
    margin-bottom: 8px;
}

.assistant-file-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 200px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid var(--assistant-line);
    border-radius: 8px;
    font-size: 13px;
    color: var(--assistant-text);
}

.assistant-file-thumb,
.assistant-file-icon {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    flex-shrink: 0;
}

.assistant-file-thumb {
    object-fit: cover;
}

.assistant-file-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--assistant-hover);
    color: var(--assistant-muted);
}

.assistant-file-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.assistant-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.assistant-file-size {
    font-size: 11px;
    color: var(--assistant-muted);
}

.assistant-file-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--assistant-muted);
    color: #fff;
    cursor: pointer;
    line-height: 1;
}

.assistant-file-remove:hover {
    background: #ef4444;
}

.assistant-file-preview,
.assistant-md img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
}

.assistant-msg.user .assistant-file-preview {
    border: 1px solid rgba(255, 255, 255, 0.35);
}

.assistant-chat-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#assistant-chat-input {
    flex: 1;
    min-width: 0;
    width: 100%;
    height: 44px;
    resize: none;
    border: none;
    background: transparent;
    padding: 10px 8px 10px 16px;
    font: inherit;
    font-size: 16px;
    line-height: 24px;
    min-height: 44px;
    max-height: 200px;
    overflow: hidden;
    box-sizing: border-box;
    color: var(--assistant-text);
}

#assistant-chat-input:focus {
    outline: none;
}

.assistant-chat-prompt-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px 0 0;
    flex-shrink: 0;
}

.assistant-chat-prompt-buttons button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--assistant-muted);
    cursor: pointer;
}

.assistant-chat-prompt-buttons button:hover {
    background: var(--assistant-hover);
}

#assistant-chat-send,
#assistant-chat-stop {
    background: var(--assistant-hover);
    color: var(--assistant-text);
}

#assistant-chat-send:hover,
#assistant-chat-stop:hover {
    background: #e0e0e0;
}

.assistant-md h1,
.assistant-md h2,
.assistant-md h3,
.assistant-md h4,
.assistant-md h5,
.assistant-md h6 {
    color: var(--assistant-blue);
    line-height: 1.3;
    font-weight: 600;
    margin-top: 2em;
    margin-bottom: 0.8em;
}

.assistant-md h1 { font-size: 1.5em; }
.assistant-md h2 { font-size: 1.4em; }
.assistant-md h3 { font-size: 1.2em; }

.assistant-md h1:first-child,
.assistant-md h2:first-child,
.assistant-md h3:first-child,
.assistant-md p:first-child {
    margin-top: 0;
}

.assistant-md p { margin: 0.8em 0; }
.assistant-md p:last-child { margin-bottom: 0; }

.assistant-md ul,
.assistant-md ol {
    margin: 1em 0;
    padding-left: 28px;
}

.assistant-md li {
    margin-bottom: 0.6em;
    padding-left: 8px;
}

.assistant-md li::marker { color: var(--assistant-blue); }

.assistant-md a {
    color: var(--assistant-blue);
    text-decoration: none;
}

.assistant-md a:hover { text-decoration: underline; }

.assistant-md hr {
    border: none;
    border-top: 2px solid var(--assistant-line);
    margin: 1.5em 0;
    opacity: 0.5;
}

.assistant-md code {
    color: var(--assistant-blue);
    background: var(--assistant-hover);
    border: 1px solid var(--assistant-line);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.9em;
}

.assistant-md pre {
    background: var(--assistant-code);
    color: #e2e8f0;
    border-radius: 10px;
    padding: 0.8rem;
    overflow: auto;
}

.assistant-md pre code {
    color: inherit;
    background: transparent;
    border: none;
    padding: 0;
}

.assistant-md blockquote {
    margin: 1em 0;
    padding: 12px 16px;
    border-left: 4px solid var(--assistant-blue);
    border-radius: 4px;
    background: var(--assistant-blue-bg);
    color: var(--assistant-muted);
}

.assistant-md .markdown-table-wrap {
    overflow-x: auto;
    margin: 1em 0;
    border: 1px solid var(--assistant-line);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(3, 105, 161, 0.08);
}

.assistant-md .table-container {
    margin: 1em 0;
    border: 1px solid var(--assistant-line);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.assistant-md .table-container .markdown-table-wrap {
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.assistant-md .table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: rgba(248, 250, 252, 0.8);
    border-bottom: 1px solid rgba(226, 232, 240, 0.9);
}

.assistant-md .table-label {
    color: #94a3b8;
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 500;
}

.assistant-md .table-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 4px;
}

.assistant-md .view-table-button,
.assistant-md .copy-table-button,
.assistant-md .download-table-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #94a3b8;
    font-size: 0.7em;
    cursor: pointer;
}

.assistant-md .view-table-button:hover,
.assistant-md .copy-table-button:hover,
.assistant-md .download-table-button:hover {
    background: rgba(3, 105, 161, 0.1);
    color: var(--assistant-blue);
}

.assistant-msg .typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 2px 4px;
}

.assistant-msg .typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--assistant-muted);
    animation: assistant-typing 1.4s ease-in-out infinite both;
}

.assistant-msg .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.assistant-msg .typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes assistant-typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

.assistant-thinking {
    margin-bottom: 8px;
    padding: 10px 12px;
    border: 1px solid var(--assistant-line);
    border-radius: 12px;
    background: #f8f9fa;
    cursor: pointer;
    user-select: none;
}

.assistant-thinking-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #94a3b8;
    font-size: 14px;
    font-weight: 500;
}

.assistant-thinking-chevron {
    transition: transform 0.2s ease;
}

.assistant-thinking.is-collapsed .assistant-thinking-chevron {
    transform: rotate(-90deg);
}

.assistant-thinking-body {
    margin-top: 8px;
    max-height: 240px;
    overflow-y: auto;
    color: var(--assistant-muted);
    font-size: 14px;
    font-style: italic;
    white-space: pre-wrap;
    user-select: text;
    cursor: text;
}

.assistant-thinking.is-collapsed .assistant-thinking-body {
    display: none;
}

#assistant-table-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.45);
}

#assistant-table-modal[hidden] {
    display: none !important;
}

.assistant-table-modal-card {
    position: relative;
    width: min(960px, 100%);
    max-height: 90vh;
    overflow: auto;
    padding: 36px 16px 16px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.18);
}

.assistant-table-modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--assistant-muted);
    font-size: 20px;
    cursor: pointer;
}

.assistant-md table {
    border-collapse: collapse;
    width: 100%;
    margin: 0;
    font-size: 0.95em;
}

.assistant-md th,
.assistant-md td {
    border: none;
    padding: 12px 16px;
    text-align: left;
    vertical-align: middle;
}

.assistant-md thead th {
    background: var(--assistant-blue-bg);
    font-weight: 600;
}

.assistant-md tbody tr:nth-of-type(even) td {
    background: var(--assistant-page);
}

.assistant-md tbody tr:hover td {
    background: var(--assistant-hover);
}

.assistant-md .katex { font-size: 1.1em; }
.assistant-md .katex-display { overflow-x: auto; overflow-y: hidden; }

.assistant-transcript-break {
    border: none;
    border-top: 2px solid #94a3b8;
    margin: 0.2rem 0 1.15rem;
}

.assistant-transcript-row {
    margin: 0 0 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--assistant-line);
}

.assistant-transcript-row.is-chat-end {
    margin-bottom: 0;
    padding-bottom: 0.15rem;
    border-bottom: none;
}

.assistant-transcript-row header {
    font-weight: 650;
    color: var(--assistant-blue);
    margin-bottom: 0.35rem;
}

.assistant-transcript-time {
    margin-left: 0.6rem;
    color: var(--assistant-muted);
    font-weight: 400;
    font-size: 0.85rem;
}
