#nw-livechat-container {
    position: fixed;
    bottom: calc(var(--fab-edge, 40px) + env(safe-area-inset-bottom, 0px));
    right: var(--fab-right, 24px);
    z-index: 99999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --primary: #3b82f6; /* Fallback if not defined */
    --primary-dark: #2563eb;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 8px 30px rgba(59, 130, 246, 0.3);
    --shadow-window: 0 10px 40px rgba(0, 0, 0, 0.15);
}

/* Chat Bubble */
#nw-livechat-bubble {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary, #3b82f6), var(--primary-dark, #2563eb));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    z-index: 2;
}

#nw-livechat-bubble:hover {
    transform: translateY(-4px) scale(1.08);
    box-shadow: var(--shadow-hover);
}

#nw-livechat-bubble:active {
    transform: translateY(2px) scale(0.92);
}

#nw-livechat-bubble svg {
    color: #fff;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

#nw-livechat-container.is-open #nw-livechat-bubble {
    transform: scale(0.9);
}

#nw-livechat-container.is-open #nw-livechat-bubble svg {
    transform: rotate(180deg) scale(0.5);
    opacity: 0;
}

/* Optional pulse effect for new messages */
@keyframes nwPulse {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

.nw-has-unread #nw-livechat-bubble {
    animation: nwPulse 2s infinite;
}

.nw-livechat-unread-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.45);
    border: 2px solid #fff;
    box-sizing: border-box;
    z-index: 3;
    pointer-events: none;
}

.nw-livechat-unread-badge[hidden] {
    display: none !important;
}

/* Chat Window */
#nw-livechat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: var(--shadow-window);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: translateY(16px) scale(0.96);
    opacity: 0;
    border: 1px solid rgba(0,0,0,0.06);
    z-index: 1;
    transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1.1),
                opacity 0.25s ease;
}

#nw-livechat-window.open {
    display: flex;
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* Header */
#nw-livechat-header {
    background: linear-gradient(135deg, var(--primary, #3b82f6), var(--primary-dark, #2563eb));
    color: #fff;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

#nw-livechat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#nw-livechat-header h3::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    background: #10b981; /* Online green indicator */
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
}

.nw-livechat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

#nw-livechat-close,
#nw-livechat-options-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

#nw-livechat-close:hover,
#nw-livechat-options-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

#nw-livechat-close:hover {
    transform: rotate(90deg);
}

.nw-livechat-dropdown-container {
    position: relative;
}

#nw-livechat-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: #ffffff;
    border-radius: 12px;
    padding: 6px;
    min-width: 160px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1), 0 2px 10px rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.05);
    transform-origin: top right;
    transform: scale(0.95);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 100;
}

#nw-livechat-dropdown-menu.show {
    transform: scale(1);
    opacity: 1;
    visibility: visible;
}

#nw-livechat-end-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: none;
    padding: 10px 12px;
    border-radius: 8px;
    color: #ef4444; /* red for ending chat */
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    text-align: left;
    font-family: inherit;
}

#nw-livechat-end-btn:hover {
    background: #fef2f2;
}

/* Body Area */
#nw-livechat-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    scroll-behavior: smooth;
}

#nw-livechat-body::-webkit-scrollbar {
    width: 6px;
}
#nw-livechat-body::-webkit-scrollbar-track {
    background: transparent;
}
#nw-livechat-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

/* Auth Form */
#nw-livechat-auth {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    animation: nwFadeInUp 0.5s ease forwards;
}

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

.nw-auth-illustration {
    width: 64px;
    height: 64px;
    background: #eff6ff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px auto;
    color: var(--primary, #3b82f6);
}

#nw-livechat-auth h4 {
    text-align: center;
    margin: 0 0 8px 0;
    color: #0f172a;
    font-size: 18px;
}

#nw-livechat-auth p {
    text-align: center;
    color: #64748b;
    font-size: 14px;
    margin: 0 0 24px 0;
    line-height: 1.5;
}

.nw-input-group {
    margin-bottom: 16px;
}

#nw-livechat-auth input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    box-sizing: border-box;
    transition: all 0.2s;
    background: #fff;
    color: #1e293b;
    font-family: inherit;
}

#nw-livechat-auth input::placeholder {
    color: #94a3b8;
}

#nw-livechat-auth input:focus {
    outline: none;
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#nw-livechat-start-btn {
    background: var(--primary, #3b82f6);
    color: #fff;
    border: none;
    padding: 14px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.2);
}

#nw-livechat-start-btn:hover {
    background: var(--primary-dark, #2563eb);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

#nw-livechat-start-btn:active {
    transform: translateY(0);
}

