/* ═══════════════════════════════════════════════════════════════
   PACS Viewer — Teaching Panel (Case Discussion + AI Tutor)
   ═══════════════════════════════════════════════════════════════ */

.piv-teaching-panel {
    background: #0a0a14;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #c8c8d4;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    min-height: 0;
}

/* Inside a playlist, remove extra margin */
.piv-playlist-slot .piv-teaching-panel {
    margin-bottom: 0;
    border-radius: 0;
    border: none;
    border-left: 1px solid #2a2a3e;
}

/* ── Teaching Tabs Bar ───────────────────────────────────────── */
.piv-teaching-tabs {
    display: flex;
    align-items: center;
    background: #12122a;
    border-bottom: 1px solid #2a2a3e;
    padding: 0;
    flex-shrink: 0;
    height: 40px;
    box-sizing: border-box;
}

.piv-teaching-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: transparent;
    border: none;
    color: #8a8ca8;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
    box-shadow: inset 0 -2px 0 transparent;
}

.piv-teaching-tab:hover {
    background: rgba(45, 90, 158, 0.15);
    color: #c8c8d4;
}

.piv-teaching-tab.active {
    color: #e0e0ec;
    box-shadow: inset 0 -2px 0 #4a8adf;
    background: rgba(45, 90, 158, 0.2);
}

.piv-teaching-tab svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.piv-teaching-tab.active svg {
    opacity: 1;
}

.piv-teaching-toggle {
    margin-left: auto;
    padding: 8px 14px;
    background: transparent;
    border: none;
    color: #5a5c78;
    font-size: 12px;
    cursor: pointer;
    transition: color 0.15s;
    white-space: nowrap;
}

.piv-teaching-toggle:hover {
    color: #9ea0b8;
}

/* ── Teaching Content Area ───────────────────────────────────── */
.piv-teaching-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: max-height 0.35s ease;
}

.piv-teaching-content.collapsed {
    max-height: 0 !important;
    flex: 0 !important;
}

.piv-tab-pane {
    display: none;
}

.piv-tab-pane.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* ── Case Discussion ─────────────────────────────────────────── */
.piv-case-discussion-content {
    padding: 20px 24px;
    max-height: 500px;
    overflow-y: auto;
    line-height: 1.7;
    font-size: 14px;
    color: #c8c8d4;
}

/* Scrollbar styling */
.piv-case-discussion-content::-webkit-scrollbar {
    width: 6px;
}
.piv-case-discussion-content::-webkit-scrollbar-track {
    background: #0a0a14;
}
.piv-case-discussion-content::-webkit-scrollbar-thumb {
    background: #3a3a52;
    border-radius: 3px;
}

/* Prose styles for dark theme */
.piv-case-discussion-content h1,
.piv-case-discussion-content h2,
.piv-case-discussion-content h3,
.piv-case-discussion-content h4 {
    color: #e0e0ec;
    margin-top: 1.2em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

.piv-case-discussion-content h2 { font-size: 18px; }
.piv-case-discussion-content h3 { font-size: 16px; }
.piv-case-discussion-content h4 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; color: #9ea0b8; }

.piv-case-discussion-content p {
    margin-bottom: 0.8em;
}

.piv-case-discussion-content ul,
.piv-case-discussion-content ol {
    padding-left: 24px;
    margin-bottom: 0.8em;
}

.piv-case-discussion-content li {
    margin-bottom: 0.3em;
}

.piv-case-discussion-content strong {
    color: #e0e0ec;
}

.piv-case-discussion-content em {
    color: #a8b0d0;
}

.piv-case-discussion-content a {
    color: #4a8adf;
    text-decoration: none;
}
.piv-case-discussion-content a:hover {
    text-decoration: underline;
}

.piv-case-discussion-content img {
    max-width: 100%;
    border-radius: 4px;
    margin: 8px 0;
}

.piv-case-discussion-content blockquote {
    border-left: 3px solid #4a8adf;
    padding-left: 16px;
    margin: 12px 0;
    color: #a8b0d0;
    font-style: italic;
}

.piv-case-discussion-content code {
    background: #1e1e36;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
    color: #e0e0ec;
}

/* Empty state */
.piv-case-empty {
    text-align: center;
    padding: 40px 20px;
    color: #5a5c78;
    font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════
   AI Tutor Chat
   ═══════════════════════════════════════════════════════════════ */

.piv-chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
}

/* ── Messages Area ───────────────────────────────────────────── */
.piv-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.piv-chat-messages::-webkit-scrollbar {
    width: 6px;
}
.piv-chat-messages::-webkit-scrollbar-track {
    background: #0a0a14;
}
.piv-chat-messages::-webkit-scrollbar-thumb {
    background: #3a3a52;
    border-radius: 3px;
}

/* Welcome message */
.piv-chat-welcome {
    text-align: center;
    padding: 30px 20px;
    color: #5a5c78;
}

.piv-chat-welcome-icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.piv-chat-welcome p {
    font-size: 13px;
    line-height: 1.6;
    max-width: 400px;
    margin: 0 auto;
}

/* ── Message Bubbles ─────────────────────────────────────────── */
.piv-chat-msg {
    display: flex;
    max-width: 85%;
    animation: pivFadeIn 0.2s ease;
}

@keyframes pivFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.piv-chat-msg.piv-chat-user {
    align-self: flex-end;
}

.piv-chat-msg.piv-chat-assistant {
    align-self: flex-start;
}

.piv-chat-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.6;
    word-wrap: break-word;
}

.piv-chat-user .piv-chat-bubble {
    background: #2d5a9e;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.piv-chat-assistant .piv-chat-bubble {
    background: #1e1e36;
    color: #c8c8d4;
    border-bottom-left-radius: 4px;
    border: 1px solid #2a2a3e;
}

/* Markdown-like formatting inside assistant bubbles */
.piv-chat-assistant .piv-chat-bubble strong {
    color: #e0e0ec;
}

.piv-chat-assistant .piv-chat-bubble code {
    background: #0a0a14;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

.piv-chat-assistant .piv-chat-bubble ul,
.piv-chat-assistant .piv-chat-bubble ol {
    padding-left: 18px;
    margin: 6px 0;
}

.piv-chat-assistant .piv-chat-bubble p {
    margin: 0 0 6px 0;
}

.piv-chat-assistant .piv-chat-bubble p:last-child {
    margin-bottom: 0;
}

/* ── Typing Indicator ────────────────────────────────────────── */
.piv-typing-dots {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}

.piv-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4a8adf;
    animation: pivDotBounce 1.4s ease-in-out infinite;
}

.piv-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.piv-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pivDotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Chat Input ──────────────────────────────────────────────── */
.piv-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: #12122a;
    border-top: 1px solid #2a2a3e;
}

.piv-chat-input {
    flex: 1;
    background: #1e1e36;
    border: 1px solid #3a3a52;
    color: #e0e0ec;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13.5px;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.15s;
}

.piv-chat-input::placeholder {
    color: #5a5c78;
}

.piv-chat-input:focus {
    border-color: #4a8adf;
}

.piv-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #2d5a9e;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.piv-chat-send:hover:not(:disabled) {
    background: #4a8adf;
    transform: scale(1.05);
}

.piv-chat-send:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ── Chat Error ──────────────────────────────────────────────── */
.piv-chat-error {
    text-align: center;
    padding: 8px 14px;
    color: #ff6b6b;
    font-size: 12px;
    background: rgba(255, 107, 107, 0.1);
    border-radius: 6px;
    margin: 4px 0;
}

/* ── AI Disabled State ───────────────────────────────────────── */
.piv-ai-disabled {
    text-align: center;
    padding: 40px 20px;
    color: #5a5c78;
    font-size: 14px;
}

/* ── Responsive — bottom sheet on mobile ──────────────────────── */
@media (max-width: 900px) {
    .piv-viewer-wrap {
        flex-direction: column !important;
        gap: 0 !important;
    }
    .piv-viewer-wrap > .piv-teaching-panel {
        flex: 0 0 auto !important;
        width: 100% !important;
        max-width: none !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 10000;
        border-radius: 16px 16px 0 0;
        border: none;
        border-top: 1px solid #2a2a3e;
        transform: translateY(calc(100% - 48px));
        transition: transform 0.3s ease;
        max-height: 60vh;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.6);
    }
    .piv-viewer-wrap > .piv-teaching-panel.piv-sheet-open {
        transform: translateY(0);
    }
    /* Drag handle pill */
    .piv-viewer-wrap > .piv-teaching-panel::before {
        content: "";
        display: block;
        width: 36px;
        height: 4px;
        background: #3a3a52;
        border-radius: 2px;
        margin: 8px auto 0;
        flex-shrink: 0;
    }
    /* Hide the toggle button on mobile (sheet replaces it) */
    .piv-teaching-toggle {
        display: none;
    }
    /* Keep content scrollable in sheet */
    .piv-teaching-content {
        overflow-y: auto;
        max-height: none !important;
    }
    .piv-case-discussion-content {
        max-height: none;
    }
}

/* Neutralize bottom sheet in fullscreen */
.piv-fullscreen .piv-teaching-panel {
    position: static !important;
    transform: none !important;
    border-radius: 0 !important;
    max-height: none !important;
    box-shadow: none !important;
}
.piv-fullscreen .piv-teaching-panel::before {
    display: none !important;
}

@media (max-width: 600px) {
    .piv-teaching-tab {
        padding: 8px 12px;
        font-size: 12px;
    }
    .piv-case-discussion-content {
        padding: 14px 16px;
        font-size: 13px;
    }
    .piv-chat-bubble {
        font-size: 13px;
    }
    .piv-chat-msg {
        max-width: 92%;
    }
}

/* ── Touch-device tap targets ────────────────────────────────── */
@media (pointer: coarse) {
    .piv-teaching-tab {
        min-height: 44px;
        padding: 10px 16px;
    }
    .piv-chat-send {
        width: 44px;
        height: 44px;
    }
    .piv-chat-input {
        min-height: 44px;
        font-size: 16px; /* prevents iOS auto-zoom on focus */
    }
}
