/* 
 * Chatbot Modern CSS - Horizon Design System Extension
 * Specific styles for AI chatbot interface
 */

/* Loading Screen */
.chatbot-loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, 
        var(--pc-color-primary) 0%, 
        var(--pc-color-secondary) 50%, 
        var(--pc-color-accent) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: loading-screen-fade-out 0.5s ease-out 3s forwards;
}

.loading-content {
    text-align: center;
    color: white;
    animation: loading-content-fade-in 0.8s ease-out;
}

.loading-icon {
    margin-bottom: var(--pc-spacing-24);
}

.loading-bot-icon {
    width: 80px;
    height: auto;
    animation: loading-icon-pulse 2s ease-in-out infinite;
    filter: drop-shadow(0 4px 20px rgba(255, 255, 255, 0.3));
}

.loading-text h2 {
    font-size: 28px;
    font-weight: 600;
    margin: 0 0 var(--pc-spacing-8) 0;
    background: linear-gradient(45deg, #ffffff, #f0f0f0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.loading-text p {
    font-size: 16px;
    margin: 0 0 var(--pc-spacing-32) 0;
    opacity: 0.9;
}

.loading-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--pc-spacing-8);
    font-size: 14px;
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.1);
    padding: var(--pc-spacing-12) var(--pc-spacing-16);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    animation: loading-notice-slide-up 0.8s ease-out 0.5s both;
}

.loading-notice svg {
    opacity: 0.9;
}

/* Loading Animations */
@keyframes loading-screen-fade-out {
    0% {
        opacity: 1;
        visibility: visible;
    }
    100% {
        opacity: 0;
        visibility: hidden;
    }
}

@keyframes loading-content-fade-in {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes loading-notice-slide-up {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 0.8;
        transform: translateY(0);
    }
}

/* Prevent body scroll on chatbot page */
body {
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    height: calc(var(--vh, 1vh) * 100); /* Fallback for older browsers */
}

/* Header overrides for chatbot page */
.header {
    height: 64px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.header-container {
    height: 100%;
    padding: 0 var(--pc-spacing-20);
}

/* Remove border-radius from header-brand to prevent logo clipping */
.header-brand {
    border-radius: 0 !important;
    overflow: visible !important;
}

/* Override horizon.css border-radius for logo */
.bot-logo {
    border-radius: 0 !important;
}

/* Main Chat Container - Full Height Layout */
.chat-main-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px); /* Dynamic viewport height */
    height: calc(var(--vh, 1vh) * 100 - 64px); /* Fallback with CSS variable */
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

/* Chat Messages Wrapper */
.chat-messages-wrapper {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding-bottom: 20px;
}

/* Chat Messages Container */
.chat-messages {
    max-width: 850px;
    margin: 0 auto;
    padding: var(--pc-spacing-32) var(--pc-spacing-20) var(--pc-spacing-48);
    display: flex;
    flex-direction: column;
    gap: var(--pc-spacing-32);
}

/* Message Styles */
.message {
    animation: messageSlideIn 0.3s ease-out;
}

.message-inner {
    display: flex;
    gap: var(--pc-spacing-12);
    align-items: flex-start;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--pc-glass-bg);
    border: 1px solid var(--pc-glass-border);
}

.message-content {
    flex: 0 1 auto;
}

.message-bubble {
    background: var(--pc-glass-bg);
    border: 1px solid var(--pc-glass-border);
    border-radius: var(--pc-radius-large);
    padding: var(--pc-spacing-16);
    line-height: 1.6;
    word-wrap: break-word;
}

/* User Message Styling */
.user-message .message-inner {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.user-message .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: 70%;
}

.user-message .message-bubble {
    background: rgba(0, 116, 255, 0.1);
    border-color: rgba(0, 116, 255, 0.2);
}

/* Bot Message Styling */
.bot-message .message-avatar {
    background: linear-gradient(135deg, var(--pc-primary-blue), var(--pc-legacy-blue));
}

.bot-message .bot-avatar-icon {
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(1); /* Make icon white */
}

/* User Avatar Styling */
.user-avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Keep white icon in light mode too */
.pc-light-mode .bot-message .bot-avatar-icon {
    filter: brightness(0) invert(1) !important;
}

/* Chat Input Wrapper - Fixed at Bottom */
.chat-input-wrapper {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, 
        var(--pc-bg-dark) 0%, 
        var(--pc-bg-dark) 60%, 
        rgba(0, 0, 0, 0.8) 90%, 
        transparent 100%
    );
    padding: var(--pc-spacing-20) 0 var(--pc-spacing-24);
    z-index: 10;
}

.chat-input-container {
    max-width: 850px;
    margin: 0 auto;
    padding: 0 var(--pc-spacing-20);
}

