:root {
  --bg: #f4f6fb;
  --card: rgba(255, 255, 255, 0.82);
  --card-border: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --muted: #5b6475;
  --accent: #4f46e5;
  --accent-2: #06b6d4;
  --accent-3: #ec4899;
  --ok: #059669;
  --danger: #dc2626;
  --user-bubble: linear-gradient(135deg, #4f46e5, #6d28d9);
  --agent-bubble: #ffffff;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.12);
  --radius: 22px;
  --level: 0;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070b18;
    --card: rgba(17, 24, 39, 0.72);
    --card-border: rgba(255, 255, 255, 0.08);
    --text: #e5e7eb;
    --muted: #9aa3b5;
    --agent-bubble: #1f2937;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); overflow-x: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
a { color: var(--accent); }

/* ---------- animated background ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.blob { position: absolute; width: 46vmax; height: 46vmax; border-radius: 50%; filter: blur(70px); opacity: 0.35; animation: drift 22s ease-in-out infinite alternate; }
.b1 { background: var(--accent); top: -18vmax; left: -12vmax; }
.b2 { background: var(--accent-2); bottom: -20vmax; right: -14vmax; animation-delay: -7s; }
.b3 { background: var(--accent-3); top: 30%; left: 45%; width: 30vmax; height: 30vmax; opacity: 0.18; animation-delay: -12s; }
@keyframes drift { 0% { transform: translate(0, 0) scale(1); } 50% { transform: translate(6vmax, 4vmax) scale(1.08); } 100% { transform: translate(-4vmax, 6vmax) scale(0.95); } }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px clamp(16px, 4vw, 40px); }
.brand { font-weight: 800; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15); }
.staff-nav { display: flex; gap: 14px; align-items: center; font-size: 0.9rem; }
.pill { background: rgba(79, 70, 229, 0.12); color: var(--accent); padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }

/* ---------- screens ---------- */
main { padding: 0 clamp(12px, 3vw, 40px) 40px; }
.screen { display: none; }
.screen.active { display: block; animation: screen-in 0.5s cubic-bezier(.2, .8, .2, 1); }
@keyframes screen-in { from { opacity: 0; transform: translateY(14px) scale(0.99); } to { opacity: 1; transform: none; } }
.card { background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }

/* ---------- start ---------- */
.intro { max-width: 640px; margin: 4vh auto 0; padding: clamp(24px, 5vw, 48px); text-align: center; }
.intro h1 { font-size: clamp(2rem, 5vw, 2.8rem); margin: 18px 0 8px; letter-spacing: -0.03em; }
.lead { color: var(--muted); font-size: 1.05rem; line-height: 1.6; margin: 0 auto 26px; max-width: 46ch; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.mode-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; padding: 18px; border-radius: 18px; border: 2px solid var(--card-border); background: transparent; color: var(--text); cursor: pointer; font: inherit; transition: transform .2s, border-color .2s, box-shadow .2s, background .2s; }
.mode-card svg { width: 28px; height: 28px; fill: var(--accent); }
.mode-card span { color: var(--muted); font-size: 0.88rem; }
.mode-card:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(79, 70, 229, 0.15); }
.mode-card.selected { border-color: var(--accent); background: rgba(79, 70, 229, 0.07); }
.code-field { display: grid; gap: 6px; text-align: left; margin-bottom: 18px; font-weight: 600; font-size: 0.9rem; }
.code-field input { font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--card-border); background: var(--agent-bubble); color: var(--text); }
.fineprint { color: var(--muted); font-size: 0.82rem; margin-top: 14px; }
.error { color: var(--danger); min-height: 1.2em; font-weight: 600; }

