/* Palette AI - Artifacts Pane Styles */

/* ============================================================================
   ARTIFACT PANE BASE
   ============================================================================ */

.artifact-pane {
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    max-width: none;
}

.artifact-pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px; /* Match chat header */
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
    height: 50px; /* Match chat header - was 55px */
}

.artifact-pane-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.artifact-count-badge {
    background: var(--accent-primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.artifact-pane-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all var(--transition-fast) var(--easing);
}

.artifact-pane-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.artifact-pane-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative; /* Added - allows absolute positioning of children */
    /* PHASE 9: Must allow overflow for children to size correctly */
}

/* ============================================================================
   LIST VIEW
   ============================================================================ */

   .artifact-list-view {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex: 1; /* PHASE 9: Take available space */
    min-height: 0;
}

.artifact-section {
    border-bottom: 1px solid var(--border-primary);
}

.artifact-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast) var(--easing);
    /* PHASE 9: Sticky section headers in list view */
    position: sticky;
    top: 0;
    z-index: 5;
}

.artifact-section-header:hover {
    background: var(--bg-hover);
}

.artifact-section-header h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.artifact-section-count {
    font-size: 10px;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 8px;
}

.artifact-section-toggle {
    color: var(--text-tertiary);
    font-size: 12px;
    transition: transform var(--transition-fast) var(--easing);
}

.artifact-section.collapsed .artifact-section-toggle {
    transform: rotate(-90deg);
}

.artifact-section-content {
    display: flex;
    flex-direction: column;
}

.artifact-section.collapsed .artifact-section-content {
    display: none;
}

/* ============================================================================
   ARTIFACT ITEMS
   ============================================================================ */

.artifact-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background var(--transition-fast) var(--easing);
    border-bottom: 1px solid var(--border-primary);
}

.artifact-item:hover {
    background: var(--bg-hover);
}

.artifact-item:active {
    background: var(--bg-tertiary);
}

.artifact-item-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.artifact-item-info {
    flex: 1;
    min-width: 0;
}

.artifact-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}

.artifact-item-meta {
    font-size: 11px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.artifact-item-language {
    background: var(--bg-tertiary);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 10px;
}

.artifact-pin-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition-fast) var(--easing);
    flex-shrink: 0;
    opacity: 0;
}

.artifact-item:hover .artifact-pin-btn {
    opacity: 1;
}

.artifact-pin-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.artifact-pin-btn.pinned {
    opacity: 1;
    color: var(--warning);
}

/* ============================================================================
   DETAIL VIEW - working
   ============================================================================ */

.artifact-detail-view {
    display: flex;
    flex-direction: column;
    flex: 1; /* PHASE 9: Take all available space */
    min-height: 0; /* CRITICAL: Allow flexbox shrinking */
}

.artifact-detail-view.hidden {
    display: none;
}

.artifact-detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
    height: 48px;
    min-height: 48px;
    max-height: 48px;
    flex-shrink: 0; /* PHASE 9: Fixed header - don't shrink */
}

.artifact-back-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all var(--transition-fast) var(--easing);
}

.artifact-back-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.artifact-detail-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.artifact-detail-metadata {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    flex-shrink: 0; /* PHASE 9: Fixed metadata - don't shrink */
}

.artifact-meta-badge {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.artifact-detail-content {
    flex: 1 1 auto; /* PHASE 9: Grow, shrink, auto basis */
    overflow-y: auto; /* This is the ONLY scrollable area */
    overflow-x: hidden;
    padding: 16px;
    background: var(--bg-primary);
    width: 100%;
    box-sizing: border-box;
    min-height: 0; /* CRITICAL - allows flex child to shrink */
    max-height: 100%; /* Prevent it from exceeding container */
}

.artifact-code-display {
    background: #1e1e1e;
    border: none;
    border-radius: 0;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.artifact-code-display pre {
    margin: 0;
    padding: 0;
    overflow-x: auto;
    background: #1e1e1e !important;
    width: 100%;
    box-sizing: border-box;
}

.artifact-code-display pre code {
    display: block;
    padding: 16px;
}

/* Line numbers styling for artifact pane */
.artifact-code-display pre.line-numbers {
    position: relative;
    padding-left: 3.8em;
    counter-reset: linenumber;
}

.artifact-code-display pre.line-numbers > code {
    position: relative;
    white-space: pre;
    padding-left: 0;
}

.artifact-code-display .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 0;
    font-size: 100%;
    left: -3.8em;
    width: 3em;
    letter-spacing: -1px;
    border-right: 1px solid #3e3e3e;
    user-select: none;
    padding: 16px 0;
}

.artifact-code-display .line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
    color: #858585;
    padding-right: 0.8em;
    text-align: right;
}

.artifact-code-display .line-numbers-rows > span:before {
    content: counter(linenumber);
}

