.chat-bubble-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-primary, #6366f1);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.chat-bubble-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.chat-bubble-btn svg {
    width: 20px;
    height: 20px;
}

/* Hide bubble when chat is open */
.chat-bubble-btn.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* Floating Chat Modal Styles */
.chat-sidebar {
    width: 400px;
    height: 500px;
    max-height: calc(100vh - 48px);
    min-height: 200px;
    display: flex;
    flex-direction: column;
    background: rgba(16, 16, 20, 0.95);
    backdrop-filter: blur(30px) saturate(1.4);
    -webkit-backdrop-filter: blur(30px) saturate(1.4);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    position: fixed;
    bottom: 24px;
    right: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s ease, opacity 0.2s ease;
    z-index: 99;
}

.chat-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 12px;
    cursor: ns-resize;
    border-radius: 16px 16px 0 0;
    z-index: 10;
}

.chat-resize-handle::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 4px;
    background: var(--border-subtle);
    border-radius: 2px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.chat-resize-handle:hover::after {
    opacity: 1;
    background: var(--text-muted);
}

.chat-sidebar.resizing {
    transition: none;
}

.chat-sidebar.collapsed {
    display: none;
    transform: scale(0.95) translateY(10px);
    opacity: 0;
    pointer-events: none;
}

/* Hard guard: if sidebar is open, bubble should never intercept taps/clicks */
.chat-sidebar:not(.collapsed)+#chat-bubble-btn {
    display: none;
    pointer-events: none;
}

/* Responsive chat modal - smaller on tablets */
@media (max-width: 1200px) {
    .chat-sidebar {
        width: 340px;
        height: 450px;
    }
}

/* Mobile - full width at bottom */
@media (max-width: 600px) {
    .chat-sidebar {
        width: calc(100% - 8px);
        height: auto;
        max-height: none;
        top: max(4px, env(safe-area-inset-top));
        bottom: max(4px, env(safe-area-inset-bottom));
        right: 4px;
        left: 4px;
        border-radius: 12px;
    }

    .chat-resize-handle {
        display: none;
    }

    .chat-bubble-btn {
        bottom: 16px;
        right: 16px;
        width: 40px;
        height: 40px;
    }

    .chat-bubble-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* Chat Header - ChatGPT Style */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-primary);
    border-radius: 16px 16px 0 0;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
}

.chat-title svg {
    width: 18px;
    height: 18px;
    color: var(--text-primary);
}

/* Context Bar - ChatGPT Style */
.chat-context-bar {
    display: none;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 1rem;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-primary);
}

.chat-context-bar.has-context {
    display: flex;
}

#chat-context-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 0.5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

#chat-context-name {
    flex: 1;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-context-clear {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 0.25rem;
    transition: background 0.15s, color 0.15s;
}

.chat-context-clear:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--red);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.chat-messages:hover {
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 3px;
}

.chat-messages:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Welcome Screen - ChatGPT Style */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    text-align: center;
    flex: 1;
}

.chat-header-main {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
}

.chat-mode-toggle {
    display: inline-flex;
    gap: 0.25rem;
    padding: 0.2rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
}

.chat-mode-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.25rem 0.7rem;
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.chat-mode-btn.active {
    background: rgba(255, 255, 255, 0.14);
    color: var(--text-primary);
}

.chat-runtime-banner,
.chat-thread-origin-banner {
    display: block;
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid var(--border-primary);
    background: rgba(255, 255, 255, 0.04);
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-secondary);
}

.chat-runtime-banner.hidden,
.chat-thread-origin-banner.hidden,
.chat-attachment-tray.hidden {
    display: none;
}

.chat-runtime-banner.error {
    background: rgba(239, 68, 68, 0.12);
    color: #fecaca;
}

.chat-runtime-banner.warn {
    background: rgba(245, 158, 11, 0.12);
    color: #fde68a;
}

.chat-runtime-banner button {
    margin-top: 0.5rem;
    border: none;
    border-radius: 999px;
    padding: 0.4rem 0.75rem;
    background: rgba(255, 255, 255, 0.14);
    color: inherit;
    cursor: pointer;
}

