/* AI Chatbot - Custom Styles with Open Props */

:root {
    /* Dark theme colors */
    --surface-bg: var(--gray-9);
    --surface-1: var(--gray-8);
    --surface-2: var(--gray-7);
    --surface-3: var(--gray-6);
    --text-primary: var(--gray-0);
    --text-secondary: var(--gray-3);
    --accent: var(--blue-6);
    --accent-hover: var(--blue-5);
    --danger: var(--red-6);
    --success: var(--green-6);
}

/* ================================
   Animation & Motion System
   ================================ */

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Message entry animations */
.message {
    animation: var(--animation-fade-in) forwards,
               var(--animation-slide-in-up) forwards;
    animation-duration: 0.4s;
    animation-timing-function: var(--ease-out-3);
}

/* Stagger messages on page load */
.message:nth-child(1) { animation-delay: 0ms; }
.message:nth-child(2) { animation-delay: 50ms; }
.message:nth-child(3) { animation-delay: 100ms; }
.message:nth-child(4) { animation-delay: 150ms; }
.message:nth-child(5) { animation-delay: 200ms; }
.message:nth-child(n+6) { animation-delay: 250ms; }

/* New message highlight pulse */
.message-new {
    animation: var(--animation-fade-in) forwards,
               var(--animation-slide-in-up) forwards,
               message-highlight 1s var(--ease-out-3);
    animation-duration: 0.4s, 0.4s, 1s;
}

@keyframes message-highlight {
    0% { box-shadow: 0 0 0 2px var(--accent); }
    100% { box-shadow: 0 0 0 2px transparent; }
}

/* Sidebar item animations */
.sidebar-item {
    animation: var(--animation-fade-in) forwards;
    animation-duration: 0.3s;
    animation-timing-function: var(--ease-out-3);
}

.sidebar-item:nth-child(1) { animation-delay: 0ms; }
.sidebar-item:nth-child(2) { animation-delay: 30ms; }
.sidebar-item:nth-child(3) { animation-delay: 60ms; }
.sidebar-item:nth-child(4) { animation-delay: 90ms; }
.sidebar-item:nth-child(5) { animation-delay: 120ms; }
.sidebar-item:nth-child(n+6) { animation-delay: 150ms; }

/* Sidebar item delete animation */
.sidebar-item.deleting {
    animation: var(--animation-fade-out) forwards,
               var(--animation-slide-out-left) forwards;
    animation-duration: 0.3s;
    animation-timing-function: var(--ease-in-3);
}

/* Button hover spring effect */
.btn {
    transition: transform 0.2s var(--ease-spring-2),
                background 0.15s var(--ease-2),
                box-shadow 0.15s var(--ease-2);
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
    transition-duration: 0.1s;
}

/* Icon button spring effect */
.btn-icon {
    transition: transform 0.2s var(--ease-spring-3),
                background 0.15s var(--ease-2),
                color 0.15s var(--ease-2);
}

.btn-icon:hover {
    transform: scale(1.1);
}

.btn-icon:active {
    transform: scale(0.95);
    transition-duration: 0.1s;
}

/* Vote button special effects */
.btn-icon.vote-btn {
    transition: transform 0.2s var(--ease-elastic-out-3),
                color 0.15s var(--ease-2);
}

.btn-icon.vote-btn:active {
    animation: var(--animation-ping) 0.4s;
}

.btn-icon.vote-btn.voted {
    animation: vote-success 0.5s var(--ease-elastic-out-3);
}

