/**
 * Advanced Chat Widget CSS
 * Professional, modern, and fully responsive chat widget
 */

/* Chat Widget Container */
#chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: block !important; /* Show widget by default - force display */
    pointer-events: auto; /* Ensure it's clickable */
}

/* Chat Widget Button (Floating) */
.chat-widget-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0B3D91 0%, #0a2d6b 100%);
    color: white;
    border: none;
    cursor: pointer !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(11, 61, 145, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible;
    pointer-events: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 10000;
}

.chat-widget-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(11, 61, 145, 0.5);
}

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

.chat-widget-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    border: 2px solid white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Widget Window */
.chat-widget-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 650px;
    max-height: calc(100vh - 100px);
    background: white;
    border-radius: 20px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25), 0 8px 16px rgba(0, 0, 0, 0.15);
    display: none; /* CRITICAL: Hidden by default - only opens when user clicks button */
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
    border: 1px solid rgba(11, 61, 145, 0.1);
    box-sizing: border-box;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-widget-window.minimized {
    height: 60px;
    overflow: hidden;
}

/* Chat Widget Header */
.chat-widget-header {
    background: linear-gradient(135deg, #0B3D91 0%, #0a2d6b 100%);
    color: white;
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
}

.chat-widget-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.chat-widget-header-info {
    flex: 1;
}

.chat-widget-header-info h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.chat-widget-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.9;
}

.chat-widget-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-widget-btn-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-left: 8px;
}

.chat-widget-btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Chat Widget Content */
.chat-widget-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: #f8fafc;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
}

.chat-widget-content::-webkit-scrollbar {
    width: 6px;
}

.chat-widget-content::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.chat-widget-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chat-widget-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Chat Widget Form */
.chat-widget-form {
    padding: 20px 24px 24px 24px;
    display: block !important; /* Ensure form is visible by default */
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 100%;
    box-sizing: border-box;
}

.chat-widget-form-header {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e2e8f0;
}

.chat-widget-form-header h4 {
    margin: 0 0 8px 0;
    color: #1e293b;
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, #0B3D91 0%, #0a2d6b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.chat-widget-form-header p {
    margin: 0;
    color: #64748b;
    font-size: 14px;
    line-height: 1.5;
}

.chat-widget-form-group {
    margin-bottom: 18px;
}

.chat-widget-form-group label {
    display: block;
    font-weight: 600;
    color: #334155;
    margin-bottom: 8px;
    font-size: 14px;
}

.chat-widget-form-group input,
.chat-widget-form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    box-sizing: border-box;
    background: white;
    color: #1e293b;
}

.chat-widget-form-group input:hover,
.chat-widget-form-group select:hover {
    border-color: #cbd5e1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chat-widget-form-group input:disabled {
    background: #f3f4f6;
    cursor: not-allowed;
    color: #64748b;
}

.chat-widget-form-group input:focus,
.chat-widget-form-group select:focus {
    outline: none;
    border-color: #0B3D91;
    box-shadow: 0 0 0 3px rgba(11, 61, 145, 0.1);
}

.chat-widget-btn-primary {
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, #0B3D91 0%, #0a2d6b 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 12px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(11, 61, 145, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-widget-btn-primary::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.chat-widget-btn-primary:hover::before {
    width: 300px;
    height: 300px;
}

.chat-widget-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(11, 61, 145, 0.4);
}

.chat-widget-btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 4px 12px rgba(11, 61, 145, 0.3);
}

.chat-widget-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Chat Messages */
.chat-widget-messages {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #f8fafc;
}

.chat-messages-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    justify-content: flex-start;
    align-items: stretch;
    min-height: 0;
    /* Prevent layout shift during updates */
    contain: layout style;
    /* Smooth scrolling */
    scroll-behavior: smooth;
    /* Optimize scrolling performance */
    will-change: scroll-position;
    /* Start from top - remove any extra spacing */
    align-content: flex-start;
    /* Ensure messages start at top */
    margin: 0;
    /* Remove any default list styling */
    list-style: none;
    /* Ensure content starts immediately from top */
    box-sizing: border-box;
    /* Remove any flex spacing that might cause blank space */
    align-items: stretch;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    /* Prevent layout shift */
    min-height: 40px;
    contain: layout style paint;
    /* Only animate new messages */
    animation: none;
    /* Ensure messages don't create extra space */
    margin: 0;
    padding: 0;
    flex-shrink: 0;
}

/* Only animate new messages, not existing ones */
.chat-message[data-new="true"] {
    animation: messageSlide 0.3s ease-out;
}

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

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

.chat-message.agent,
.chat-message.system {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    position: relative;
}

.chat-message.customer .chat-message-bubble {
    background: linear-gradient(135deg, #0B3D91 0%, #0a2d6b 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.agent .chat-message-bubble {
    background: white;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.chat-message.system .chat-message-bubble {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
    text-align: center;
    font-size: 13px;
    font-style: italic;
}

.chat-message-content {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.chat-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-message.customer .chat-message-time {
    color: rgba(255, 255, 255, 0.8);
}

.chat-message.agent .chat-message-time {
    color: #64748b;
}

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

.chat-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typing 1.4s infinite;
}

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

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

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

/* Chat Input Area */
.chat-widget-input-area {
    border-top: 3px solid #e2e8f0;
    background: #ffffff;
    padding: 20px 24px;
    flex-shrink: 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08), 0 -2px 8px rgba(11, 61, 145, 0.1);
    position: relative;
    z-index: 10;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: visible;
}

.chat-widget-input-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #0B3D91 0%, #0a2d6b 100%);
    opacity: 0.3;
}

