/* ===========================================================================
   Live AI Agent — demo screen
   LiveUCX / ProUCX dark brand.  Self-contained, no external assets.
   Tokens mirror the product design system (globals.css idiom).
   =========================================================================== */

:root {
  /* Brand */
  --bg:            #060B22;   /* ProUCX dark navy */
  --bg-2:          #0A1233;   /* raised navy */
  --surface:       #0E1740;   /* card surface */
  --surface-2:     #131E52;   /* caller bubble */
  --line:          rgba(255,255,255,.10);
  --line-strong:   rgba(255,255,255,.18);

  --ink:           #EAF0FF;   /* primary text */
  --muted:         #9AA6C8;   /* secondary text */
  --faint:         #667099;   /* tertiary / timestamps */

  --cyan:          #1BD7E7;   /* accent */
  --blue:          #1B81E7;   /* primary */
  --ok:            #34D399;
  --live:          #FF4D6D;   /* live-call red pulse */

  --radius:        16px;
  --radius-lg:     22px;
  --shadow-card:   0 18px 50px rgba(0,0,0,.45);
  --shadow-glow:   0 0 0 1px rgba(27,215,231,.25), 0 10px 40px rgba(27,129,231,.20);

  --maxw:          1180px;
  --font: "Roboto", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 80% -10%, rgba(27,129,231,.16), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(27,215,231,.12), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;               /* stage scrolls, body never does */
}

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 20;
  background: var(--blue); color: #fff; padding: 10px 16px;
  border-radius: 10px; text-decoration: none; font-weight: 600;
  transition: top .15s ease;
}
.skip-link:focus { top: 12px; }

/* Global focus visibility */
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ─────────────────────────── App shell ─────────────────────────── */
.app {
  height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(14px, 2.2vw, 28px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(12px, 1.6vw, 20px);
}

/* ─────────────────────────── Header ─────────────────────────── */
.app__header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(14px, 2vw, 28px);
  padding: clamp(12px, 1.4vw, 18px) clamp(16px, 1.8vw, 24px);
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand__glyph { display: inline-flex; filter: drop-shadow(0 4px 12px rgba(27,215,231,.35)); }
.brand__word {
  font-weight: 800; letter-spacing: .2px; font-size: 1.15rem; white-space: nowrap;
}
.brand__word span { color: var(--cyan); }

.agent { min-width: 0; }
.agent__name {
  font-weight: 700;
  font-size: clamp(1.05rem, 1.5vw, 1.4rem);
  letter-spacing: .2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent__tag {
  color: var(--muted);
  font-size: clamp(.72rem, 1vw, .84rem);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 2px;
}
.agent__provider {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--ink);
  font-size: .74rem; font-weight: 600;
  background: rgba(255,255,255,.04);
}
.agent__provider .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
}

/* Call-state pill */
.callstate {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 9px 16px 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,.04);
  font-weight: 600; font-size: .9rem; white-space: nowrap;
  transition: background .3s ease, border-color .3s ease, color .3s ease;
}
.callstate__dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 0 rgba(255,77,109,0);
}
.callstate[data-state="live"] { color: #fff; border-color: rgba(255,77,109,.5); background: rgba(255,77,109,.12); }
.callstate[data-state="live"] .callstate__dot {
  background: var(--live);
  animation: pulse 1.6s ease-out infinite;
}
.callstate[data-state="ended"] { color: var(--muted); border-color: var(--line-strong); }
.callstate[data-state="ended"] .callstate__dot { background: var(--muted); }
.callstate[data-state="idle"] .callstate__dot { background: var(--faint); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255,77,109,.55); }
  70%  { box-shadow: 0 0 0 12px rgba(255,77,109,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,77,109,0); }
}

/* ─────────────────────────── Stage / conversation ─────────────────────────── */
.stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.012)),
    var(--bg-2);
  box-shadow: var(--shadow-card);
}
.stage:focus-visible { outline-offset: -3px; }

/* Empty / idle */
.empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
  gap: 8px;
  transition: opacity .4s ease;
}
.empty.is-hidden { opacity: 0; pointer-events: none; }
.empty__title {
  margin: 8px 0 0; font-size: clamp(1.3rem, 2.4vw, 1.9rem); font-weight: 700; letter-spacing: .2px;
}
.empty__sub { margin: 0; color: var(--muted); max-width: 42ch; }