/* Chat Messages */
@keyframes nwMessagePop {
    0% { opacity: 0; transform: scale(0.9) translateY(15px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.nw-message {
    max-width: 82%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: nwMessagePop 0.4s cubic-bezier(0.2, 0.8, 0.2, 1.1) forwards;
    position: relative;
    margin-bottom: 4px;
}

.nw-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary, #3b82f6), var(--primary-dark, #2563eb));
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(59,130,246,0.15);
}

.nw-message.admin {
    align-self: flex-start;
    background: #ffffff;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.03);
}

/* Group messages by sender */
.nw-message.user + .nw-message.user {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}
.nw-message.admin + .nw-message.admin {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

.nw-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 6px;
    display: block;
}
.nw-message.user .nw-message-time { text-align: right; }
.nw-message.admin .nw-message-time { text-align: left; color: #94a3b8; }

.read-receipt {
    display: inline-block;
    margin-left: 4px;
    font-size: 10px;
    font-weight: bold;
}
.read-receipt.single { color: rgba(255, 255, 255, 0.6); }
.read-receipt.double { color: #60a5fa; /* light blue */ }

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 14px 18px !important;
    background: #f1f5f9 !important;
    color: #94a3b8 !important;
}

.typing-indicator .dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBlink 1.4s infinite both;
}

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

@keyframes typingBlink {
    0% { opacity: 0.2; transform: scale(0.8); }
    20% { opacity: 1; transform: scale(1.1); }
    100% { opacity: 0.2; transform: scale(0.8); }
}

/* Chat Input Area */
#nw-livechat-footer {
    display: none;
    padding: 16px 20px;
    background: #fff;
    border-top: 1px solid #f1f5f9;
}

#nw-livechat-form {
    display: flex;
    gap: 12px;
    align-items: center;
}

#nw-livechat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    background: #f8fafc;
    font-family: inherit;
}

#nw-livechat-input:focus {
    background: #fff;
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#nw-livechat-attachment-preview {
    display: none;
    position: absolute;
    top: -42px;
    left: 12px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    color: #334155;
    max-width: 80%;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    z-index: 10;
    animation: nwFadeInUp 0.2s ease forwards;
}

#nw-livechat-attachment-preview svg {
    color: #64748b;
    flex-shrink: 0;
}

#nw-livechat-attachment-preview .filename {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

#nw-livechat-attachment-preview .remove-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 16px;
    padding: 0 2px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

#nw-livechat-attachment-preview .remove-btn:hover {
    color: #ef4444;
}

#nw-livechat-attach-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-right: -4px;
}

#nw-livechat-attach-btn:hover {
    background: #f1f5f9;
    color: var(--primary, #3b82f6);
}

#nw-livechat-attach-btn:active {
    transform: scale(0.95);
}

#nw-livechat-send {
    background: var(--primary, #3b82f6);
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(59,130,246,0.2);
}

#nw-livechat-send:hover {
    background: var(--primary-dark, #2563eb);
    transform: scale(1.05);
}

#nw-livechat-send:active {
    transform: scale(0.95);
}

#nw-livechat-send svg {
    margin-left: -2px; /* optical centering */
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    #nw-livechat-window {
        position: fixed !important;
        bottom: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 999999 !important;
        transform: translateY(100%);
        box-shadow: none !important;
        display: flex;
        flex-direction: column;
    }
    
    #nw-livechat-window.open {
        transform: translateY(0);
    }
    
    #nw-livechat-header {
        border-radius: 0;
        padding-top: calc(env(safe-area-inset-top, 0px) + 20px);
        padding-bottom: 20px;
    }

    #nw-livechat-footer {
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    }
    
    .nw-message {
        max-width: 92%;
        font-size: 15px;
    }
    
    #nw-livechat-auth {
        padding: 0 16px;
    }
    
    #nw-livechat-auth h4 {
        font-size: 24px;
        margin-bottom: 12px;
    }
    
    /* Hide the chat bubble when the window is open on mobile to prevent overlap with the full screen interface */
    #nw-livechat-container.is-open #nw-livechat-bubble {
        display: none !important;
    }
    
    /* Ensure body doesn't scroll when chat is open */
    body.livechat-mobile-open {
        overflow: hidden !important;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

.nw-star {
    cursor: pointer;
    color: #cbd5e1;
    transition: color 0.2s, transform 0.2s;
}
.nw-star:hover, .nw-star.active {
    color: #f59e0b;
    transform: scale(1.1);
}

