/* Call page: Teams-like meeting UI, dark or light (the admin's theme choice). Things drawn ON the video (captions,
   name plates, the self view) stay dark in both themes so they stay readable over any picture. */
body.call-page {
  --stage: #141414; --bar: #292929; --panel: #1f1f1f; --tile: #2b2b2b; --txt: #f5f5f5; --txt2: #adadad;
  --line: #333; --hover: #3a3a3a; --sep: #4a4a4a; --chip: #3d3d3d; --lobby: #1b1b1b; --preview: #1f1f1f; --audio-bg: #2f2f3a;
  --elev: #2d2d2d; --bubble: #2d2d2d; --bubble-user: #3d3e66; --card-shadow: 0 8px 32px rgba(0,0,0,.45); --meter-track: rgba(255,255,255,.2);
  --disabled: #555; --switch-line: #adadad; --switch-knob: #d6d6d6; --accent: var(--brand-light); --off: #f1707b;
  --ok-ink: #92c353; --warn-ink: #ffaa44;
  --tile-grad: radial-gradient(circle at 50% 42%, #33335a 0%, #24243a 40%, var(--tile) 75%);
  background: var(--stage); color: var(--txt); height: 100dvh; overflow: hidden; margin: 0; transition: background-color .2s, color .2s; }
body.call-page[data-bs-theme="light"] {
  --stage: #eef0f5; --bar: #ffffff; --panel: #ffffff; --tile: #e7e8f1; --txt: #242424; --txt2: #5f5f68;
  --line: #e1e2e8; --hover: #eeeff5; --sep: #d3d4dc; --chip: #ececf2; --lobby: #f3f4f8; --preview: #e4e5ee; --audio-bg: #f5f5fd;
  --elev: #ffffff; --bubble: #f0f1f6; --bubble-user: #e6e8fb; --card-shadow: 0 6px 24px rgba(28,30,70,.10); --meter-track: rgba(0,0,0,.12);
  --disabled: #c7c7cf; --switch-line: #8a8a93; --switch-knob: #8a8a93; --accent: #5b5fc7; --off: #c4314b;
  --ok-ink: #2f7d32; --warn-ink: #9a5b00;
  --tile-grad: radial-gradient(circle at 50% 42%, #d9daf7 0%, #e3e4f6 40%, var(--tile) 78%);
}
.call-page .btn-primary { font-weight: 600; }

/* ---------- pre-join (lobby), Teams-style ---------- */
.lobby { height: 100vh; height: 100dvh; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: safe center; padding: 1.5rem 1rem; gap: 1.1rem; background: var(--lobby); }
.lobby h1 { font-size: 1.3rem; font-weight: 600; margin: 0; text-align: center; }
.lobby .sub { color: var(--txt2); margin: .25rem 0 0; text-align: center; font-size: .9rem; }
/* flex-shrink: 0 - the card must never be squeezed below its content (that clipped the controls and the note) */
.lobby-card { width: min(920px, 100%); flex-shrink: 0; display: grid; grid-template-columns: 1.45fr 1fr; gap: 1rem; }
.lobby-left { display: flex; flex-direction: column; background: var(--bar); border-radius: 12px; overflow: hidden; box-shadow: var(--card-shadow); }
.lobby-preview { position: relative; flex: 1 1 auto; min-height: 300px; background: var(--preview); display: grid; place-items: center; overflow: hidden; }
.lobby-preview video { position: absolute; inset: 0; }
.lobby-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.lobby-preview .off { color: var(--txt2); text-align: center; font-size: .9rem; display: flex; flex-direction: column; align-items: center; gap: .6rem; }
.me-circle { width: 96px; height: 96px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 2.6rem; }
.lobby-mic-off { position: absolute; left: .7rem; bottom: .7rem; background: rgba(0,0,0,.7); color: #fff; font-size: .8rem; padding: .25rem .6rem; border-radius: 4px; }
/* Teams control strip under the preview: icon + toggle switch */
.lobby-toggles { display: flex; align-items: center; justify-content: center; gap: .4rem; padding: .7rem 1rem; background: var(--bar); border-top: 1px solid var(--line); }
.ts-toggle { display: inline-flex; align-items: center; gap: .6rem; border: 0; background: transparent; color: var(--txt); padding: .4rem .7rem; border-radius: 6px; cursor: pointer;
  transition: background-color .15s; }
.ts-toggle:hover { background: var(--hover); }
.ts-toggle .bi { font-size: 1.25rem; }
.ts-toggle:focus-visible { outline: 2px solid var(--brand-light); outline-offset: 2px; }
.ts-switch { position: relative; width: 40px; height: 20px; border-radius: 10px; border: 1px solid var(--switch-line); background: transparent; transition: background .15s, border-color .15s; }
.ts-switch > span { position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--switch-knob); transition: left .15s, background .15s; }
.ts-toggle[aria-checked="true"] .ts-switch { background: var(--accent); border-color: var(--accent); }
.ts-toggle[aria-checked="true"] .ts-switch > span { left: 23px; background: #fff; }
.ts-sep { width: 1px; height: 24px; background: var(--sep); margin: 0 .4rem; }
/* right column: "Computer audio" like Teams */
.lobby-side { padding: 1.3rem 1.4rem; display: flex; flex-direction: column; gap: .95rem; background: var(--bar); border-radius: 12px; box-shadow: var(--card-shadow); }
.lobby-card, .lobby-head { animation: rise-in .3s ease-out; }
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.lobby-agent { display: flex; align-items: center; gap: .75rem; }
.lobby-agent img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; border: 2px solid var(--brand-light); }
.audio-panel { border: 1px solid var(--accent); border-radius: 8px; padding: .85rem .95rem; background: var(--audio-bg); }
.audio-title { display: flex; align-items: center; gap: .5rem; font-weight: 600; margin-bottom: .5rem; }
.radio-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); display: grid; place-items: center; }
.radio-dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.lobby-actions { display: flex; justify-content: flex-end; }
.lobby-side .note { font-size: .76rem; color: var(--txt2); }
.switch-row { display: flex; align-items: center; gap: .55rem; color: var(--txt); font-size: .9rem; }
.btn-join { background: var(--brand); border: 0; color: #fff; font-weight: 600; padding: .6rem 1.7rem; border-radius: 6px; min-width: 130px;
  transition: background-color .15s, box-shadow .15s, transform .15s; }
