/* Livechat Popup Styles */

/* Force hide popup initially - but allow animation */
#livechat-popup:not(.show) {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.livechat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(30, 60, 114, 0.3);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: white;
    font-size: 24px;
}

.livechat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(30, 60, 114, 0.4);
}

.livechat-toggle.shake {
    animation: shake 0.6s ease-in-out;
}

.livechat-toggle.bounce {
    animation: bounce-click 0.4s ease-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes bounce-click {
    0% { transform: translateY(-2px) scale(1); }
    30% { transform: translateY(-6px) scale(1.05); }
    60% { transform: translateY(-2px) scale(0.98); }
    100% { transform: translateY(-2px) scale(1); }
}

/* Livechat popup main styles - loaded after initial hide */
.livechat-popup {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    width: 350px !important;
    height: 500px !important;
    background: white !important;
    border-radius: 15px !important;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1) !important;
    z-index: 1001 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    border: 1px solid #e9ecef !important;
    overscroll-behavior: contain !important;
    touch-action: pan-y !important;
    
    /* Initial hidden state */
    transform: translateY(100%) !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    
    /* Animation properties */
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
                opacity 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                visibility 0.4s ease !important;
}

.livechat-popup.show {
    transform: translateY(0) !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

/* Keyframe animations for better control */
@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
        visibility: hidden;
    }
    to {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
        visibility: hidden;
    }
}

.livechat-popup.animate-in {
    animation: slideUp 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards !important;
}

.livechat-popup.animate-out {
    animation: slideDown 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards !important;
}

.livechat-header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%) !important;
    color: white !important;
    padding: 15px 20px !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    position: relative !important;
    flex-shrink: 0 !important;
}

.header-info {
    flex: 1;
}

.header-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.header-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin: 2px 0 0 0;
}

.header-actions {
    display: flex;
    gap: 5px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    display: inline-block;
    line-height: 14px;
    text-align: center;
    font-weight: 700;
    border: 2px solid white;
    box-shadow: 0 1px 4px rgba(255, 71, 87, 0.5);
    z-index: 1002;
    animation: pulse-notification 2s infinite;
}

@keyframes pulse-notification {
    0% {
        transform: scale(1);
        box-shadow: 0 1px 4px rgba(255, 71, 87, 0.5);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 2px 8px rgba(255, 71, 87, 0.7);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 1px 4px rgba(255, 71, 87, 0.5);
    }
}

/* Login Required Panel Styles */
.login-required-panel {
    flex: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 20px !important;
    text-align: center !important;
    min-height: 0 !important;
}

.login-message {
    max-width: 280px;
}

.login-icon {
    font-size: 48px;
    color: #1e3c72;
    margin-bottom: 15px;
}

.login-message h4 {
    color: #1e3c72;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
}

.login-message p {
    color: #6c757d;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
}

.login-benefits {
    margin-bottom: 25px;
}

.benefit-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    color: #495057;
}

.benefit-item i {
    color: #28a745;
    font-size: 14px;
}

.login-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-login, .btn-register {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-login {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(30, 60, 114, 0.3);
    color: white;
    text-decoration: none;
}

.btn-register {
    background: #f8f9fa;
    color: #495057;
    border: 1px solid #e9ecef;
}

.btn-register:hover {
    background: #e9ecef;
    color: #495057;
    text-decoration: none;
}

/* Responsive Design */
@media (max-width: 768px) {
    .livechat-popup {
        width: 320px;
        height: 450px;
        bottom: 15px;
        right: 15px;
    }
    
    .livechat-toggle {
        bottom: 15px;
        right: 15px;
        width: 55px;
        height: 55px;
        font-size: 22px;
    }
    
    .login-message {
        max-width: 250px;
    }
    
    .login-message h4 {
        font-size: 16px;
    }
    
    .login-message p {
        font-size: 13px;
    }
}

/* Auto Scroll Toggle Button */
.auto-scroll-toggle {
    position: absolute;
    bottom: 70px;
    right: 15px;
    width: 35px;
    height: 35px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(30, 60, 114, 0.3);
    z-index: 1003;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: white;
    font-size: 16px;
    opacity: 0.8;
}

.auto-scroll-toggle:hover {
    opacity: 1;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(30, 60, 114, 0.4);
}

.auto-scroll-toggle.disabled {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    opacity: 0.6;
}

.auto-scroll-toggle.disabled:hover {
    opacity: 0.8;
}

.auto-scroll-toggle.pulse {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 2px 10px rgba(30, 60, 114, 0.3);
    }
    50% {
        box-shadow: 0 2px 20px rgba(30, 60, 114, 0.6);
    }
    100% {
        box-shadow: 0 2px 10px rgba(30, 60, 114, 0.3);
    }
}

