/* ============================================================
   RADIOWAVE v2.2 — chat.css
   Chat widget · Bubble design · Multi-window · Toggle
   Accent color follows currently playing station
   ============================================================ */

/* ── VARIABLES (override via JS on station change) ── */
:root {
  --chat-accent:      var(--accent);
  --chat-accent-glow: var(--glow);
  --chat-deep:        #0a0a0f;
  --chat-paper:       #111118;
  --chat-card:        #16161f;
  --chat-mist:        rgba(255,255,255,.08);
  --chat-ink:         #f0f0f8;
  --chat-muted:       #8888aa;
}

/* ── GLOBAL CHAT TOGGLE (bottom-right) ── */
.chat-toggle-main {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1001;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--chat-accent) 0%, rgba(0,0,0,.3) 100%);
  color: #fff;
  box-shadow: 0 6px 28px var(--chat-accent-glow);
  font-size: 1.45rem;
  cursor: pointer;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1),
              box-shadow .25s,
              background .6s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
}
.chat-toggle-main:hover {
  transform: scale(1.12) rotate(-8deg);
  box-shadow: 0 10px 38px var(--chat-accent-glow);
}
.chat-toggle-main.open {
  background: linear-gradient(135deg, #333 0%, #111 100%);
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}

/* Unread badge */
.chat-unread-badge {
  position: absolute;
  top: -5px; right: -5px;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  background: #e05c5c;
  color: #fff; font-size: .66rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px; pointer-events: none;
  box-shadow: 0 2px 8px rgba(224,92,92,.5);
  animation: badgePop .3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes badgePop { from { transform: scale(0); } to { transform: scale(1); } }

/* ── MULTI-WINDOW CONTAINER ── */
.chat-windows-container {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}

/* ── INDIVIDUAL CHAT WINDOW ── */
.chat-window {
  pointer-events: all;
  width: min(400px, calc(100vw - 28px));
  max-height: min(580px, 80vh);
  background: var(--chat-paper);
  border: 1px solid rgba(255,255,255,.1);
  box-shadow: 0 24px 80px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.2);
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow .3s;
}
.chat-window:focus-within {
  box-shadow: 0 24px 80px rgba(0,0,0,.5), 0 0 0 2px var(--chat-accent);
}
.chat-window.animate-in {
  animation: chatSlideIn .28s cubic-bezier(.22,1,.36,1) forwards;
}
@keyframes chatSlideIn {
  from { opacity: 0; transform: translateY(18px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.chat-window.minimized { max-height: 56px; overflow: hidden; }

/* ── WINDOW HEADER ── */
.cw-head {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, var(--chat-deep) 0%, #1a1020 100%);
  padding: 13px 16px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: background .6s ease;
}
.cw-head::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 80% -20%, rgba(255,255,255,.06) 0%, transparent 60%);
  pointer-events: none;
}
/* Accent stripe left border */
.cw-head::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--chat-accent);
  transition: background .6s ease;
}

.cw-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--chat-accent), rgba(0,0,0,.4));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: #fff;
  box-shadow: 0 0 0 3px rgba(255,255,255,.1);
  position: relative; z-index: 1;
  transition: background .6s ease;
}
.cw-avatar-ring {
  position: absolute; inset: -3px; border-radius: 50%;
  border: 2px solid var(--chat-accent); opacity: .4;
  animation: chatRing 2.5s infinite ease-in-out;
  transition: border-color .6s ease;
}
@keyframes chatRing {
  0%,100% { transform: scale(1); opacity: .4; }
  50%      { transform: scale(1.15); opacity: 0; }
}

.cw-info { flex: 1; min-width: 0; position: relative; z-index: 1; }
.cw-title {
  display: block; font-size: .88rem; font-weight: 600;
  color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cw-sub {
  display: flex; align-items: center; gap: 5px;
  color: rgba(255,255,255,.55); font-size: .72rem; margin-top: 2px;
}
.cw-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 5px rgba(45,255,138,.6);
  flex-shrink: 0;
}