.btn-join:hover:not(:disabled) { background: var(--brand-hover); color: #fff; box-shadow: 0 4px 14px rgba(91,95,199,.4); transform: translateY(-1px); }
.btn-join:active:not(:disabled) { transform: translateY(0); }
.btn-join:disabled { background: var(--disabled); }

/* ---------- meeting ---------- */
.meeting { height: 100dvh; display: flex; flex-direction: column; }
.meet-bar { height: 56px; flex: none; background: var(--bar); display: flex; align-items: center; gap: .6rem; padding: 0 .6rem 0 1rem; border-bottom: 1px solid var(--line); }
.meet-title { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meet-timer { color: var(--txt2); font-size: .85rem; font-variant-numeric: tabular-nums; }
.conn-badge { font-size: .72rem; padding: .1rem .5rem; border-radius: 1rem; background: var(--chip); color: var(--txt2); white-space: nowrap; transition: background-color .2s, color .2s; }
.conn-badge.ok { background: rgba(84,176,84,.18); color: var(--ok-ink); } .conn-badge.warn { background: rgba(255,170,68,.18); color: var(--warn-ink); }
.meet-controls { margin-left: auto; display: flex; align-items: center; gap: .15rem; }
.ctl { border: 0; background: transparent; color: var(--txt); width: 58px; height: 50px; border-radius: 6px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; font-size: .66rem; line-height: 1; transition: background-color .15s, color .15s; }
.ctl .bi { font-size: 1.2rem; transition: transform .15s; } .ctl:hover { background: var(--hover); } .ctl:hover .bi { transform: translateY(-1px); }
.ctl.on { color: var(--accent); }
.ctl.off .bi { color: var(--off); }
.ctl-sep { width: 1px; height: 30px; background: var(--sep); margin: 0 .35rem; }
.btn-leave { background: #c4314b; color: #fff; border: 0; border-radius: 6px; height: 34px; padding: 0 .95rem; font-weight: 600; font-size: .85rem;
  display: inline-flex; align-items: center; gap: .4rem; margin-left: .35rem; transition: background-color .15s, box-shadow .15s; }
.btn-leave:hover { background: #a72037; color: #fff; box-shadow: 0 3px 12px rgba(196,49,75,.4); }
.meet-body { flex: 1; min-height: 0; display: flex; }
.stage { position: relative; flex: 1; min-width: 0; padding: .75rem; display: flex; }
.alerts { position: absolute; top: .9rem; left: 50%; transform: translateX(-50%); width: min(560px, 92%); z-index: 6; }
.alerts .alert { font-size: .88rem; box-shadow: 0 4px 16px rgba(0,0,0,.4); }

/* tiles */
.agent-tile { position: relative; flex: 1; border-radius: 10px; overflow: hidden;
  background: var(--tile-grad, radial-gradient(circle at 50% 42%, #33335a 0%, #24243a 40%, var(--tile) 75%));
  display: grid; place-items: center; outline: 2px solid transparent; outline-offset: -2px; transition: outline-color .2s; --level: 0; }
.agent-tile.speaking, .agent-tile[data-state="speaking"] { outline-color: var(--brand-light); }
.avatar-wrap { position: relative; width: min(34vh, 34vw, 320px); aspect-ratio: 1; border-radius: 50%;
  transform: scale(calc(1 + var(--level) * .04)); transition: transform 70ms linear; }
.avatar-wrap::before { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 3px solid rgba(127,133,245,calc(.15 + var(--level) * .85));
  box-shadow: 0 0 calc(8px + var(--level) * 50px) calc(var(--level) * 10px) rgba(127,133,245,calc(.2 + var(--level) * .6)); transition: all 70ms linear; }
.avatar-img { position: relative; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.agent-tile[data-state="listening"] .avatar-wrap::before { animation: breathe 3.2s ease-in-out infinite; }
.agent-tile[data-state="thinking"] .avatar-wrap::before { border-style: dashed; border-color: #ffaa44; animation: spin 5s linear infinite; }
@keyframes breathe { 50% { box-shadow: 0 0 26px 4px rgba(127,133,245,.35); } }
@keyframes spin { to { transform: rotate(360deg); } }
.name-plate { position: absolute; left: 10px; bottom: 10px; display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .6rem;
  border-radius: 4px; background: rgba(0,0,0,.6); font-size: .82rem; color: #fff; max-width: calc(100% - 20px); }
.ai-badge { font-size: .66rem; font-weight: 700; padding: .05rem .35rem; border-radius: 3px; background: var(--brand); color: #fff; letter-spacing: .02em; }
.state-text { color: var(--txt2); font-size: .76rem; }
.name-plate .state-text { color: rgba(255,255,255,.75); }  /* the plate is dark in both themes */
.state-text::before { content: "· "; }
.self-tile { position: absolute; right: 1.5rem; bottom: 1.5rem; width: clamp(140px, 20vw, 260px); aspect-ratio: 16/10; border-radius: 8px; overflow: hidden;
  background: #3a3a3a; box-shadow: 0 6px 20px rgba(0,0,0,.55); z-index: 4; }
.self-tile video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.self-off { position: absolute; inset: 0; display: grid; place-items: center; }
.self-off .initials { width: 54px; height: 54px; border-radius: 50%; background: #6264a7; display: grid; place-items: center; font-weight: 600; font-size: 1.1rem; }
.self-tile .name-plate { font-size: .74rem; left: 6px; bottom: 6px; padding: .12rem .45rem; }

/* live captions overlay */
.live-captions { position: absolute; left: 50%; bottom: 3.6rem; transform: translateX(-50%);
  /* centred, and never under the self-view in the corner (both sides keep the self tile's width free) */
  width: min(680px, calc(100% - 2 * (clamp(140px, 20vw, 260px) + 2.5rem))); z-index: 3; pointer-events: none;
  display: flex; flex-direction: column; gap: .3rem; }
.live-captions .lc { background: rgba(0,0,0,.72); color: #fff; border-radius: 8px; padding: .45rem .75rem; font-size: 1rem; line-height: 1.35;
  animation: rise-in .16s ease-out; }
.live-captions .lc b { display: block; font-size: .75rem; color: #c9c9d1; font-weight: 600; margin-bottom: .1rem; }
.live-captions .lc.interim { opacity: .7; }

/* side panel: transcript as chat */
.side-panel { width: 340px; flex: none; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { height: 48px; flex: none; display: flex; align-items: center; padding: 0 .5rem 0 1rem; font-weight: 600; border-bottom: 1px solid var(--line); }
.side-head .close { margin-left: auto; background: transparent; border: 0; color: var(--txt2); width: 32px; height: 32px; border-radius: 6px; transition: background-color .15s, color .15s; }
.side-head .close:hover { background: var(--hover); color: var(--txt); }
.chat { flex: 1; overflow-y: auto; padding: 1rem .9rem; display: flex; flex-direction: column; gap: .7rem; scrollbar-width: thin; scrollbar-color: var(--sep) transparent; }
.chat .hint { color: var(--txt2); font-size: .85rem; text-align: center; margin: auto 0; }
.msg { display: flex; gap: .5rem; max-width: 92%; animation: rise-in .18s ease-out; }
.msg .av { width: 28px; height: 28px; border-radius: 50%; flex: none; object-fit: cover; background: var(--chip); }
.msg .bubble { background: var(--bubble); border-radius: 10px; padding: .5rem .75rem; font-size: .9rem; line-height: 1.45; }
.msg .meta { font-size: .7rem; color: var(--txt2); margin-bottom: .1rem; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .bubble { background: var(--bubble-user); }
.msg.user .meta { text-align: right; }
.msg.interim .bubble { opacity: .65; font-style: italic; }
.msg.system { align-self: center; } .msg.system .bubble { background: transparent; color: var(--txt2); font-size: .78rem; padding: 0; }

/* ended screen */
.ended { height: 100dvh; display: grid; place-items: center; text-align: center; padding: 1rem; background: var(--lobby); }
.ended > div { animation: rise-in .3s ease-out; }
.ended .bi { font-size: 2.6rem; color: var(--txt2); }

/* admin avatar preview reuses the tile */
.preview-stage { background: var(--stage, #141414); border-radius: 8px; padding: .6rem; height: 360px; display: flex; }
.preview-stage .agent-tile { --tile: #2b2b2b; color: #fff; }
.preview-stage .state-text { color: #adadad; }

@media (max-width: 991.98px) {
  .side-panel { position: absolute; right: 0; top: 56px; bottom: 0; width: min(360px, 100%); z-index: 8; box-shadow: -8px 0 24px rgba(0,0,0,.5); }
}
@media (max-width: 767.98px) {
  .lobby-card { grid-template-columns: 1fr; }
  .meet-bar { height: auto; flex-wrap: wrap; padding: .4rem .5rem; row-gap: .2rem; }
  .meet-controls { margin-left: 0; width: 100%; justify-content: space-between; }
  .ctl { width: 52px; } .ctl-sep { display: none; }
  .side-panel { top: 104px; }
  .stage { padding: .4rem; }
  .self-tile { right: .9rem; bottom: .9rem; width: 34vw; aspect-ratio: 3/4; }
  .live-captions { width: 92%; bottom: auto; top: .8rem; }
  /* the agent's name-plate wraps instead of running under the self-view (its state stays readable) */
  .agent-tile > .name-plate { max-width: calc(100% - 34vw - 2.4rem); flex-wrap: wrap; row-gap: .1rem; }
  .avatar-wrap { width: min(55vw, 260px); }
}

.mic-meter { display: inline-block; width: 38px; height: 4px; border-radius: 2px; background: var(--meter-track); overflow: hidden; }
.name-plate .mic-meter { background: rgba(255,255,255,.2); }
.mic-meter span { display: block; height: 100%; background: #92c353; transform: scaleX(0); transform-origin: left; transition: transform 60ms linear; }
.mic-meter.wide { width: 90px; }
.dev-block { display: flex; flex-direction: column; }
.dev-label { font-size: .78rem; color: var(--txt2); margin-bottom: .25rem; }
.dev-panel { position: absolute; right: 0; top: 54px; width: 300px; background: var(--elev); border: 1px solid var(--sep); border-radius: 10px;
  padding: .85rem; z-index: 20; box-shadow: var(--card-shadow); animation: rise-in .15s ease-out; }
@media (max-width: 767.98px) { .dev-panel { position: fixed; left: .5rem; right: .5rem; width: auto; top: 108px; } }

/* video avatar: the video fills the agent tile; the photo is the poster while it connects */
.avatar-video, .avatar-poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 30%; background: #111; }
.avatar-poster { filter: brightness(.8); }
.agent-tile.video-on .avatar-wrap { display: none; }
.ai-disclosure { position: absolute; top: 10px; left: 10px; padding: .15rem .5rem; border-radius: 4px; font-size: .72rem; font-weight: 600;
  background: rgba(0,0,0,.6); color: #fff; z-index: 2; }
.agent-tile.video-on .name-plate { z-index: 2; }

/* top bar (pre-join and end screens): company name + admin login */
.site-head { position: fixed; top: 0; left: 0; right: 0; z-index: 10; height: 48px; display: flex; align-items: center;
  justify-content: space-between; padding: 0 1rem; background: var(--bar); border-bottom: 1px solid var(--line); }
.site-brand { font-weight: 600; font-size: .95rem; color: var(--txt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-brand .bi { color: var(--accent); }
.site-sub { color: var(--txt2); font-weight: 400; }
.site-admin { color: var(--txt); text-decoration: none; font-size: .85rem; padding: .3rem .75rem; border: 1px solid var(--sep); border-radius: 6px; white-space: nowrap;
  transition: background-color .15s, border-color .15s; }
.site-admin:hover { background: var(--hover); color: var(--txt); border-color: var(--accent); }
.lobby, .ended { padding-top: calc(48px + 1.5rem); }
body:has(#meeting:not(.d-none)) .site-head { display: none; }
@media (max-width: 480px) { .site-sub { display: none; } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }

/* "Connecting to <name>…" screen: covers the call tile from Join until the agent is live */
.connecting { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .55rem;
  background: var(--tile-grad, radial-gradient(circle at 50% 42%, #33335a 0%, #24243a 40%, var(--tile) 80%)); transition: opacity .4s ease; text-align: center; padding: 1rem; }
.connecting.done { opacity: 0; pointer-events: none; }
.conn-avatar { position: relative; flex: none; width: min(30vh, 30vw, 220px); height: min(30vh, 30vw, 220px); }
.conn-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; position: relative; filter: brightness(.9); }
.conn-ring { position: absolute; inset: -9px; border-radius: 50%; border: 3px solid rgba(127,133,245,.22); border-top-color: var(--brand-light, #7f85f5); animation: conn-spin 1.1s linear infinite; }
.conn-title { font-size: 1.25rem; font-weight: 600; margin-top: 1rem; }
.conn-sub { color: var(--txt2); font-size: .92rem; min-height: 1.3em; }
.conn-dots { display: flex; gap: 6px; margin-top: .2rem; }
.conn-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--brand-light, #7f85f5); animation: conn-dot 1.2s ease-in-out infinite; }
.conn-dots i:nth-child(2) { animation-delay: .2s; } .conn-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes conn-spin { to { transform: rotate(360deg); } }
@keyframes conn-dot { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1.15); } }