.chat-thread-filter-row {
    display: flex;
    gap: 0.4rem;
    padding: 0 1rem 0.75rem;
}

.chat-thread-filter-chip {
    border: none;
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
}

.chat-thread-filter-chip.active {
    background: rgba(255, 255, 255, 0.16);
    color: var(--text-primary);
}

.chat-attachment-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 0 0 0.7rem;
}

.chat-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    max-width: 100%;
    padding: 0.42rem 0.62rem;
    border-radius: 0.8rem;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    font-size: 0.76rem;
}

.chat-attachment-chip button {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
}

.chat-thread-origin-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
}

.chat-thread-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.chat-thread-item-main {
    min-width: 0;
}

.chat-thread-archive {
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
}

.chat-codex-message {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.chat-codex-bubble {
    max-width: 88%;
    border-radius: 1rem;
    padding: 0.8rem 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-codex-bubble.user {
    align-self: flex-end;
    background: rgba(59, 130, 246, 0.18);
    color: #dbeafe;
}

.chat-codex-bubble.assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.chat-codex-card {
    align-self: stretch;
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.8rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.chat-codex-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.65rem;
}

.chat-codex-card-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.chat-codex-card-status {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.chat-codex-card pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
    color: #d1d5db;
}

.chat-codex-list,
.chat-codex-media-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.chat-codex-media-link {
    color: #bfdbfe;
    text-decoration: none;
    word-break: break-all;
}

.chat-approval-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.chat-approval-actions button {
    border: none;
    border-radius: 999px;
    padding: 0.42rem 0.75rem;
    cursor: pointer;
    font-size: 0.74rem;
    font-weight: 600;
}

.chat-approval-approve {
    background: rgba(34, 197, 94, 0.18);
    color: #bbf7d0;
}

.chat-approval-deny {
    background: rgba(239, 68, 68, 0.18);
    color: #fecaca;
}

.chat-approval-session {
    background: rgba(250, 204, 21, 0.18);
    color: #fde68a;
}

.chat-approval-helper {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.chat-codex-empty {
    padding: 1.2rem 0.6rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.82rem;
}

@media (max-width: 600px) {
    .chat-header {
        align-items: flex-start;
        gap: 0.75rem;
    }

    .chat-header-main {
        flex: 1;
    }

    .chat-codex-bubble {
        max-width: 100%;
    }
}

.chat-welcome p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.5;
    margin: 0 0 0.75rem;
}

.chat-welcome .chat-hint {
    font-size: 0.8125rem;
    color: var(--text-muted);
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 0.75rem;
    margin-top: 0.5rem;
}

.chat-welcome-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.chat-welcome-section {
    margin-bottom: 1rem;
    width: 100%;
}

.chat-welcome-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.chat-welcome-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.chat-welcome-examples button {
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s;
}

.chat-welcome-examples button:hover {
    background: var(--bg-hover);
    border-color: var(--border-secondary);
    color: var(--text-primary);
}

.chat-welcome-hint {
    margin-top: 1rem;
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* Chat Options (multiple choice prompts) - ChatGPT Style */
.chat-options {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    margin-top: 0.75rem;
}

.chat-option {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 0.75rem;
    padding: 0.875rem 1rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-option:hover {
    border-color: var(--text-secondary);
}

.chat-option-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.chat-option-num {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    padding: 0.1875rem 0.5rem;
    border-radius: 0.25rem;
    letter-spacing: 0.025em;
}

.chat-option-title {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.chat-option-prompt {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-bottom: 0.75rem;
    padding: 0.625rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
}

.chat-option-actions {
    display: flex;
    gap: 0.375rem;
}

.chat-option-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.4375rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border-primary);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.15s;
}

.chat-option-btn:hover {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--bg-primary);
}

.chat-option-btn svg {
    width: 14px;
    height: 14px;
}

.chat-option-copy {
    padding: 0.4375rem 0.5rem;
}

/* Message Bubbles - ChatGPT Style (no avatars) */
.chat-message {
    max-width: 100%;
    padding: 0;
    position: relative;
}

.chat-message-user {
    align-self: flex-end;
    max-width: 85%;
}

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

.chat-message-error {
    align-self: flex-start;
}

.chat-message-content {
    line-height: 1.6;
    font-size: 0.9375rem;
    color: var(--text-primary);
    display: block;
}

.chat-message-user .chat-message-content {
    background: var(--bg-tertiary);
    padding: 0.75rem 1rem;
    border-radius: 1.5rem;
}

.chat-user-skill-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.12rem 0.48rem;
    margin-right: 0.35rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 650;
    line-height: 1.1;
    color: #6f3af2;
    border: 1px solid rgba(111, 58, 242, 0.25);
    background: rgba(111, 58, 242, 0.14);
    vertical-align: baseline;
}

.chat-message-assistant .chat-message-content,
.chat-message-error .chat-message-content {
    padding: 0;
}

.chat-message-error .chat-message-content {
    color: #f87171;
}

.chat-thoughts {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border-left: 2px solid var(--border-secondary);
    border-radius: 0.25rem;
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

.chat-code-block {
    background: rgba(16, 16, 22, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    overflow-x: auto;
    margin: 0.75rem 0;
    white-space: pre-wrap;
    color: #d4d4d4;
}

/* Message action buttons (copy + regenerate) */
.chat-message-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.15s;
}

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

.chat-copy-btn,
.chat-regen-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    padding: 0.375rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: opacity 0.15s, background 0.15s;
    color: var(--text-secondary);
}

.chat-copy-btn svg,
.chat-regen-btn svg {
    width: 14px;
    height: 14px;
}

.chat-copy-btn:hover,
.chat-regen-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Empty response recovery */
.chat-empty-response {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: var(--radius-md);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.chat-empty-message {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Tool recovery buttons */
.chat-tool-recovery {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* Skipped tool state */
.tool-skipped {
    color: var(--text-muted);
    font-style: italic;
}

/* Stream interrupted indicator */
.chat-stream-interrupted {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(245, 158, 11, 0.1);
    border-radius: var(--radius-md);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.chat-interrupted-message {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--warning, #f59e0b);
    font-size: 0.85rem;
}

.chat-interrupted-message i {
    width: 14px;
    height: 14px;
}

/* Input Area - ChatGPT Style */
.chat-input-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0.75rem 1rem 1rem;
    border-top: none;
    background: var(--bg-primary);
    position: relative;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.25rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 1.75rem;
    padding: 0.5rem 0.5rem 0.5rem 0.75rem;
    transition: border-color 0.2s;
}

.chat-skill-token {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    max-width: 46%;
    padding: 0.24rem 0.5rem;
    margin: 0 0.25rem 0.12rem 0;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    font-size: 0.78rem;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.chat-skill-token.hidden {
    display: none;
}

.chat-skill-token-clear {
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}

.chat-skill-token-clear:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.12);
}

.chat-skill-token-clear svg {
    width: 12px;
    height: 12px;
}

.chat-input-wrapper:focus-within {
    border-color: var(--border-secondary);
}

.chat-input {
    flex: 1;
    min-height: 24px;
    max-height: 200px;
    resize: none;
    border: none;
    background: transparent;
    color: var(--text-primary);
    padding: 0.375rem 0.75rem;
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
}

.chat-input:focus {
    outline: none;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-send-btn {
    background: #fff;
    color: #1a1a1a;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

.chat-send-btn:hover {
    opacity: 0.85;
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.chat-send-btn svg {
    width: 16px;
    height: 16px;
}

.chat-input-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.chat-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    color: var(--text-muted);
}

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

.chat-upload-btn svg {
    width: 18px;
    height: 18px;
}

.chat-sidebar.drag-over {
    outline: 2px dashed var(--primary);
    outline-offset: -4px;
}

/* Chat Header Actions - ChatGPT Style */
.chat-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.chat-header-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.chat-header-btn svg {
    width: 18px;
    height: 18px;
}

/* Thread List - ChatGPT Style */
.chat-thread-list {
    max-height: 320px;
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-primary);
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.chat-thread-list:hover {
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.chat-thread-list::-webkit-scrollbar {
    width: 6px;
}

.chat-thread-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-thread-list::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 3px;
}

.chat-thread-list:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

.chat-thread-list.hidden {
    display: none;
}

.chat-thread-item {
    padding: 0.625rem 0.75rem;
    cursor: pointer;
    border-radius: 0.5rem;
    position: relative;
    margin-bottom: 2px;
    transition: background 0.15s ease;
}

.chat-thread-item:hover {
    background: var(--bg-tertiary);
}

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

.chat-thread-title {
    font-weight: 400;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 28px;
    color: var(--text-primary);
}

.chat-thread-preview {
    display: none;
}

/* Show preview for search results */
.chat-thread-item.search-result .chat-thread-preview {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-thread-meta {
    position: absolute;
    top: 0.625rem;
    right: 2rem;
    font-size: 0.65rem;
    color: var(--text-muted);
}

.chat-thread-delete {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    border-radius: 0.25rem;
}

.chat-thread-item:hover .chat-thread-delete {
    opacity: 1;
}

.chat-thread-delete:hover {
    color: var(--red);
    background: rgba(239, 68, 68, 0.1);
}

.chat-thread-delete svg {
    width: 14px;
    height: 14px;
}

.chat-thread-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-primary);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.chat-thread-regenerate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.chat-thread-regenerate-btn:hover {
    background: var(--bg-secondary);
    color: var(--accent);
}

.chat-thread-regenerate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-thread-regenerate-btn svg {
    width: 14px;
    height: 14px;
}

.chat-thread-regenerate-btn .spin {
    animation: spin 1s linear infinite;
}

.chat-thread-search-input {
    flex: 1;
    max-width: 100px;
    height: 22px;
    padding: 0 8px;
    margin: 0 8px;
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.7rem;
    outline: none;
    transition: border-color 0.15s, max-width 0.2s;
}

.chat-thread-search-input:focus {
    border-color: var(--accent);
    max-width: 140px;
}

.chat-thread-search-input::placeholder {
    color: var(--text-muted);
}

.search-highlight {
    background: rgba(59, 130, 246, 0.4);
    color: var(--text-primary);
    border-radius: 2px;
    padding: 0 1px;
}

.chat-thread-items {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 0.5rem;
}

.chat-sidebar.chat-thread-list-open .chat-thread-list {
    flex: 1;
    max-height: none;
    border-bottom: none;
}

.chat-sidebar.chat-thread-list-open .chat-context-bar,
.chat-sidebar.chat-thread-list-open .chat-messages {
    display: none;
}

.chat-sidebar.chat-thread-list-open .chat-input-container {
    border-top: 1px solid var(--border-primary);
}

.chat-thread-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Chat Attachments - ChatGPT Style */
.chat-attachment {
    margin-bottom: 0.5rem;
    position: relative;
    display: inline-block;
}

.chat-attachment-img {
    max-width: 200px;
    max-height: 160px;
    border-radius: 1rem;
    cursor: pointer;
    transition: opacity 0.15s;
}

.chat-attachment-img:hover {
    opacity: 0.9;
}

/* Loading Message - ChatGPT Style */
.chat-message-loading {
    align-self: flex-start;
    padding: 0;
    min-height: 24px;
}

.chat-loading-dots {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: 1px;
}

.chat-loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: chatPulse 1.4s infinite ease-in-out both;
}

.chat-loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.chat-loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.chat-loading-dots span:nth-child(3) {
    animation-delay: 0s;
}

.chat-loading-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
}

.chat-loading-message {
    color: var(--text-muted);
    font-size: 0.85rem;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes chatPulse {

    0%,
    80%,
    100% {
        transform: scale(0.5);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Typing Cursor - shows during streaming */
.chat-typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--text-primary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: chatCursorBlink 0.8s infinite;
}

@keyframes chatCursorBlink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

/* Chat Tool Styles */
.chat-tool-call {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
}

.chat-tool-auto {
    margin: 0.5rem 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-tool-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.chat-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.15s;
}

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

.chat-tool-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

.chat-tool-btn i {
    width: 16px;
    height: 16px;
}

.chat-tool-btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.5rem 0.75rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
}

.chat-tool-btn-secondary:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.chat-tool-btn-secondary i {
    width: 14px;
    height: 14px;
}

.chat-tool-args {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.chat-tool-prompt {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    font-style: italic;
    border-left: 3px solid var(--primary);
}

.chat-tool-model,
.chat-tool-num-images {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

.chat-tool-model:focus,
.chat-tool-num-images:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-tool-status {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tool-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.tool-success {
    color: var(--success, #22c55e);
}

.tool-error {
    color: var(--error, #ef4444);
}

.tool-history-note {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-style: italic;
}

.chat-tool-model-label {
    padding: 0.25rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chat-tool-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.chat-tool-label i {
    width: 14px;
    height: 14px;
}

.chat-tool-results {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* Metadata display */
.chat-tool-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* Image grid for multiple images */
.chat-tool-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.chat-tool-img-wrap {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    max-width: 140px;
}

.chat-tool-img {
    display: block;
    width: 100%;
    height: auto;
    cursor: pointer;
    transition: filter 0.2s;
}

.chat-tool-img:hover {
    filter: brightness(1.1);
}

.chat-tool-img-info {
    padding: 0.5rem 0.6rem;
    background: var(--bg-tertiary);
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    border-top: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.chat-tool-img-info span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-tool-video {
    max-width: 300px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
    margin-top: 0.5rem;
}

/* Run results container (for multiple generations) */
.chat-tool-run-results {
    margin-bottom: 0.75rem;
}

.chat-tool-run-header {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-tool-run-header .run-model {
    font-weight: 500;
    color: var(--text-secondary);
}

.chat-tool-run-separator {
    height: 1px;
    background: var(--border-primary);
    margin: 0.75rem 0;
}

/* Motion Prompts Result */
.motion-prompts-result {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    border: 1px solid var(--border-primary);
}

.motion-analysis {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-primary);
}

.motion-shot-type {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--accent-primary);
    background: var(--accent-primary-alpha);
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    white-space: nowrap;
}

.motion-scene {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.motion-prompts-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.motion-prompt-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 0.375rem;
    border: 1px solid var(--border-secondary);
}

.motion-prompt-num {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
    min-width: 1.25rem;
    text-align: center;
}

.motion-prompt-text {
    flex: 1;
    font-size: 0.75rem;
    color: var(--text-primary);
    line-height: 1.5;
}

.motion-prompt-copy {
    background: none;
    border: none;
    padding: 0.25rem;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 0.25rem;
    opacity: 0.6;
    transition: opacity 0.2s, color 0.2s;
}

.motion-prompt-copy:hover {
    opacity: 1;
    color: var(--text-primary);
}

.motion-prompt-copy i {
    width: 14px;
    height: 14px;
}

.motion-prompts-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.motion-save-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--bg-primary);
    background: var(--accent-primary);
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.motion-save-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.motion-save-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.motion-save-btn.saved {
    background: var(--success);
    cursor: default;
}

.motion-save-btn i {
    width: 14px;
    height: 14px;
}

.motion-story-potential {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 0.375rem;
    margin-bottom: 0.75rem;
    font-style: italic;
}

.motion-category {
    margin-bottom: 0.75rem;
    border: 1px solid var(--border-primary);
    border-radius: 0.5rem;
    overflow: hidden;
}

.motion-category-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--bg-secondary);
}

.motion-category-header i {
    width: 14px;
    height: 14px;
}

.motion-category-header.camera-only {
    color: var(--success);
}

.motion-category-header.add-action {
    color: var(--warning);
}

.motion-category-header.add-character {
    color: var(--accent-primary);
}

.motion-category-badge {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
    margin-left: auto;
}

.motion-category-badge.safe {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.motion-category-badge.medium {
    background: rgba(234, 179, 8, 0.2);
    color: var(--warning);
}

.motion-category-badge.bold {
    background: var(--accent-primary-alpha);
    color: var(--accent-primary);
}

.motion-category-warning {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.7rem;
    color: var(--warning);
    background: rgba(234, 179, 8, 0.1);
    border-bottom: 1px solid var(--border-primary);
}

.motion-category-warning i {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.motion-category .motion-prompts-list {
    padding: 0.5rem;
    margin: 0;
}

/* Chat Lightbox */
.chat-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-lightbox-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.chat-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chat-lightbox-content img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.chat-lightbox-info {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    flex-wrap: wrap;
    justify-content: center;
}

.chat-lightbox-sep {
    color: var(--text-muted);
    opacity: 0.5;
}

.chat-lightbox-filename {
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.chat-lightbox-model {
    color: var(--primary);
}

.chat-lightbox-run {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* Navigation buttons */
.chat-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: white;
    cursor: pointer;
    padding: 1rem 0.75rem;
    opacity: 0.7;
    transition: opacity 0.15s, background 0.15s;
    border-radius: var(--radius-md);
}

.chat-lightbox-nav:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.8);
}

.chat-lightbox-prev {
    left: -4rem;
}

.chat-lightbox-next {
    right: -4rem;
}

.chat-lightbox-count {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

.chat-lightbox-close {
    position: absolute;
    top: -2.5rem;
    right: 0;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.chat-lightbox-close:hover {
    opacity: 1;
}

.chat-lightbox-open {
    position: absolute;
    top: -2.5rem;
    right: 2.5rem;
    color: white;
    padding: 0.5rem;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.chat-lightbox-open:hover {
    opacity: 1;
}

.chat-lightbox-actions {
    position: absolute;
    bottom: -3rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
}

.chat-lightbox-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.chat-lightbox-action-btn:hover {
    background: var(--primary-hover);
}

.chat-lightbox-action-btn i {
    width: 16px;
    height: 16px;
}

.chat-ref-item {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

.chat-ref-item code {
    font-family: var(--font-mono);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* === Inline Image Grids for Chat === */

/* Runs list grid */
.chat-inline-runs {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.75rem;
    max-width: 100%;
}

.chat-inline-run {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    border: 1px solid var(--border-primary);
}

.chat-inline-run-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
}

.chat-inline-run-id {
    font-family: var(--font-mono);
    background: var(--bg-secondary);
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
    color: var(--primary);
}

.chat-inline-run-model {
    color: var(--text-muted);
}

.chat-inline-run-count {
    color: var(--text-muted);
    margin-left: auto;
}

/* Inline images grid */
.chat-inline-images {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chat-inline-img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    border: 1px solid var(--border-primary);
}

.chat-inline-img:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.chat-inline-more {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.75rem;
    border: 1px solid var(--border-primary);
}

/* DAM search results in chat */
.chat-dam-results {
    margin-top: 0.5rem;
}

.chat-dam-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.chat-dam-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.chat-dam-thumb {
    aspect-ratio: 1;
    cursor: pointer;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.15s;
}

.chat-dam-thumb:hover {
    border-color: var(--accent-primary);
    transform: scale(1.02);
}

.chat-dam-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-dam-no-results {
    color: var(--text-muted);
    font-style: italic;
    padding: 0.5rem 0;
}

.chat-dam-view-all {
    color: var(--accent-primary);
    text-decoration: none;
    margin-left: 0.5rem;
    font-weight: 500;
}

.chat-dam-view-all:hover {
    text-decoration: underline;
}

/* Enhanced DAM search results with metadata */
.chat-dam-grid-enhanced {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}

.chat-dam-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-light);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-dam-card:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.chat-dam-card .chat-dam-thumb {
    aspect-ratio: 1;
    position: relative;
    border-radius: 0;
    border: none;
    overflow: hidden;
}

.dam-type-badges {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 2px;
}

.dam-type-badge {
    font-size: 0.6rem;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
}

.dam-type-badge.style {
    background: rgba(139, 92, 246, 0.9);
    color: white;
}

.dam-type-badge.context {
    background: rgba(34, 197, 94, 0.9);
    color: white;
}

.dam-card-info {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.dam-card-id {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}

.dam-card-id code {
    font-size: 0.65rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 2px 4px;
    border-radius: 3px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dam-card-id:hover code {
    color: var(--accent-primary);
}

.dam-copy-icon {
    width: 12px;
    height: 12px;
    color: var(--text-muted);
    opacity: 0.5;
}

.dam-card-id:hover .dam-copy-icon {
    opacity: 1;
    color: var(--accent-primary);
}

.dam-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.dam-tag {
    font-size: 0.6rem;
    padding: 1px 4px;
    background: var(--bg-secondary);
    border-radius: 3px;
    color: var(--text-secondary);
}

/* No results suggestions */
.chat-dam-no-results {
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

.no-results-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.no-results-tip {
    font-size: 0.8rem;
    color: var(--accent-primary);
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.no-results-filters {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
}

.filter-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-right: 0.25rem;
}

.filter-chip {
    font-size: 0.7rem;
    padding: 2px 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.filter-chip:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* Full image grid for show_run */
.chat-inline-images-full {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.chat-inline-img-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-inline-img-wrap .chat-inline-img {
    width: 120px;
    height: 120px;
}

.chat-inline-img-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-inline-video {
    max-width: 200px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
}

/* Favorites grid */
.chat-inline-favorites {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.chat-inline-fav-slot {
    position: relative;
}

.chat-inline-fav-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background: var(--primary);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    z-index: 1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.chat-inline-fav-slot .chat-inline-img {
    width: 100px;
    height: 100px;
}

/* Cross-project search results grid */
.chat-inline-search-results {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.chat-inline-search-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.chat-inline-search-item .chat-inline-img {
    width: 100px;
    height: 100px;
}

.chat-inline-search-item .chat-inline-video {
    width: 140px;
    max-width: 140px;
}

.chat-inline-search-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.6rem;
    font-weight: 500;
    z-index: 1;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-inline-search-item.search-approved {
    box-shadow: 0 0 0 2px var(--success);
}

.chat-inline-search-item.search-rejected {
    opacity: 0.5;
}

/* ============ Canvas Panel ============ */
.canvas-panel {
    width: 380px;
    height: calc(100vh - 80px);
    max-height: 700px;
    display: flex;
    flex-direction: column;
    background: rgba(20, 20, 24, 0.90);
    backdrop-filter: blur(30px) saturate(1.4);
    -webkit-backdrop-filter: blur(30px) saturate(1.4);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    position: fixed;
    bottom: 24px;
    right: 440px;
    /* Position next to chat sidebar */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transition: transform 0.25s ease, opacity 0.25s ease;
    z-index: 98;
}

.canvas-panel.hidden {
    transform: translateX(20px);
    opacity: 0;
    pointer-events: none;
}

.canvas-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-primary);
    border-radius: 16px 16px 0 0;
}

.canvas-panel-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.canvas-panel-title svg {
    width: 18px;
    height: 18px;
    color: var(--primary);
}

.canvas-panel-actions {
    display: flex;
    gap: 0.25rem;
}

.canvas-panel-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.canvas-panel-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.canvas-panel-btn svg {
    width: 16px;
    height: 16px;
}

.canvas-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.canvas-panel-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

.canvas-panel-empty svg {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

.canvas-panel-empty p {
    margin: 0;
    font-size: 0.9rem;
}

.canvas-panel-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-primary);
    display: flex;
    justify-content: center;
}

.canvas-load-context-btn {
    width: 100%;
    justify-content: center;
}

.canvas-load-context-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Canvas List View */
.canvas-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.canvas-list-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.canvas-list-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

.canvas-list-title {
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.canvas-list-title svg {
    width: 14px;
    height: 14px;
    color: var(--primary);
}

.canvas-list-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.canvas-list-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

/* Canvas Single View */
.canvas-view-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-primary);
}

.canvas-view-back {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}

.canvas-view-back:hover {
    color: var(--text-primary);
}

.canvas-view-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    margin: 0;
}

.canvas-blocks {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Canvas Block Styles */
.canvas-block {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
}

.canvas-block-text {
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.5;
}

.canvas-block-heading {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
    border-left: 3px solid var(--primary);
    padding-left: 0.75rem;
}

.canvas-block-image {
    padding: 0;
    overflow: hidden;
}

.canvas-block-image img {
    width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
    transition: transform 0.2s;
}

.canvas-block-image img:hover {
    transform: scale(1.02);
}

.canvas-block-image-info {
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.canvas-block-image-caption {
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.canvas-block-video {
    padding: 0;
    overflow: hidden;
}

.canvas-block-video video {
    width: 100%;
    display: block;
}

.canvas-block-copy {
    position: relative;
}

.canvas-block-copy-text {
    font-size: 1rem;
    color: var(--text-primary);
    font-style: italic;
    line-height: 1.5;
}

.canvas-block-copy-status {
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

.canvas-block-copy-status.draft {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.canvas-block-copy-status.approved {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.canvas-block-copy-status.rejected {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error);
}

.canvas-block-shot {
    border-left: 3px solid var(--warning);
}

.canvas-block-shot-desc {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.canvas-block-shot-prompt {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Canvas indicator in chat messages */
.chat-canvas-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--primary);
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 0.5rem;
}

.chat-canvas-indicator:hover {
    background: rgba(59, 130, 246, 0.25);
}

.chat-canvas-indicator svg {
    width: 12px;
    height: 12px;
}

/* Canvas context link in chat - document icon linking back to canvas */
.chat-canvas-context-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    margin-top: 0.75rem;
}

.chat-canvas-context-link:hover {
    background: var(--bg-secondary);
    border-color: var(--primary);
}

.chat-canvas-context-link svg {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

/* Responsive */
@media (max-width: 900px) {
    .canvas-panel {
        right: 24px;
        width: calc(100% - 48px);
        max-width: 380px;
    }
}


/* Chat shell mount */
#chat-root {
    position: fixed;
    right: 0;
    bottom: 0;
    z-index: 1000;
    pointer-events: none;
}

#chat-root #chat-sidebar,
#chat-root #chat-bubble-btn,
#chat-root #chat-lightbox,
#chat-root .chat-skill-menu {
    pointer-events: auto;
}

.chat-shell-error {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 0.65rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
}

/* Slash skills menu */
#chat-root .chat-skill-menu {
    margin-top: 0.5rem;
    border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.12));
    border-radius: 10px;
    background: var(--bg-secondary, #1b1d23);
    max-height: 260px;
    overflow-y: auto;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
    position: absolute;
    left: 1rem;
    right: 1rem;
    bottom: calc(100% + 0.45rem);
    margin-top: 0;
    z-index: 1100;
}

#chat-root .chat-skill-menu.hidden {
    display: none;
}

#chat-root .chat-skill-item {
    all: unset;
    box-sizing: border-box;
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.52rem 0.7rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-primary, #eceff5);
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1.2;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

#chat-root .chat-skill-item:last-child {
    border-bottom: 0;
}

#chat-root .chat-skill-item:hover,
#chat-root .chat-skill-item.selected {
    background: rgba(255, 255, 255, 0.09);
}

#chat-root .chat-skill-name {
    font-weight: 700;
    letter-spacing: 0.01em;
}

#chat-root .chat-skill-risk {
    font-size: 0.66rem;
    font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
    color: #ffcc78;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.1rem 0.35rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 204, 120, 0.35);
}

#chat-root .chat-skill-empty {
    padding: 0.7rem;
    color: var(--text-muted, #9ba6b6);
    font-size: 0.78rem;
}

@media (max-width: 600px) {
    .chat-input-container {
        padding: 0.65rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
    }

    #chat-root .chat-skill-menu {
        left: 0.75rem;
        right: 0.75rem;
        bottom: calc(100% + 0.35rem);
        max-height: min(42dvh, 340px);
    }

    .chat-thread-list {
        max-height: min(44dvh, 360px);
    }

    .chat-sidebar.chat-thread-list-open .chat-thread-list {
        max-height: none;
    }
}

/* Assistant attachments */
.chat-attachments {
    display: grid;
    gap: 0.45rem;
    margin-top: 0.45rem;
}

.chat-attachment {
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.16);
}

.chat-attachment-img,
.chat-attachment-video-el {
    width: 100%;
    height: auto;
    display: block;
    max-height: 320px;
    object-fit: cover;
}

.chat-attachment-audio-el {
    width: 100%;
    display: block;
}

.chat-attachment-caption {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary, #adb7c6);
}

.chat-attachment-file a {
    display: block;
    padding: 0.5rem 0.6rem;
    color: var(--accent, #89b4fa);
    text-decoration: none;
    font-size: 0.8rem;
}

.chat-attachment-file a:hover {
    text-decoration: underline;
}
