/* FIXED Live Chat Widget Styles - Enhanced for Session Persistence */

:root {
    --chat-primary-color: #007bff;
    --chat-secondary-color: #6c757d;
    --chat-white: #ffffff;
    --chat-light-gray: #f8f9fa;
    --chat-dark-gray: #343a40;
    --chat-border-radius: 12px;
    --chat-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    --chat-z-index: 999999;
    --chat-success-color: #28a745;
    --chat-warning-color: #ffc107;
    --chat-danger-color: #dc3545;
    --chat-info-color: #17a2b8;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --chat-white: #1a1a1a;
        --chat-light-gray: #2d3748;
        --chat-dark-gray: #e2e8f0;
    }
}

/* Chat Widget Container */
.chat-widget {
    position: fixed;
    z-index: var(--chat-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: var(--chat-dark-gray);
    box-sizing: border-box;
}

.chat-widget *, 
.chat-widget *::before, 
.chat-widget *::after {
    box-sizing: border-box;
}

/* Position variants */
.chat-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.chat-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

.chat-widget.top-right {
    top: 20px;
    right: 20px;
}

.chat-widget.top-left {
    top: 20px;
    left: 20px;
}

/* Size variants */
.chat-widget.size-small .chat-toggle {
    width: 50px;
    height: 50px;
    font-size: 20px;
}

.chat-widget.size-medium .chat-toggle {
    width: 60px;
    height: 60px;
    font-size: 24px;
}

.chat-widget.size-large .chat-toggle {
    width: 70px;
    height: 70px;
    font-size: 28px;
}

.chat-widget.size-small .chat-window {
    width: 300px;
    height: 400px;
}

.chat-widget.size-medium .chat-window {
    width: 350px;
    height: 450px;
}

.chat-widget.size-large .chat-window {
    width: 400px;
    height: 500px;
}

/* Chat Toggle Button */
.chat-toggle {
    background: var(--chat-primary-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chat-shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--chat-white);
    position: relative;
    overflow: hidden;
    outline: none;
    user-select: none;
}

.chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 35px rgba(0, 123, 255, 0.3);
}

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

.chat-toggle.chat-open {
    background: var(--chat-secondary-color);
}

.chat-toggle .chat-icon {
    transition: transform 0.3s ease;
    font-size: inherit;
    line-height: 1;
}

.chat-toggle.chat-open .chat-icon {
    transform: rotate(45deg);
}

/* FIXED: Enhanced notification badge with pulsing animation */
.chat-toggle .notification-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--chat-danger-color);
    color: var(--chat-white);
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    animation: pulse 2s infinite;
    border: 2px solid var(--chat-white);
}

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

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    background: var(--chat-white);
    border-radius: var(--chat-border-radius);
    box-shadow: var(--chat-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.open {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Position adjustments for different positions */
.chat-widget.top-right .chat-window,
.chat-widget.top-left .chat-window {
    bottom: auto;
    top: 80px;
}

.chat-widget.bottom-left .chat-window,
.chat-widget.top-left .chat-window {
    right: auto;
    left: 0;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary-color), #0056b3);
    color: var(--chat-white);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
}

.chat-header-content {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 12px;
}

.chat-header-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-header-text {
    flex: 1;
}

.chat-header-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.chat-header-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin-top: 2px;
}

.chat-close {
    background: transparent;
    border: none;
    color: var(--chat-white);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s ease;
    border-radius: 4px;
}

.chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* FIXED: Enhanced connection status indicator */
.chat-status {
    padding: 12px 16px;
    text-align: center;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-bottom: 1px solid #e9ecef;
    position: relative;
}

