/* =============================================================
   "Listen to Alex" demo widget — iMessage-style chat bubble UI
   Compact phone status bar header + chat bubble transcript synced
   to MP3 audio sequencer. Inherits design tokens from style.css.
   ============================================================= */

.demo-modal {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(11, 18, 32, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.demo-modal[aria-hidden="false"] { display: flex; }

.demo-modal__card {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  background: var(--bone-50);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: demoModalIn 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes demoModalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.demo-modal__close {
  position: absolute;
  top: 36px; right: 36px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--bone-50);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 160ms ease;
  z-index: 1;
}
.demo-modal__close:hover { background: rgba(255, 255, 255, 0.2); }

/* ---------- Compact phone status bar header ---------- */
.demo-phone {
  background: linear-gradient(180deg, var(--ink-900) 0%, var(--ink-800) 100%);
  color: var(--bone-50);
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--ink-700);
  flex: 0 0 auto;
}
.demo-phone--compact { padding: 10px 20px 12px; }

.demo-phone__statusbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink-300);
}
.demo-phone__time { font-weight: 500; letter-spacing: -0.01em; }

.demo-phone__badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.14);
  color: #4ade80;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.demo-phone__dot {
  width: 7px; height: 7px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: demoPulse 1.6s ease-out infinite;
}
@keyframes demoPulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70%  { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.demo-phone__name {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 500;
  margin-bottom: 1px;
  letter-spacing: -0.01em;
}
.demo-phone__sub {
  font-size: 12px;
  color: var(--ink-300);
}

/* ---------- Player ---------- */
.demo-player {
  background: var(--ink-800);
  color: var(--bone-50);
  padding: 14px 20px 16px;
  border-bottom: 1px solid var(--bone-200);
  flex: 0 0 auto;
}
.demo-player__row {
  display: flex; align-items: center; gap: 12px;
}
.demo-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--amber-600);
  color: white;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 120ms ease, background 160ms ease;
}
.demo-btn:hover { background: var(--amber-500); transform: scale(1.05); }
.demo-btn--secondary {
  width: 32px; height: 32px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--bone-50);
}
.demo-btn--secondary:hover { background: rgba(255, 255, 255, 0.15); transform: none; }

.demo-progress {
  flex: 1 1 auto;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
  cursor: pointer;
}
.demo-progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--amber-500), var(--amber-400));
  width: 0%;
  border-radius: 999px;
  transition: width 100ms linear;
}
.demo-time {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-300);
  min-width: 76px;
  text-align: right;
}

/* ---------- Chat-bubble transcript ---------- */
.demo-transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 18px 20px;
  background: linear-gradient(180deg, #f1ede1 0%, var(--bone-50) 60%);
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Group container — speaker label + bubble + time */
.demo-bubble-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 260ms ease, transform 260ms ease;
}
.demo-bubble-group.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.demo-bubble-group.is-past:not(.is-active) { opacity: 0.6; }

.demo-bubble-group--alex { align-items: flex-end; }
.demo-bubble-group--homeowner { align-items: flex-start; }

.demo-bubble-meta {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-500);
  padding: 0 10px;
}
.demo-bubble-meta__name { font-weight: 600; }
.demo-bubble-group--alex .demo-bubble-meta__name { color: var(--amber-600); }
.demo-bubble-group--homeowner .demo-bubble-meta__name { color: var(--ink-700); }
.demo-bubble-meta__time {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-300);
  font-size: 10px;
}

.demo-bubble {
  position: relative;
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  transition: box-shadow 220ms ease, transform 220ms ease;
}

/* Alex (right side, amber) */
.demo-bubble-group--alex .demo-bubble {
  background: linear-gradient(135deg, var(--amber-600), var(--amber-500));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.demo-bubble-group--alex .demo-bubble::after {
  content: '';
  position: absolute;
  right: -4px;
  bottom: 0;
  width: 12px;
  height: 14px;
  background: var(--amber-500);
  border-bottom-left-radius: 14px 10px;
  z-index: -1;
}

/* Homeowner / caller (left side, neutral dark grey) */
.demo-bubble-group--homeowner .demo-bubble {
  background: #2c3344;
  color: #f5f3ed;
  border-bottom-left-radius: 4px;
}
.demo-bubble-group--homeowner .demo-bubble::after {
  content: '';
  position: absolute;
  left: -4px;
  bottom: 0;
  width: 12px;
  height: 14px;
  background: #2c3344;
  border-bottom-right-radius: 14px 10px;
  z-index: -1;
}

/* Active bubble — subtle glow + pulse */
.demo-bubble-group.is-active .demo-bubble {
  box-shadow:
    0 0 0 3px rgba(249, 115, 22, 0.18),
    0 8px 22px -8px rgba(234, 88, 12, 0.45);
  animation: demoBubblePulse 2.2s ease-in-out infinite;
}
.demo-bubble-group--homeowner.is-active .demo-bubble {
  box-shadow:
    0 0 0 3px rgba(203, 213, 225, 0.35),
    0 8px 22px -8px rgba(15, 23, 42, 0.32);
}
@keyframes demoBubblePulse {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-1px); }
}

/* Typing indicator (precedes a bubble before it appears) */
.demo-typing {
  align-self: flex-start;
  background: #2c3344;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 11px 14px;
  display: inline-flex;
  gap: 4px;
  align-items: center;
  margin-bottom: 6px;
  animation: demoTypingIn 200ms ease-out;
}
.demo-typing--alex {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--amber-600), var(--amber-500));
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}
.demo-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  animation: demoBlink 1.2s infinite;
}
.demo-typing--alex .demo-typing__dot { background: rgba(255, 255, 255, 0.85); }
.demo-typing__dot:nth-child(2) { animation-delay: 0.18s; }
.demo-typing__dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes demoBlink {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40%           { opacity: 1; transform: translateY(-3px); }
}
@keyframes demoTypingIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.demo-modal__hint {
  padding: 10px 24px 16px;
  font-size: 12px;
  color: var(--ink-500);
  text-align: center;
  background: var(--bone-100);
  border-top: 1px solid var(--bone-200);
  flex: 0 0 auto;
}

/* ---------- Mobile: full-screen ---------- */
@media (max-width: 540px) {
  .demo-modal { padding: 0; }
  .demo-modal__card {
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
  }
  .demo-modal__close { top: 14px; right: 14px; }
  .demo-phone { padding: 10px 16px 12px; }
  .demo-player { padding: 12px 16px 14px; }
  .demo-transcript { padding: 14px 14px 18px; }
  .demo-bubble { font-size: 14px; max-width: 82%; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .demo-bubble-group.is-active .demo-bubble { animation: none; }
  .demo-bubble-group {
    transition: opacity 200ms ease;
    transform: none;
  }
}