@keyframes vote-success {
    0% { transform: scale(1); }
    25% { transform: scale(1.3); }
    50% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

/* Copy button success ping */
.btn-copy-success {
    animation: var(--animation-ping) 0.6s var(--ease-out-3);
    color: var(--success) !important;
}

/* Artifact button pulse when available */
.btn-icon[title^="Open artifact"] {
    animation: artifact-pulse 2s var(--ease-in-out-2) infinite;
}

.btn-icon[title^="Open artifact"]:hover {
    animation: none;
}

@keyframes artifact-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

/* Shake animation for errors */
.shake {
    animation: var(--animation-shake-x);
    animation-duration: 0.5s;
}

/* Float animation for loading states */
.floating {
    animation: var(--animation-float);
    animation-duration: 3s;
    animation-iteration-count: infinite;
}

/* Bounce animation for attention */
.bounce {
    animation: var(--animation-bounce);
    animation-duration: 1s;
}

/* Spin animation for loaders */
.spinning {
    animation: var(--animation-spin);
    animation-duration: 1s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

/* Blink animation for notifications */
.blinking {
    animation: var(--animation-blink);
    animation-duration: 1s;
    animation-iteration-count: 3;
}

/* Greeting animation */
.greeting {
    animation: var(--animation-fade-in-bloom) forwards;
    animation-duration: 0.6s;
    animation-timing-function: var(--ease-out-3);
}

.greeting h1 {
    animation: var(--animation-fade-in) forwards,
               var(--animation-slide-in-up) forwards;
    animation-duration: 0.5s;
    animation-delay: 0.1s;
    animation-timing-function: var(--ease-out-4);
    opacity: 0;
}

.greeting p {
    animation: var(--animation-fade-in) forwards;
    animation-duration: 0.5s;
    animation-delay: 0.3s;
    opacity: 0;
}

/* Reset and base */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: var(--surface-bg);
    color: var(--text-primary);
    font-family: var(--font-sans);
}

/* App Container - True 3x3 Grid Layout */
.app-container {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "sidebar-header  main-header   artifact-header"
        "sidebar-nav     main-content  artifact-content"
        "sidebar-footer  main-input    artifact-footer";
    height: 100vh;
    overflow: hidden;
}

/* ================================
   Left Column - Sidebar
   ================================ */

.sidebar-header {
    grid-area: sidebar-header;
    width: 280px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--size-4);
    background: var(--surface-1);
    border-right: 1px solid var(--surface-3);
    border-bottom: 1px solid var(--surface-3);
    transition: width 0.4s var(--ease-spring-3), padding 0.4s var(--ease-spring-3);
}

.sidebar-header h2 {
    font-size: var(--font-size-3);
    margin: 0;
    font-weight: var(--font-weight-6);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-header.sidebar-closed {
    width: 0;
    padding: var(--size-4) 0;
    overflow: hidden;
    border-right-color: transparent;
}

.sidebar-nav {
    grid-area: sidebar-nav;
    width: 280px;
    background: var(--surface-1);
    border-right: 1px solid var(--surface-3);
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--size-2);
    transition: width 0.4s var(--ease-spring-3), padding 0.4s var(--ease-spring-3);
}

.sidebar-nav.sidebar-closed {
    width: 0;
    padding: var(--size-2) 0;
    overflow: hidden;
    border-right-color: transparent;
}

.sidebar-footer {
    grid-area: sidebar-footer;
    width: 280px;
    background: var(--surface-1);
    border-right: 1px solid var(--surface-3);
    border-top: 1px solid var(--surface-3);
    padding: var(--size-3);
    transition: width 0.4s var(--ease-spring-3), padding 0.4s var(--ease-spring-3);
}

.sidebar-footer.sidebar-closed {
    width: 0;
    padding: var(--size-3) 0;
    overflow: hidden;
    border-right-color: transparent;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--size-4);
    border-bottom: 1px solid var(--surface-3);
}

.sidebar-header h2 {
    font-size: var(--font-size-3);
    margin: 0;
    font-weight: var(--font-weight-6);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--size-2);
}

.sidebar-empty {
    color: var(--text-secondary);
    text-align: center;
    padding: var(--size-4);
    font-size: var(--font-size-1);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--size-2);
    padding: var(--size-3);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    text-decoration: none;
    margin-bottom: var(--size-1);
    transition: background var(--ease-2) 0.15s;
}

.sidebar-item:hover {
    background: var(--surface-2);
}

.sidebar-item.active {
    background: var(--surface-3);
    view-transition-name: active-chat;
}

.sidebar-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--font-size-1);
}

.sidebar-item .btn-delete {
    opacity: 0;
    transition: opacity var(--ease-2) 0.15s;
}

.sidebar-item:hover .btn-delete {
    opacity: 1;
}

.sidebar-footer {
    padding: var(--size-3);
    border-top: 1px solid var(--surface-3);
}

.connection-indicator {
    display: flex;
    align-items: center;
    gap: var(--size-2);
    font-size: var(--font-size-0);
    color: var(--text-secondary);
    transition: color 0.3s var(--ease-2);
}

.connection-indicator .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--yellow-5);
    animation: connection-pulse 1.5s var(--ease-in-out-2) infinite;
    transition: background 0.3s var(--ease-2);
}

.connection-indicator[data-connected="true"] .dot {
    background: var(--green-5);
    animation: connection-success 0.5s var(--ease-elastic-out-3);
}

.connection-indicator[data-connected="true"] {
    color: var(--green-5);
}

@keyframes connection-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}

@keyframes connection-success {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); }
    100% { transform: scale(1); }
}

/* ================================
   Center Column - Main Chat
   ================================ */

/* Header */
.main-header {
    grid-area: main-header;
    display: flex;
    align-items: center;
    gap: var(--size-3);
    padding: var(--size-3) var(--size-4);
    background: var(--surface-1);
    border-bottom: 1px solid var(--surface-3);
}

.header-title {
    flex: 1;
    font-weight: var(--font-weight-5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--size-2);
}