/* Chat Actions (Close Chat Button) */
.chat-widget-actions {
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 8px;
}

.chat-widget-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fecaca;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-widget-action-btn:hover {
    background: #fecaca;
    border-color: #fca5a5;
}

.chat-widget-action-btn svg {
    width: 14px;
    height: 14px;
}

.chat-widget-input-form {
    display: flex;
    gap: 12px;
    align-items: center;
    background: #f8fafc;
    padding: 10px 12px;
    border-radius: 36px;
    border: 2px solid #e2e8f0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 60px;
    box-sizing: border-box;
    overflow: visible;
}

.chat-widget-input-form:focus-within {
    border-color: #0B3D91;
    box-shadow: 0 0 0 4px rgba(11, 61, 145, 0.1), 0 4px 16px rgba(11, 61, 145, 0.15);
    background: #ffffff;
    transform: translateY(-1px);
}

#chat-message-input {
    flex: 1;
    padding: 14px 18px;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Prevent input from being affected by re-renders */
    contain: layout style;
    background: transparent;
    color: #1e293b;
    min-height: 40px;
    line-height: 1.5;
    box-sizing: border-box;
}

#chat-message-input::placeholder {
    color: #94a3b8;
    opacity: 1;
    font-weight: 400;
}

#chat-message-input:hover {
    background: rgba(255, 255, 255, 0.8);
}

#chat-message-input:focus {
    outline: none;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(11, 61, 145, 0.1);
}

#chat-message-input:focus::placeholder {
    color: #cbd5e1;
}

.chat-widget-btn-send {
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0B3D91 0%, #0a2d6b 100%);
    color: white;
    border: 3px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(11, 61, 145, 0.3), 0 2px 8px rgba(11, 61, 145, 0.2);
    position: relative;
    overflow: visible;
    box-sizing: border-box;
}

.chat-widget-btn-send::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.4s, height 0.4s;
}

.chat-widget-btn-send:hover::before {
    width: 200px;
    height: 200px;
}

.chat-widget-btn-send:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 20px rgba(11, 61, 145, 0.4);
}

.chat-widget-btn-send:active {
    transform: scale(0.95) rotate(0deg);
}

.chat-widget-btn-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 6px rgba(11, 61, 145, 0.2);
}

/* Attach File Button */
.chat-widget-btn-attach {
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    color: #64748b;
    border: 2px solid #e2e8f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
    overflow: visible;
}

.chat-widget-btn-attach:hover {
    background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
    border-color: #94a3b8;
    color: #334155;
    transform: scale(1.05) rotate(-15deg);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.chat-widget-btn-attach:active {
    transform: scale(0.95) rotate(0deg);
}

/* File Attachment Display */
.chat-message-attachment {
    margin-top: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-message.customer .chat-message-attachment {
    background: rgba(255, 255, 255, 0.2);
}

.chat-message-attachment-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    flex-shrink: 0;
}

.chat-message.customer .chat-message-attachment-icon {
    background: rgba(255, 255, 255, 0.3);
}

.chat-message-attachment-info {
    flex: 1;
    min-width: 0;
}

.chat-message-attachment-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-message-attachment-size {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 2px;
}

.chat-message-attachment-link {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.chat-message-attachment-link:hover {
    opacity: 0.8;
}

/* Image Attachment Preview */
.chat-message-attachment-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    margin-top: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-message-attachment-image:hover {
    transform: scale(1.05);
}

/* Chat Closed State */
.chat-widget-closed {
    opacity: 0.6;
    pointer-events: none;
}

.chat-widget-closed-message {
    padding: 20px;
    text-align: center;
    color: #64748b;
    font-size: 14px;
    background: #f1f5f9;
    border-radius: 8px;
    margin: 20px;
}

/* Responsive Design */
@media (max-width: 768px) {
    #chat-widget-container {
        bottom: 10px;
        right: 10px;
    }
    
    .chat-widget-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 80px);
        max-height: calc(100vh - 80px);
        bottom: 70px;
        right: 0;
        border-radius: 16px 16px 0 0;
    }
    
    .chat-widget-btn {
        width: 56px;
        height: 56px;
    }
}

/* RTL Support */
[dir="rtl"] #chat-widget-container {
    right: auto;
    left: 20px;
}

[dir="rtl"] .chat-widget-window {
    right: auto;
    left: 0;
}

[dir="rtl"] #chat-widget-container {
    right: auto;
    left: 20px;
}

[dir="rtl"] .chat-message.customer {
    align-self: flex-start;
}

[dir="rtl"] .chat-message.agent {
    align-self: flex-end;
}

/* Notification Sound (optional) */
.chat-notification-sound {
    display: none;
}

