/*
 * Artifact card — downloadable AI-generated assets (PPTX, DOCX, PDF, code).
 * Rendered by Components/Pages/Chat/Parts/ArtifactCard.razor when the
 * assistant message body contains a <<ARTIFACT_CARD>> marker pair. The
 * download button is bound by wwwroot/js/document/documentInterops.js
 * via MutationObserver — keep the .ai-artifact-container class name in sync.
 */

.ai-artifact-container {
    margin-top: 0.75rem;
    margin-bottom: 0.5rem;
}

.ai-artifact-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--rz-base-300, #e0e0e0);
    border-radius: 10px;
    background: var(--rz-base-50, #ffffff);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.ai-artifact-card:hover {
    border-color: var(--rz-primary, #1976d2);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
}

.ai-artifact-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border-radius: 8px;
    background: var(--rz-primary-lighter, #e3f2fd);
    color: var(--rz-primary, #1976d2);
}

.ai-artifact-icon.rzi {
    font-size: 22px;
}

.ai-artifact-info {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-artifact-title {
    font-weight: 600;
    color: var(--rz-text-color, #212121);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-artifact-meta {
    font-size: 0.8125rem;
    color: var(--rz-text-tertiary-color, #6b6b6b);
    text-transform: lowercase;
}

.ai-artifact-download,
.ai-artifact-preview-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--rz-primary, #1976d2);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.ai-artifact-download:hover:not(:disabled),
.ai-artifact-preview-btn:hover:not(:disabled) {
    background: var(--rz-primary-lighter, #e3f2fd);
    border-color: var(--rz-primary, #1976d2);
}

.ai-artifact-download:disabled,
.ai-artifact-preview-btn:disabled {
    opacity: 0.55;
    cursor: progress;
}

.ai-artifact-download .rzi,
.ai-artifact-preview-btn .rzi {
    font-size: 20px;
}

/* Dark mode — Radzen toggles `rz-dark` on :root. We mirror its tokens
   with a slightly cooler palette so the card never washes into the
   message bubble. */
:root.rz-dark .ai-artifact-card {
    background: var(--rz-base-800, #2a2d31);
    border-color: var(--rz-base-700, #3a3d41);
}

:root.rz-dark .ai-artifact-card:hover {
    border-color: var(--rz-primary-light, #82b1ff);
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
}

:root.rz-dark .ai-artifact-icon {
    background: rgba(130, 177, 255, 0.18);
    color: var(--rz-primary-light, #82b1ff);
}

:root.rz-dark .ai-artifact-title {
    color: var(--rz-text-color, #e6e6e6);
}

:root.rz-dark .ai-artifact-meta {
    color: var(--rz-text-tertiary-color, #a8a8a8);
}

:root.rz-dark .ai-artifact-download,
:root.rz-dark .ai-artifact-preview-btn {
    color: var(--rz-primary-light, #82b1ff);
}

:root.rz-dark .ai-artifact-download:hover:not(:disabled),
:root.rz-dark .ai-artifact-preview-btn:hover:not(:disabled) {
    background: rgba(130, 177, 255, 0.18);
    border-color: var(--rz-primary-light, #82b1ff);
}

@media (max-width: 600px) {
    .ai-artifact-title {
        font-size: 0.9375rem;
    }
    .ai-artifact-meta {
        font-size: 0.75rem;
    }
}

/* ──────────────────────────────────────────────────────────────────────
 * Split fullscreen layout — when ChatUIState.HasArtifactPreview is true
 * the Razor side adds .with-artifact-preview to .fullscreen-chat-container
 * and we expose a third grid column for the preview pane. The base layout
 * already lays out (sidebar | main); this rule extends it to a third track.
 * Transitions are purely CSS so the user gets smooth slide-in / slide-out
 * + fullscreen toggle without any animation logic in C#.
 * ────────────────────────────────────────────────────────────────────── */
.fullscreen-chat-container.with-artifact-preview {
    grid-template-columns: var(--conversations-sidebar-width, 260px) minmax(0, 1fr) minmax(360px, 0.85fr);
    transition: grid-template-columns 220ms ease;
}

/* Fullscreen artifact mode — collapses the chat column so the preview owns
 * the entire main area. The conversations sidebar remains visible so the
 * user can still navigate sessions. The chat column is kept in the grid
 * (zero width) instead of display:none so the existing focus/scroll state
 * is preserved when the user exits fullscreen. */
.fullscreen-chat-container.with-artifact-preview-full {
    grid-template-columns: var(--conversations-sidebar-width, 260px) 0fr minmax(0, 1fr);
}

.fullscreen-chat-container.with-artifact-preview-full .fullscreen-chat-main {
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
}

@media (max-width: 1100px) {
    .fullscreen-chat-container.with-artifact-preview {
        /* Stack the preview pane below the main chat on narrow viewports
           rather than squeezing both into a half-screen each. The user can
           dismiss it from the toolbar without losing chat scroll. */
        grid-template-columns: var(--conversations-sidebar-width, 260px) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
    }
    .fullscreen-chat-container.with-artifact-preview .artifact-preview-pane {
        grid-column: 1 / -1;
        max-height: 50vh;
    }
    /* On narrow viewports fullscreen forces the preview to take the
       remaining height (sidebar still visible). Stacked rows are kept so
       the header / row sizing logic above stays consistent. */
    .fullscreen-chat-container.with-artifact-preview-full {
        grid-template-columns: var(--conversations-sidebar-width, 260px) minmax(0, 1fr);
        grid-template-rows: 0fr minmax(0, 1fr);
    }
    .fullscreen-chat-container.with-artifact-preview-full .artifact-preview-pane {
        max-height: none;
    }
}

/* When the preview is fullscreen we drop the left border (no chat column to
   separate from) and slightly increase header padding so the chrome scales
   with the larger surface. */
.artifact-preview-pane.is-fullscreen {
    border-left: 0;
}

.artifact-preview-pane.is-fullscreen .artifact-preview-pane__header {
    padding: 0.65rem 1rem;
}

/* ──────────────────────────────────────────────────────────────────────
 * Artifact preview pane — rendered by Components/Pages/Chat/Parts/ArtifactPreview.razor
 * ────────────────────────────────────────────────────────────────────── */
.artifact-preview-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-left: 1px solid var(--rz-base-300, #e0e0e0);
    background: var(--rz-base-50, #ffffff);
}

.artifact-preview-pane__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--rz-base-300, #e0e0e0);
}

.artifact-preview-pane__icon {
    color: var(--rz-primary, #1976d2);
    font-size: 22px;
}

.artifact-preview-pane__title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.artifact-preview-pane__type-badge {
    flex: 0 0 auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--rz-primary-lighter, #e3f2fd);
    color: var(--rz-primary, #1976d2);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.artifact-preview-pane__actions {
    display: flex;
    gap: 0.25rem;
}

.artifact-preview-pane__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--rz-text-tertiary-color, #6b6b6b);
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    transition: background 120ms ease, color 120ms ease;
}

.artifact-preview-pane__action:hover {
    background: var(--rz-base-100, #f4f4f5);
    color: var(--rz-text-color, #212121);
}

.artifact-preview-pane__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 0.75rem;
}

.artifact-preview-pane__iframe {
    width: 100%;
    height: 100%;
    min-height: 480px;
    border: 0;
    border-radius: 8px;
    background: #f8f8f8;
}

.artifact-preview-pane__placeholder {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    text-align: center;
    color: var(--rz-text-tertiary-color, #6b6b6b);
}

.artifact-preview-pane__cta {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    background: var(--rz-primary, #1976d2);
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
}

.artifact-preview-pane__cta:hover {
    filter: brightness(1.05);
}

.artifact-preview-pane__pptx-host {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* XLSX SheetJS preview — the JS side paints a tab bar + scrollable tables
   inside this host. The host itself is a plain flex column so each sheet
   stretches to the available height. */
.artifact-preview-pane__xlsx-host {
    display: flex;
    flex-direction: column;
    min-height: 320px;
    gap: 0.5rem;
    height: 100%;
}

.artifact-preview-pane__xlsx-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    color: var(--rz-text-tertiary-color, #6b6b6b);
}

.rzi-spin {
    animation: artifact-spin 1.1s linear infinite;
    display: inline-block;
}

@keyframes artifact-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.artifact-xlsx-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: #217346;
    color: #fff;
    border-radius: 8px 8px 0 0;
    font-weight: 600;
    font-size: 0.8125rem;
}

.artifact-xlsx-tabs {
    display: flex;
    gap: 0;
    padding: 0 0.5rem;
    background: var(--rz-base-100, #f3f3f3);
    border-bottom: 1px solid var(--rz-base-300, #d4d4d4);
    overflow-x: auto;
    flex-shrink: 0;
}

.artifact-xlsx-tab {
    padding: 0.4rem 0.85rem;
    border: 0;
    background: transparent;
    color: var(--rz-text-secondary-color, #555);
    font-size: 0.8125rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.artifact-xlsx-tab:hover {
    background: var(--rz-base-200, #e8e8e8);
    color: var(--rz-text-color, #212121);
}

.artifact-xlsx-tab.is-active {
    color: #217346;
    background: var(--rz-base-50, #fff);
    border-bottom-color: #217346;
    font-weight: 600;
}

.artifact-xlsx-grid {
    flex: 1 1 auto;
    overflow: auto;
    background: #fff;
    border-radius: 0 0 8px 8px;
    border: 1px solid var(--rz-base-200, #e0e0e0);
    border-top: 0;
}

.artifact-xlsx-sheet {
    display: none;
}

.artifact-xlsx-sheet.is-active {
    display: block;
}

.artifact-xlsx-sheet table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    color: #1e1e1e;
}

.artifact-xlsx-sheet th {
    background: #e2efda;
    color: #1e1e1e;
    padding: 0.4rem 0.65rem;
    text-align: left;
    font-weight: 600;
    border: 1px solid #c6e0b4;
    position: sticky;
    top: 0;
    z-index: 1;
}

.artifact-xlsx-sheet td {
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--rz-base-200, #e0e0e0);
    vertical-align: top;
    white-space: nowrap;
}

.artifact-xlsx-sheet tr:hover td {
    background: var(--rz-base-100, #f5f5f5);
}

.artifact-xlsx-sheet td.is-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.artifact-xlsx-sheet td.is-neg {
    color: #c0392b;
}

.artifact-xlsx-error {
    padding: 1rem;
    border-radius: 8px;
    background: #fff4f4;
    color: #b3261e;
    font-size: 0.875rem;
}

:root.rz-dark .artifact-xlsx-tabs {
    background: var(--rz-base-800, #2a2d31);
    border-bottom-color: var(--rz-base-700, #3a3d41);
}

:root.rz-dark .artifact-xlsx-tab {
    color: var(--rz-text-secondary-color, #b8b8b8);
}

:root.rz-dark .artifact-xlsx-tab:hover {
    background: var(--rz-base-700, #3a3d41);
}

:root.rz-dark .artifact-xlsx-tab.is-active {
    background: var(--rz-base-900, #1f2125);
    color: #4ade80;
    border-bottom-color: #4ade80;
}

:root.rz-dark .artifact-xlsx-grid {
    background: var(--rz-base-900, #1f2125);
    border-color: var(--rz-base-700, #3a3d41);
}

:root.rz-dark .artifact-xlsx-sheet table {
    color: var(--rz-text-color, #e6e6e6);
}

:root.rz-dark .artifact-xlsx-sheet th {
    background: rgba(34, 197, 94, 0.18);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.35);
}

:root.rz-dark .artifact-xlsx-sheet td {
    border-color: var(--rz-base-700, #3a3d41);
}

:root.rz-dark .artifact-xlsx-sheet tr:hover td {
    background: var(--rz-base-800, #2a2d31);
}

/* PPTX preview slides — painted by aiDocument.renderPptxPreviewInto. The
   16:9 aspect ratio + content padding mirror the PPTX renderer at runtime
   so the user sees the same general layout before downloading. */
.artifact-pptx-preview__slide {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 1px solid var(--rz-base-300, #e0e0e0);
    border-radius: 8px;
    padding: 18px 24px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.artifact-pptx-preview__slide--title {
    display: flex;
    align-items: center;
    justify-content: center;
}

.artifact-pptx-preview__slide-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.3;
}

.artifact-pptx-preview__slide-heading {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
}

.artifact-pptx-preview__slide-content {
    font-size: 0.875rem;
    line-height: 1.4;
    margin-bottom: 0.4rem;
    white-space: pre-wrap;
}

.artifact-pptx-preview__bullets {
    margin: 0;
    padding-left: 1rem;
    font-size: 0.85rem;
    line-height: 1.4;
}

.artifact-pptx-preview__bullets li {
    margin-bottom: 0.25rem;
}

.artifact-pptx-preview__bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.artifact-pptx-preview__num {
    position: absolute;
    bottom: 6px;
    right: 10px;
    font-size: 0.7rem;
    color: var(--rz-text-tertiary-color, #9e9e9e);
}

.artifact-pptx-preview__error {
    padding: 0.75rem;
    border-radius: 8px;
    background: #fff4f4;
    color: #b3261e;
    font-size: 0.875rem;
}

:root.rz-dark .artifact-preview-pane {
    background: var(--rz-base-900, #1f2125);
    border-left-color: var(--rz-base-700, #3a3d41);
}

:root.rz-dark .artifact-preview-pane__header {
    border-bottom-color: var(--rz-base-700, #3a3d41);
}

:root.rz-dark .artifact-preview-pane__action:hover {
    background: var(--rz-base-800, #2a2d31);
    color: var(--rz-text-color, #e6e6e6);
}

/* Artifact type icon colour variants — each type gets a tinted background
   for the icon box so the card communicates the format at a glance. */
.ai-artifact-icon-xlsx {
    background: rgba(16, 185, 129, 0.12) !important;
    color: #10b981 !important;
}
.ai-artifact-icon-dashboard {
    background: rgba(99, 102, 241, 0.12) !important;
    color: #6366f1 !important;
}

:root.rz-dark .ai-artifact-icon-xlsx {
    background: rgba(16, 185, 129, 0.18) !important;
    color: #34d399 !important;
}
:root.rz-dark .ai-artifact-icon-dashboard {
    background: rgba(99, 102, 241, 0.18) !important;
    color: #818cf8 !important;
}

:root.rz-dark .artifact-pptx-preview__slide {
    border-color: var(--rz-base-700, #3a3d41);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