/* Main content - messages area */
.main-content {
    grid-area: main-content;
    overflow-y: auto;
    padding: var(--size-4);
}

/* Input area */
.main-input {
    grid-area: main-input;
    background: var(--surface-1);
}

.model-selector {
    background: var(--surface-2);
    color: var(--text-primary);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    padding: var(--size-2) var(--size-3);
    font-size: var(--font-size-1);
    cursor: pointer;
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--size-4);
}

.messages {
    max-width: 800px;
    margin: 0 auto;
}

.greeting {
    text-align: center;
    padding: var(--size-8) var(--size-4);
    color: var(--text-secondary);
}

.greeting h1 {
    font-size: var(--font-size-5);
    margin-bottom: var(--size-3);
    color: var(--text-primary);
}

.message {
    display: flex;
    gap: var(--size-3);
    padding: var(--size-4);
    border-radius: var(--radius-3);
    margin-bottom: var(--size-3);
}

.message-user {
    background: var(--surface-1);
}

.message-assistant {
    background: var(--surface-2);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface-3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.message-role {
    font-size: var(--font-size-0);
    font-weight: var(--font-weight-6);
    margin-bottom: var(--size-1);
    color: var(--text-secondary);
}

.message-text {
    line-height: var(--line-height-3);
    word-break: break-word;
}

.message-actions {
    display: flex;
    gap: var(--size-1);
    margin-top: var(--size-2);
    opacity: 0;
    transition: opacity var(--ease-2) 0.15s;
}

.message:hover .message-actions {
    opacity: 1;
}

/* Artifact button always visible when present */
.message-actions .btn-icon[title^="Open artifact"] {
    color: var(--accent);
}

.message:has(.message-actions .btn-icon[title^="Open artifact"]) .message-actions {
    opacity: 1;
}

/* Input */
.input-container {
    padding: var(--size-4);
    background: var(--surface-1);
    border-top: 1px solid var(--surface-3);
}

.input-form {
    display: flex;
    flex-direction: column;
    gap: var(--size-2);
    max-width: 800px;
    margin: 0 auto;
}

.input-wrapper {
    width: 100%;
}

.input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--size-3);
    width: 100%;
}

.input-toolbar-left {
    display: flex;
    align-items: center;
    gap: var(--size-2);
}

.input-toolbar .disclaimer {
    flex: 1;
    margin: 0;
    font-size: var(--font-size-0);
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
}

.model-selector-compact {
    background: var(--surface-2);
    color: var(--text-primary);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    padding: var(--size-1) var(--size-2);
    font-size: var(--font-size-0);
    cursor: pointer;
    max-width: 160px;
}

.model-selector-compact:focus {
    outline: none;
    border-color: var(--accent);
}

.input-actions {
    display: flex;
    gap: var(--size-2);
    justify-content: flex-end;
}

.message-input {
    width: 100%;
    background: var(--surface-2);
    color: var(--text-primary);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    padding: var(--size-3);
    font-family: inherit;
    font-size: var(--font-size-2);
    resize: none;
    min-height: 48px;
    max-height: 200px;
}

.message-input:focus {
    outline: none;
    border-color: var(--accent);
}

.message-input::placeholder {
    color: var(--text-secondary);
}

.message-preview,
.message-preview-empty {
    background: var(--surface-2);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    padding: var(--size-3);
    min-height: 48px;
    max-height: 200px;
    overflow-y: auto;
}

.message-preview-empty {
    display: flex;
    align-items: center;
}

.btn-preview {
    opacity: 0.6;
}

.btn-preview:hover,
.btn-preview[aria-pressed="true"] {
    opacity: 1;
}

.btn-preview[aria-pressed="true"] {
    color: var(--accent);
}

.disclaimer {
    text-align: center;
    font-size: var(--font-size-0);
    color: var(--text-secondary);
    margin-top: var(--size-2);
    margin-bottom: 0;
}

/* Send button with hover glow */
.btn-send {
    position: relative;
}

.btn-send:hover:not(:disabled) {
    box-shadow: 0 0 20px rgba(66, 153, 225, 0.4);
}

.btn-send:active:not(:disabled) {
    animation: send-press 0.2s var(--ease-out-2);
}

@keyframes send-press {
    0% { transform: scale(1); }
    50% { transform: scale(0.9); }
    100% { transform: scale(1) translateY(-1px); }
}

/* Stop button pulse */
.btn-stop {
    animation: stop-pulse 1.5s var(--ease-in-out-2) infinite;
}

