/**
 * ChatV2 Styles
 * 
 * Minimalistic, monochrome chat UI.
 * Prompt bar replicates chat v1 for easy migration.
 */

/* ============================================
   ChatV2 Mode - Hide Legacy UI
   ============================================ */

body.chatv2-mode .tips-modal,
body.chatv2-mode .tips-modal-content,
body.chatv2-mode .tips-prompt-protection-layer,
body.chatv2-mode .inspirational-prompt,
body.chatv2-mode .chat-container:not(#chatContainerV2),
body.chatv2-mode .main-content > .input-section:not(#chatContainerV2 .input-section) {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ============================================
   Container
   ============================================ */

#chatContainerV2 {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: transparent;
}

/* ============================================
   Prompt Bar - Panel Aware (left only)
   ============================================ */

.prompt-area {
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sidebar open: shift prompt bar right */
.sidebar.open ~ .main-content .prompt-area {
    margin-left: var(--sidebar-width, 330px);
}

@media (max-width: 768px) {
    .sidebar.open ~ .main-content .prompt-area {
        margin-left: 0;
    }
}

#chatContainerV2 .chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 20px 16px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Minimal scrollbar */
#chatContainerV2 .chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

#chatContainerV2 .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* ============================================
   Message - Base
   ============================================ */

#chatContainerV2 .message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 85%;
}

/* User messages - right aligned */
#chatContainerV2 .message.user {
    align-self: flex-end;
    flex-direction: row;
}

#chatContainerV2 .message.user .message-avatar {
    order: 2;
}

#chatContainerV2 .message.user .message-content {
    order: 1;
}

/* Assistant messages - left aligned */
#chatContainerV2 .message.assistant {
    align-self: flex-start;
    flex-direction: row;
}

/* ============================================
   Avatar - Circular
   ============================================ */

#chatContainerV2 .message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    background-size: cover;
    background-position: center;
}

/* User avatar */
#chatContainerV2 .message.user .message-avatar {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
}

/* Assistant avatar */
#chatContainerV2 .message.assistant .message-avatar {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.7);
}

#chatContainerV2 .message.assistant .message-avatar svg {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

/* ============================================
   Message Content - Pill Bubble
   ============================================ */

#chatContainerV2 .message-content {
    padding: 10px 14px;
    border-radius: 18px;
    max-width: 100%;
}

/* User bubble */
#chatContainerV2 .message.user .message-content {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 18px 18px 4px 18px;
}

/* Assistant bubble */
#chatContainerV2 .message.assistant .message-content {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 18px 18px 18px 4px;
}

/* ============================================
   Message Text
   ============================================ */

#chatContainerV2 .message-text {
    font-size: 14px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.88);
    word-wrap: break-word;
}

#chatContainerV2 .message-text code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
}

#chatContainerV2 .message-text pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

#chatContainerV2 .message-text pre code {
    background: none;
    padding: 0;
}

#chatContainerV2 .message-time {
    display: none;
}

/* ============================================
   Image Previews
   ============================================ */

#chatContainerV2 .image-previews {
    display: flex;
    gap: 6px;
    padding: 8px 0;
    overflow-x: auto;
}

#chatContainerV2 .image-preview-item {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

#chatContainerV2 .image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#chatContainerV2 .image-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

#chatContainerV2 .image-preview-item:hover .image-preview-remove {
    opacity: 1;
}

/* ============================================
   Message Images
   ============================================ */

#chatContainerV2 .message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    margin-bottom: 6px;
}

#chatContainerV2 .message-image,
#chatContainerV2 .generated-image,
#chatContainerV2 .message-images img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#chatContainerV2 .message-image:hover,
#chatContainerV2 .generated-image:hover,
#chatContainerV2 .message-images img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Single large image - still constrained */
#chatContainerV2 .message-images:has(img:only-child) img {
    max-width: 280px;
    max-height: 280px;
}

/* Mobile: smaller images */
@media (max-width: 600px) {
    #chatContainerV2 .message-image,
    #chatContainerV2 .generated-image,
    #chatContainerV2 .message-images img {
        max-width: 160px;
        max-height: 160px;
    }
    
    #chatContainerV2 .message-images:has(img:only-child) img {
        max-width: 220px;
        max-height: 220px;
    }
}

