/* =========================================================
   CHAT DOCK — Facebook-style, max 4 open, rest as bubbles
========================================================= */

:root {
  --cd-text: var(--text);
  --cd-muted: var(--text-sub);
  --cd-cyan: var(--primary);
  --cd-border: rgba(var(--primary-rgb),.16);
  --cd-shadow: 0 26px 90px rgba(0,0,0,.55);
  --cd-ease: cubic-bezier(.2,.9,.2,1);
}

/* ── DOCK CONTAINER ─────────────────────────────────────── */
.chat-dock {
  position: fixed;
  right: 14px;
  bottom: 0;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
  z-index: 3000;
  pointer-events: none;
}
.chat-dock > * { pointer-events: auto; }

/* ── CHAT WINDOW ─────────────────────────────────────────── */
.chat-box {
  width: 300px;
  height: 390px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 14px 14px 0 0;
  border: 1px solid var(--cd-border);
  border-bottom: none;
  background: rgba(14, 18, 38, .72);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: var(--cd-shadow);
  position: relative;
  animation: cdSlideUp .22s var(--cd-ease) both;
}

@keyframes cdSlideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* holographic border */
.chat-box::before {
  content: "";
  position: absolute;
  inset: -1px -1px 0 -1px;
  border-radius: 14px 14px 0 0;
  pointer-events: none;
  background: linear-gradient(135deg,
    rgba(var(--primary-rgb),.32),
    rgba(255,123,241,.18),
    rgba(179,156,255,.22)
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  padding: 1px;
  opacity: .75;
}

/* ── HEADER ─────────────────────────────────────────────── */
.chat-box__head {
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 8px 0 12px;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  cursor: pointer;
  user-select: none;
}

.chat-box__title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  color: var(--cd-text);
  overflow: hidden;
}
.chat-box__title > span {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.chat-box__status {
  font-size: 10px;
  font-weight: 400;
  color: rgba(255,255,255,.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1;
}
.chat-box__status--on { color: #4ade80; }
[data-theme="light"] .chat-box__status { color: var(--muted); }
[data-theme="light"] .chat-box__status--on { color: #16a34a; }

.chat-box__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(var(--primary-rgb),.15);
  border: 1px solid rgba(var(--primary-rgb),.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--cd-cyan);
  flex-shrink: 0;
  overflow: hidden;
}
.chat-box__avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-box__head-actions { display: flex; gap: 4px; flex-shrink: 0; }

.chat-box__head-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.06);
  color: var(--cd-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  transition: background .15s;
}
.chat-box__head-btn:hover { background: rgba(255,255,255,.14); }

/* ── COLLAPSED STATE ─────────────────────────────────────── */
.chat-box.is-collapsed {
  height: 44px;
}
.chat-box.is-collapsed .chat-box__body,
.chat-box.is-collapsed .chat-box__input {
  display: none;
}

/* ── BODY ───────────────────────────────────────────────── */
.chat-box__body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  font-size: 12.5px;
  color: var(--cd-text);
  scroll-behavior: smooth;
}
.chat-box__body::-webkit-scrollbar { width: 3px; }
.chat-box__body::-webkit-scrollbar-thumb { background: rgba(var(--primary-rgb),.18); border-radius: 4px; }

/* ── MESSAGES ───────────────────────────────────────────── */
.chat-box__msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
  animation: cdPop .16s var(--cd-ease) both;
}
@keyframes cdPop {
  from { transform: translateY(5px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

.chat-box__msg .u {
  font-size: 11px;
  font-weight: 700;
  opacity: .85;
  color: var(--text-sub);
}
.chat-box__msg .t {
  line-height: 1.45;
  word-break: break-word;
  padding: 7px 10px;
  border-radius: 14px;
  max-width: 82%;
  font-size: 12.5px;
}

.chat-box__msg.is-me   { align-items: flex-end;   }
.chat-box__msg.is-other{ align-items: flex-start;  }

.chat-box__msg.is-me .t {
  background: rgba(var(--primary-rgb),.14);
  border: 1px solid rgba(var(--primary-rgb),.22);
  color: var(--text);
  border-radius: 14px 14px 4px 14px;
}
.chat-box__msg.is-other .t {
  background: var(--border);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px 14px 14px 4px;
}
.chat-box__msg.is-me .u { color: rgba(var(--primary-rgb),.95); }
.chat-box__msg.is-pending { opacity: .65; }
.chatdock-story-card { width: 158px; border-radius: 12px; overflow: hidden; display: inline-flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); }
.chatdock-story-card__img { width: 100%; height: 112px; object-fit: cover; display: block; filter: brightness(0.65); }
.chatdock-story-card__body { padding: 6px 9px 7px; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); }
.chatdock-story-card__ctx { font-size: 10px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatdock-story-card__msg { font-size: 12px; color: var(--text); word-break: break-word; line-height: 1.4; }

.chat-box__sys {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 6px 0;
}

/* ── INPUT ──────────────────────────────────────────────── */
.chat-box__input {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: flex;
  gap: 6px;
  background: rgba(255,255,255,.02);
}
.chat-box__input input {
  flex: 1;
  height: 36px;
  border-radius: 18px;
  padding: 0 12px;
  background: rgba(8,12,28,.45);
  border: 1px solid var(--border);
  color: var(--cd-text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.chat-box__input input::placeholder { color: var(--muted); }
.chat-box__input input:focus { border-color: rgba(var(--primary-rgb),.3); }

.chat-box__input button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(var(--primary-rgb),.18);
  color: var(--cd-cyan);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .12s;
}
.chat-box__input button:hover  { background: rgba(var(--primary-rgb),.28); transform: scale(1.05); }
.chat-box__input button:active { transform: scale(.96); }

/* ── MINIMIZED BUBBLES COLUMN ───────────────────────────── */
#chat-bubbles {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  z-index: 3001;
  pointer-events: none;
}
#chat-bubbles > * { pointer-events: auto; }

.chat-bubble {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(14,18,38,.85);
  border: 2px solid rgba(var(--primary-rgb),.35);
  box-shadow: 0 4px 20px rgba(0,0,0,.5), 0 0 0 0 rgba(var(--primary-rgb),.3);
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--cd-cyan);
  overflow: hidden;
  transition: transform .15s var(--cd-ease), border-color .15s, box-shadow .15s;
  animation: bubblePop .2s var(--cd-ease) both;
  backdrop-filter: blur(10px);
}
@keyframes bubblePop {
  from { transform: scale(.4); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}
.chat-bubble:hover {
  transform: scale(1.1);
  border-color: rgba(var(--primary-rgb),.6);
  box-shadow: 0 4px 20px rgba(0,0,0,.5), 0 0 0 4px rgba(var(--primary-rgb),.15);
}
.chat-bubble img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.chat-bubble__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ff4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid rgba(14,18,38,1);
}

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 1280px) {
  .chat-box { width: 270px; }
}
@media (max-width: 900px) {
  .chat-box { width: 240px; height: 360px; }
}
@media (max-width: 600px) {
  .chat-box { width: calc(100vw - 28px); height: 340px; border-radius: 14px 14px 0 0; }
  .chat-dock { right: 14px; }
}

/* ===== LIGHT MODE ===== */
[data-theme="light"] .chat-box {
  background: rgba(255,255,255,.96);
  border-color: rgba(0,0,0,.15);
  backdrop-filter: blur(20px);
}
[data-theme="light"] .chat-box::before { opacity: .4; }
[data-theme="light"] .chat-box__head { background: rgba(0,0,0,.02); border-color: rgba(0,0,0,.08); }
[data-theme="light"] .chat-box__title { color: var(--text); }
[data-theme="light"] .chat-box__head-btn { background: rgba(0,0,0,.05); color: var(--muted); }
[data-theme="light"] .chat-box__head-btn:hover { background: rgba(0,0,0,.1); }
[data-theme="light"] .chat-box__body { color: var(--text); }
[data-theme="light"] .chat-box__msg .u { color: var(--primary); }
[data-theme="light"] .chat-box__msg.is-me .t {
  background: rgba(var(--primary-rgb),.12);
  border-color: rgba(var(--primary-rgb),.25);
  color: var(--text);
}
[data-theme="light"] .chat-box__msg.is-me .u { color: var(--primary); }
[data-theme="light"] .chat-box__msg.is-other .t {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .chat-box__sys { color: var(--muted); }
[data-theme="light"] .chat-box__input { border-color: rgba(0,0,0,.08); background: rgba(0,0,0,.02); }
[data-theme="light"] .chat-box__input input {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .chat-box__input input::placeholder { color: var(--muted); }
[data-theme="light"] .chat-box__input input:focus { border-color: rgba(var(--primary-rgb),.4); }
[data-theme="light"] .chat-bubble { background: rgba(255,255,255,.95); border-color: rgba(var(--primary-rgb),.4); }
[data-theme="light"] .chat-bubble__badge { border-color: #ffffff; }
