/*!
 * Modern TYPNI Chatbot - Redesigned
 * Clean, contemporary interface with smooth animations
 * Version: 3.0
 */

:root {
    /* TYPNI Brand Colors */
    --typni-primary: #390099;
    --typni-secondary: #4D1AA3;
    --typni-accent: #FF0054;
    --typni-yellow: #FFDE21;
    
    /* Modern Color System */
    --chat-bg: #ffffff;
    --chat-surface: #f8fafc;
    --chat-border: #e2e8f0;
    --chat-hover: #f1f5f9;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 25px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.15);
    
    /* Typography */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --text-inverse: #ffffff;
    
    /* Message Colors */
    --msg-bot-bg: var(--chat-surface);
    --msg-bot-text: var(--text-primary);
    --msg-user-bg: var(--typni-primary);
    --msg-user-text: var(--text-inverse);
    
    /* Animations */
    --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --transition-fast: 0.2s var(--ease-out);
    --transition-smooth: 0.3s var(--ease-out);
    
    /* Layout */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 20px;
    --spacing-xl: 24px;
    
    /* Theme Variables (for compatibility) */
    --primary-color: var(--typni-primary);
    --secondary-color: var(--typni-secondary);
    --accent-color: var(--typni-accent);
    --highlight-color: var(--typni-yellow);
}

/* Modern Chatbot Widget */
.chat-widget {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Floating Action Button */
.chat-button {
    width: 64px;
    height: 64px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--typni-primary) 0%, var(--typni-secondary) 100%);
    color: var(--text-inverse);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.chat-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.chat-button:hover::before {
    opacity: 1;
}

.chat-button:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-xl);
}

.chat-button i {
    font-size: 24px;
    transition: transform var(--transition-fast);
}

.chat-button:hover i {
    transform: scale(1.1);
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 24px;
    height: 24px;
    background: var(--typni-accent);
    color: var(--text-inverse);
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--chat-bg);
    opacity: 0;
    transform: scale(0);
    transition: all var(--transition-smooth);
}

.notification-badge.visible {
    opacity: 1;
    transform: scale(1);
}

/* Modern Chat Container */
.chat-box {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--chat-border);
    opacity: 0;
    transform: translateX(-20px) translateY(20px) scale(0.95);
    transition: all var(--transition-smooth);
}

.chat-box.active {
    display: flex;
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1);
}

/* Clean Header */
.chat-header {
    background: linear-gradient(135deg, var(--typni-primary) 0%, var(--typni-secondary) 100%);
    color: var(--text-inverse);
    padding: var(--spacing-lg) var(--spacing-xl);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    position: relative;
    overflow: hidden;
}

.chat-header::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.typni-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: var(--spacing-md);
    background-image: url('../../../assets/img/TYPNI-11.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.chat-header h4 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    flex: 1;
    z-index: 1;
    letter-spacing: -0.5px;
    color: var(--text-inverse);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    z-index: 1;
}

.chat-actions span {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    backdrop-filter: blur(10px);
}

.chat-actions span:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.close-chat {
    font-size: 18px;
}

/* Messages Container */
.chat-messages {
    flex: 1;
    padding: var(--spacing-lg);
    background: var(--chat-bg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* Custom Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Modern Message Bubbles */
.message {
    max-width: 85%;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    animation: messageSlideIn 0.3s var(--ease-out) forwards;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
    margin-bottom: 0;
}

.message.bot {
    align-self: flex-start;
    background: var(--msg-bot-bg);
    color: var(--msg-bot-text);
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 6px;
}

.message.user {
    align-self: flex-end;
    background: var(--msg-user-bg);
    color: var(--msg-user-text);
    border-bottom-right-radius: 6px;
}

/* Remove old message tails */
.message.bot::before,
.message.bot::after,
.message.user::before,
.message.user::after {
    display: none;
}

/* Quick Reply Buttons */
.quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-sm);
}

.prompt-chip {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--chat-hover);
    color: var(--typni-primary);
    border: 1px solid rgba(57, 0, 153, 0.2);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.prompt-chip:hover {
    background: var(--typni-primary);
    color: var(--text-inverse);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* Typing Indicator */
.typing-indicator {
    align-self: flex-start;
    background: var(--msg-bot-bg);
    border: 1px solid var(--chat-border);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 6px;
    padding: var(--spacing-sm) var(--spacing-md);
    display: none;
    align-items: center;
    gap: var(--spacing-xs);
    max-width: 80px;
}

.typing-indicator.show {
    display: flex;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: typingPulse 1.4s infinite ease-in-out;
}

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

/* Input Area */
.chat-input {
    padding: var(--spacing-lg) var(--spacing-xl);
    background: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
}

.chat-input input {
    flex: 1;
    min-height: 44px;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--chat-border);
    border-radius: 22px;
    background: var(--chat-surface);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
    outline: none;
    transition: all var(--transition-smooth);
    color: var(--text-primary);
}

.chat-input input:focus {
    border-color: var(--typni-primary);
    box-shadow: 0 0 0 2px rgba(57, 0, 153, 0.1);
    background: var(--chat-bg);
}

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

.chat-input button {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--typni-primary);
    color: var(--text-inverse);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 20px;
    transition: all var(--transition-smooth);
    box-shadow: var(--shadow-md);
}

