/* ============================================================================
   EcuTunerx — Live chat (operator ↔ customer). Shared by track.html + dashboard.
   ========================================================================== */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }

.chat__head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--glass-2); backdrop-filter: blur(var(--glass-blur)); }
.chat__avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--grad-accent); display: grid; place-items: center; font-family: var(--font-display); font-size: 0.8rem; color: var(--accent-ink); flex: none; }
.chat__title { font-weight: 600; font-size: var(--fs-sm); }
.chat__presence { display: flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-top: 2px; }
.chat__presence .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.chat__presence.is-online .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.chat__conn { margin-left: auto; font-family: var(--font-mono); font-size: 0.58rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.chat__conn.is-live { color: var(--accent); }

.chat__msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.chat__empty { margin: auto; text-align: center; color: var(--faint); font-family: var(--font-mono); font-size: var(--fs-sm); }

.msg { max-width: 78%; display: flex; flex-direction: column; gap: 4px; animation: msgIn .25s var(--ease-out); }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg--me { align-self: flex-end; align-items: flex-end; }
.msg--them { align-self: flex-start; align-items: flex-start; }
.msg__bubble { padding: 10px 14px; border-radius: 16px; font-size: var(--fs-sm); line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.msg--me .msg__bubble { background: var(--accent-soft); border: 1px solid rgba(25,230,255,0.25); color: var(--text); border-bottom-right-radius: 5px; }
.msg--them .msg__bubble { background: var(--surface-2); border: 1px solid var(--line); color: var(--text-dim); border-bottom-left-radius: 5px; }
.msg__meta { font-family: var(--font-mono); font-size: 0.58rem; color: var(--faint); letter-spacing: 0.04em; }
.msg__meta .rcpt { color: var(--accent); }
.msg__img { max-width: 240px; max-height: 240px; border-radius: 12px; border: 1px solid var(--line); display: block; }
.msg__file { display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); color: var(--accent); font-size: var(--fs-sm); text-decoration: none; }
.msg__file svg { width: 16px; height: 16px; }

.msg--system { align-self: center; max-width: 90%; }
.msg--system .msg__bubble { background: rgba(255,255,255,0.04); border: 1px dashed var(--line-strong); color: var(--muted); font-family: var(--font-mono); font-size: var(--fs-xs); text-align: center; border-radius: var(--r-pill); }

.chat__typing { align-self: flex-start; display: none; align-items: center; gap: 5px; padding: 8px 12px; }
.chat__typing.show { display: flex; }
.chat__typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: typedot 1.2s infinite; }
.chat__typing span:nth-child(2) { animation-delay: .2s; } .chat__typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typedot { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.chat__quick { display: flex; gap: 6px; padding: 8px 12px 0; flex-wrap: wrap; }
.chat__quick button { padding: 6px 11px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); color: var(--text-dim); font-size: var(--fs-xs); cursor: pointer; transition: all var(--dur); white-space: nowrap; }
.chat__quick button:hover { border-color: var(--accent); color: var(--accent); }

.chat__composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat__attach { width: 40px; height: 40px; flex: none; border-radius: 50%; border: 1px solid var(--line-strong); display: grid; place-items: center; color: var(--text-dim); cursor: pointer; transition: all var(--dur); }
.chat__attach:hover { border-color: var(--accent); color: var(--accent); }
.chat__attach svg { width: 18px; height: 18px; }
.chat__input { flex: 1; resize: none; max-height: 120px; min-height: 40px; padding: 10px 14px; border-radius: var(--r-lg); background: var(--surface-2); border: 1px solid var(--line); color: var(--text); font: inherit; font-size: var(--fs-sm); }
.chat__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat__send { width: 44px; height: 44px; flex: none; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; box-shadow: var(--glow-cyan); transition: transform var(--dur) var(--ease-spring); }
.chat__send:hover { transform: scale(1.06); }
.chat__send:active { transform: scale(0.94); }
.chat__send svg { width: 20px; height: 20px; }
.chat__attach-preview { padding: 0 12px 8px; }
.chat__attach-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--r-pill); background: var(--accent-soft); border: 1px solid rgba(25,230,255,0.25); color: var(--accent); font-size: var(--fs-xs); }
.chat__attach-chip button { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 1.1em; line-height: 1; }

/* unread badge (dashboard) */
.unread-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--hot); color: #fff; font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700; margin-left: 6px; vertical-align: middle; }

/* ── floating chat bubble (customer) ───────────────────────────────────────── */
.chat-fab { position: fixed; right: 22px; bottom: 22px; z-index: var(--z-modal); width: 60px; height: 60px; border-radius: 50%;
  background: var(--grad-accent); display: grid; place-items: center; cursor: pointer; border: none;
  box-shadow: 0 10px 30px -8px rgba(25,230,255,0.5), 0 0 0 1px rgba(25,230,255,0.4);
  transition: transform var(--dur) var(--ease-spring), box-shadow var(--dur); animation: fabIn .4s var(--ease-out); }
.chat-fab:hover { transform: scale(1.07); }
.chat-fab svg { width: 26px; height: 26px; color: var(--accent-ink); }
.chat-fab .x { display: none; }
.chat-fab.is-open .bubble { display: none; }
.chat-fab.is-open .x { display: block; }
@keyframes fabIn { from { opacity: 0; transform: scale(0.5) translateY(20px); } to { opacity: 1; transform: none; } }
.chat-fab__badge { position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--hot); color: #fff; font-family: var(--font-mono); font-size: 0.66rem; font-weight: 700; display: none; place-items: center;
  border: 2px solid var(--bg); animation: pulseBadge 1.6s infinite; }
.chat-fab__badge.show { display: grid; }
@keyframes pulseBadge { 0%,100% { box-shadow: 0 0 0 0 rgba(255,45,85,0.5); } 50% { box-shadow: 0 0 0 6px rgba(255,45,85,0); } }

.chat-pop { position: fixed; right: 22px; bottom: 94px; z-index: var(--z-modal); width: 380px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 130px); border-radius: var(--r-lg); overflow: hidden;
  box-shadow: var(--shadow-lg); border: 1px solid var(--line-strong);
  opacity: 0; visibility: hidden; transform: translateY(16px) scale(0.98); transform-origin: bottom right;
  transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out), visibility var(--dur); }
.chat-pop.is-open { opacity: 1; visibility: visible; transform: none; }
.chat-pop .chat { height: 100%; border: none; border-radius: 0; }
@media (max-width: 460px) {
  .chat-pop { right: 8px; left: 8px; bottom: 86px; width: auto; height: 70vh; }
  .chat-fab { right: 16px; bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) { .chat-fab, .chat-fab__badge, .chat-pop { animation: none; transition: none; } }
