/**
 * Vigthoria Prompt Studio - Final Fixes
 * Fixes for AI Assistant, Simple Mode layout, and animations
 * Date: October 6, 2025
 */

/* ============================================
   1. SIMPLE MODE LAYOUT FIX - Prevent Content Cutoff
   ============================================ */

.simple-mode {
    min-height: calc(100vh - 80px); /* Ensure full viewport coverage */
    padding-bottom: 60px; /* Extra padding at bottom */
    overflow-y: auto; /* Enable scrolling */
}

.simple-mode .simple-container {
    max-height: none !important; /* Remove max-height restriction */
    padding-bottom: 40px; /* Add bottom padding */
}

.simple-description {
    margin-bottom: 30px; /* More space below description */
}

.advanced-generate-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.advanced-generate-toolbar .advanced-generate-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding-inline: 18px;
}

.advanced-generate-toolbar .advanced-generate-hint {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.75);
}

.simple-form-layout {
    padding-bottom: 40px; /* Ensure form doesn't get cut off */
}

/* Fix for "Choose your technology" section */
.simple-mode .technology-group {
    margin-bottom: 25px; /* More space */
    padding-bottom: 15px;
}

/* Fix for generate button area */
.simple-mode .generate-group {
    margin-top: 30px;
    padding-top: 20px;
    padding-bottom: 30px; /* Extra padding at bottom */
}

/* Ensure simple generated prompt area has space */
.simple-generated-prompt {
    margin-top: 30px;
    margin-bottom: 40px; /* Space below */
    padding-bottom: 20px;
}

/* ============================================
   2. PROMPT AREA UPDATE ANIMATION
   ============================================ */

/* Highlight animation when prompt fields are updated by AI */
@keyframes promptFieldUpdate {
    0% {
        background: linear-gradient(135deg, rgba(var(--accent-rgb), 0.1), rgba(var(--accent-rgb), 0.05));
        box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.3);
        transform: scale(1);
    }
    50% {
        background: linear-gradient(135deg, rgba(var(--accent-rgb), 0.15), rgba(var(--accent-rgb), 0.08));
        box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.4), 0 4px 12px rgba(var(--accent-rgb), 0.2);
        transform: scale(1.01);
    }
    100% {
        background: var(--bg-secondary);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        transform: scale(1);
    }
}

/* Apply to form fields when updated */
.form-group.ai-updated textarea,
.form-group.ai-updated input {
    animation: promptFieldUpdate 0.8s ease-out;
    transition: all 0.3s ease;
}

/* Pulse effect for updated fields */
.form-group.ai-updated label::before {
    content: '✨ ';
    animation: labelPulse 2s ease-in-out;
}

@keyframes labelPulse {
    0%, 100% { opacity: 0; transform: scale(0.5); }
    50% { opacity: 1; transform: scale(1); }
}

/* Glow effect for the entire form when AI updates */
.advanced-mode.ai-updating {
    position: relative;
}

.advanced-mode.ai-updating::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, 
        transparent,
        rgba(var(--accent-rgb), 0.1),
        transparent
    );
    border-radius: 12px;
    animation: glowSweep 2s ease-in-out;
    pointer-events: none;
    z-index: 0;
}

@keyframes glowSweep {
    0% { opacity: 0; transform: translateX(-100%); }
    50% { opacity: 1; }
    100% { opacity: 0; transform: translateX(100%); }
}

/* ============================================
   3. AI ASSISTANT AUTO-SCROLL IMPROVEMENTS
   ============================================ */

/* Smooth scroll behavior for AI chat */
#aiChat,
.ai-assistant-body {
    scroll-behavior: smooth;
}

/* Ensure messages area is scrollable */
.messages-area {
    max-height: calc(100% - 120px);
    overflow-y: auto;
    scroll-behavior: smooth;
    padding-bottom: 20px;
}

/* New message indicator */
.ai-message.new-message {
    animation: newMessageSlide 0.4s ease-out;
}

@keyframes newMessageSlide {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Auto-scroll indicator (shows when not at bottom) */
.ai-scroll-indicator {
    position: absolute;
    bottom: 80px;
    right: 20px;
    background: var(--accent-primary);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: scrollBounce 1s ease-in-out infinite;
    z-index: 100;
    display: none; /* Hidden by default, shown via JS */
}

.ai-scroll-indicator.show {
    display: flex;
    align-items: center;
    gap: 6px;
}

@keyframes scrollBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* ============================================
   4. TYPING INDICATOR IMPROVEMENTS
   ============================================ */

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(var(--accent-rgb), 0.05);
    border-radius: 12px;
    margin: 10px 0;
    animation: typingFadeIn 0.3s ease-out;
}

@keyframes typingFadeIn {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.typing-indicator .dot {
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: typingDotPulse 1.4s ease-in-out infinite;
}

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

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

@keyframes typingDotPulse {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.7;
    }
    30% {
        transform: scale(1.3);
        opacity: 1;
    }
}

/* ============================================
   5. PROMPT SYNC VISUAL FEEDBACK
   ============================================ */

/* When prompt is synced from AI to main editor */
.prompt-syncing {
    position: relative;
    overflow: hidden;
}

.prompt-syncing::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        transparent,
        rgba(var(--accent-rgb), 0.2),
        transparent
    );
    animation: syncSweep 1s ease-out;
}

@keyframes syncSweep {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Success checkmark animation */
.sync-success-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--success-color, #10b981);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    animation: badgePopIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

@keyframes badgePopIn {
    0% {
        opacity: 0;
        transform: scale(0.5) rotate(-10deg);
    }
    70% {
        transform: scale(1.1) rotate(5deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

/* ============================================
   6. RESPONSIVE FIXES FOR SIMPLE MODE
   ============================================ */

@media (max-width: 768px) {
    .simple-mode {
        padding: 20px 15px 80px;
    }
    
    .simple-mode .simple-container {
        padding: 25px 20px 60px;
    }
    
    .simple-description {
        margin-bottom: 20px;
    }
    
    .simple-mode .generate-group {
        padding-bottom: 50px; /* Extra space on mobile */
    }
}

/* ============================================
   7. SCROLL TO TOP BUTTON FOR SIMPLE MODE
   ============================================ */

.simple-scroll-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    z-index: 1000;
    display: none; /* Hidden by default */
}

/* ============================================
   8. ADVANCED MODE VISION INPUT HIGHLIGHT
   ============================================ */

.vision-input-group {
    border: 1px dashed rgba(var(--accent-rgb), 0.4);
    border-radius: 12px;
    padding: 18px;
    background: rgba(var(--accent-rgb), 0.05);
    transition: border-color 0.3s ease, background 0.3s ease;
    position: relative;
}

.vision-input-group::before {
    content: 'Vision Priority';
    position: absolute;
    top: -12px;
    left: 18px;
    background: var(--bg-primary);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    padding: 4px 10px;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

body.template-active .vision-input-group,
body[data-template-default="true"] .vision-input-group {
    border-color: rgba(var(--accent-rgb), 0.8);
    background: rgba(var(--accent-rgb), 0.08);
}

.vision-input-group textarea {
    min-height: 140px;
    resize: vertical;
}

.simple-scroll-top.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeInUp 0.3s ease-out;
}

.simple-scroll-top:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

@keyframes fadeInUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}
