/* Application Avatar - visitor page.
   Dark, calm stage so the video carries the page; the visiting company's
   brand colour (from its website) is used as the only accent. */

:root {
  --brand: #3b7dd8;
  --brand-ink: #ffffff;
  --bg: #0b1220;
  --bg-2: #101a2c;
  --panel: #121d31;
  --panel-2: #17243b;
  --line: rgba(255, 255, 255, .08);
  --text: #e8edf6;
  --muted: #95a3ba;
  --danger: #ff6b6b;
  --ok: #37d399;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(0, 0, 0, .45);
  --level: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 15% -10%, color-mix(in srgb, var(--brand) 22%, transparent), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 60%),
    var(--bg);
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
a { color: color-mix(in srgb, var(--brand) 55%, white); }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

.app { min-height: 100%; }
.screen { min-height: 100vh; min-height: 100dvh; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid transparent; border-radius: 12px; padding: 13px 20px;
  font-weight: 650; cursor: pointer; text-decoration: none; transition: transform .12s, background .2s, border-color .2s, opacity .2s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: var(--brand-ink); box-shadow: 0 8px 24px color-mix(in srgb, var(--brand) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: rgba(255, 255, 255, .04); border-color: var(--line); color: var(--text); }
.btn.ghost:hover { border-color: rgba(255, 255, 255, .22); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; padding: 8px; }

.ai-badge {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  background: rgba(8, 12, 22, .66); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .16); padding: 4px 10px; border-radius: 999px;
}

.lang-toggle { align-self: flex-start; display: inline-flex; background: rgba(255, 255, 255, .05); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.lang-toggle button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 600; }
.lang-toggle button.active { background: var(--brand); color: var(--brand-ink); }
.lang-toggle.small button { padding: 3px 10px; font-size: 13px; }

/* ---------- welcome ---------- */
.screen.welcome { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px 16px; gap: 18px; }
.welcome-card {
  width: min(1040px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line);
  border-radius: 26px; overflow: hidden; box-shadow: var(--shadow);
}
.welcome-media { position: relative; background: #000; min-height: 360px; }
.welcome-media video, .welcome-media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.welcome-body { padding: 34px 38px 28px; display: flex; flex-direction: column; gap: 14px; }
.cobrand { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.cobrand img { max-height: 34px; max-width: 130px; object-fit: contain; background: #fff; border-radius: 8px; padding: 5px 8px; }
.welcome h1 { font-size: clamp(24px, 3vw, 32px); line-height: 1.2; margin: 4px 0 0; letter-spacing: -.015em; }
.headline { margin: 0; color: color-mix(in srgb, var(--brand) 45%, white); font-weight: 600; }
.intro { margin: 0; color: var(--muted); }
.start-form { display: flex; flex-direction: column; gap: 14px; margin-top: 4px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.fields input, .end-mail input {
  background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; outline: none;
}
.fields input:focus, .end-mail input:focus, .composer textarea:focus { border-color: color-mix(in srgb, var(--brand) 70%, white); }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; color: var(--muted); cursor: pointer; }
.consent input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 200px; }
.fine { font-size: 12.5px; color: var(--muted); margin: 0; }
.error { color: var(--danger); margin: 0; font-weight: 600; }
.legal { font-size: 13px; color: var(--muted); }
.legal a { color: var(--muted); }

/* ---------- conversation ---------- */
.screen.talk { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr); gap: 20px; padding: 20px; height: 100vh; height: 100dvh; }
.stage { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.avatar {
  position: relative; flex: 1; min-height: 0; border-radius: var(--radius); overflow: hidden; background: #05080f;
  box-shadow: var(--shadow), 0 0 0 1px var(--line);
}
.avatar-layers { position: absolute; inset: 0; }
.avatar-layers video, .avatar-layers img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%;
  opacity: 0; transition: opacity .32s ease-in-out;  /* FADE_MS in avatar.js */
}
.avatar-layers .show { opacity: 1; }
.avatar-layers .base { opacity: 1; }
.avatar-glow {
  position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 calc(2px + var(--level) * 5px) color-mix(in srgb, var(--brand) calc(20% + var(--level) * 70%), transparent);
  opacity: 0; transition: opacity .25s;
}
.avatar[data-state="speaking"] .avatar-glow { opacity: 1; }
/* Photo fallback: no video clips uploaded yet. */
.avatar.photo .avatar-layers img { opacity: 1; animation: breathe 6s ease-in-out infinite; transform-origin: 50% 70%; }
.avatar.photo[data-state="speaking"] .avatar-layers img { transform: scale(calc(1.01 + var(--level) * .018)); animation: none; transition: transform .08s linear; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.012); } }

.state-pill {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 5;
  display: inline-flex; align-items: center; gap: 9px; padding: 7px 14px; border-radius: 999px;
  background: rgba(8, 12, 22, .7); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, .14); font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.state-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.avatar[data-state="listening"] .dot { background: var(--ok); animation: pulse 1.6s ease-in-out infinite; }