.chat-input button:hover {
    background: var(--typni-secondary);
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

.chat-input button:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
    transform: none;
}

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

@keyframes typingPulse {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    30% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Theme Support (for backward compatibility) */
.theme-violet {
    --primary-color: var(--typni-primary);
    --secondary-color: var(--typni-secondary);
    --accent-color: var(--typni-accent);
    --highlight-color: var(--typni-yellow);
}

.theme-yellow {
    --primary-color: var(--typni-yellow);
    --secondary-color: var(--typni-primary);
    --accent-color: var(--typni-accent);
    --highlight-color: var(--typni-secondary);
}

/* Apply theme colors to elements */
.chat-button {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.chat-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.notification-badge {
    background: var(--accent-color);
}

.prompt-chip {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.prompt-chip:hover {
    background: var(--primary-color);
}

.chat-input button {
    background: var(--primary-color);
}

.chat-input button:hover {
    background: var(--secondary-color);
}

.chat-input input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(57, 0, 153, 0.1);
}

/* Message formatting */
.message p {
    margin: 0 0 8px 0;
    line-height: 1.5;
}

.message p:last-child {
    margin-bottom: 0;
}

.message ul, .message ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.message a {
    color: var(--primary-color);
    text-decoration: none;
}

.message.user a {
    color: var(--text-inverse);
    text-decoration: underline;
}

/* Remove all emoji-related features */
.reaction-emojis,
.reaction-emoji,
.emoji-button,
.emoji-picker,
.emoji-group,
.emoji-item {
    display: none !important;
}

/* Desktop Responsiveness */
@media (min-width: 769px) {
    .chat-widget {
        bottom: 24px;
        left: 24px;
    }
    
    .chat-button {
        width: 64px;
        height: 64px;
        font-size: 28px;
    }
    
    .chat-box {
        width: 400px;
        height: 600px;
        left: 0;
        bottom: 80px;
    }
}

/* Tablet and Small Desktop */
@media (min-width: 769px) and (max-width: 1024px) {
    .chat-box {
        width: 360px;
        height: 550px;
        max-width: calc(100vw - 60px);
        max-height: calc(100vh - 140px);
    }
}

/* Large Desktop */
@media (min-width: 1025px) {
    .chat-widget {
        bottom: 32px;
        left: 32px;
    }
    
    .chat-button {
        width: 70px;
        height: 70px;
        font-size: 30px;
    }
    
    .chat-box {
        width: 420px;
        height: 650px;
        bottom: 90px;
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 20px;
        left: 20px;
        right: 20px;
        position: fixed;
        z-index: 9999;
    }
    
    .chat-button {
        width: 56px;
        height: 56px;
        font-size: 24px;
        position: fixed;
        bottom: 20px;
        left: 20px;
        z-index: 10000;
    }
    
    .chat-box {
        width: 100vw;
        height: 100vh;
        max-width: none;
        max-height: none;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        border: none;
        position: fixed;
        z-index: 9999;
    }
    
    .chat-header {
        border-radius: 0;
        padding: var(--spacing-lg) var(--spacing-xl);
        padding-top: max(var(--spacing-lg), env(safe-area-inset-top));
        position: sticky;
        top: 0;
        z-index: 1;
    }
    
    .chat-messages {
        padding: var(--spacing-md);
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom));
    }
    
    .chat-input {
        padding: var(--spacing-md);
        padding-bottom: max(var(--spacing-md), env(safe-area-inset-bottom));
        position: sticky;
        bottom: 0;
        background: var(--chat-bg);
        border-top: 1px solid var(--chat-border);
    }
    
    .chat-input input {
        font-size: 16px; /* Prevents iOS zoom */
        min-height: 44px; /* Touch target size */
    }
    
    .chat-input button {
        min-width: 44px;
        min-height: 44px;
    }
    
    .message {
        max-width: 90%;
        font-size: 14px;
    }
    
    .prompt-chip {
        font-size: 13px;
        padding: 8px 12px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

@media (max-width: 480px) {
    .chat-button {
        width: 52px;
        height: 52px;
        font-size: 22px;
        bottom: 16px;
        left: 16px;
    }
    
    .chat-widget {
        bottom: 16px;
        left: 16px;
        right: 16px;
    }
    
    .chat-messages {
        padding: var(--spacing-sm);
    }
    
    .chat-input {
        padding: var(--spacing-sm);
    }
    
    .message {
        font-size: 13px;
        padding: 10px 12px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --chat-bg: #1e293b;
        --chat-surface: #334155;
        --chat-border: #475569;
        --chat-hover: #475569;
        --text-primary: #f1f5f9;
        --text-secondary: #cbd5e1;
        --text-tertiary: #94a3b8;
        --msg-bot-bg: var(--chat-surface);
        --msg-bot-text: var(--text-primary);
        
        --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 25px rgba(0, 0, 0, 0.5);
        --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.6);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .chat-box,
    .message,
    .chat-button,
    .prompt-chip,
    .chat-input button {
        transition: none;
        animation: none;
    }
    
    .typing-indicator span {
        animation: none;
        opacity: 0.6;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --chat-border: #000000;
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.8);
    }
    
    .message.bot {
        border: 2px solid var(--text-primary);
    }
}