@keyframes stop-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--size-2);
    padding: var(--size-2) var(--size-4);
    border-radius: var(--radius-2);
    border: none;
    font-family: inherit;
    font-size: var(--font-size-1);
    font-weight: var(--font-weight-5);
    cursor: pointer;
    transition: transform 0.2s var(--ease-spring-2),
                background 0.15s var(--ease-3),
                box-shadow 0.15s var(--ease-3);
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-danger {
    background: var(--red-7);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: var(--red-8);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-2);
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s var(--ease-spring-3),
                background 0.15s var(--ease-3),
                color 0.15s var(--ease-3);
}

.btn-icon:hover {
    background: var(--surface-3);
    color: var(--text-primary);
    transform: scale(1.1);
}

.btn-icon:active {
    transform: scale(0.95);
}

/* Vote button active state */
.btn-icon.vote-btn.voted {
    color: var(--blue-6);
}

.btn-icon.vote-btn.voted:hover {
    color: var(--blue-5);
}

/* Old artifact panel styles moved to Artifact Panel Styles section below */

.artifact-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--size-3) var(--size-4);
    border-bottom: 1px solid var(--surface-3);
    font-weight: var(--font-weight-5);
}

.artifact-content {
    flex: 1;
    overflow: auto;
    padding: var(--size-4);
}

/* Artifact Content Styles */
.artifact-text {
    line-height: var(--font-lineheight-3);
}

.artifact-code {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.artifact-code .code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--size-2) var(--size-3);
    background: var(--surface-2);
    border-radius: var(--radius-2) var(--radius-2) 0 0;
}

.artifact-code .code-language {
    font-size: var(--font-size-0);
    color: var(--text-secondary);
    text-transform: uppercase;
}

.artifact-code pre {
    flex: 1;
    margin: 0;
    padding: var(--size-3);
    background: var(--surface-2);
    border-radius: 0;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: var(--font-size-1);
    line-height: var(--font-lineheight-3);
}

.artifact-code .code-output {
    padding: var(--size-3);
    background: var(--gray-9);
    color: var(--gray-1);
    font-family: var(--font-mono);
    font-size: var(--font-size-0);
    border-radius: 0 0 var(--radius-2) var(--radius-2);
    min-height: 60px;
    max-height: 200px;
    overflow: auto;
}

.artifact-code .code-output:empty::before {
    content: 'Output will appear here...';
    color: var(--gray-5);
    font-style: italic;
}

.artifact-sheet {
    overflow: auto;
}

.sheet-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-1);
}

.sheet-table th,
.sheet-table td {
    padding: var(--size-2) var(--size-3);
    border: 1px solid var(--surface-3);
    text-align: left;
}

.sheet-table th {
    background: var(--surface-2);
    font-weight: var(--font-weight-5);
    position: sticky;
    top: 0;
}

.sheet-table tr:hover td {
    background: var(--surface-2);
}