/* ============================================
   User Attachments (uploaded images)
   ============================================ */

#chatContainerV2 .message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

#chatContainerV2 .attachment-item {
    display: inline-block;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

#chatContainerV2 .attachment-img {
    max-width: 180px;
    max-height: 180px;
    object-fit: cover;
    display: block;
    cursor: pointer;
    transition: transform 0.2s ease;
}

#chatContainerV2 .attachment-img:hover {
    transform: scale(1.02);
}

/* Single attachment - slightly larger */
#chatContainerV2 .message-attachments.single-attachment .attachment-img {
    max-width: 240px;
    max-height: 240px;
}

/* Multiple attachments - smaller */
#chatContainerV2 .message-attachments.multi-attachment .attachment-img {
    max-width: 150px;
    max-height: 150px;
}

/* Mobile: smaller attachments */
@media (max-width: 600px) {
    #chatContainerV2 .attachment-img {
        max-width: 140px;
        max-height: 140px;
    }
    
    #chatContainerV2 .message-attachments.single-attachment .attachment-img {
        max-width: 200px;
        max-height: 200px;
    }
}

/* ============================================
   Thinking Dots - Animated
   ============================================ */

#chatContainerV2 .thinking-message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    align-self: flex-start;
}

#chatContainerV2 .thinking-content {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 18px 18px 18px 4px;
}

#chatContainerV2 .thinking-dots {
    display: flex;
    gap: 4px;
}

#chatContainerV2 .thinking-dots span {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: thinkingPulse 1.4s infinite ease-in-out;
}

#chatContainerV2 .thinking-dots span:nth-child(1) { animation-delay: 0s; }
#chatContainerV2 .thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
#chatContainerV2 .thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinkingPulse {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.85);
    }
    30% {
        opacity: 1;
        transform: scale(1.1);
    }
}

/* ============================================
   Prompt Area - Replica of Chat v1
   ============================================ */

#chatContainerV2 .prompt-area {
    flex-shrink: 0;
    padding: 12px 12px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

/* Message Input Container - Exact replica of v1 */
#chatContainerV2 .message-input-container {
    display: flex;
    gap: 8px;
    align-items: center;
    /* Glass blur effect - matching v1 */
    background: rgba(5, 5, 5, 0.75);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 322px;
    padding: 8px;
    /* No max-width - expand to fill available space */
    width: 100%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#chatContainerV2 .message-input-container:focus-within {
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* Plus Button - v1 style */
#chatContainerV2 #addImageBtnV2 {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    font-size: 24px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chatContainerV2 #addImageBtnV2:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
    transform: scale(1.02);
}

/* Text Input - v1 style */
#chatContainerV2 #chatInputV2 {
    flex: 1;
    min-height: 24px;
    max-height: 150px;
    resize: none;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.95);
    font-size: 15px;
    line-height: 1.4;
    padding: 12px 8px;
    font-family: inherit;
}

#chatContainerV2 #chatInputV2:focus {
    outline: none;
}

#chatContainerV2 #chatInputV2::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

/* Send Button - v1 style */
#chatContainerV2 #sendBtnV2 {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(96, 165, 250, 0.9);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chatContainerV2 #sendBtnV2:hover {
    background: rgba(96, 165, 250, 0.95);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
    transform: scale(1.03);
}

#chatContainerV2 #sendBtnV2:active {
    transform: scale(0.98);
}

#chatContainerV2 #sendBtnV2:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ============================================
   Intent/Confirmation Messages
   ============================================ */

#chatContainerV2 .message.assistant.intent-message .message-content,
#chatContainerV2 .message.assistant[data-confirmation="true"] .message-content {
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: rgba(255, 255, 255, 0.85);
}

#chatContainerV2 .message.assistant.intent-message .message-text::before,
#chatContainerV2 .message.assistant[data-confirmation="true"] .message-text::before {
    content: "▶ ";
    color: rgba(59, 130, 246, 0.8);
}

/* ============================================
   Reasoning Message (Typing Effect)
   ============================================ */

#chatContainerV2 .message.reasoning-message {
    animation: fadeInUp 0.3s ease;
}