/* Admin Inbox Styles */
.admin-inbox {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    background: #f8f9fa !important;
    min-height: 0 !important;
    transition: all 0.3s ease-in-out !important;
}

.inbox-header {
    padding: 15px 20px 10px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
}

.inbox-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #1e3c72;
}

.refresh-btn {
    background: none;
    border: none;
    color: #1e3c72;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s;
}

.refresh-btn:hover {
    background: rgba(30, 60, 114, 0.1);
}

.chat-users-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    overscroll-behavior: contain;
}

.chat-user-item {
    background: white;
    border-radius: 10px;
    padding: 12px 15px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid #e9ecef;
    position: relative;
    animation: slideInLeft 0.4s ease-out;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.chat-user-item:hover {
    background: #f0f7ff;
    border-color: #1e3c72;
    transform: translateY(-1px);
}

.chat-user-item:hover .user-name {
    color: #1e3c72;
}

.chat-user-item:hover .message-time {
    color: #2a5298;
}

.chat-user-item.active {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    border-color: #1e3c72;
}

.chat-user-item.active .user-name,
.chat-user-item.active .user-email,
.chat-user-item.active .last-message,
.chat-user-item.active .message-time {
    color: white;
    opacity: 1;
}

.user-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 5px;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.user-email {
    font-size: 11px;
    opacity: 0.7;
    color: #666;
}

.last-message {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 5px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #555;
}

.message-time {
    font-size: 10px;
    opacity: 0.6;
    color: #888;
}

.unread-count {
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    position: absolute;
    top: 8px;
    right: 8px;
}

.chat-user-item.active .unread-count {
    background: rgba(255, 255, 255, 0.3);
}

.no-chats {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.no-chats h5 {
    color: #495057;
    margin-bottom: 10px;
}

.no-chats p {
    color: #6c757d;
}

.no-chats i {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
    color: #6c757d;
}

.chat-messages {
    flex: 1 !important;
    padding: 15px !important;
    overflow-y: auto !important;
    background: #f8f9fa !important;
    min-height: 0 !important;
    overscroll-behavior: contain !important;
    display: block !important;
    transition: all 0.3s ease-in-out !important;
    scroll-behavior: smooth !important;
    /* Prevent content jumping during updates */
    contain: layout style !important;
}

.message {
    margin-bottom: 12px;
    max-width: 80%;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    animation: fadeInUp 0.3s ease-out;
    /* Prevent layout shifts */
    will-change: transform;
    transform: translateZ(0);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(5px) translateZ(0);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateZ(0);
    }
}

/* Prevent flash of content during updates */
.chat-messages.updating {
    pointer-events: none;
}

.chat-messages.updating .message {
    animation: none;
}

/* Smooth transitions for message container */
.chat-messages-container {
    transition: opacity 0.2s ease-in-out;
}

.chat-messages-container.loading {
    opacity: 0.7;
}

.message.sent {
    margin-left: auto;
    text-align: right;
}

.message.sent > div:first-child {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 10px 15px;
    border-radius: 18px 18px 5px 18px;
    display: inline-block;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.message.received > div:first-child {
    background: white;
    color: #333;
    padding: 10px 15px;
    border-radius: 18px 18px 18px 5px;
    display: inline-block;
    border: 1px solid #e9ecef;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.message.admin {
    margin-left: auto;
    text-align: right;
}

.message.admin > div:first-child {
    background: linear-gradient(135deg, #4fc3f7 0%, #29b6f6 100%);
    color: white;
    padding: 10px 15px;
    border-radius: 18px 18px 5px 18px;
    display: inline-block;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.message-time {
    font-size: 11px;
    color: #6c757d;
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
}

/* Read Status Indicators */
.read-status {
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}

.read-status.unread {
    color: #dc3545; /* Red color for unread (single check) */
}

.read-status.read {
    color: #28a745; /* Green color for read (double check) */
}

/* Style for sent messages read status */
.message.sent .read-status {
    color: rgba(255, 255, 255, 0.8);
}

.message.sent .read-status.unread {
    color: rgba(255, 182, 193, 0.9); /* Light red for unread in sent messages */
}

.message.sent .read-status.read {
    color: rgba(144, 238, 144, 0.9); /* Light green for read in sent messages */
}

/* Link styling in messages */
.message a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
    overflow-wrap: break-word;
    hyphens: none;
}

.message.sent a {
    color: #e3f2fd;
}

.message.received a {
    color: #1976d2;
}

.message.admin a {
    color: #e1f5fe;
}

/* Force break long URLs and text */
.message > div:first-child {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.4;
}

.chat-input {
    padding: 15px !important;
    background: white !important;
    border-top: 1px solid #e9ecef !important;
    display: flex !important;
    gap: 10px !important;
    align-items: center !important;
    min-height: 75px !important;
    box-sizing: border-box !important;
    flex-shrink: 0 !important;
    position: relative !important;
    transition: all 0.3s ease-in-out !important;
}

.chat-input input,
.chat-input textarea {
    flex: 1;
    border: 2px solid #ddd;
    border-radius: 25px;
    padding: 12px 18px;
    outline: none;
    font-size: 14px;
    background: #f8f9fa;
    color: #333;
    min-height: 45px;
    max-height: 120px;
    box-sizing: border-box;
    font-family: inherit;
    transition: all 0.2s ease;
    resize: none;
    overflow-y: auto;
    line-height: 1.4;
}

.chat-input textarea {
    height: 70px;
    padding-top: 14px;
    padding-bottom: 14px;
}

.chat-input input::placeholder,
.chat-input textarea::placeholder {
    color: #6c757d;
    opacity: 1;
}

.chat-input input:focus,
.chat-input textarea:focus {
    border-color: #2a5298;
    background: white;
    box-shadow: 0 0 0 3px rgba(42, 82, 152, 0.1);
}

.chat-input textarea::-webkit-scrollbar {
    width: 4px;
}

.chat-input textarea::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input textarea::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 2px;
}

.chat-input textarea::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

.send-btn {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border: none;
    color: white;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.send-btn:hover {
    transform: scale(1.05);
}

.auto-scroll-toggle {
    position: absolute;
    bottom: 90px;
    right: 15px;
    background: rgba(30, 60, 114, 0.8);
    color: white;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 18px;
    opacity: 0.7;
}

.auto-scroll-toggle:hover {
    opacity: 1;
    transform: scale(1.1);
}

.auto-scroll-toggle.disabled {
    background: rgba(108, 117, 125, 0.8);
}

/* Force Flexbox Layout - Override any external CSS */
#livechat-popup {
    display: flex !important;
    flex-direction: column !important;
}

#livechat-popup .livechat-header {
    flex-shrink: 0 !important;
}

#livechat-popup .chat-messages {
    flex: 1 !important;
    min-height: 0 !important;
}

