/* ============================================================
   Chat hỗ trợ trực tuyến 24/7 — widget phía khách/user.
   Dùng biến --theme-primary của hệ thống. Nổi mọi trang.
   ============================================================ */
:root {
    --pmchat-primary: var(--theme-primary, #0c4c29);
    --pmchat-primary-dark: #08331c;
    --pmchat-secondary: #064e3b;
    --pmchat-bg: #f4f8f6;
    --pmchat-text: #050505;
    --pmchat-text-sub: #65676b;
    --pmchat-border: rgba(12, 76, 41, 0.12);
    --pmchat-shadow: 0 16px 48px rgba(12, 76, 41, 0.16);
    --pmchat-radius-panel: 22px;
    --pmchat-radius-bubble: 16px;
    --pmchat-radius-btn: 12px;
}

/* 1. Launcher Button */
.pmchat-launcher {
    position: fixed;
    right: 20px;
    bottom: 24px;
    z-index: 10000;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--pmchat-primary) 0%, var(--pmchat-secondary) 100%);
    color: #fff;
    box-shadow: 0 8px 30px rgba(12, 76, 41, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.25);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.pmchat-launcher::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border-radius: 50%;
    border: 2px solid rgba(12, 76, 41, 0.3);
    animation: pmchatLauncherRipple 2s infinite ease-out;
    z-index: -1;
}
.pmchat-launcher:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 35px rgba(12, 76, 41, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.pmchat-launcher i {
    font-size: 1.6rem;
    transition: transform 0.3s ease;
}
.pmchat-launcher:hover i {
    transform: rotate(8deg) scale(1.05);
}
.pmchat-launcher .pmchat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: #ef4444;
    color: #fff;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    z-index: 2;
}
.pmchat-launcher .pmchat-badge.show {
    display: inline-flex;
}

@keyframes pmchatLauncherRipple {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* 2. Alert Tooltip */
.pmchat-tooltip {
    position: absolute;
    right: 74px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(12, 76, 41, 0.95);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #fff;
    padding: 8px 16px;
    border-radius: 50px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    box-shadow: 0 8px 25px rgba(12, 76, 41, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.2);
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: pmchatTooltipFloat 3s infinite ease-in-out;
}
.pmchat-tooltip i {
    font-size: 0.85rem;
    color: #4ade80;
}
.pmchat-tooltip::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: transparent transparent transparent rgba(12, 76, 41, 0.95);
}

@keyframes pmchatTooltipFloat {
    0% { transform: translateY(-50%) translateX(0); }
    50% { transform: translateY(-50%) translateX(-6px); }
    100% { transform: translateY(-50%) translateX(0); }
}

