/* Khung chat trợ lý CANPOS (góc phải dưới, mọi trang). Tiền tố cpw- để không đụng CSS trang. */
.cpw-root {
    --cpw-primary: #7928ca;
    --cpw-primary-2: #ff007a;
    --cpw-bg: #ffffff;
    --cpw-soft: #f4f1fa;
    --cpw-line: #e7e1f2;
    --cpw-text: #1f1830;
    --cpw-muted: #6d6585;
    font-family: 'Be Vietnam Pro', system-ui, sans-serif;
    position: fixed;
    /* Nằm trên nút Zalo (Zalo ở right 30, bottom 30, cao 56) — nút chat là dòng đầu */
    right: 27px;
    bottom: 100px;
    z-index: 10000;
    color: var(--cpw-text);
}
.cpw-root * { box-sizing: border-box; }

/* Nút tròn mở chat */
.cpw-launcher {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--cpw-primary), var(--cpw-primary-2));
    box-shadow: 0 10px 28px rgba(121, 40, 202, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    position: relative;
}
.cpw-launcher:hover { transform: scale(1.06); }
.cpw-launcher svg { width: 30px; height: 30px; fill: #fff; }
.cpw-launcher .cpw-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
}

/* Lời chào tự bật */
.cpw-greet {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 240px;
    background: var(--cpw-bg);
    border-radius: 14px;
    padding: 10px 28px 10px 12px;
    box-shadow: 0 12px 32px rgba(20, 10, 40, 0.25);
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
    animation: cpw-pop 0.25s ease-out;
}
.cpw-greet b { color: var(--cpw-primary-2); font-weight: 800; }
.cpw-greet-hot {
    font-weight: 900;
    font-size: 14.5px;
    color: var(--cpw-primary);
    margin-bottom: 3px;
}
.cpw-greet-cta {
    display: block;
    width: 100%;
    margin-top: 9px;
    padding: 9px 10px;
    border: none;
    border-radius: 10px;
    font: inherit;
    font-size: 14px;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, var(--cpw-primary), var(--cpw-primary-2));
    box-shadow: 0 6px 16px rgba(121, 40, 202, 0.35);
}
.cpw-greet-close {
    position: absolute;
    top: 6px;
    right: 8px;
    border: none;
    background: none;
    font-size: 18px;
    color: var(--cpw-muted);
    cursor: pointer;
    line-height: 1;
}

