/*
 * SLS Interview Fullscreen Chat Styles
 * Sprint 7: Dedicated fullscreen chat interface (ChatGPT-style)
 */

/* ===========================================
   FULLSCREEN CHAT - BASE STYLES
   Sprint 10: Viewport-fixed on desktop too (no page scroll)
   =========================================== */

/* Sprint 10: Reduce space above chat for viewport-fixed layout */
.woocommerce-account .woocommerce-MyAccount-content:has(.sls-chat-fullscreen) h2 {
    margin-top: 10px !important;
    margin-bottom: 10px !important;
}

/* Sprint 10: Remove styling from workflow-interface-container when it has chat */
.sls-workflow-interface-container:has(.sls-chat-fullscreen) {
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: none !important;
    box-shadow: none !important;
}

/* Desktop: Fixed viewport - no page scrolling, only chat scrolls */
.sls-chat-fullscreen {
    position: fixed;
    top: 110px; /* Sprint 10: Account for "My Song" title (40px) + spacing (70px) */
    left: 340px; /* Left nav (280px) + padding (60px) */
    right: 60px; /* Right padding to match left */
    bottom: 20px; /* Sprint 10: Footer hidden, just need spacing from bottom */
    display: flex;
    flex-direction: column;
    max-width: 1000px;
    margin: 0 auto;
    background: var(--sls-black);
    overflow: hidden; /* Container doesn't scroll */
}

.sls-chat-fullscreen .sls-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    scroll-behavior: smooth;
}

/* Chat Messages */
.sls-chat-message {
    display: flex;
    align-items: flex-start;
    margin-bottom: 24px;
    animation: slideIn 0.3s ease;
}

.sls-chat-message.assistant {
    justify-content: flex-start;
}

.sls-chat-message.user {
    justify-content: flex-end;
}

.sls-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
}

.sls-message-bubble {
    max-width: 70%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
}

.sls-chat-message.assistant .sls-message-bubble {
    background: var(--sls-dark-gray);
    color: var(--sls-text-light);
    border: 1px solid var(--sls-border);
}

.sls-chat-message.user .sls-message-bubble {
    background: var(--sls-gradient-primary);
    color: white;
    border: none;
}

/* Typing Indicator */
.sls-typing-indicator {
    display: flex;
    align-items: center;
    padding: 0 !important; /* Bug #9 Fix: No padding to prevent dark bar appearance */
    margin: 0 0 15px 20px !important; /* Bug #9 Fix: Use margin instead for spacing */
    color: var(--sls-text-muted);
    font-size: 14px;
    background: transparent !important; /* Bug #6 Fix: Remove black background */
}

.sls-typing-dots {
    display: inline-flex;
    gap: 4px;
    margin-right: 8px;
}

.sls-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sls-purple);
    animation: bounce 1.4s infinite ease-in-out;
}

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

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

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Chat Input */
.sls-chat-fullscreen .sls-chat-input,
.sls-chat-input,
div.sls-chat-input {
    flex-shrink: 0 !important;
    padding: 20px !important;
    background: transparent !important; /* Bug #9 Fix: Transparent so typing indicator doesn't appear on dark bar */
    border-top: 1px solid var(--sls-border) !important;
    display: flex !important; /* Sprint 10: Override display:block so child grid works */
}

.sls-chat-input form,
#sls-chat-form {
    display: grid !important; /* Sprint 10: Grid instead of flex to force layout */
    grid-template-columns: 1fr auto !important; /* Sprint 10: Input takes remaining, button is auto */
    gap: 16px !important; /* Sprint 10: Space between input and button */
    align-items: center !important;
    max-width: 1000px !important;
    margin: 0 auto !important;
    width: 100% !important;
}

.sls-chat-input textarea,
#sls-message-input {
    grid-column: 1 !important; /* Sprint 10: First column in grid */
    min-height: 44px !important;
    max-height: 120px !important;
    height: 44px; /* Sprint 10: Starting height - grows to max-height via JS auto-expand */
    width: 100% !important; /* Sprint 10: Fill grid cell */
    padding: 12px 18px !important;
    margin-right: 10px !important; /* Sprint 10: Space from button since gap doesn't work */
    font-size: 15px !important;
    font-family: var(--sls-font-body) !important;
    line-height: 1.4 !important;
    color: var(--sls-text-light) !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid var(--sls-border) !important;
    border-radius: 22px !important;
    resize: none !important;
    overflow-y: auto !important;
    transition: border-color 0.2s ease, height 0.1s ease !important;
    box-sizing: border-box !important;
    align-self: end !important; /* Sprint 10: Anchor to bottom of grid cell, grow upward */
}

.sls-chat-input textarea:focus {
    outline: none;
    border-color: var(--sls-purple);
}

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

.sls-chat-input button,
#sls-send-button {
    grid-column: 2 !important; /* Sprint 10: Second column in grid */
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: var(--sls-gradient-primary) !important;
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    transition: transform 0.2s ease, opacity 0.2s ease !important;
    margin: 0 !important;
    padding: 0 !important;
}

.sls-chat-input button:hover {
    transform: scale(1.05);
}

.sls-chat-input button:active {
    transform: scale(0.95);
}

.sls-chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sls-chat-input button .send-text {
    display: none;
}

.sls-chat-input button .send-icon {
    font-size: 24px;
    font-weight: bold;
    color: white;
    transform: rotate(-90deg);
}