.artifact-image {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.artifact-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ================================
   Responsive / Mobile Styles
   ================================ */

@media (max-width: 768px) {
    /* On mobile, revert to simpler stacked layout */
    .app-container {
        display: flex;
        flex-direction: column;
        grid-template-areas: none;
    }

    /* Sidebar becomes fixed overlay on mobile */
    .sidebar-header,
    .sidebar-nav,
    .sidebar-footer {
        position: fixed;
        left: 0;
        width: 280px;
        z-index: 100;
        transition: transform 0.4s var(--ease-spring-3);
    }

    .sidebar-header { top: 0; }
    .sidebar-nav { top: 60px; bottom: 120px; }
    .sidebar-footer { bottom: 0; height: auto; }

    .sidebar-header.sidebar-closed,
    .sidebar-nav.sidebar-closed,
    .sidebar-footer.sidebar-closed {
        transform: translateX(-100%);
        width: 280px;
    }

    /* Main content stacks vertically */
    .main-header {
        order: 1;
    }

    .main-content {
        order: 2;
        flex: 1;
        min-height: 0;
    }

    .main-input {
        order: 3;
    }
    
    /* Artifact panel becomes full-width overlay on mobile */
    .artifact-header,
    .artifact-content,
    .artifact-footer {
        position: fixed;
        right: 0;
        width: 100%;
        max-width: none;
        z-index: 100;
        transition: transform 0.4s var(--ease-spring-3);
    }

    .artifact-header { top: 0; }
    .artifact-content { top: 60px; bottom: 60px; }
    .artifact-footer { bottom: 0; }

    .artifact-header.artifact-closed,
    .artifact-content.artifact-closed,
    .artifact-footer.artifact-closed {
        display: none;
    }

    /* Chat area adjustments */
    .main-content {
        padding: var(--size-2);
    }

    .main-header {
        padding: var(--size-2) var(--size-3);
    }

    .message {
        padding: var(--size-2);
        gap: var(--size-2);
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: var(--font-size-0);
    }

    .message-content {
        font-size: var(--font-size-1);
    }

    /* Input area */
    .input-container {
        padding: var(--size-2);
    }

    .input-form {
        padding: var(--size-2);
        gap: var(--size-2);
    }

    .input-textarea {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px;
    }

    /* Model selector smaller on mobile */
    .model-select {
        font-size: var(--font-size-0);
        padding: var(--size-1) var(--size-2);
    }

    /* Smaller buttons on mobile */
    .btn {
        padding: var(--size-2) var(--size-3);
        font-size: var(--font-size-0);
    }

    .btn-icon {
        width: 36px;
        height: 36px;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95vw;
        max-height: 85vh;
    }

    /* Toast adjustments */
    .toast-container {
        left: var(--size-2);
        right: var(--size-2);
        bottom: var(--size-2);
        max-width: none;
    }

    .toast {
        padding: var(--size-2) var(--size-3);
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .sidebar-header h2 {
        font-size: var(--font-size-2);
    }

    .chat-header h1 {
        font-size: var(--font-size-2);
    }

    .message-actions {
        flex-wrap: wrap;
    }
}

/* ================================
   Modal Styles (Popover API)
   ================================ */

/* Popover backdrop */
.modal-popover::backdrop {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
}

/* Main popover modal container */
.modal-popover {
    position: fixed;
    inset: 0;
    margin: auto;
    border: none;
    padding: 0;
    background: transparent;
    max-width: 100vw;
    max-height: 100vh;
    overflow: visible;
}

/* Opening/closing animation */
.modal-popover {
    opacity: 0;
    transform: scale(0.9) translateY(10px);
    transition: opacity 0.25s var(--ease-out-3),
                transform 0.25s var(--ease-spring-3),
                overlay 0.25s var(--ease-out-3) allow-discrete,
                display 0.25s var(--ease-out-3) allow-discrete;
}

.modal-popover:popover-open {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* Starting style for entry animation */
@starting-style {
    .modal-popover:popover-open {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }
}

.modal-content {
    background: var(--surface-1);
    border-radius: var(--radius-3);
    width: min(400px, 90vw);
    max-height: 90vh;
    overflow: auto;
    box-shadow: var(--shadow-5);
    border: 1px solid var(--surface-3);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--size-4);
    border-bottom: 1px solid var(--surface-3);
}

.modal-header h2 {
    margin: 0;
    font-size: var(--font-size-3);
    font-weight: var(--font-weight-6);
}

.modal-close {
    opacity: 0.6;
}

.modal-close:hover {
    opacity: 1;
}

.modal-description {
    padding: 0 var(--size-4);
    color: var(--text-secondary);
    font-size: var(--font-size-1);
    line-height: 1.6;
}

.modal-footer {
    padding: var(--size-3) var(--size-4) var(--size-4);
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--font-size-0);
}

.modal-footer p {
    margin: 0;
}

/* ================================
   Auth Form Styles
   ================================ */

.auth-form {
    padding: var(--size-4);
}

.form-group {
    margin-bottom: var(--size-4);
}

.form-group label {
    display: block;
    margin-bottom: var(--size-2);
    font-size: var(--font-size-1);
    font-weight: var(--font-weight-5);
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: var(--size-3);
    font-size: var(--font-size-1);
    background: var(--surface-2);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}

.form-group input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.form-hint {
    display: block;
    margin-top: var(--size-1);
    font-size: var(--font-size-0);
    color: var(--text-secondary);
}

.form-error {
    display: flex;
    align-items: center;
    gap: var(--size-2);
    padding: var(--size-3);
    margin-bottom: var(--size-3);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    border-radius: var(--radius-2);
    color: var(--danger);
    font-size: var(--font-size-1);
}

.form-error[data-show="false"] {
    display: none;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: var(--size-2) var(--size-3);
    font-size: var(--font-size-0);
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 0;
    font-size: inherit;
    text-decoration: underline;
    text-decoration-color: transparent;
    transition: text-decoration-color 0.15s;
}

.btn-link:hover {
    text-decoration-color: var(--accent);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text-primary);
    border: 1px solid var(--surface-3);
}

.btn-secondary:hover {
    background: var(--surface-3);
}

/* ================================
   Sidebar Auth/User Styles
   ================================ */

.sidebar-auth {
    padding: var(--size-3);
    border-top: 1px solid var(--surface-3);
    display: flex;
    flex-direction: column;
    gap: var(--size-2);
    text-align: center;
}

.sidebar-auth .btn-link {
    font-size: var(--font-size-0);
    color: var(--text-secondary);
}

.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--size-3);
    border-top: 1px solid var(--surface-3);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--size-2);
    font-size: var(--font-size-1);
    color: var(--text-secondary);
    overflow: hidden;
}

.user-info i {
    font-size: var(--font-size-4);
    color: var(--accent);
}