.artifact-code-display code {
    font-family: 'Fira Code', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #d4d4d4 !important;
    background: transparent !important;
}

/* Prism theme overrides for dark mode in artifact pane */
.artifact-code-display .token.comment,
.artifact-code-display .token.prolog,
.artifact-code-display .token.doctype,
.artifact-code-display .token.cdata {
    color: #6a9955;
}

.artifact-code-display .token.punctuation {
    color: #d4d4d4;
}

.artifact-code-display .token.property,
.artifact-code-display .token.tag,
.artifact-code-display .token.boolean,
.artifact-code-display .token.number,
.artifact-code-display .token.constant,
.artifact-code-display .token.symbol,
.artifact-code-display .token.deleted {
    color: #b5cea8;
}

.artifact-code-display .token.selector,
.artifact-code-display .token.attr-name,
.artifact-code-display .token.string,
.artifact-code-display .token.char,
.artifact-code-display .token.builtin,
.artifact-code-display .token.inserted {
    color: #ce9178;
}

.artifact-code-display .token.operator,
.artifact-code-display .token.entity,
.artifact-code-display .token.url,
.artifact-code-display .language-css .token.string,
.artifact-code-display .style .token.string {
    color: #d4d4d4;
}

.artifact-code-display .token.atrule,
.artifact-code-display .token.attr-value,
.artifact-code-display .token.keyword {
    color: #c586c0;
}

.artifact-code-display .token.function,
.artifact-code-display .token.class-name {
    color: #dcdcaa;
}

.artifact-code-display .token.regex,
.artifact-code-display .token.important,
.artifact-code-display .token.variable {
    color: #d16969;
}

.artifact-detail-actions {
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    min-height: 67px;
    max-height: 67px; /* PHASE 9: Force footer height */
    align-items: center;
    flex-shrink: 0; /* PHASE 9: Fixed footer - don't shrink */
    flex-basis: 67px; /* PHASE 9: Explicitly set basis */
}

.artifact-action-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast) var(--easing);
    display: flex;
    align-items: center;
    gap: 6px;
}

.artifact-action-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

.artifact-action-btn.primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.artifact-action-btn.primary:hover {
    background: var(--accent-hover);
}

.artifact-action-btn.danger {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.artifact-action-btn.danger:hover {
    opacity: 0.9;
}

/* ============================================================================
   EDIT MODE
   ============================================================================ */

.artifact-edit-textarea {
    width: 100%;
    min-height: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    padding: 16px;
    resize: vertical;
}

.artifact-edit-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ============================================================================
   EMPTY STATE
   ============================================================================ */

/* In artifacts.css - Add this to completely hide the empty state */

.artifact-empty-state {
    display: none !important; /* Force hide - never show */
}

.artifact-empty-state.show {
    display: flex; /* Only show when this class is added */
}

.artifact-empty-icon {
    margin-bottom: 16px;
    opacity: 0.5;
}

.artifact-empty-title {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.artifact-empty-text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-tertiary);
    max-width: 300px;
}
/* ============================================================================
   STREAMING ANIMATIONS
   ============================================================================ */

/* Pulsing circle - no rotation */
.artifact-streaming-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgb(99, 102, 241);
    border-radius: 50%;
    animation: pulse-circle 1.5s ease-in-out infinite;
}

@keyframes pulse-circle {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.9); }
}

/* Streaming dots animation (for text) */
.streaming-dots::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 1023px) {
    /* Tablet: Overlay mode */
    .app-container.artifacts-open .artifact-pane {
        position: fixed;
        top: 48px;
        right: 0;
        bottom: 0;
        width: 90%;
        max-width: 450px;
        z-index: 300;
        box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
    }
    
    /* Backdrop */
    .app-container.artifacts-open::after {
        content: '';
        position: fixed;
        top: 48px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 299;
    }
}

@media (max-width: 767px) {
    /* Mobile: Full screen modal */
    .app-container.artifacts-open .artifact-pane {
        width: 100%;
        max-width: none;
    }
}

/* ============================================================================
   NEW ARTIFACT BADGE (on header button)
   ============================================================================ */

.header-icon-btn.has-new-artifacts::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    background: var(--error);
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}

.header-icon-btn {
    position: relative;
}

/* ============================================================================
   ARTIFACT CARDS (in chat messages)
   ============================================================================ */

   .artifact-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-normal) var(--easing);
    margin: 8px 0;
}

.artifact-card:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.artifact-card-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.artifact-card.streaming .artifact-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.artifact-card.complete {
    cursor: pointer;
}

.artifact-card.streaming {
    cursor: default;
}

.artifact-card-content {
    flex: 1;
    min-width: 0;
}

.artifact-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.artifact-card-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.artifact-card-action {
    font-size: 13px;
    color: var(--accent-primary);
    font-weight: 500;
    flex-shrink: 0;
}