#chatContainerV2 .reasoning-content {
    background: rgba(139, 92, 246, 0.06) !important;
    border: 1px solid rgba(139, 92, 246, 0.15) !important;
    font-size: 13px;
}

#chatContainerV2 .reasoning-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 11px;
    color: rgba(139, 92, 246, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#chatContainerV2 .reasoning-icon {
    font-size: 14px;
}

#chatContainerV2 .reasoning-text {
    color: rgba(255, 255, 255, 0.75);
    line-height: 1.5;
    font-style: italic;
}

#chatContainerV2 .reasoning-text::after {
    content: '▋';
    animation: blink 0.8s infinite;
    color: rgba(139, 92, 246, 0.6);
    margin-left: 2px;
}

#chatContainerV2 .reasoning-text.typing-done::after {
    display: none;
}

#chatContainerV2 .reasoning-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

#chatContainerV2 .reasoning-meta span {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.5);
}

#chatContainerV2 .meta-type {
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#chatContainerV2 .meta-confidence {
    color: rgba(16, 185, 129, 0.8) !important;
    background: rgba(16, 185, 129, 0.1) !important;
}

#chatContainerV2 .meta-tool {
    color: rgba(59, 130, 246, 0.8) !important;
    background: rgba(59, 130, 246, 0.1) !important;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Error
   ============================================ */

#chatContainerV2 .error-message,
#chatContainerV2 .message.error .message-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(255, 80, 80, 0.1);
    border: 1px solid rgba(255, 80, 80, 0.2);
    border-radius: 12px;
    color: rgba(255, 120, 120, 0.9);
    font-size: 13px;
}

/* ============================================
   Quality Check Indicator (cancellable)
   ============================================ */

#chatContainerV2 .quality-check-indicator {
    display: flex;
    justify-content: flex-start;
    padding: 8px 16px;
    animation: fadeIn 0.3s ease;
}

#chatContainerV2 .qci-content {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 8px 16px;
}

#chatContainerV2 .qci-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: rgba(139, 92, 246, 0.8);
    border-radius: 50%;
    animation: qci-spin 0.8s linear infinite;
}

#chatContainerV2 .qci-text {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
}

#chatContainerV2 .qci-cancel {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: all 0.2s ease;
}

#chatContainerV2 .qci-cancel:hover {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
}

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

/* Quality Feedback Messages */
#chatContainerV2 .message.quality-feedback .message-content {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

#chatContainerV2 .message.quality-issue .message-content {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.2);
}

/* Image-only results (clean display) */
#chatContainerV2 .message.image-result .message-content {
    background: transparent;
    padding: 4px;
}

/* ============================================
   Loading & Scroll
   ============================================ */

#chatContainerV2 .scroll-sentinel {
    height: 1px;
    pointer-events: none;
}

#chatContainerV2 .loading-older {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
}

#chatContainerV2 .loading-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

#chatContainerV2 .no-more-messages {
    text-align: center;
    padding: 12px;
    color: rgba(255, 255, 255, 0.25);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   Empty State
   ============================================ */

#chatContainerV2 .chat-messages:empty::after {
    content: '';
}

/* ============================================
   Drag Over
   ============================================ */

#chatContainerV2 .chat-messages.drag-over::before {
    content: 'Drop image';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ============================================
   Responsive
   ============================================ */

@media (min-width: 1024px) {
    #chatContainerV2 .message {
        max-width: 70%;
    }
    
    #chatContainerV2 .chat-messages {
        padding: 24px 20px;
    }
    
    #chatContainerV2 .prompt-area {
        padding: 12px 12px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 600px) {
    #chatContainerV2 .message {
        max-width: 90%;
    }
    
    #chatContainerV2 .message-avatar {
        width: 24px;
        height: 24px;
        font-size: 10px;
    }
    
    #chatContainerV2 .message-content {
        padding: 8px 12px;
    }
    
    #chatContainerV2 .message-text {
        font-size: 13px;
    }
    
    #chatContainerV2 #addImageBtnV2,
    #chatContainerV2 #sendBtnV2 {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    #chatContainerV2 .message-input-container {
        padding: 6px;
    }
}

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    #chatContainerV2 .thinking-dots span,
    #chatContainerV2 .loading-spinner {
        animation: none;
    }
}