/* ---------- buttons ---------- */
.btn { font: inherit; border: 0; border-radius: 14px; padding: 12px 20px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; transition: transform .15s, box-shadow .2s, opacity .2s, background .2s; }
.btn:active { transform: scale(0.97); }
.btn.primary { color: #fff; background: linear-gradient(135deg, var(--accent), #7c3aed); box-shadow: 0 10px 30px rgba(79, 70, 229, 0.35); }
.btn.primary:hover { box-shadow: 0 14px 38px rgba(79, 70, 229, 0.45); transform: translateY(-1px); }
.btn.big { padding: 16px 30px; font-size: 1.05rem; width: 100%; }
.btn.small { padding: 9px 14px; font-size: 0.9rem; }
.btn.danger { background: rgba(220, 38, 38, 0.1); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--card-border); }
.btn[disabled] { opacity: 0.6; cursor: progress; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; display: none; animation: spin 0.8s linear infinite; }
.btn.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 46px; height: 46px; flex: 0 0 46px; border-radius: 14px; border: 0; cursor: pointer; display: grid; place-items: center; background: rgba(79, 70, 229, 0.1); transition: transform .15s, background .2s; }
.icon-btn svg { width: 22px; height: 22px; fill: var(--accent); }
.icon-btn:hover { transform: translateY(-1px); background: rgba(79, 70, 229, 0.18); }
.icon-btn.send { background: linear-gradient(135deg, var(--accent), #7c3aed); }
.icon-btn.send svg { fill: #fff; }
.icon-btn.mic[aria-pressed="true"] { background: rgba(220, 38, 38, 0.14); }
.icon-btn.mic[aria-pressed="true"] svg { fill: var(--danger); }

/* ---------- orb ---------- */
.orb { position: relative; width: 150px; height: 150px; margin: 0 auto; transform: scale(calc(1 + var(--level) * 0.35)); transition: transform 0.08s linear; }
.orb-small { width: 84px; height: 84px; }
.orb .core { position: absolute; inset: 18%; border-radius: 50%; background: radial-gradient(circle at 30% 30%, #fff 0%, var(--accent-2) 22%, var(--accent) 60%, #312e81 100%); box-shadow: 0 0 40px rgba(79, 70, 229, 0.55), inset 0 0 20px rgba(255, 255, 255, 0.35); animation: breathe 4s ease-in-out infinite; }
.orb .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(79, 70, 229, 0.35); animation: ripple 3.2s ease-out infinite; }
.orb .r2 { animation-delay: 1.6s; }
@keyframes breathe { 0%, 100% { transform: scale(0.96); } 50% { transform: scale(1.04); } }
@keyframes ripple { from { transform: scale(0.75); opacity: 0.9; } to { transform: scale(1.25); opacity: 0; } }
.orb.speaking .core { background: radial-gradient(circle at 30% 30%, #fff 0%, #67e8f9 20%, var(--accent-2) 55%, var(--accent) 100%); box-shadow: 0 0 60px rgba(6, 182, 212, 0.6); }
.orb.listening .core { background: radial-gradient(circle at 30% 30%, #fff 0%, #f9a8d4 20%, var(--accent-3) 55%, #7c3aed 100%); box-shadow: 0 0 60px rgba(236, 72, 153, 0.55); }
.orb.thinking .ring { border-style: dashed; animation: spin 2.4s linear infinite; opacity: 0.8; }
.orb.thinking .r2 { animation-direction: reverse; inset: 8%; }
.orb-wrap { padding: 18px 0 6px; text-align: center; transition: padding .3s; }
.orb-label { margin: 14px 0 0; color: var(--muted); font-weight: 600; min-height: 1.4em; }
.text-mode .orb-wrap { display: flex; align-items: center; gap: 14px; justify-content: center; padding: 10px 0 0; }
.text-mode .orb { width: 46px; height: 46px; margin: 0; }
.text-mode .orb-label { margin: 0; }

/* ---------- chat layout ---------- */
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; max-width: 1180px; margin: 1vh auto 0; }
.stage { display: flex; flex-direction: column; min-height: min(78vh, 820px); padding: 12px clamp(12px, 2vw, 22px) 16px; position: relative; overflow: hidden; }
.messages { list-style: none; margin: 0; padding: 12px 4px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.msg { max-width: 82%; padding: 11px 15px; border-radius: 18px; line-height: 1.5; animation: pop 0.32s cubic-bezier(.2, .9, .3, 1.2); white-space: pre-wrap; word-wrap: break-word; }
.msg.agent { align-self: flex-start; background: var(--agent-bubble); border: 1px solid var(--card-border); border-bottom-left-radius: 6px; box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06); }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: #fff; border-bottom-right-radius: 6px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 0.85rem; text-align: center; }
.msg.interrupted { opacity: 0.6; }
.msg.interrupted::after { content: " ⋯"; }
.msg.streaming::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 3px; vertical-align: -2px; background: currentColor; animation: blink 1s steps(2) infinite; }
.msg.pending { opacity: 0.75; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: 0; } }
.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: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-5px); opacity: 1; } }
.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 0; transition: min-height .2s; }
.chip { font: inherit; border: 1px solid var(--accent); color: var(--accent); background: rgba(79, 70, 229, 0.06); padding: 8px 16px; border-radius: 999px; cursor: pointer; font-weight: 600; animation: pop 0.3s ease; transition: background .2s, color .2s; }
.chip:hover { background: var(--accent); color: #fff; }
.composer { display: flex; gap: 10px; align-items: center; margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--card-border); }
.composer input { flex: 1; min-width: 0; font: inherit; padding: 13px 16px; border-radius: 14px; border: 1px solid var(--card-border); background: var(--agent-bubble); color: var(--text); transition: border-color .2s, box-shadow .2s; }
.composer input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15); }
.text-mode .mic { display: none; }
.tool-toast { position: absolute; left: 50%; bottom: 92px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; display: flex; gap: 8px; align-items: center; transition: opacity .25s, transform .25s; }
.tool-toast.show { opacity: 0.92; transform: translate(-50%, 0); }
.tool-toast::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-top-color: transparent; animation: spin 0.8s linear infinite; }

