/* Khung chat hỗ trợ (public/js/chat-widget.js). Màu lấy từ public/css/theme.css. */
.cw-fab {
    position: fixed; z-index: 55; width: 56px; height: 56px; border-radius: 50%;
    border: none; background: var(--grad); color: #fff; cursor: grab;
    box-shadow: 0 8px 24px rgba(159, 18, 57, 0.28); display: flex; align-items: center; justify-content: center;
    touch-action: none; user-select: none; -webkit-user-select: none; padding: 0;
    transition: transform 0.15s, left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease, border-radius 0.25s ease;
}
.cw-fab.cw-dragging { cursor: grabbing; transform: scale(1.06); transition: none; }
.cw-fab svg { width: 44px; height: 44px; flex: none; pointer-events: none; }
/* Đuôi bong bóng quay về mép đang dính (icon vẽ sẵn đuôi bên trái) */
.cw-fab[data-side="right"] svg { transform: scaleX(-1); }
/* Núp vào mép (trang /practice): thẻ mảnh bo góc, gấu trúc ló nửa mặt */
.cw-fab.cw-tucked {
    width: 14px; height: 40px; border-radius: 12px 0 0 12px; overflow: hidden; opacity: 0.92;
    box-shadow: 0 4px 14px rgba(159, 18, 57, 0.25);
}
.cw-fab.cw-tucked[data-side="left"] { border-radius: 0 12px 12px 0; }
.cw-fab.cw-tucked svg { width: 34px; height: 34px; }
.cw-fab.cw-tucked[data-side="right"] svg { margin-right: -20px; }
.cw-fab.cw-tucked[data-side="left"] svg { margin-left: -20px; }
/* Núp mà còn tin chưa đọc: chấm đỏ nhỏ nằm gọn trong thẻ ở mép, không che nội dung trang */
.cw-fab.cw-tucked .cw-badge {
    top: 4px; right: auto; left: 3px; min-width: 0; width: 8px; height: 8px; padding: 0;
    font-size: 0; background: #ef4444; box-shadow: 0 0 0 1.5px #fff;
}
.cw-fab.cw-tucked .cw-badge[hidden] { display: none; }
.cw-badge {
    position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 5px;
    border-radius: 10px; background: #fff; color: var(--primary); font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--primary);
}
.cw-badge[hidden] { display: none; }

.cw-toast {
    position: fixed; z-index: 55; max-width: 260px; background: #fff; color: var(--ink);
    border-radius: 14px; padding: 12px 34px 12px 14px; font-size: 14px; line-height: 1.45;
    box-shadow: 0 10px 30px rgba(58, 24, 32, 0.18); cursor: pointer; animation: cw-pop 0.2s ease-out;
}
.cw-toast-close {
    position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border: none; background: none;
    color: var(--faint); font-size: 18px; cursor: pointer; border-radius: 50%;
}

.cw-panel {
    position: fixed; z-index: 56; width: 360px; height: min(560px, calc(100vh - 32px));
    background: #fff; border-radius: 18px; box-shadow: 0 18px 48px rgba(58, 24, 32, 0.25);
    display: flex; flex-direction: column; overflow: hidden; color: var(--ink); animation: cw-pop 0.18s ease-out;
}
.cw-panel[hidden] { display: none; }
.cw-head { background: var(--grad); color: #fff; padding: 12px 8px 12px 16px; display: flex; align-items: center; gap: 8px; }
.cw-head-title { flex: 1; min-width: 0; }
.cw-head-title strong { display: block; font-size: 15px; }
.cw-head button {
    border: none; background: rgba(255, 255, 255, 0.18); color: #fff; border-radius: 999px;
    height: 34px; min-width: 34px; padding: 0 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.cw-list { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); overscroll-behavior: contain; }
.cw-msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.cw-msg a { color: inherit; font-weight: 600; }
.cw-msg a.cw-link { color: #2563eb; text-decoration: underline; text-underline-offset: 2px; }
.cw-msg-user a.cw-link { color: #fff; }
.cw-msg-user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.cw-msg-bot, .cw-msg-proactive { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.cw-msg-admin { align-self: flex-start; background: var(--primary-soft); border: 1px solid var(--primary-line); border-bottom-left-radius: 4px; }
.cw-who { font-size: 11px; color: var(--muted-2); margin-bottom: 2px; font-weight: 600; }
.cw-empty { color: var(--muted); font-size: 14px; text-align: center; margin: auto 0; line-height: 1.5; }
.cw-typing { align-self: flex-start; color: var(--muted-2); font-size: 13px; padding: 4px 2px; }
.cw-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.cw-form textarea {
    flex: 1; resize: none; border: 1px solid var(--line-strong); border-radius: 12px; padding: 9px 12px;
    font-size: 15px; line-height: 1.35; max-height: 96px; min-height: 40px; color: var(--ink); overflow-y: hidden;
}
.cw-form textarea:focus { outline: none; border-color: var(--primary); }
.cw-form button { border: none; border-radius: 12px; background: var(--grad); color: #fff; font-weight: 700; padding: 0 16px; cursor: pointer; font-size: 14px; }
.cw-form button:disabled { opacity: 0.5; cursor: not-allowed; }
.cw-note { font-size: 11px; color: var(--faint); text-align: center; padding: 0 10px 8px; background: #fff; }

@keyframes cw-pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* Điện thoại: khung chat trượt từ dưới lên, chiếm gần hết màn hình */
@media (max-width: 640px) {
    .cw-panel {
        left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important;
        width: 100%; height: 88vh; height: 88dvh; border-radius: 18px 18px 0 0;
    }
    .cw-form { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
    .cw-form textarea { font-size: 16px; } /* iOS không tự phóng to khi gõ */
}
@media (prefers-reduced-motion: reduce) {
    .cw-fab, .cw-panel, .cw-toast { transition: none; animation: none; }
}