/* Bug #10 Fix: Desktop genre button transformation when interview complete */
.sls-chat-input button.sls-genre-button-desktop {
    grid-column: 1 / -1 !important; /* Span both columns */
    width: 100% !important;
    height: 52px !important;
    min-width: 100% !important;
    max-width: 100% !important;
    border-radius: 26px !important;
    font-size: 16px !important;
    font-weight: 600;
    background: var(--sls-gradient-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.sls-chat-input button.sls-genre-button-desktop:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 16px rgba(124, 58, 237, 0.4);
}

.sls-chat-input button.sls-genre-button-desktop:active {
    transform: scale(0.98);
}

/* Interview Status */
/* Sprint 10: Position as overlay on chat when interview complete */
.sls-interview-status {
    position: absolute;
    bottom: 80px; /* Above input area */
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    z-index: 10;
    pointer-events: none; /* Allow clicks through when hidden */
}

.sls-interview-status > div {
    padding: 24px;
    background: var(--sls-dark-gray);
    border: 2px solid var(--sls-blue);
    border-radius: var(--sls-border-radius);
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    pointer-events: auto; /* Re-enable clicks on the content */
}

.sls-interview-status h3 {
    font-size: 24px;
    color: var(--sls-blue);
    margin-bottom: 12px;
}

.sls-interview-status p {
    font-size: 16px;
    color: var(--sls-text-light);
    line-height: 1.6;
    margin-bottom: 12px;
}

/* Sprint 10 Bug Fix: Hide completion elements by default (WordPress strips inline display:none) */
#interview-ready-notice,
#interview-submitting,
#interview-complete-notice,
#sls-typing-indicator {
    display: none;
}

/* Sprint 10 Cleanup: Move inline styles to CSS (WordPress-safe) */
#genre-redirect-message {
    margin-top: 10px;
    font-style: italic;
}

#manual-proceed-btn {
    margin-top: 10px;
}

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

@media (max-width: 768px) {
    /* Sprint 7.5: Prevent body scroll on mobile - only chat messages should scroll */
    body:has(.sls-chat-fullscreen.sls-mobile-optimized) {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100vh !important;
    }

    /* Prevent parent containers from scrolling */
    .sls-chat-fullscreen.sls-mobile-optimized ~ *,
    .woocommerce-MyAccount-content:has(.sls-chat-fullscreen.sls-mobile-optimized) {
        overflow: hidden !important;
    }

    /* Position chat to fill remaining viewport */
    .sls-chat-fullscreen.sls-mobile-optimized {
        position: fixed;
        top: 132px; /* Nav (60px) + Title (52px) + Extra spacing (20px) */
        left: 20px;
        right: 20px;
        bottom: 20px; /* Match left/right spacing */
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        max-width: none !important;
        background: transparent;
        z-index: 1;
        overflow: hidden !important; /* Container itself should not scroll */
    }

    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-messages {
        padding: 12px;
        background: var(--sls-black);
        border-radius: 8px 8px 0 0;
        flex: 1 1 auto; /* Allow to grow and shrink */
        overflow-y: auto !important; /* Only this element scrolls */
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        height: auto !important;
        max-height: none !important;
        min-height: 0 !important;
    }

    /* Chat input should stick to bottom of container */
    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input {
        flex-shrink: 0 !important; /* Never shrink, stay at bottom */
        padding: 12px 12px 20px 12px; /* Extra bottom padding for mobile safe area */
        margin: 0;
        background: transparent;
        border: none;
        border-top: 1px solid var(--sls-border);
        border-radius: 0 0 8px 8px;
    }

    /* Hide interview status section on mobile - it's outside the fixed container */
    .sls-chat-fullscreen.sls-mobile-optimized .sls-interview-status {
        display: none !important;
    }

    /* CHATGPT STYLE: Hide avatar and timestamp on mobile */
    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-avatar {
        display: none !important;
    }

    /* CHATGPT STYLE: Assistant messages - full width, no bubble */
    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-message.assistant .sls-message-bubble {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        max-width: 100% !important;
        color: var(--sls-text-light);
        font-size: 15px;
        line-height: 1.6;
    }

    /* CHATGPT STYLE: User messages - keep subtle bubble */
    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-message.user .sls-message-bubble {
        background: rgba(255, 255, 255, 0.08) !important;
        border: 1px solid rgba(255, 255, 255, 0.12) !important;
        padding: 12px 16px !important;
        max-width: 85%;
        font-size: 15px;
        line-height: 1.5;
        border-radius: 18px !important;
    }

    /* Input area */
    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input {
        padding: 20px 10px 10px 10px !important;
    }

    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input form {
        gap: 8px;
    }

    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
        min-height: 44px;
        padding: 12px 16px;
        border-radius: 22px;
    }

    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input button {
        width: 44px;
        height: 44px;
    }

    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input button .send-icon {
        font-size: 20px;
    }

    /* Sprint 7.5: Transform send button into full-width genre button on mobile */
    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input button.sls-genre-button-mobile {
        width: 100% !important;
        height: 52px !important;
        border-radius: 26px !important;
        font-size: 16px !important;
        font-weight: 600;
        background: var(--sls-gradient-primary);
        color: white;
        box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
    }

    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input button.sls-genre-button-mobile:hover {
        transform: scale(1.02);
        box-shadow: 0 6px 16px rgba(124, 58, 237, 0.4);
    }

    .sls-chat-fullscreen.sls-mobile-optimized .sls-chat-input button.sls-genre-button-mobile:active {
        transform: scale(0.98);
    }

    /* Interview status */
    .sls-interview-status > div {
        padding: 16px;
    }

    .sls-interview-status h3 {
        font-size: 20px;
    }

    .sls-interview-status p {
        font-size: 14px;
    }
}

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