/* ---------- profile panel ---------- */
.profile { padding: 20px; align-self: start; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.profile h2 { margin: 0 0 4px; font-size: 1.1rem; }
.steps { list-style: none; display: flex; gap: 6px; padding: 0; margin: 16px 0; }
.steps li { flex: 1; text-align: center; font-size: 0.72rem; font-weight: 700; color: var(--muted); padding-top: 10px; position: relative; text-transform: uppercase; letter-spacing: 0.03em; }
.steps li::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 5px; border-radius: 5px; background: var(--card-border); transition: background .4s; }
.steps li.done::before { background: var(--ok); }
.steps li.current::before { background: linear-gradient(90deg, var(--accent), var(--accent-2)); background-size: 200% 100%; animation: shimmer 1.6s linear infinite; }
.steps li.current { color: var(--accent); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: 0 0; } }
.progress { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: 16px; background: rgba(79, 70, 229, 0.06); margin-bottom: 14px; }
.progress div { display: grid; }
.ring-progress { width: 52px; height: 52px; transform: rotate(-90deg); }
.ring-progress circle { fill: none; stroke-width: 4; }
.ring-progress .track { stroke: var(--card-border); }
.ring-progress .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray 0.6s cubic-bezier(.2, .8, .2, 1); }
.fields { display: grid; gap: 14px; }
.group h3 { margin: 0 0 6px; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.field { display: grid; grid-template-columns: 110px 1fr; gap: 8px; padding: 7px 10px; border-radius: 10px; font-size: 0.9rem; animation: field-in 0.5s ease; }
.field dt { color: var(--muted); }
.field dd { margin: 0; font-weight: 600; word-break: break-word; }
.field.flash { animation: flash 1.4s ease; }
.field .ok { color: var(--ok); margin-left: 4px; }
@keyframes field-in { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }
@keyframes flash { 0% { background: rgba(6, 182, 212, 0.35); } 100% { background: transparent; } }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--card-border); }
.empty { font-size: 0.9rem; }
.crm-link { display: block; margin-top: 18px; font-weight: 700; text-decoration: none; }

/* ---------- done ---------- */
.done-card { max-width: 600px; margin: 5vh auto 0; padding: clamp(24px, 5vw, 44px); text-align: center; }
.done-icon { width: 76px; height: 76px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--ok), #10b981); animation: pop-big 0.6s cubic-bezier(.2, 1.4, .3, 1); box-shadow: 0 16px 40px rgba(5, 150, 105, 0.35); }
.done-icon svg { width: 40px; height: 40px; fill: #fff; }
@keyframes pop-big { from { transform: scale(0.3); opacity: 0; } to { transform: none; opacity: 1; } }
.pipeline { list-style: none; padding: 0; margin: 24px 0; text-align: left; display: grid; gap: 4px; }
.pipeline li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 12px; color: var(--muted); transition: color .3s, background .3s; }
.pipeline .dot { width: 20px; height: 20px; flex: 0 0 20px; border-radius: 50%; border: 2px solid var(--card-border); transition: all .3s; }
.pipeline li.active { color: var(--text); background: rgba(79, 70, 229, 0.07); }
.pipeline li.active .dot { border-color: var(--accent); border-top-color: transparent; animation: spin 0.9s linear infinite; }
.pipeline li.done { color: var(--text); }
.pipeline li.done .dot { border-color: var(--ok); background: var(--ok); box-shadow: inset 0 0 0 4px var(--card); }
.pipeline li.failed .dot { border-color: var(--danger); background: var(--danger); }
.done-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
#site-link { margin-top: 6px; animation: pop-big 0.5s ease; }

.site-footer { text-align: center; color: var(--muted); font-size: 0.82rem; padding: 18px 16px 26px; }
.conn-error { margin: 10px auto 0; max-width: 520px; text-align: center; color: var(--danger); font-weight: 600; }

/* ---------- responsive / a11y ---------- */
@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; }
  .profile { position: static; max-height: none; }
  .stage { min-height: 70vh; }
}
@media (max-width: 520px) {
  .modes { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
  .orb { width: 120px; height: 120px; }
}
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .orb { transform: none; }
}
