/* ==========================================================================
   ZALO WEB MODERN CHAT THEME (Clean, Crisp & Fully Responsive)
   ========================================================================== */

.pirate-chat-widget,
.pirate-chat-widget *,
.pirate-chat-trigger,
.pirate-chat-trigger *,
.chat-fullpage-wrap,
.chat-fullpage-wrap * {
    box-sizing: border-box !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Floating Chat Trigger Button (Zalo Blue) */
.pirate-chat-trigger {
    position: fixed;
    bottom: 18px;
    right: 18px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    border: none;
    background: linear-gradient(135deg, #0084ff, #0068ff);
    color: #ffffff;
    font-weight: 700;
    font-size: 12.5px;
    box-shadow: 0 4px 14px rgba(0, 104, 255, 0.4);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

.pirate-chat-trigger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 104, 255, 0.5);
    background: linear-gradient(135deg, #0091ff, #005ae0);
}

.pirate-chat-trigger .chat-icon {
    font-size: 15px;
    display: inline-block;
}

.pirate-chat-trigger .chat-unread-badge {
    display: none;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    padding: 1px 5px;
    border-radius: 999px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.25);
    animation: pulseBadge 1.5s infinite;
}

@keyframes pulseBadge {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Chat Backdrop for Mobile */
.pirate-chat-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 9998;
    display: none;
    backdrop-filter: blur(1.5px);
    -webkit-backdrop-filter: blur(1.5px);
}

.pirate-chat-backdrop.is-active {
    display: block;
}

/* Floating Chat Container Modal (Zalo Card) */
.pirate-chat-widget {
    position: fixed;
    bottom: 65px;
    right: 18px;
    width: 340px;
    max-width: calc(100vw - 32px);
    height: 460px;
    max-height: calc(100vh - 85px);
    z-index: 10000;
    display: none;
    flex-direction: column;
    background: #ebf0f9;
    border: 1px solid #c7dcff;
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0, 40, 100, 0.18), 0 2px 8px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    animation: slideUpChat 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.pirate-chat-widget.is-open {
    display: flex;
}

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

/* Chat Header (Zalo Blue) */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #0068ff;
    color: #ffffff;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 13.5px;
    letter-spacing: 0.1px;
}

.chat-header-title .online-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    border: 1.5px solid #ffffff;
    flex-shrink: 0;
}

.chat-live-badge {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-header-btn {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    color: #ffffff;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    transition: background 0.15s ease;
    text-decoration: none;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* Chat Messages List (Zalo Pale Blue-Gray) */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
    background: #ebf0f9;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #c5d4e8;
    border-radius: 4px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9fb7d6;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

/* Individual Message Layout */
.chat-item {
    display: flex;
    gap: 6px;
    max-width: 84%;
    animation: fadeInMsg 0.12s ease;
}

.chat-item.is-consecutive {
    margin-top: -4px;
}

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

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

.chat-item.is-me {
    align-self: flex-end;
}

/* Avatar on left for other users */
.zalo-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #dbeafe;
    border: 1px solid #bfdbfe;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    margin-top: 1px;
}

.zalo-avatar-spacer {
    width: 28px;
    flex-shrink: 0;
}

.chat-item-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-item.is-me .chat-item-body {
    align-items: flex-end;
}

/* Sender Name Header */
/* Sender Name Header */
.chat-sender-info {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 3px;
    font-size: 11px;
    flex-wrap: wrap;
}

.chat-item.is-me .chat-sender-info {
    justify-content: flex-end;
}

.chat-sender-name {
    font-weight: 700;
    color: #1e3a8a;
    font-size: 11.5px;
}

.chat-sender-name.is-admin-name {
    color: #dc2626;
    font-weight: 800;
}

.chat-badge-admin {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #ffffff;
    font-size: 8.5px;
    font-weight: 900;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    box-shadow: 0 1px 2px rgba(220, 38, 38, 0.3);
}

.chat-badge-user {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    font-size: 8.5px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
}

.chat-badge-verified {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    background: #0068ff;
    color: #ffffff;
    font-size: 9px;
    font-weight: 900;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 104, 255, 0.4);
    margin-left: 2px;
}

.chat-badge-level {
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 8.5px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
}

.chat-badge-class {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10.5px;
}