/* 3. Main Chat Panel */
.pmchat-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 10010;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: 560px;
    max-height: calc(100dvh - 32px);
    background: #ffffff;
    border-radius: var(--pmchat-radius-panel);
    border: 1px solid var(--pmchat-border);
    box-shadow: var(--pmchat-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Montserrat', sans-serif;
}
.pmchat-panel.open {
    display: flex;
    animation: pmchatPanelOpen 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes pmchatPanelOpen {
    from { opacity: 0; transform: scale(0.9) translateY(24px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* 4. Chat Header */
.pmchat-head {
    background: linear-gradient(135deg, var(--pmchat-primary) 0%, var(--pmchat-secondary) 100%);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    box-shadow: 0 4px 16px rgba(12, 76, 41, 0.15);
    z-index: 1;
}
.pmchat-head .pmchat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.pmchat-head .pmchat-htitle {
    font-weight: 700;
    font-size: 0.98rem;
    line-height: 1.2;
    letter-spacing: -0.01em;
}
.pmchat-head .pmchat-hsub {
    font-size: 0.74rem;
    opacity: 0.92;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}
.pmchat-head .pmchat-hsub .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    box-shadow: 0 0 8px #4ade80;
}
.pmchat-head .pmchat-close {
    margin-left: auto;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.45rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.85;
    transition: opacity 0.2s, transform 0.2s;
}
.pmchat-head .pmchat-close:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* 5. Chat Body */
.pmchat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    background: var(--pmchat-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Scrollbar Customization */
.pmchat-body::-webkit-scrollbar {
    width: 6px;
}
.pmchat-body::-webkit-scrollbar-track {
    background: transparent;
}
.pmchat-body::-webkit-scrollbar-thumb {
    background: rgba(12, 76, 41, 0.15);
    border-radius: 99px;
}
.pmchat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(12, 76, 41, 0.3);
}

/* Message Bubbles */
.pmchat-msg {
    display: flex;
    max-width: 84%;
}
.pmchat-msg.us {
    align-self: flex-end;
    justify-content: flex-end;
}
.pmchat-msg.them {
    align-self: flex-start;
}
.pmchat-bubble {
    padding: 10px 14px;
    border-radius: var(--pmchat-radius-bubble);
    font-size: 0.86rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}
.pmchat-msg.us .pmchat-bubble {
    background: linear-gradient(135deg, var(--pmchat-primary) 0%, var(--pmchat-primary-dark) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(12, 76, 41, 0.15);
}
.pmchat-msg.them .pmchat-bubble {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid rgba(12, 76, 41, 0.08);
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}
.pmchat-msg.sys {
    align-self: center;
    max-width: 90%;
    margin: 4px 0;
}
.pmchat-msg.sys .pmchat-bubble {
    background: rgba(12, 76, 41, 0.08);
    color: var(--pmchat-primary);
    font-size: 0.76rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 5px 14px;
    box-shadow: none;
    border: 1px solid rgba(12, 76, 41, 0.06);
}
.pmchat-time {
    font-size: 0.66rem;
    color: #94a3b8;
    margin-top: 4px;
    padding: 0 4px;
}
.pmchat-msg.us .pmchat-time {
    text-align: right;
}
.pmchat-bubble img {
    max-width: 200px;
    border-radius: 10px;
    display: block;
    margin-top: 6px;
    cursor: pointer;
    transition: transform 0.25s ease;
}
.pmchat-bubble img:hover {
    transform: scale(1.02);
}
/* Trạng thái gửi tin nhắn */
.pmchat-msg.pmchat-msg-sending .pmchat-bubble {
    opacity: 0.65;
    transition: opacity 0.2s ease;
}
.pmchat-msg.pmchat-msg-failed .pmchat-bubble {
    background: #fecaca !important;
    color: #991b1b !important;
    border: 1px solid #fca5a5 !important;
}
.pmchat-msg.pmchat-msg-failed .pmchat-time {
    color: #ef4444;
    font-weight: bold;
}

/* 6. Chat Footer Input Area */
.pmchat-foot {
    flex: 0 0 auto;
    border-top: 1px solid rgba(12, 76, 41, 0.08);
    background: #ffffff;
    padding: 10px 14px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.02);
}
.pmchat-inputrow {
    display: flex;
    align-items: center;
    gap: 8px;
}
.pmchat-inputrow textarea {
    flex: 1 1 auto;
    resize: none;
    border: 1px solid #dbe3ef;
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 0.86rem;
    max-height: 90px;
    line-height: 1.4;
    transition: border-color 0.25s, box-shadow 0.25s;
    font-family: inherit;
}
.pmchat-inputrow textarea:focus {
    outline: none;
    border-color: var(--pmchat-primary);
    box-shadow: 0 0 0 3px rgba(12, 76, 41, 0.12);
}
.pmchat-iconbtn {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}
.pmchat-attach {
    background: #f1f5f9;
    color: #475569;
}
.pmchat-attach:hover {
    background: #e2e8f0;
    color: #1e293b;
    transform: scale(1.05);
}
.pmchat-send {
    background: linear-gradient(135deg, var(--pmchat-primary) 0%, var(--pmchat-primary-dark) 100%);
    color: #fff;
    box-shadow: 0 3px 8px rgba(12, 76, 41, 0.25);
}
.pmchat-send:hover:not(:disabled) {
    transform: scale(1.05) translateY(-1px);
    box-shadow: 0 5px 12px rgba(12, 76, 41, 0.35);
}
.pmchat-send:active:not(:disabled) {
    transform: translateY(1px);
}
.pmchat-send:disabled {
    opacity: 0.45;
    cursor: default;
    box-shadow: none;
}
.pmchat-previews {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 0 4px 8px;
}
.pmchat-previews .pv {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    overflow: visible;
    border: 1px solid rgba(12, 76, 41, 0.1);
}
.pmchat-previews .pv img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
}
.pmchat-previews .pv .rm {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 0.72rem;
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.35);
    transition: transform 0.2s;
}
.pmchat-previews .pv .rm:hover {
    transform: scale(1.15);
}

/* 7. Guest Start Form UI */
.pmchat-guest {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #ffffff;
    flex: 1 1 auto;
}
.pmchat-guest h6 {
    font-weight: 700;
    color: #0f172a;
    margin: 0;
    font-size: 1.1rem;
}
.pmchat-guest p {
    font-size: 0.84rem;
    color: #64748b;
    margin: 0 0 6px;
    line-height: 1.45;
}
.pmchat-guest input {
    border: 1px solid #dbe3ef;
    border-radius: var(--pmchat-radius-btn);
    padding: 11px 14px;
    font-size: 0.88rem;
    transition: border-color 0.25s, box-shadow 0.25s;
    font-family: inherit;
}
.pmchat-guest input:focus {
    outline: none;
    border-color: var(--pmchat-primary);
    box-shadow: 0 0 0 3px rgba(12, 76, 41, 0.12);
}
.pmchat-form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.pmchat-error-msg {
    font-size: 0.72rem;
    color: #ef4444;
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    min-height: 15px;
    display: none;
    padding-left: 4px;
}
.pmchat-guest input.is-invalid {
    border-color: #ef4444 !important;
    background-color: #fffefb;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}
.pmchat-guest input.is-valid {
    border-color: var(--pmchat-primary, #0c4c29) !important;
    background-color: #fbfdfb;
}
.pmchat-guest .pmchat-startbtn {
    background: linear-gradient(135deg, var(--pmchat-primary) 0%, var(--pmchat-secondary) 100%);
    color: #fff;
    border: none;
    border-radius: var(--pmchat-radius-btn);
    padding: 12px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 6px;
    box-shadow: 0 4px 12px rgba(12, 76, 41, 0.25);
    transition: all 0.25s ease;
    font-family: inherit;
    font-size: 0.88rem;
}
.pmchat-guest .pmchat-startbtn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(12, 76, 41, 0.35);
}
.pmchat-guest .pmchat-startbtn:active:not(:disabled) {
    transform: translateY(1px);
}
.pmchat-guest .pmchat-startbtn:disabled {
    opacity: 0.55;
    cursor: default;
    box-shadow: none;
}

.pmchat-empty {
    text-align: center;
    color: #94a3b8;
    font-size: 0.84rem;
    margin: auto;
}

/* 8. Mobile Breakpoint Overrides */
@media (max-width: 480px) {
    .pmchat-panel {
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        border: none;
    }
    .pmchat-launcher {
        bottom: 24px;
    }
    .pmchat-tooltip {
        display: none !important;
    }
    .pmchat-head {
        padding: 14px 16px;
    }
    .pmchat-guest {
        padding: 20px;
    }
}
