/* ---- Khung livechat trên trang khách ---- */
.chat-root { position: fixed; z-index: 50; right: 20px; bottom: 20px; }

.chat-fab {
  position: relative; display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28); transition: transform 0.15s;
}
.chat-fab:hover { transform: translateY(-2px); }
.chat-badge {
  position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--bad); color: #fff; font: 700 12px/20px var(--font); text-align: center;
}

.chat-panel {
  display: flex; flex-direction: column; width: 370px; height: min(580px, calc(100vh - 40px));
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow), 0 20px 60px rgba(0, 0, 0, 0.3);
}
.chat-head { display: flex; align-items: center; gap: 6px; padding: 12px 10px 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.chat-head-text { display: grid; flex: 1; min-width: 0; }
.chat-head-text b { font-size: 15px; }
.chat-id { justify-self: start; margin: 1px 0 2px; padding: 1px 6px; border: 1px dashed var(--line); border-radius: 6px; background: transparent; color: inherit; font-family: inherit; font-size: 12px; font-weight: 600; line-height: 1.5; font-variant-numeric: tabular-nums; letter-spacing: .02em; cursor: copy; }
.chat-id:hover { border-color: currentColor; }
.chat-presence { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.chat-presence::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.chat-presence.on { color: var(--ok); }
.chat-presence.on::before { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.chat-end { height: 30px; padding: 0 10px; font-size: 12px; }

.chat-list { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.chat-empty { margin: auto; max-width: 260px; text-align: center; color: var(--muted); font-size: 14px; }
.chat-sys { align-self: center; max-width: 90%; text-align: center; font-size: 12px; color: var(--muted); background: var(--bg-2); border-radius: 10px; padding: 6px 10px; }
.chat-msg { display: flex; flex-direction: column; max-width: 82%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.theirs { align-self: flex-start; align-items: flex-start; }
.chat-who { font-size: 11px; font-weight: 600; color: var(--muted); margin: 0 0 3px 4px; }
.chat-bubble { padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.45; }
.chat-msg.mine .chat-bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.chat-msg.theirs .chat-bubble { background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-img { display: block; max-width: 220px; max-height: 260px; border-radius: 8px; }
.chat-bubble:has(.chat-img) { padding: 4px; }
.chat-meta { font-size: 11px; color: var(--muted); margin: 3px 4px 0; }
.chat-typing { padding: 0 16px 6px; font-size: 12px; color: var(--muted); font-style: italic; }

.chat-closed { padding: 12px 14px 14px; border-top: 1px solid var(--line); display: grid; gap: 10px; font-size: 14px; }
.chat-closed p { margin: 0; }
.chat-rate { display: grid; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.chat-rate textarea { min-height: 0; font-size: 14px; }
.chat-stars { display: flex; gap: 4px; }
.chat-star { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--line-2); cursor: pointer; padding: 0 2px; }
.chat-star.on { color: var(--warn); }

.chat-composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px; border-top: 1px solid var(--line); background: var(--surface); }
.chat-input { flex: 1; min-height: 40px; max-height: 120px; resize: none; padding: 9px 12px; font-size: 14px; line-height: 1.4; border-radius: 12px; }
.chat-attach { width: 40px; height: 40px; }
.chat-send { width: 44px; height: 40px; padding: 0; }

@media (max-width: 520px) {
  .chat-root { right: 14px; bottom: 14px; }
  .chat-root.is-open { inset: 0; }
  .chat-root.is-open .chat-panel { width: 100%; height: 100%; border-radius: 0; border: 0; }
}