.zalo-avatar.is-admin {
    background: #fee2e2;
    border-color: #f87171;
}

/* Bubble Styling (Zalo Signature Bubbles) */
.chat-bubble {
    position: relative;
    padding: 7px 11px;
    font-size: 12.5px;
    line-height: 1.42;
    word-break: break-word;
}

/* Other users: Pure White Bubble */
.chat-item.is-other .chat-bubble {
    background: #ffffff;
    color: #081c36;
    border: 1px solid #e2e8f0;
    border-radius: 14px 14px 14px 2px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* My own messages: Zalo Soft Blue Bubble */
.chat-item.is-me .chat-bubble {
    background: #e5efff;
    color: #081c36;
    border: 1px solid #c7dcff;
    border-radius: 14px 14px 2px 14px;
    box-shadow: 0 1px 2px rgba(0, 104, 255, 0.06);
}

/* Time and Delete Button */
.chat-bubble-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
}

.chat-time {
    font-size: 9px;
    color: #72808e;
}

.chat-delete-btn {
    background: none;
    border: none;
    color: #ef4444;
    font-size: 10px;
    cursor: pointer;
    padding: 0;
    opacity: 0.7;
}
.chat-delete-btn:hover {
    opacity: 1;
}

/* Chat Footer / Input Area (Zalo White Toolbar) */
.chat-footer {
    padding: 8px 10px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-photo-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.15s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    margin: 0;
}

.chat-photo-btn:hover {
    background: #f1f5f9;
}

.chat-image-preview-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    margin-bottom: 6px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    width: fit-content;
    max-width: 100%;
}

.chat-preview-img {
    max-width: 60px;
    max-height: 60px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid #e2e8f0;
}

.chat-remove-preview {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #dc2626;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.chat-bubble-image {
    margin-bottom: 4px;
    border-radius: 8px;
    overflow: hidden;
    max-width: 220px;
}

.chat-bubble-image img {
    display: block;
    max-width: 100%;
    max-height: 180px;
    border-radius: 8px;
    object-fit: cover;
    transition: transform 0.15s ease;
    cursor: zoom-in;
}

.chat-bubble-image img:hover {
    opacity: 0.95;
}

.chat-emoji-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.15s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.chat-emoji-btn:hover {
    background: #f1f5f9;
}

.chat-input {
    flex: 1;
    height: 32px;
    padding: 6px 12px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    font-size: 13px;
    color: #081c36;
    outline: none;
    transition: all 0.15s ease;
}

.chat-input:focus {
    border-color: #0068ff;
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(0, 104, 255, 0.12);
}

.chat-input::placeholder {
    color: #94a3b8;
}

.chat-send-btn {
    height: 32px;
    padding: 0 14px;
    background: #0068ff;
    border: none;
    border-radius: 16px;
    color: #ffffff;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.15s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.chat-send-btn:hover {
    background: #005ae0;
}

.chat-send-btn.is-loading {
    opacity: 0.7;
    pointer-events: none;
}

/* Guest Login Prompt */
.chat-guest-prompt {
    padding: 8px 12px;
    background: #eff6ff;
    border-radius: 8px;
    border: 1px solid #bfdbfe;
    text-align: center;
    font-size: 11.5px;
    color: #1e40af;
    font-weight: 500;
}

.chat-guest-prompt a {
    color: #0068ff;
    font-weight: 700;
    text-decoration: underline;
    margin: 0 2px;
}

/* Emoji Tray (Zalo Style) */
.chat-emoji-tray {
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    padding: 6px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 6px;
    max-height: 90px;
    overflow-y: auto;
}

.chat-emoji-tray.is-open {
    display: grid;
}

.chat-emoji-item {
    font-size: 16px;
    text-align: center;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    transition: background 0.1s ease;
    user-select: none;
}

.chat-emoji-item:hover {
    background: #e2e8f0;
    transform: scale(1.15);
}

/* Full Page Chat Card (/Users/Chat) */
.chat-fullpage-wrap {
    padding: 12px 14px 24px;
}
.chat-fullpage-card {
    border: 1px solid #c7dcff;
    border-radius: 12px;
    background: #ebf0f9;
    box-shadow: 0 4px 16px rgba(0, 40, 100, 0.08);
    height: 520px;
    max-height: calc(100vh - 260px);
    min-height: 380px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 20px;
    font-weight: 900;
    text-decoration: none;
    margin-right: 6px;
    padding: 0 4px;
    line-height: 1;
    transition: transform 0.15s ease;
}
.chat-back-btn:hover {
    transform: scale(1.2);
    color: #ffffff;
}

