:root {
  --yellow: #FBCD00;
  --navy: #1C3F6E;
  --navy-dark: #142f52;
  --navy-light: #2a5ba0;
  --bg: #F0F2F5;
  --white: #FFFFFF;
  --text: #1A1A2E;
  --muted: #8a8a9a;
  --border: #E4E4EF;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.10);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --yellow-light: #FFF8CC;
  --agent-bubble: #FFFFFF;
  --customer-bubble: #1C3F6E;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-bg {
  width: 100%;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f2542 0%, #1C3F6E 60%, #2a5ba0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ── Chat shell ────────────────────────────────────── */
.chat-app {
  width: 420px;
  height: 700px;
  background: var(--bg);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Header ────────────────────────────────────────── */
.chat-header {
  background: var(--navy);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.logo { display: flex; align-items: center; gap: 10px; }

.logo-icon {
  width: 38px;
  height: 38px;
  background: var(--yellow);
  color: var(--navy);
  font-weight: 900;
  font-size: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -1px;
}

.logo-text .brand {
  display: block;
  color: var(--yellow);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.1;
}

.logo-text .subtitle {
  display: block;
  color: rgba(255,255,255,0.55);
  font-size: 11px;
  margin-top: 1px;
}

.role-toggle {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.toggle-label {
  color: rgba(255,255,255,0.45);
  font-size: 10px;
  letter-spacing: 0.3px;
}

.toggle-group {
  display: flex;
  background: rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 2px;
  gap: 1px;
}

.role-btn {
  padding: 4px 11px;
  border: none;
  border-radius: 18px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: rgba(255,255,255,0.6);
  transition: all 0.18s;
}

.role-btn.active {
  background: var(--yellow);
  color: var(--navy);
  font-weight: 700;
}

/* ── Connection banner ─────────────────────────────── */
.connection-status {
  background: #fff3cd;
  color: #856404;
  font-size: 12px;
  text-align: center;
  padding: 6px;
  display: none;
  flex-shrink: 0;
}

.connection-status.show { display: block; }

/* ── Messages area ─────────────────────────────────── */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg);
  scroll-behavior: smooth;
}

.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Date divider */
.date-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
}
.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.date-divider span {
  font-size: 11px;
  color: var(--muted);
}

/* ── Message wrapper ───────────────────────────────── */
.msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  margin-bottom: 6px;
}

.msg-wrap.agent  { align-self: flex-start; align-items: flex-start; }
.msg-wrap.customer { align-self: flex-end;   align-items: flex-end; }

.sender-label {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 3px;
  padding: 0 4px;
  font-weight: 500;
}

/* Bubble row: bubble + react trigger side-by-side */
.bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 5px;
}

/* Agent: [bubble] [react], Customer: [react] [bubble] via row-reverse */
.msg-wrap.customer .bubble-row { flex-direction: row-reverse; }

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}

.msg-wrap.agent .bubble {
  background: var(--white);
  color: var(--text);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}

.msg-wrap.customer .bubble {
  background: var(--customer-bubble);
  color: var(--white);
  border-bottom-right-radius: 5px;
}

/* ── React trigger ─────────────────────────────────── */
.react-trigger {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, transform 0.1s;
  box-shadow: var(--shadow-sm);
  line-height: 1;
}

.msg-wrap:hover .react-trigger { opacity: 1; }
.react-trigger:hover { transform: scale(1.15); }

/* ── Timestamp ─────────────────────────────────────── */
.msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
  padding: 0 4px;
}

/* ── Reactions bar ─────────────────────────────────── */
.reactions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
  padding: 0 2px;
}

.reaction-badge {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.12s, border-color 0.12s;
  animation: pop-in 0.18s ease;
}

.reaction-badge:hover {
  background: #f0f0f0;
  border-color: #c0c0c0;
}

/* Badge where the current viewer has reacted — visually distinct from hover */
.reaction-badge.mine {
  background: var(--yellow-light);
  border-color: var(--yellow);
  font-weight: 600;
}

.reaction-badge.mine .rc { color: var(--navy); }

.reaction-badge.mine:hover {
  background: #fff0a0;
  border-color: #e6b800;
}

.reaction-badge .rc { font-size: 11px; color: var(--muted); font-weight: 500; }

/* ── Reactor tooltip ───────────────────────────────── */
.reactor-tooltip {
  position: fixed;
  background: rgba(28, 63, 110, 0.92);
  color: var(--white);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, 0);
  opacity: 0;
  transition: opacity 0.12s;
}

.reactor-tooltip.show { opacity: 1; }

.reactor-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(28, 63, 110, 0.92);
}

@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Emoji picker ──────────────────────────────────── */
.emoji-picker {
  position: fixed;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 6px 8px;
  display: flex;
  gap: 2px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.16);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85) translateY(6px);
  transition: opacity 0.14s, transform 0.14s;
}

.emoji-picker.show {
  opacity: 1;
  pointer-events: all;
  transform: scale(1) translateY(0);
}

.emoji-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 5px;
  border-radius: 8px;
  line-height: 1;
  transition: transform 0.1s, background 0.1s;
}

.emoji-btn:hover {
  background: var(--bg);
  transform: scale(1.35);
}

/* ── Canned panel ──────────────────────────────────── */
.canned-panel {
  position: absolute;
  bottom: 68px;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 2px solid var(--yellow);
  max-height: 230px;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  box-shadow: 0 -6px 20px rgba(0,0,0,0.10);
}

.canned-panel.open { transform: translateY(0); }

.canned-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--yellow);
  flex-shrink: 0;
}

.canned-header span {
  font-weight: 700;
  font-size: 12px;
  color: var(--navy);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.close-canned {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--navy);
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}

.close-canned:hover { background: rgba(0,0,0,0.08); }

.canned-list {
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.canned-item {
  padding: 9px 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  border: 1px solid transparent;
  width: 100%;
  transition: background 0.12s, border-color 0.12s;
  line-height: 1.45;
}

.canned-item:hover {
  background: var(--yellow-light);
  border-color: var(--yellow);
  color: var(--navy);
}

/* ── Input area ────────────────────────────────────── */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.canned-trigger {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.14s, background 0.14s;
}

.canned-trigger svg { width: 20px; height: 20px; }
.canned-trigger:hover,
.canned-trigger.active { color: var(--navy); background: var(--bg); }

#messageInput {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.14s, background 0.14s;
}

#messageInput:focus {
  border-color: var(--navy);
  background: var(--white);
}

#messageInput::placeholder { color: var(--muted); }

.send-btn {
  width: 40px;
  height: 40px;
  background: var(--navy);
  color: var(--yellow);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.14s, transform 0.1s;
}

.send-btn:hover { background: var(--navy-dark); transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }
