/* Minimal layout for iframe embedding */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: var(--bg-gradient);
    background-attachment: fixed;
}

.tutor-container {
    max-width: 35rem;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.tutor-header {
    text-align: center;
    margin-bottom: 2rem;
}

.tutor-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.tutor-tagline {
    color: var(--text-secondary);
    font-size: 1rem;
    margin: 0;
}

.recent-sessions {
    margin-top: auto;
    padding-top: 1rem;
}

.recent-sessions h6 {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tutor-footer {
    text-align: center;
    padding-top: 1.5rem;
    margin-top: auto;
    color: var(--text-secondary);
}

.tutor-footer a {
    color: var(--tiber-primary);
    text-decoration: none;
}

.tutor-footer a:hover {
    text-decoration: underline;
}

/* ============================
   Page Layout with History Sidebar
   ============================ */

.vt-page-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.vt-page-layout > .vt-container {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    scrollbar-width: thin;
}

/* ============================
   Session History Panel
   ============================ */

.session-history-panel {
    width: 320px;
    min-width: 320px;
    background: var(--card-bg);
    border-left: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow: hidden;
    z-index: 1100;
}

.session-history-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.session-history-header h6 {
    margin: 0;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.session-history-header h6 i {
    color: var(--tiber-primary);
}

.session-history-collapse {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.1rem;
    line-height: 1;
    border-radius: 4px;
    transition: color 0.2s ease, background 0.2s ease;
}

.session-history-collapse:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* Desktop collapsed state */
.session-history-panel.collapsed {
    width: 0;
    min-width: 0;
    border-left: none;
    overflow: hidden;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.session-history-panel:not(.collapsed) {
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.session-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.session-history-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--card-border);
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.session-history-item:last-child {
    border-bottom: none;
}

.session-history-item:hover {
    background: rgba(0, 173, 188, 0.04);
}

.session-history-item.active {
    background: rgba(0, 173, 188, 0.1);
    border-left: 3px solid var(--tiber-primary);
}

.session-detail-chevron {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    color: var(--tiber-primary);
    cursor: pointer;
    font-size: 0.7rem;
    transition: all 0.2s ease;
}

.session-detail-chevron:hover {
    background: var(--tiber-primary);
    color: var(--tiber-white);
    border-color: var(--tiber-primary);
}

.session-history-item-content {
    flex: 1;
    min-width: 0;
}

.session-history-item-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.3rem;
}

.session-history-item-date i {
    font-size: 0.7rem;
}

.session-history-item-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.session-history-item-summary {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-top: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Scrollbar for history list */
.session-history-list::-webkit-scrollbar {
    width: 5px;
}

.session-history-list::-webkit-scrollbar-track {
    background: transparent;
}

.session-history-list::-webkit-scrollbar-thumb {
    background: var(--tiber-primary);
    border-radius: 3px;
}

/* Toggle tab for reopening collapsed/mobile history */
.history-toggle-btn {
    display: none;
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1050;
    writing-mode: vertical-rl;
    padding: 0.75rem 0.4rem;
    background: var(--tiber-primary);
    color: var(--tiber-white);
    border: 1px solid var(--tiber-primary-dark);
    border-radius: 8px 0 0 8px;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: lowercase;
    cursor: pointer;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.15);
    transition: background 0.2s ease, padding 0.2s ease;
    font-variant: small-caps;
}

/* Show on desktop when panel is collapsed */
.history-toggle-btn.visible {
    display: flex;
}

.history-toggle-btn:hover {
    background: var(--tiber-primary-dark);
    padding-left: 0.55rem;
}

/* Backdrop for mobile flyout */
.session-history-backdrop {
    display: none;
}

/* ============================
   Session Detail Flyout Pane
   ============================ */

.session-detail-pane {
    position: fixed;
    /* Push down by the system banner height (set as a CSS var by Select.cshtml) */
    top: calc(3px + var(--system-banner-height, 0px));
    right: 0; /* sits to the left of the history sidebar */
    bottom: 3px;
    width: calc(100% - 350px);
    background: var(--card-bg);
    transform: translateX(100%);
    z-index: 1050; /* below the history panel */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    opacity: 0;
}

.session-detail-pane.open {
    transform: translateX(-320px);
    opacity: 1;
}

/* When the history sidebar is collapsed, the detail pane slides right by
   320px to occupy the space the panel just freed. */
.session-detail-pane.open.history-collapsed {
    transform: translateX(0);
}

.session-detail-backdrop {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 320px;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1049;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.session-detail-backdrop.history-collapsed {
    right: 0;
}

.session-detail-backdrop.visible {
    opacity: 1;
    pointer-events: all;
}

.session-detail-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.session-detail-header h6 {
    margin: 0;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.session-detail-back {
    background: none;
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    font-size: 1rem;
    line-height: 1;
    border-radius: 6px;
    transition: color 0.2s ease, background 0.2s ease;
}

.session-detail-back:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.session-detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.session-detail-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem;
    font-size: 0.9rem;
}

.session-detail-meta {
    margin-bottom: 1.5rem;
}

.session-detail-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.35rem;
}

.session-detail-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.session-detail-summary-section {
    margin-bottom: 1.5rem;
}

.session-detail-summary-section h6 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.session-detail-full-summary {
    font-size: 0.95rem;
    color: var(--text-primary);
    line-height: 1.6;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    border: 1px solid var(--card-border);
}

.session-detail-full-summary p:last-child,
.session-message-text p:last-child {
    margin-bottom: 0;
}

.session-detail-full-summary ul,
.session-detail-full-summary ol,
.session-message-text ul,
.session-message-text ol {
    padding-left: 1.25rem;
    margin-bottom: 0.5rem;
}

.session-detail-full-summary code,
.session-message-text code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
}

.session-detail-full-summary strong,
.session-message-text strong {
    font-weight: 600;
}

/* Inline generated-image thumbnails on assistant messages in the session
   history panel. Click opens the full image in a new tab via the absolute
   URL the proxy attached server-side. */
.session-message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.session-message-image-thumb {
    display: inline-block;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    line-height: 0;
}

.session-message-image-thumb:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

.session-message-image-thumb img {
    display: block;
    width: 100px;
    height: 100px;
    object-fit: cover;
    background: #f7f7f7;
}

.session-detail-divider {
    border: none;
    border-top: 2px solid var(--card-border);
    margin: 1.25rem 0;
}

/* Revisit Topic */
.revisit-topic-section {
    margin-bottom: 0.25rem;
}

.revisit-topic-heading {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.revisit-topic-heading i {
    color: var(--tiber-primary);
}

.revisit-topic-buttons {
    display: flex;
    gap: 0.5rem;
}

.revisit-topic-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 0.75rem;
    border: 1.5px solid var(--card-border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.revisit-topic-btn:hover {
    border-color: var(--tiber-primary);
    background: linear-gradient(135deg, #00999A 0%, #024748 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 153, 154, 0.25);
}

.revisit-topic-btn i {
    font-size: 0.85rem;
}

.revisit-topic-btn--disabled {
    opacity: 0.45;
    pointer-events: none;
    cursor: not-allowed;
    border-color: var(--card-border);
    background: var(--card-bg);
    box-shadow: none;
}

.session-detail-collapsible {
    margin-bottom: 0.5rem;
}

.session-detail-collapse-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    background: none;
    border: none;
    padding: 0.5rem 0;
    cursor: pointer;
    color: var(--text-primary);
    transition: color 0.2s ease;
}

.session-detail-collapse-toggle:hover {
    color: var(--tiber-primary);
}

.session-detail-collapse-toggle i {
    font-size: 0.7rem;
    width: 1rem;
    text-align: center;
    color: var(--tiber-primary);
    transition: transform 0.2s ease;
}

.session-detail-collapse-toggle h6 {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: inherit;
}

.session-detail-collapse-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}

.session-detail-collapse-body.open {
    max-height: 5000px;
    opacity: 1;
}

.session-detail-messages-section {
    padding-top: 0.5rem;
}

.session-detail-messages {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.session-detail-no-messages {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 1.5rem;
    font-style: italic;
}

.session-message {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    max-width: 85%;
}

.session-message--student {
    background: rgba(0, 173, 188, 0.08);
    border: 1px solid rgba(0, 173, 188, 0.15);
    align-self: flex-end;
    margin-left: auto;
}

.session-message--tutor {
    background: var(--bg-secondary);
    border: 1px solid var(--card-border);
    align-self: flex-start;
}

.session-message-role {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
}

.session-message--tutor .session-message-role {
    color: var(--tiber-primary);
}

.session-message-time {
    font-weight: 400;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-left: 0.35rem;
}

.session-message-text {
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.5;
}

/* ============================
   Dark Mode - Session History
   ============================ */

[data-theme="dark"] .session-history-item {
    border-bottom-color: var(--card-border);
}

[data-theme="dark"] .session-history-item:hover {
    background: rgba(0, 173, 188, 0.08);
}

[data-theme="dark"] .session-history-item.active {
    background: rgba(0, 173, 188, 0.15);
}

[data-theme="dark"] .session-detail-pane {
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .session-message--student {
    background: rgba(0, 173, 188, 0.12);
    border-color: rgba(0, 173, 188, 0.2);
}

/* ============================
   Responsive - Session History
   ============================ */

/* Flyout overlay at 1024px and below */
@media (max-width: 1024px) {
    .vt-page-layout {
        display: block;
        height: auto;
        overflow: visible;
    }

    .history-toggle-btn {
        display: flex;
    }

    .session-history-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 85%;
        min-width: 0;
        max-width: 360px;
        z-index: 1060;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
        border-left: none;
    }

    .session-history-panel.open {
        transform: translateX(0);
    }

    .session-history-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1055;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .session-history-backdrop.visible {
        opacity: 1;
        pointer-events: all;
    }

    /* Detail pane: full screen on mobile (still respects the system banner) */
    .session-detail-pane {
        top: var(--system-banner-height, 0px);
        right: 0;
        bottom: 0;
        width: 100%;
        z-index: 1080;
    }

    .session-detail-pane.open {
        transform: translateX(0);
    }

    /* On mobile, when the history panel slides off-screen, the detail pane
       slides off with it (preserving its open state internally). */
    .session-detail-pane.open.history-collapsed {
        transform: translateX(100%);
    }

    .session-detail-backdrop {
        right: 0;
        z-index: 1075;
    }
}