.cw-actions { display: flex; gap: 4px; position: relative; z-index: 1; }
.cw-btn {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.65);
  font-size: .85rem;
  cursor: pointer;
  width: 28px; height: 28px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.cw-btn:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── MESSAGES AREA ── */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--chat-paper);
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.08) transparent;
}
.cw-messages::-webkit-scrollbar { width: 3px; }
.cw-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 3px; }

/* Day divider */
.chat-day-div {
  display: flex; align-items: center; gap: 8px;
  margin: 8px 0; font-size: .65rem;
  color: var(--chat-muted); text-transform: uppercase; letter-spacing: .08em;
}
.chat-day-div::before, .chat-day-div::after {
  content: ''; flex: 1; height: 1px; background: var(--chat-mist);
}

/* Welcome state */
.chat-welcome-state {
  text-align: center; padding: 28px 16px; color: var(--chat-muted);
}
.chat-welcome-state .cws-icon { font-size: 36px; margin-bottom: 10px; }
.chat-welcome-state p { font-size: 13px; line-height: 1.5; }
.chat-welcome-state .cws-station {
  margin-top: 10px; font-size: 11px; color: var(--chat-accent);
  font-family: var(--fm); display: flex; align-items: center; justify-content: center; gap: 5px;
}

/* ── BUBBLE ROW ── */
.bubble-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 4px;
}
.bubble-row.me    { align-items: flex-end; }
.bubble-row.them  { align-items: flex-start; }