.chat-status.online {
    background: linear-gradient(90deg, #d4edda, #c3e6cb);
    color: #155724;
}

.chat-status.offline {
    background: linear-gradient(90deg, #f8d7da, #f5c6cb);
    color: #721c24;
}

.chat-status.connecting {
    background: linear-gradient(90deg, #d1ecf1, #bee5eb);
    color: #0c5460;
}

.chat-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.chat-status.online::before {
    background: var(--chat-success-color);
    animation: pulse 2s infinite;
}

.chat-status.offline::before {
    background: var(--chat-danger-color);
}

.chat-status.connecting::before {
    background: var(--chat-info-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Chat Form */
.chat-form {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.chat-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--chat-dark-gray);
}

.chat-form-input,
.chat-form-textarea {
    padding: 10px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s ease;
    font-family: inherit;
    outline: none;
    background: var(--chat-white);
}

.chat-form-input:focus,
.chat-form-textarea:focus {
    border-color: var(--chat-primary-color);
}

.chat-form-textarea {
    min-height: 80px;
    resize: vertical;
}

.chat-form-submit {
    background: var(--chat-primary-color);
    color: var(--chat-white);
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.chat-form-submit:hover {
    background: #0056b3;
    transform: translateY(-1px);
}

.chat-form-submit:active {
    transform: translateY(0);
}

/* Chat Interface */
.chat-interface {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 350px;
}

/* FIXED: Enhanced chat messages container with better scrolling */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: linear-gradient(180deg, #f8f9fa 0%, #ffffff 100%);
}

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

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* FIXED: Enhanced message styling with better visual separation */
.chat-message {
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease-out;
    max-width: 85%;
}

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

.chat-message.client {
    align-self: flex-end;
    margin-left: auto;
}

.chat-message.staff {
    align-self: flex-start;
    margin-right: auto;
}

.chat-message-content {
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
    font-size: 14px;
    line-height: 1.4;
}

.chat-message.client .chat-message-content {
    background: var(--chat-primary-color);
    color: var(--chat-white);
    border-bottom-right-radius: 4px;
}

.chat-message.staff .chat-message-content {
    background: #e9ecef;
    color: var(--chat-dark-gray);
    border-bottom-left-radius: 4px;
}

.chat-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.chat-message.staff .chat-message-time {
    text-align: left;
}

/* FIXED: Enhanced temp message styling for better UX */
.chat-message.temp {
    opacity: 0.6;
    position: relative;
}

.chat-message.temp::after {
    content: '';
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 12px;
    height: 12px;
    border: 2px solid var(--chat-white);
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* FIXED: Enhanced typing indicator */
.typing-indicator {
    padding: 12px 16px;
    display: none;
    align-items: center;
    gap: 8px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--chat-secondary-color);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

.typing-text {
    font-size: 12px;
    color: var(--chat-secondary-color);
    font-style: italic;
}

/* Chat Input Area */
.chat-input-area {
    border-top: 1px solid #e9ecef;
    background: var(--chat-white);
}

.chat-input-form {
    display: flex;
    padding: 12px;
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 2px solid #e9ecef;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    font-family: inherit;
    max-height: 100px;
    min-height: 40px;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: var(--chat-primary-color);
}

.chat-send {
    background: var(--chat-primary-color);
    color: var(--chat-white);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send:hover {
    background: #0056b3;
    transform: scale(1.05);
}

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

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

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 10px;
        right: 10px;
    }
    
    .chat-widget.size-small .chat-window,
    .chat-widget.size-medium .chat-window,
    .chat-widget.size-large .chat-window {
        width: calc(100vw - 20px);
        max-width: 350px;
        height: 450px;
        max-height: calc(100vh - 100px);
    }
    
    .chat-toggle {
        width: 55px !important;
        height: 55px !important;
        font-size: 22px !important;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .chat-header-title {
        font-size: 15px;
    }
    
    .chat-form {
        padding: 16px;
    }
    
    .chat-messages {
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .chat-widget.size-small .chat-window,
    .chat-widget.size-medium .chat-window,
    .chat-widget.size-large .chat-window {
        width: calc(100vw - 10px);
        height: calc(100vh - 80px);
        bottom: 70px;
        border-radius: 12px 12px 0 0;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chat-toggle {
        border: 3px solid var(--chat-white);
    }
    
    .chat-message.client .chat-message-content {
        border: 1px solid #0056b3;
    }
    
    .chat-message.staff .chat-message-content {
        border: 1px solid var(--chat-secondary-color);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .chat-toggle,
    .chat-window,
    .chat-message,
    .typing-dot {
        animation: none;
        transition: none;
    }
}

/* FIXED: Connection status indicators */
.chat-widget.disconnected .chat-header {
    background: linear-gradient(135deg, var(--chat-danger-color), #c82333);
}

.chat-widget.connecting .chat-header {
    background: linear-gradient(135deg, var(--chat-warning-color), #e0a800);
}

/* FIXED: Session restoration indicator */
.chat-widget.restoring .chat-status {
    background: linear-gradient(90deg, #fff3cd, #ffeeba);
    color: #856404;
}

.chat-widget.restoring .chat-status::before {
    background: var(--chat-warning-color);
    animation: pulse 1s infinite;
}

/* FIXED: Enhanced error states */
.chat-error {
    background: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    margin: 8px 16px;
    font-size: 13px;
    text-align: center;
}

.chat-success {
    background: #d4edda;
    color: #155724;
    padding: 12px 16px;
    border: 1px solid #c3e6cb;
    border-radius: 8px;
    margin: 8px 16px;
    font-size: 13px;
    text-align: center;
}

/* FIXED: Loading states */
.chat-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: var(--chat-secondary-color);
}

.chat-loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--chat-primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

/* FIXED: Welcome message styling */
.chat-welcome {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb);
    color: #0d47a1;
    padding: 16px;
    margin: 8px;
    border-radius: 12px;
    border-left: 4px solid var(--chat-primary-color);
    font-size: 13px;
    line-height: 1.5;
}

.chat-welcome h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
}

.chat-welcome p {
    margin: 0;
    opacity: 0.9;
}