#livechat-popup .chat-input {
    flex-shrink: 0 !important;
}

#livechat-popup .admin-inbox {
    flex: 1 !important;
    min-height: 0 !important;
}

#livechat-popup .login-required-panel {
    flex: 1 !important;
    min-height: 0 !important;
}

/* Admin View States - Class-based approach for better control */
.livechat-popup .admin-inbox {
    display: flex !important;
    flex: 1 !important;
    min-height: 0 !important;
    flex-direction: column !important;
}

.livechat-popup .admin-inbox.hidden {
    display: none !important;
}

.livechat-popup .admin-inbox.visible {
    display: flex !important;
}

.livechat-popup .chat-messages {
    flex: 1 !important;
    min-height: 0 !important;
}

.livechat-popup .chat-messages.hidden {
    display: none !important;
}

.livechat-popup .chat-messages.visible {
    display: block !important;
}

.livechat-popup .chat-input {
    flex-shrink: 0 !important;
}

.livechat-popup .chat-input.hidden {
    display: none !important;
}

.livechat-popup .chat-input.visible {
    display: flex !important;
}

/* Only override when JavaScript explicitly sets display styles */
.livechat-popup[id="livechat-popup"] .admin-inbox[style*="display: none"] {
    display: none !important;
}

.livechat-popup[id="livechat-popup"] .chat-messages[style*="display: none"] {
    display: none !important;
}

.livechat-popup[id="livechat-popup"] .chat-input[style*="display: none"] {
    display: none !important;
}

.livechat-popup[id="livechat-popup"] .admin-inbox[style*="display: flex"] {
    display: flex !important;
    flex-direction: column !important;
}

.livechat-popup[id="livechat-popup"] .chat-messages[style*="display: block"] {
    display: block !important;
}

.livechat-popup[id="livechat-popup"] .chat-input[style*="display: flex"] {
    display: flex !important;
}

/* Mobile Responsive Updates */
@media (max-width: 576px) {
    #livechat-popup {
        width: calc(100vw - 30px) !important;
        height: calc(100vh - 100px) !important;
        bottom: 15px !important;
        right: 15px !important;
        left: 15px !important;
        max-width: none !important;
    }
    
    .livechat-toggle {
        bottom: 15px !important;
        right: 15px !important;
    }
    
    .login-actions {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .btn-login, .btn-register {
        padding: 10px 16px !important;
        font-size: 13px !important;
    }
}