.user-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ================================
   Right Column - Artifact Panel
   ================================ */

.artifact-header {
    grid-area: artifact-header;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--size-3) var(--size-4);
    background: var(--surface-1);
    border-left: 1px solid var(--surface-3);
    border-bottom: 1px solid var(--surface-3);
    white-space: nowrap;
    width: 50vw;
    max-width: 700px;
    opacity: 1;
    transition: width 0.4s var(--ease-spring-3),
                padding 0.4s var(--ease-spring-3),
                opacity 0.3s var(--ease-out-3),
                display 0.3s var(--ease-out-3) allow-discrete;
}

.artifact-header.artifact-closed {
    display: none;
    width: 0;
    padding: var(--size-3) 0;
    opacity: 0;
}

@starting-style {
    .artifact-header {
        opacity: 0;
        width: 0;
    }
}

.artifact-title {
    display: flex;
    align-items: center;
    gap: var(--size-2);
    font-weight: var(--font-weight-6);
}

.artifact-actions {
    display: flex;
    align-items: center;
    gap: var(--size-2);
}

.artifact-content {
    grid-area: artifact-content;
    width: 50vw;
    max-width: 700px;
    background: var(--surface-1);
    border-left: 1px solid var(--surface-3);
    overflow-y: auto;
    opacity: 1;
    transition: width 0.4s var(--ease-spring-3),
                opacity 0.3s var(--ease-out-3),
                display 0.3s var(--ease-out-3) allow-discrete;
}

.artifact-content.artifact-closed {
    display: none;
    width: 0;
    opacity: 0;
}

@starting-style {
    .artifact-content {
        opacity: 0;
        width: 0;
    }
}

.artifact-footer {
    grid-area: artifact-footer;
    width: 50vw;
    max-width: 700px;
    background: var(--surface-1);
    border-left: 1px solid var(--surface-3);
    border-top: 1px solid var(--surface-3);
    padding: var(--size-3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--size-2);
    color: var(--text-secondary);
    font-size: var(--font-size-0);
    opacity: 1;
    transition: width 0.4s var(--ease-spring-3),
                padding 0.4s var(--ease-spring-3),
                opacity 0.3s var(--ease-out-3),
                display 0.3s var(--ease-out-3) allow-discrete;
}

.artifact-footer.artifact-closed {
    display: none;
    width: 0;
    padding: var(--size-3) 0;
    opacity: 0;
}

@starting-style {
    .artifact-footer {
        opacity: 0;
        width: 0;
    }
}

/* Text Artifact */
.artifact-text {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.artifact-text-content {
    flex: 1;
    overflow-y: auto;
    line-height: var(--line-height-4);
}

.artifact-text-content.markdown h1,
.artifact-text-content.markdown h2,
.artifact-text-content.markdown h3 {
    margin-top: var(--size-4);
    margin-bottom: var(--size-2);
}

.artifact-text-content.markdown code {
    background: var(--surface-3);
    padding: 0.2em 0.4em;
    border-radius: var(--radius-1);
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.artifact-textarea {
    width: 100%;
    min-height: 300px;
    padding: var(--size-3);
    background: var(--surface-2);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--font-size-1);
    resize: vertical;
}

/* Code Artifact */
.artifact-code {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.artifact-code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--size-3);
}

.language-badge {
    background: var(--accent);
    color: white;
    padding: var(--size-1) var(--size-2);
    border-radius: var(--radius-1);
    font-size: var(--font-size-0);
    font-weight: var(--font-weight-6);
}

.btn-run {
    background: var(--success);
    color: white;
    padding: var(--size-2) var(--size-3);
    border: none;
    border-radius: var(--radius-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--size-2);
}

.btn-run:hover {
    filter: brightness(1.1);
}

.btn-run:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.artifact-code-editor {
    flex: 1;
    overflow: auto;
}

.code-block {
    margin: 0;
    padding: var(--size-4);
    background: var(--gray-9);
    border-radius: var(--radius-2);
    overflow-x: auto;
}

.code-block code {
    font-family: var(--font-mono);
    font-size: var(--font-size-1);
    line-height: var(--line-height-3);
    color: var(--text-primary);
    white-space: pre;
}

.artifact-code-textarea {
    width: 100%;
    min-height: 300px;
    padding: var(--size-3);
    background: var(--gray-9);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-1);
    resize: vertical;
    line-height: var(--line-height-3);
}

.artifact-console {
    margin-top: var(--size-3);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    overflow: hidden;
}

.console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--size-2) var(--size-3);
    background: var(--gray-9);
    color: var(--text-secondary);
    font-size: var(--font-size-0);
}