/* ==========================================================================
   MOBILE RESPONSIVE (Screens <= 640px - Zalo Mobile Experience)
   ========================================================================== */
@media (max-width: 639px) {
    /* Pure Dedicated Mobile App View */
    html.chat-mobile-open,
    body.chat-mobile-open,
    html.page-chat-active,
    body.page-chat-active {
        position: fixed !important;
        width: 100% !important;
        width: 100vw !important;
        height: 100% !important;
        height: 100dvh !important;
        overflow: hidden !important;
        touch-action: none;
    }

    body.page-chat-active #root,
    body:has(.chat-fullpage-wrap) #root {
        overflow: hidden !important;
        height: 100% !important;
    }

    body.page-chat-active .pirate-footer-box,
    body.page-chat-active img[alt="footerLogo"],
    body.page-chat-active img[alt="bgTopMenu"],
    body.page-chat-active .header-actions,
    body.page-chat-active .flex.flex-row.justify-evenly,
    body.page-chat-active img[alt="headerLogo"],
    body:has(.chat-fullpage-wrap) .pirate-footer-box,
    body:has(.chat-fullpage-wrap) img[alt="footerLogo"],
    body:has(.chat-fullpage-wrap) img[alt="bgTopMenu"],
    body:has(.chat-fullpage-wrap) .header-actions,
    body:has(.chat-fullpage-wrap) .flex.flex-row.justify-evenly,
    body:has(.chat-fullpage-wrap) img[alt="headerLogo"] {
        display: none !important;
    }

    body.page-chat-active .chat-fullpage-wrap,
    body:has(.chat-fullpage-wrap) .chat-fullpage-wrap {
        padding: 0 !important;
        margin: 0 !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        z-index: 9999 !important;
        background: #ebf0f9 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    body.page-chat-active .chat-fullpage-card,
    body:has(.chat-fullpage-wrap) .chat-fullpage-card {
        height: 100% !important;
        max-height: 100% !important;
        min-height: 100% !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        display: flex !important;
        flex-direction: column !important;
        flex: 1 1 auto !important;
    }

    /* Floating Trigger button at bottom right */
    .pirate-chat-trigger {
        bottom: 12px;
        right: 12px;
        padding: 6px 12px;
        font-size: 11.5px;
        gap: 4px;
        z-index: 9998;
    }
    .pirate-chat-trigger .chat-icon {
        font-size: 13px;
    }

    /* Full-Screen Zalo App View on Mobile (Seamless Keyboard Docking) */
    .pirate-chat-widget {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        z-index: 99999 !important;
        background: #ebf0f9 !important;
        display: none;
        flex-direction: column !important;
    }

    .pirate-chat-widget.is-open {
        display: flex !important;
    }

    .chat-header {
        flex: 0 0 auto !important;
        padding: 12px 14px;
        border-radius: 0;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    .chat-header-title {
        font-size: 14px;
        font-weight: 700;
    }
    .chat-header-actions .chat-header-btn {
        font-size: 16px;
        width: 28px;
        height: 28px;
    }

    .chat-messages {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        padding: 10px 8px;
        gap: 8px;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-y !important;
    }

    .chat-item {
        max-width: 88%;
    }
    .chat-bubble {
        font-size: 12.5px;
        padding: 7px 11px;
    }

    .chat-footer {
        flex: 0 0 auto !important;
        width: 100% !important;
        box-sizing: border-box !important;
        padding: 6px 8px env(safe-area-inset-bottom, 6px) !important;
        background: #ffffff;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
    }
    .chat-input {
        font-size: 14px !important;
        height: 36px;
    }
    .chat-emoji-btn, .chat-send-btn, .chat-photo-btn {
        height: 36px;
    }
    .chat-send-btn {
        padding: 0 14px;
        font-size: 12.5px;
    }

    .chat-emoji-tray {
        grid-template-columns: repeat(6, 1fr);
        max-height: 80px;
    }
}
