/* Chat Widget Styles
   Uses site design system variables from variables.css
   Dark theme design with purple brand accent
*/

/* Floating Widget Container */
.chat-widget {
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    z-index: 1072; /* Above nav (1070), below modals (1075+) */
    font-family: var(--font-family-base);
}

/* When chat is open: hide bubble and position panel at bottom */
.chat-widget-open .chat-bubble {
    display: none;
}

.chat-widget-open .chat-panel {
    bottom: 0;
}

/* Floating Bubble Button */
.chat-bubble {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: var(--radius-full);
    background: var(--brand-primary);
    color: var(--text-on-brand);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(113, 44, 249, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-all-fast);
}

.chat-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(113, 44, 249, 0.5);
    background: var(--brand-primary-light);
}

.chat-bubble:active {
    transform: scale(0.98);
}

/* Proactive message indicator - subtle pulsing animation */
.chat-bubble.has-proactive-message {
    animation: proactivePulse 2s ease-in-out infinite;
}

@keyframes proactivePulse {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(113, 44, 249, 0.4);
    }
    50% {
        box-shadow: 0 4px 30px rgba(113, 44, 249, 0.7), 0 0 0 8px rgba(113, 44, 249, 0.15);
    }
}

.chat-bubble-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Unread Badge */
.chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    background: var(--color-danger);
    color: var(--text-primary);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Chat Panel */
.chat-panel {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatPanelSlideIn 0.2s ease;
}

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

/* Panel Header */
.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    background: var(--bg-surface-raised);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header-title {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.chat-status {
    font-size: var(--text-xs);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-muted);
}

.chat-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
}

.chat-status-online::before {
    background: var(--color-success);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.chat-status-offline::before {
    background: var(--text-disabled);
}

.chat-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-all-fast);
}

.chat-close-btn:hover {
    color: var(--text-primary);
    background: var(--glass-white-10);
}

/* Messages Container */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    background: var(--bg-secondary);
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--glass-white-20);
    border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--glass-white-30);
}

/* Welcome Message */
.chat-welcome {
    text-align: center;
    padding: var(--space-6) var(--space-4);
}

.chat-welcome-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin: 0 0 var(--space-2) 0;
}

.chat-welcome-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin: 0;
    line-height: var(--leading-relaxed);
}

/* Message Bubbles */
.chat-message {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.chat-message-own {
    align-self: flex-end;
}

.chat-message-other {
    align-self: flex-start;
}

.chat-message-sender {
    font-size: 11px;
    font-weight: var(--font-medium);
    color: var(--text-muted);
    padding-left: var(--space-1);
}

.chat-message-content {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-2xl);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-message-own .chat-message-content {
    background: var(--brand-primary);
    color: var(--text-on-brand);
    border-bottom-right-radius: var(--radius-sm);
}

.chat-message-other .chat-message-content {
    background: var(--bg-surface-raised);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: var(--radius-sm);
}

.chat-message-time {
    font-size: 10px;
    color: var(--text-disabled);
    padding: 0 var(--space-1);
}

.chat-message-own .chat-message-time {
    text-align: right;
}

/* Message Header - shows sender info for admin view */
.chat-message-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: var(--space-1);
}

.chat-message-type {
    color: var(--text-disabled);
}

/* System Message */
.chat-message-system {
    align-self: center;
    max-width: 90%;
}

.chat-message-system .chat-message-content {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    border-radius: var(--radius-lg);
}

.chat-message-system .chat-message-time {
    text-align: center;
}

/* Typing Indicator */
.chat-typing-indicator {
    display: flex;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-2xl);
    border-bottom-left-radius: var(--radius-sm);
    width: fit-content;
    align-self: flex-start;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: var(--radius-full);
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-4px);
    }
}

/* Input Forms */
.chat-start-form,
.chat-message-form {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.chat-input-group {
    display: flex;
    gap: var(--space-2);
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-family: inherit;
    resize: none;
    outline: none;
    transition: var(--transition-all-fast);
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.chat-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 2px rgba(113, 44, 249, 0.2);
}

.chat-textarea {
    min-height: 40px;
    max-height: 100px;
    line-height: var(--leading-normal);
    overflow-y: auto;
    border-radius: var(--radius-xl);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--brand-primary);
    color: var(--text-on-brand);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition-all-fast);
}

.chat-send-btn:hover {
    background: var(--brand-primary-light);
    box-shadow: 0 0 12px rgba(113, 44, 249, 0.4);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

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

/* Error Toast */
.chat-error-toast {
    position: fixed;
    bottom: 100px;
    right: var(--space-5);
    background: var(--color-danger);
    color: var(--text-primary);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    z-index: 1073; /* Above chat widget (1072), below modals (1075+) */
    animation: fadeIn 0.2s ease;
    box-shadow: var(--shadow-md);
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .chat-widget {
        bottom: var(--space-3);
        right: var(--space-3);
    }

    .chat-bubble {
        width: 56px;
        height: 56px;
    }

    .chat-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
        border-bottom: none;
    }
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .chat-panel {
        animation: none;
    }

    .chat-bubble:hover {
        transform: none;
    }

    .typing-dot {
        animation: none;
    }
}