.console-output {
    margin: 0;
    padding: var(--size-3);
    background: var(--gray-10, #111);
    color: var(--green-4);
    font-family: var(--font-mono);
    font-size: var(--font-size-1);
    min-height: 100px;
    max-height: 200px;
    overflow: auto;
    white-space: pre-wrap;
}

/* Sheet Artifact */
.artifact-sheet {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.artifact-sheet-toolbar {
    display: flex;
    gap: var(--size-2);
    margin-bottom: var(--size-3);
}

.artifact-sheet-container {
    flex: 1;
    overflow: auto;
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
}

.sheet-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-1);
}

.sheet-table th,
.sheet-table td {
    padding: var(--size-2) var(--size-3);
    border: 1px solid var(--surface-3);
    text-align: left;
}

.sheet-table th {
    background: var(--surface-2);
    font-weight: var(--font-weight-6);
    position: sticky;
    top: 0;
}

.sheet-table td.row-number,
.sheet-table th.row-number {
    background: var(--surface-2);
    color: var(--text-secondary);
    width: 40px;
    text-align: center;
}

.artifact-csv-textarea {
    width: 100%;
    min-height: 200px;
    padding: var(--size-3);
    background: var(--surface-2);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-1);
    resize: vertical;
}

/* Image Artifact */
.artifact-image {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.artifact-image-toolbar {
    display: flex;
    gap: var(--size-2);
    margin-bottom: var(--size-3);
}

.artifact-image-preview {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--surface-2);
    border-radius: var(--radius-2);
    padding: var(--size-4);
    overflow: auto;
}

.artifact-image-preview img,
.artifact-image-preview svg {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.svg-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.svg-container svg {
    max-width: 100%;
    max-height: 400px;
}

.image-placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.image-placeholder i {
    font-size: 48px;
    margin-bottom: var(--size-2);
}

.artifact-svg-textarea {
    width: 100%;
    min-height: 300px;
    padding: var(--size-3);
    background: var(--surface-2);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-1);
    resize: vertical;
}

/* Artifact Edit Actions */
.artifact-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--size-2);
    margin-top: var(--size-3);
}

.btn-edit {
    margin-top: var(--size-3);
}

/* Version Selector */
.version-selector {
    padding: var(--size-1) var(--size-2);
    background: var(--surface-2);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-1);
    color: var(--text-primary);
    font-size: var(--font-size-0);
}

/* ================================
   Toast Notifications
   ================================ */

.toast-container {
    position: fixed;
    bottom: var(--size-4);
    right: var(--size-4);
    z-index: 300;
    display: flex;
    flex-direction: column-reverse;
    gap: var(--size-2);
    pointer-events: none;
    max-width: min(400px, calc(100vw - var(--size-8)));
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--size-3);
    padding: var(--size-3) var(--size-4);
    background: var(--surface-1);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-2);
    box-shadow: var(--shadow-4);
    pointer-events: auto;
    animation: toast-enter 0.4s var(--ease-spring-3);
}

.toast-exit {
    animation: toast-exit 0.3s var(--ease-in-2) forwards;
}