.empty__pulse { display: flex; align-items: center; gap: 10px; height: 48px; }
.empty__pulse span {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  animation: bob 1.4s ease-in-out infinite;
  opacity: .9;
}
.empty__pulse span:nth-child(2) { animation-delay: .18s; }
.empty__pulse span:nth-child(3) { animation-delay: .36s; }
@keyframes bob {
  0%, 100% { transform: translateY(6px) scale(.85); opacity: .5; }
  50%      { transform: translateY(-6px) scale(1);  opacity: 1;  }
}

/* Thread — the scrolling bubble column */
.thread {
  list-style: none;
  margin: 0;
  padding: clamp(16px, 2.4vw, 30px) clamp(14px, 2.2vw, 30px) clamp(20px, 3vw, 36px);
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.thread[aria-hidden="true"] { display: none; }
.thread::-webkit-scrollbar { width: 10px; }
.thread::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }

/* A turn */
.turn {
  display: flex; flex-direction: column;
  max-width: min(76%, 680px);
  animation: rise .35s cubic-bezier(.2,.7,.3,1) both;
}
.turn--caller { align-self: flex-start; align-items: flex-start; }
.turn--agent  { align-self: flex-end;   align-items: flex-end; }

.turn__meta {
  display: flex; align-items: center; gap: 8px;
  font-size: .72rem; color: var(--faint); margin: 0 4px 5px;
}
.turn__who { font-weight: 700; letter-spacing: .3px; text-transform: uppercase; font-size: .66rem; }
.turn--caller .turn__who { color: var(--muted); }
.turn--agent  .turn__who { color: var(--cyan); }

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: clamp(.95rem, 1.25vw, 1.08rem);
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
}
.turn--caller .bubble {
  background: var(--surface-2);
  border-bottom-left-radius: 6px;
  color: var(--ink);
}
.turn--agent .bubble {
  background: linear-gradient(135deg, rgba(27,215,231,.16), rgba(27,129,231,.20));
  border-color: rgba(27,215,231,.35);
  border-bottom-right-radius: 6px;
  color: #F2F9FF;
  box-shadow: var(--shadow-glow);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Typing indicator (agent "speaking") */
.turn--typing .bubble {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 14px 18px;
}
.typing-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--cyan);
  animation: type 1.1s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .30s; }
@keyframes type {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* Caret cue on the newest agent bubble while streaming (reserved for future partials) */
.caret::after {
  content: "▍";
  margin-left: 2px;
  color: var(--cyan);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Call-ended divider */
.divider {
  align-self: center;
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: .78rem; font-weight: 600;
  padding: 6px 14px; margin: 6px 0;
  border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255,255,255,.03);
  animation: rise .35s ease both;
}
.divider .bi { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }

/* ─────────────────────────── Footer ─────────────────────────── */
.app__footer {
  display: flex; align-items: center; gap: 12px;
  padding: 4px clamp(6px, 1vw, 12px) 2px;
  font-size: .78rem; color: var(--faint);
}
.footer__spacer { flex: 1; }
.footer__brand { letter-spacing: .3px; }

.conn { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.conn__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); transition: background .3s; }
.conn[data-conn="live"]  .conn__dot { background: var(--ok); }
.conn[data-conn="mock"]  .conn__dot { background: var(--cyan); }
.conn[data-conn="error"] .conn__dot { background: var(--live); }
.conn[data-conn="connecting"] .conn__dot { background: var(--blue); animation: bob 1s ease-in-out infinite; }
.conn[data-conn="live"]  .conn__label { color: var(--ok); }
.conn[data-conn="mock"]  .conn__label { color: var(--cyan); }
.conn[data-conn="error"] .conn__label { color: var(--live); }

/* ─────────────────────────── Responsive ─────────────────────────── */
@media (max-width: 640px) {
  .app__header {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand state" "agent agent";
    row-gap: 10px;
  }
  .brand    { grid-area: brand; }
  .callstate{ grid-area: state; }
  .agent    { grid-area: agent; }
  .turn { max-width: 88%; }
  .footer__brand { display: none; }
}

/* Big-screen / presentation mode — scale type up for a room */
@media (min-width: 1600px) {
  body { font-size: 18px; }
  .turn { max-width: min(70%, 820px); }
}

/* ─────────────────────────── Reduced motion ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
  .callstate[data-state="live"] .callstate__dot { box-shadow: 0 0 0 3px rgba(255,77,109,.35); }
  .typing-dot { opacity: .8; }
  .empty__pulse span { opacity: .9; transform: none; }
}