/* Meta (username, time) */
.bubble-meta {
  display: flex; align-items: center; gap: 5px;
  font-size: .64rem; color: var(--chat-muted);
  padding: 0 4px; margin-bottom: 3px;
}
.bubble-row.me .bubble-meta { justify-content: flex-end; }
.bm-avatar {
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.bm-name { font-weight: 500; color: var(--chat-ink); opacity: .8; }
.bm-time { opacity: .6; }

/* The bubble itself */
.bubble {
  max-width: 80%;
  padding: 9px 13px;
  font-size: .875rem;
  border-radius: 18px;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
}
.bubble.me {
  background: linear-gradient(135deg, var(--chat-accent) 0%, rgba(0,0,0,.2) 120%);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 2px 8px var(--chat-accent-glow);
  transition: background .6s ease, box-shadow .6s ease;
  font-weight: 500;
}
.bubble.them {
  background: var(--chat-card);
  color: var(--chat-ink);
  border-bottom-left-radius: 5px;
  border: 1px solid rgba(255,255,255,.07);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.bubble.system {
  align-self: center;
  background: rgba(255,255,255,.04);
  color: var(--chat-muted);
  font-size: .72rem; font-style: italic;
  padding: 4px 12px; border-radius: 20px;
  max-width: 100%;
  border: 1px solid rgba(255,255,255,.07);
  margin: 4px 0;
}

/* Bubble image */
.bubble-img {
  max-width: 200px; max-height: 200px;
  border-radius: 12px; object-fit: cover;
  cursor: pointer; display: block;
  border: 1px solid rgba(255,255,255,.1);
  transition: opacity .15s;
}
.bubble-img:hover { opacity: .88; }

/* Station tag below bubble */
.bubble-station-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .65rem; font-family: var(--fm);
  color: var(--chat-accent); margin-top: 3px;
  transition: color .6s ease;
}
.bst-dot { width: 5px; height: 5px; background: var(--green); border-radius: 50%; }

/* ── TYPING INDICATOR ── */
.cw-typing {
  padding: 0 14px 6px;
  font-size: .74rem;
  color: var(--chat-muted);
  display: flex; align-items: center; gap: 8px;
  min-height: 24px; flex-shrink: 0;
}
.typing-bubble {
  background: var(--chat-card);
  border-radius: 18px; border-bottom-left-radius: 5px;
  border: 1px solid rgba(255,255,255,.07);
  padding: 8px 13px;
  display: inline-flex; align-items: center; gap: 4px;
}
.typing-dots { display: flex; gap: 4px; align-items: center; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,.4);
  animation: typingPulse 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingPulse {
  0%,60%,100% { transform: translateY(0); opacity: .4; }
  30%          { transform: translateY(-5px); opacity: 1; }
}

/* ── LISTENERS STRIP ── */
.cw-listeners {
  padding: 5px 12px;
  border-top: 1px solid var(--chat-mist);
  display: flex; gap: 5px; overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none; min-height: 34px; align-items: center;
}
.cw-listeners::-webkit-scrollbar { display: none; }
.listener-chip {
  display: flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  background: rgba(255,255,255,.04);
  border-radius: 20px; border: 1px solid rgba(255,255,255,.07);
  white-space: nowrap; flex-shrink: 0; font-size: 11px;
}
.lc-av {
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: #fff; font-weight: 700; flex-shrink: 0;
}
.lc-name    { color: var(--chat-muted); }
.lc-station { font-family: var(--fm); font-size: 9px; color: var(--chat-accent); transition: color .6s ease; }

/* ── INPUT AREA ── */
.cw-input-area {
  background: var(--chat-paper);
  border-top: 1px solid rgba(255,255,255,.06);
  padding: 10px 12px 12px;
  flex-shrink: 0;
}
.cw-input-row {
  display: flex; align-items: center;
  background: var(--chat-card);
  border-radius: 14px;
  border: 1.5px solid rgba(255,255,255,.08);
  transition: border-color .18s, box-shadow .18s;
}
.cw-input-row:focus-within {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 3px var(--chat-accent-glow);
  transition: border-color .18s, box-shadow .18s, color .6s;
}
.cw-attach {
  background: none; border: none;
  color: var(--chat-muted);
  padding: 0 11px; font-size: 1rem;
  transition: color .15s; flex-shrink: 0;
}
.cw-attach:hover { color: var(--chat-accent); }
.cw-text {
  flex: 1; border: none; padding: 11px 4px;
  background: none; color: var(--chat-ink);
  outline: none; font-size: .88rem; min-width: 0;
  font-family: var(--fb);
}
.cw-text::placeholder { color: var(--chat-muted); }
.cw-send {
  background: linear-gradient(135deg, var(--chat-accent), rgba(0,0,0,.2));
  border: none; color: #fff;
  width: 34px; height: 34px; border-radius: 9px;
  margin: 0 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem;
  transition: transform .18s, box-shadow .18s, background .6s ease;
  box-shadow: 0 2px 8px var(--chat-accent-glow);
  flex-shrink: 0;
}
.cw-send:hover { transform: scale(1.1); box-shadow: 0 4px 14px var(--chat-accent-glow); }
.cw-send:disabled { opacity: .3; cursor: default; transform: none; box-shadow: none; }

/* Quick emoji row */
.cw-emoji-row {
  display: flex; gap: 3px; flex-wrap: wrap;
  padding: 6px 1px 0;
}
.cw-emoji-row button {
  border: none; background: none; color: var(--chat-ink);
  padding: 3px 5px; font-size: .9rem; border-radius: 5px;
  transition: background .1s;
}
.cw-emoji-row button:hover { background: rgba(255,255,255,.07); }

/* ── IMAGE LIGHTBOX ── */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92); z-index: 99999;
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out; animation: fadeIn .2s ease;
}
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; object-fit: contain; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── RESPONSIVE: mobile ── */
@media (max-width: 600px) {
  .chat-windows-container { right: 0; bottom: 80px; width: 100vw; }
  .chat-window { width: 100vw; border-radius: 22px 22px 0 0; }
  .chat-toggle-main { right: 16px; bottom: 86px; width: 52px; height: 52px; font-size: 1.25rem; }
}