/* Khung chat */
.cpw-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 370px;
    height: min(600px, calc(100vh - 200px));
    background: var(--cpw-bg);
    border-radius: 20px;
    box-shadow: 0 18px 48px rgba(20, 10, 40, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: cpw-pop 0.2s ease-out;
}
.cpw-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--cpw-primary), #4c1d95);
    color: #fff;
}
.cpw-head img { width: 36px; height: 36px; border-radius: 10px; background: #fff; }
.cpw-head-title { flex: 1; min-width: 0; }
.cpw-head-title strong { display: block; font-size: 15px; }
.cpw-head-title span { font-size: 12px; opacity: 0.85; }
.cpw-close {
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    font-size: 20px;
    cursor: pointer;
}

.cpw-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: var(--cpw-soft);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.cpw-msg {
    max-width: 85%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.cpw-msg a { color: var(--cpw-primary); font-weight: 600; word-break: break-all; }
.cpw-bot { align-self: flex-start; background: var(--cpw-bg); border: 1px solid var(--cpw-line); border-bottom-left-radius: 4px; }
.cpw-user { align-self: flex-end; background: var(--cpw-primary); color: #fff; border-bottom-right-radius: 4px; }
.cpw-user img { display: block; max-width: 180px; border-radius: 10px; }

/* Thẻ tài khoản dùng thử */
.cpw-cred { align-self: stretch; max-width: 100%; background: var(--cpw-bg); border: 2px solid var(--cpw-primary); border-radius: 14px; padding: 12px; }
.cpw-cred-title { font-weight: 800; margin-bottom: 8px; color: var(--cpw-primary); }
.cpw-cred-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px dashed var(--cpw-line); }
.cpw-cred-row span { font-size: 12px; color: var(--cpw-muted); }
.cpw-cred-row b { font-size: 16px; letter-spacing: 0.3px; }
.cpw-copy { border: 1px solid var(--cpw-line); background: var(--cpw-soft); border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer; font-weight: 600; color: var(--cpw-primary); }

/* Nút trả lời nhanh */
.cpw-chips { display: flex; flex-wrap: wrap; gap: 8px; align-self: flex-start; }
.cpw-chip {
    border: 1.5px solid var(--cpw-primary);
    background: var(--cpw-bg);
    color: var(--cpw-primary);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}
.cpw-chip.cpw-main { background: linear-gradient(135deg, var(--cpw-primary), var(--cpw-primary-2)); color: #fff; border: none; }

/* Đang soạn */
.cpw-typing { align-self: flex-start; background: var(--cpw-bg); border: 1px solid var(--cpw-line); border-radius: 14px; padding: 10px 12px; font-size: 13px; color: var(--cpw-muted); }
.cpw-typing i { display: inline-block; width: 6px; height: 6px; margin: 0 1px; border-radius: 50%; background: var(--cpw-muted); animation: cpw-blink 1.2s infinite; }
.cpw-typing i:nth-child(2) { animation-delay: 0.2s; }
.cpw-typing i:nth-child(3) { animation-delay: 0.4s; }

/* Chân khung chat: chỉ nút gửi ảnh menu + Zalo tư vấn */
.cpw-photo-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 12px;
    padding: 12px;
    font: inherit;
    font-size: 15px;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, var(--cpw-primary), var(--cpw-primary-2));
}
.cpw-photo-btn svg { width: 22px; height: 22px; fill: #fff; }
.cpw-photo-btn:disabled { opacity: 0.6; cursor: default; }
.cpw-zalo-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 14px;
    border-radius: 12px;
    background: #0068ff;
    color: #fff;
    font-size: 13.5px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

/* Ô nhập */
.cpw-input { display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; padding: 10px; border-top: 1px solid var(--cpw-line); background: var(--cpw-bg); }
.cpw-name {
    flex: 1 1 100%;
    border: 1px solid var(--cpw-line);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    font-size: 16px; /* >= 16px để iPhone không tự phóng to khi gõ */
    color: var(--cpw-text);
    background: #fff;
    outline: none;
}
.cpw-name:focus { border-color: var(--cpw-primary); }
.cpw-input textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--cpw-line);
    border-radius: 12px;
    padding: 9px 12px;
    font: inherit;
    font-size: 14px;
    max-height: 96px;
    outline: none;
    color: var(--cpw-text);
    background: #fff;
}
.cpw-input textarea:focus { border-color: var(--cpw-primary); }
.cpw-icon-btn { width: 40px; height: 40px; border-radius: 12px; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cpw-icon-btn svg { width: 22px; height: 22px; }
.cpw-attach { background: var(--cpw-soft); }
.cpw-attach svg { fill: var(--cpw-primary); }
.cpw-send { background: var(--cpw-primary); }
.cpw-send svg { fill: #fff; }
.cpw-icon-btn:disabled { opacity: 0.5; cursor: default; }

/* Có khung chat thì ẩn nút gọi điện, chỉ giữ Zalo dưới nút chat */
body.cpw-on .floating-contact .phone-btn { display: none !important; }

@keyframes cpw-pop { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes cpw-blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

@media (max-width: 600px) {
    .cpw-root { right: 16px; bottom: 80px; }
    .cpw-launcher { width: 56px; height: 56px; }
    .cpw-panel { position: fixed; inset: auto 0 0 0; width: 100vw; height: 88vh; border-radius: 20px 20px 0 0; }
    .cpw-greet { width: min(240px, calc(100vw - 32px)); }
    .cpw-open .cpw-launcher { display: none; }
}