@keyframes toast-enter {
    from {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toast-exit {
    from {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
}

.toast-icon {
    font-size: var(--font-size-3);
    flex-shrink: 0;
}

.toast[data-type="success"] .toast-icon {
    color: var(--green-5);
}

.toast[data-type="error"] .toast-icon {
    color: var(--red-5);
}

.toast[data-type="warning"] .toast-icon {
    color: var(--yellow-5);
}

.toast[data-type="info"] .toast-icon {
    color: var(--blue-5);
}

.toast-message {
    flex: 1;
    font-size: var(--font-size-1);
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    opacity: 0.5;
    transition: opacity 0.15s var(--ease-2),
                transform 0.15s var(--ease-spring-2);
}

.toast-close:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* ================================
   Streaming/Typing Indicator
   ================================ */

.message-streaming-indicator {
    display: flex;
    align-items: center;
    gap: var(--size-2);
    padding-top: var(--size-2);
}

/* Hide when streaming is complete */
.message[data-streaming="false"] .message-streaming-indicator {
    display: none;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing-bounce 1.4s var(--ease-in-out-2) infinite;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

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

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

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

/* AI "thinking" pulse for message avatar during streaming */
.message[data-streaming="true"] .message-avatar {
    animation: thinking-pulse 2s var(--ease-in-out-2) infinite;
}

@keyframes thinking-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(66, 153, 225, 0);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(66, 153, 225, 0.3);
    }
}

/* ================================
   Utility Animation Classes
   ================================ */

/* Entrance animations */
.animate-fade-in {
    animation: var(--animation-fade-in) forwards;
    animation-duration: 0.3s;
    animation-timing-function: var(--ease-out-3);
}

.animate-slide-up {
    animation: var(--animation-fade-in) forwards,
               var(--animation-slide-in-up) forwards;
    animation-duration: 0.4s;
    animation-timing-function: var(--ease-out-3);
}

.animate-slide-down {
    animation: var(--animation-fade-in) forwards,
               var(--animation-slide-in-down) forwards;
    animation-duration: 0.4s;
    animation-timing-function: var(--ease-out-3);
}

.animate-slide-left {
    animation: var(--animation-fade-in) forwards,
               var(--animation-slide-in-left) forwards;
    animation-duration: 0.4s;
    animation-timing-function: var(--ease-out-3);
}

.animate-slide-right {
    animation: var(--animation-fade-in) forwards,
               var(--animation-slide-in-right) forwards;
    animation-duration: 0.4s;
    animation-timing-function: var(--ease-out-3);
}

.animate-scale-up {
    animation: var(--animation-scale-up) forwards,
               var(--animation-fade-in) forwards;
    animation-duration: 0.3s;
    animation-timing-function: var(--ease-spring-3);
}

.animate-bloom {
    animation: var(--animation-fade-in-bloom) forwards;
    animation-duration: 0.4s;
    animation-timing-function: var(--ease-out-3);
}

/* Exit animations */
.animate-fade-out {
    animation: var(--animation-fade-out) forwards;
    animation-duration: 0.2s;
    animation-timing-function: var(--ease-in-2);
}

.animate-slide-out-up {
    animation: var(--animation-fade-out) forwards,
               var(--animation-slide-out-up) forwards;
    animation-duration: 0.3s;
    animation-timing-function: var(--ease-in-2);
}

.animate-slide-out-down {
    animation: var(--animation-fade-out) forwards,
               var(--animation-slide-out-down) forwards;
    animation-duration: 0.3s;
    animation-timing-function: var(--ease-in-2);
}

.animate-scale-down {
    animation: var(--animation-scale-down) forwards,
               var(--animation-fade-out) forwards;
    animation-duration: 0.2s;
    animation-timing-function: var(--ease-in-2);
}

/* Attention animations */
.animate-shake {
    animation: var(--animation-shake-x);
    animation-duration: 0.5s;
}

.animate-bounce {
    animation: var(--animation-bounce);
    animation-duration: 0.6s;
}

.animate-ping {
    animation: var(--animation-ping);
    animation-duration: 0.6s;
}

.animate-pulse {
    animation: var(--animation-pulse);
    animation-duration: 2s;
    animation-iteration-count: infinite;
}

.animate-float {
    animation: var(--animation-float);
    animation-duration: 3s;
    animation-iteration-count: infinite;
}

.animate-spin {
    animation: var(--animation-spin);
    animation-duration: 1s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

/* Hover interaction enhancements */
.hover-lift {
    transition: transform 0.2s var(--ease-spring-2),
                box-shadow 0.2s var(--ease-2);
}

.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-3);
}

.hover-glow {
    transition: box-shadow 0.2s var(--ease-2);
}

.hover-glow:hover {
    box-shadow: 0 0 20px rgba(66, 153, 225, 0.3);
}

.hover-scale {
    transition: transform 0.2s var(--ease-spring-3);
}

.hover-scale:hover {
    transform: scale(1.05);
}

/* Focus ring animation */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    animation: focus-ring-pulse 0.3s var(--ease-out-3);
}

@keyframes focus-ring-pulse {
    0% {
        outline-offset: 0px;
        outline-color: transparent;
    }
    100% {
        outline-offset: 2px;
        outline-color: var(--accent);
    }
}

/* Loading skeleton shimmer */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--surface-2) 25%,
        var(--surface-3) 50%,
        var(--surface-2) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s var(--ease-in-out-2) infinite;
    border-radius: var(--radius-2);
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Code block appear animation */
.code-block {
    animation: var(--animation-fade-in) forwards;
    animation-duration: 0.3s;
    animation-timing-function: var(--ease-out-2);
}

/* ================================
   View Transitions
   ================================ */

@view-transition {
    navigation: auto;
}

/* Smooth crossfade transition */
::view-transition-old(root) {
    animation: 300ms var(--ease-out-3) both vt-fade-out;
}

::view-transition-new(root) {
    animation: 300ms var(--ease-out-3) both vt-fade-in;
}

@keyframes vt-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes vt-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Keep sidebar stable during transitions */
.sidebar {
    view-transition-name: sidebar;
}

::view-transition-old(sidebar),
::view-transition-new(sidebar) {
    animation: none;
    mix-blend-mode: normal;
}

/* Animate active chat indicator moving between items */
::view-transition-old(active-chat),
::view-transition-new(active-chat) {
    animation: 300ms var(--ease-out-3) both;
    height: 100%;
}

::view-transition-group(active-chat) {
    animation: 300ms var(--ease-out-3) both;
}