.chat-input-inner {
    background: var(--pc-glass-bg);
    border: 1px solid var(--pc-glass-border);
    border-radius: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    gap: var(--pc-spacing-8);
    transition: all 0.2s ease;
    min-height: 48px;
    box-sizing: border-box;
}

.chat-input-inner:focus-within {
    border-color: var(--pc-primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 116, 255, 0.1);
}

/* Chat Input Textarea */
.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--pc-text-primary);
    font-size: var(--pc-text-body);
    font-family: inherit;
    resize: none;
    outline: none;
    height: 48px;
    max-height: 120px;
    line-height: 48px;
    padding: 0 24px;
    overflow-y: auto;
    box-sizing: border-box;
}

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

/* Chat Actions */
.chat-input-actions {
    display: flex;
    gap: var(--pc-spacing-8);
    align-items: center;
    padding-right: var(--pc-spacing-8);
}

.chat-action-btn,
.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-action-btn {
    background: transparent;
    color: var(--pc-text-secondary);
}

.chat-action-btn:hover {
    background: var(--pc-glass-hover);
    color: var(--pc-text-primary);
}

.send-btn {
    background: var(--pc-primary-blue);
    color: white;
}

.send-btn:hover:not(:disabled) {
    background: var(--pc-hover-blue);
    transform: scale(1.05);
}

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

/* Input Hint */
.chat-input-hint {
    text-align: center;
}

/* Message Animation */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typing Indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--pc-text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

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

/* Scrollbar styling */
.chat-messages-wrapper::-webkit-scrollbar {
    width: 8px;
}

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

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

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

/* Message formatting */
.message-bubble {
    font-size: var(--pc-text-body);
}

.message-bubble strong {
    font-weight: 600;
    color: var(--pc-text-primary);
}

.message-bubble em {
    font-style: italic;
}

.message-bubble code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.message-bubble pre {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--pc-glass-border);
    border-radius: var(--pc-radius-medium);
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
}

.message-bubble pre code {
    background: transparent;
    padding: 0;
}

/* Theme Toggle Button */
.theme-toggle-btn {
    background: var(--pc-glass-bg);
    border: 1px solid var(--pc-glass-border);
    border-radius: var(--pc-radius-pill);
    color: var(--pc-text-primary);
    cursor: pointer;
    padding: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.theme-toggle-btn:hover {
    background: var(--pc-glass-hover);
    border-color: var(--pc-glass-border-strong);
}

.theme-icon {
    transition: opacity 0.2s ease;
}

.theme-icon-light {
    display: none;
}

.pc-light-mode .theme-icon-dark {
    display: none;
}

.pc-light-mode .theme-icon-light {
    display: block;
}

/* Logo Styling - Special filter for bot logo */
.bot-logo {
    filter: brightness(0) invert(1); /* Make gray parts white in dark mode */
}

/* Light mode adjustments */
.pc-light-mode .bot-logo {
    filter: none; /* Show original colors in light mode */
}

.pc-light-mode .chat-input-wrapper {
    background: linear-gradient(to top, 
        var(--pc-bg-light) 0%, 
        var(--pc-bg-light) 60%, 
        rgba(255, 255, 255, 0.8) 90%, 
        transparent 100%
    );
}

/* Fix header z-index to ensure it's above chat content */
.header {
    z-index: 100;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

/* Ensure smooth scrolling and proper layout */
.chat-messages-wrapper {
    scroll-behavior: smooth;
}


/* User avatar styling */
.user-message .message-avatar {
    background: var(--pc-glass-bg);
    border: 1px solid var(--pc-glass-border);
}

/* Mobile responsive */
/* Bot logo styling */
.bot-logo {
    filter: brightness(0) invert(1); /* Make gray parts white in dark mode */
    border-radius: 0 !important; /* Override pc-radius-low-height */
}

.pc-light-mode .bot-logo {
    filter: none; /* Keep original colors in light mode */
    border-radius: 0 !important;
}

@media (max-width: 768px) {
    .chat-main-container {
        top: 56px; /* Smaller header on mobile */
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px); /* Dynamic viewport height */
    }
    
    .header {
        height: 56px;
    }
    
    .chat-messages {
        padding: var(--pc-spacing-20) var(--pc-spacing-16);
        gap: var(--pc-spacing-20);
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .user-message .message-content {
        max-width: 85%;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
    }
    
    .bot-message .bot-avatar-icon {
        width: 20px;
        height: 20px;
    }
    
    .chat-input-container {
        padding: 0 var(--pc-spacing-16);
    }
    
    /* Keep same input style on mobile */
    .chat-input-inner {
        min-height: 48px;
        border-radius: 24px;
        padding: 0;
    }
    
    .chat-input {
        height: 48px;
        padding: 0 24px;
        line-height: 48px;
    }
    
    /* Smaller logo on mobile */
    .bot-logo {
        height: 14px !important;
        border-radius: 0 !important;
    }
    
    .header-nav-link:not(.active) {
        display: none;
    }
    
    .header-nav {
        gap: var(--pc-spacing-8);
    }
    
    .theme-toggle-btn {
        width: 32px;
        height: 32px;
    }
}

/* Loading animation for AI response */
.loading-response .message-bubble {
    position: relative;
    overflow: hidden;
}

.loading-response .message-bubble::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.05),
        transparent
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    to {
        left: 100%;
    }
}