.avatar[data-state="thinking"] .dot { background: #f5c451; animation: blink 1s steps(2) infinite; }
.avatar[data-state="speaking"] .dot { background: var(--brand); box-shadow: 0 0 0 calc(var(--level) * 7px) color-mix(in srgb, var(--brand) 40%, transparent); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(55, 211, 153, .55); } 50% { box-shadow: 0 0 0 7px rgba(55, 211, 153, 0); } }
@keyframes blink { 50% { opacity: .35; } }

.controls { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.ctl {
  display: inline-flex; align-items: center; gap: 8px; padding: 11px 16px; border-radius: 999px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); font-weight: 600; transition: background .2s, border-color .2s, opacity .2s;
}
.ctl:hover:not([disabled]) { border-color: rgba(255, 255, 255, .25); }
.ctl[disabled] { opacity: .4; cursor: not-allowed; }
.ctl.mic[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #06261a; }
.ctl.mic.unsupported { display: none; }
.ctl .off { display: none; }
#btn-sound[aria-pressed="false"] .on { display: none; }
#btn-sound[aria-pressed="false"] .off { display: inline; }
.ctl.end { background: color-mix(in srgb, var(--danger) 16%, var(--panel-2)); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.panel {
  display: flex; flex-direction: column; min-height: 0; background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head .who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.panel-head .who span { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-tools { display: flex; align-items: center; gap: 10px; flex: none; }
.p-logo { max-height: 28px; max-width: 90px; object-fit: contain; background: #fff; border-radius: 6px; padding: 3px 6px; }

.transcript { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg { max-width: 88%; padding: 11px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; animation: rise .22s ease-out; }
.msg.from-avatar { align-self: flex-start; background: rgba(255, 255, 255, .06); border: 1px solid var(--line); border-top-left-radius: 6px; }
.msg.from-visitor { align-self: flex-end; background: color-mix(in srgb, var(--brand) 85%, black); color: var(--brand-ink); border-top-right-radius: 6px; }
.msg .meta { display: block; font-size: 11.5px; opacity: .7; margin-bottom: 2px; font-weight: 600; }
.msg.from-notice { align-self: center; background: none; color: var(--muted); font-size: 13px; text-align: center; padding: 4px; }
.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .45; } 40% { transform: translateY(-5px); opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.interim { margin: 0 18px 8px; padding: 9px 12px; border-radius: 12px; border: 1px dashed color-mix(in srgb, var(--ok) 60%, transparent); color: var(--muted); font-style: italic; font-size: 14px; }
.suggestions { display: flex; gap: 8px; padding: 0 18px 10px; overflow-x: auto; scrollbar-width: none; }
.suggestions::-webkit-scrollbar { display: none; }
.suggestions button {
  flex: none; border: 1px solid var(--line); background: rgba(255, 255, 255, .04); border-radius: 999px; padding: 7px 13px;
  cursor: pointer; font-size: 13.5px; color: var(--text); transition: border-color .2s, background .2s;
}
.suggestions button:hover { border-color: color-mix(in srgb, var(--brand) 70%, white); background: color-mix(in srgb, var(--brand) 14%, transparent); }
.composer { display: flex; gap: 10px; padding: 12px 14px 14px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 140px; background: rgba(0, 0, 0, .25); border: 1px solid var(--line);
  border-radius: 14px; padding: 11px 14px; outline: none; line-height: 1.4;
}
.send { width: 46px; height: 46px; border-radius: 14px; border: 0; background: var(--brand); color: var(--brand-ink); cursor: pointer; display: grid; place-items: center; }
.send:disabled { opacity: .4; }
.talk-hint { margin: -6px 18px 12px; font-size: 12.5px; color: var(--muted); }
.ai-disclosure { margin: -6px 18px 10px; font-size: 11.5px; color: var(--muted); }

/* ---------- end ---------- */
.screen.end { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px 16px; gap: 18px; }
.end-card { width: min(620px, 100%); background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line); border-radius: 24px; padding: 34px; box-shadow: var(--shadow); text-align: center; }
.end-card h2 { margin: 0 0 10px; font-size: 28px; }
.end-summary { color: var(--muted); text-align: left; background: rgba(0, 0, 0, .2); border-radius: 12px; padding: 14px 16px; }
.end-summary:empty { display: none; }
.end-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0 10px; }
.end-mail { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.end-mail input { flex: 1; max-width: 320px; }
.end-contact { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 20px 0 6px; }
.end-busy { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .welcome-card { grid-template-columns: 1fr; }
  .welcome-media { min-height: 0; aspect-ratio: 1 / .78; }
  .welcome-body { padding: 24px 20px 22px; }
  .fields { grid-template-columns: 1fr; }
  .screen.talk { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); padding: 10px; gap: 10px; }
  .stage { gap: 8px; }
  .avatar { flex: none; height: 38vh; height: 38dvh; }
  .ctl { padding: 9px 12px; }
  .ctl .ctl-label { display: none; }
  .ctl.end .ctl-label { display: inline; }
  .msg { max-width: 94%; }
}
@media (max-width: 480px) {
  .p-logo { display: none; }
  .panel-head { padding: 10px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