/* User info display */
.user-nickname {
    font-size: var(--pc-text-caption);
    color: var(--pc-text-secondary);
    margin-bottom: 4px;
}

/* Fireworks Animation */
.firework {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
}

.firework-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    will-change: transform, opacity;
    filter: blur(0.5px);
}

.firework-particle::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, 
        currentColor 0%, 
        transparent 70%
    );
    border-radius: 50%;
    top: -50%;
    left: -50%;
    opacity: 0.6;
    filter: blur(2px);
}

/* Spark effect for particles */
.firework-spark {
    position: absolute;
    width: 2px;
    height: 10px;
    background: linear-gradient(to bottom, 
        transparent, 
        currentColor 30%, 
        transparent
    );
    opacity: 0;
    animation: spark-fall 2s ease-out;
}

@keyframes spark-fall {
    0% {
        transform: translateY(0) scaleY(0);
        opacity: 0;
    }
    10% {
        transform: translateY(5px) scaleY(1);
        opacity: 1;
    }
    100% {
        transform: translateY(80px) scaleY(0.5);
        opacity: 0;
    }
}

/* Flash effect for explosion */
.firework-flash {
    position: fixed;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, 
        rgba(255, 255, 255, 0.9) 0%, 
        rgba(255, 255, 255, 0.4) 30%, 
        transparent 70%
    );
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 9998;
    animation: flash-burst 0.2s ease-out forwards;
}

@keyframes flash-burst {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

/* Particle trail streaks */
.firework-particle::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 300%;
    background: linear-gradient(to bottom,
        transparent 0%,
        currentColor 50%,
        transparent 100%
    );
    top: -100%;
    left: 0;
    opacity: 0;
    transform-origin: center bottom;
    animation: particle-streak 3.6s ease-out;
}

@keyframes particle-streak {
    0%, 10% {
        opacity: 0;
        transform: scaleY(0);
    }
    15% {
        opacity: 0.6;
        transform: scaleY(1);
    }
    100% {
        opacity: 0;
        transform: scaleY(0.5);
    }
}

/* User Menu Dropdown Styles */
.user-menu-container {
    position: relative;
    display: inline-block;
}

.user-menu-btn {
    display: flex !important;
    align-items: center;
    gap: 6px;
    background: rgba(30, 30, 30, 0.59) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 18px !important;
    padding: 8px 16px !important;
    color: var(--pc-text-primary) !important;
    transition: all 0.2s ease;
    cursor: pointer;
    font-size: var(--pc-text-small);
    font-weight: 400;
}

.user-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    transform: translateY(-1px);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: rgba(30, 30, 30, 0.59);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    padding: 16px;
    min-width: 180px;
    z-index: 1001;
    transition: all 0.2s ease;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--pc-text-primary);
    text-decoration: none;
    font-size: var(--pc-text-small);
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    box-sizing: border-box;
}

.user-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--pc-text-primary);
    text-decoration: none;
}

.user-menu-item svg {
    width: 18px;
    height: 18px;
    color: var(--pc-text-secondary);
    transition: color 0.2s ease;
}

.user-menu-item:hover svg {
    color: var(--pc-text-primary);
}

.user-menu-divider {
    border: none;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 8px 0;
}

.logout-btn {
    color: var(--pc-family-red) !important;
}

.logout-btn:hover {
    background: rgba(224, 75, 75, 0.1) !important;
}

.logout-btn svg {
    color: var(--pc-family-red) !important;
}

/* Light mode adjustments for user menu */
.pc-light-mode .user-menu-btn {
    background: rgba(255, 255, 255, 0.8) !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
    color: var(--pc-text-primary) !important;
}

.pc-light-mode .user-menu-btn:hover {
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(0, 0, 0, 0.15) !important;
}

.pc-light-mode .user-menu-dropdown {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.pc-light-mode .user-menu-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.pc-light-mode .user-menu-divider {
    background: rgba(0, 0, 0, 0.1);
}