/* Orbi public chat widget */

:root {
  --bg-page:    #000;
  --bg-panel:   #0b0f1a;
  --bg-card:    #1a2236;
  --bg-card-2:  #21294a;
  --bg-input:   #0f1626;
  --border:     rgba(32,220,255,0.24);
  --text:       #eaf0ff;
  --text-dim:   #b8c6e0;
  --text-soft:  #8fa3c7;
  --accent:     #20dcff;
  --accent-hov: #0698ff;
  --danger:     #ff5555;
  --good:       #6fdc94;
  --warn:       #7d4dff;
  --bad:        #ff8b8b;
  --shadow:     0 12px 48px rgba(0,0,0,0.25);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  min-height: 100vh;
  background: var(--bg-page);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* When the page is the full-page chat (standalone or embed iframe),
   the body becomes dark and the panel fills the viewport. */
body.fullpage-chat {
  background: var(--bg-panel);
  color: var(--text);
  overflow: hidden;
  height: 100vh; height: 100dvh;
}
body.fullpage-chat .orbi-panel.standalone-mode,
body.fullpage-chat .orbi-panel.embed-mode {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  border-radius: 0 !important;
  transform: none !important;
  opacity: 1 !important;
}

/* --------------------------------------------------------------
   LANDING (used only by /static/embed-demo.html)
   -------------------------------------------------------------- */
.landing {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background:
    radial-gradient(1200px 600px at 20% 0%, rgba(125,77,255,0.08), transparent 60%),
    radial-gradient(900px 500px at 80% 100%, rgba(139,92,246,0.08), transparent 60%);
}
.landing-card {
  max-width: 540px;
  text-align: center;
}
.landing-logo {
  width: 64px; height: 64px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: #000 url('/static/myorbi-icon.png') center/cover no-repeat;
  box-shadow: 0 0 24px rgba(32,220,255,0.35);
}
.landing-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
  color: #f5f9ff;
}
.landing-card p {
  margin: 0;
  color: var(--text-dim);
  font-size: 16px;
}

/* --------------------------------------------------------------
   FLOATING LAUNCHER
   -------------------------------------------------------------- */
.orbi-launcher {
  position: fixed;
  bottom: 24px; right: 24px;
  min-height: 76px;
  padding: 14px 30px 14px 18px;
  border-radius: 44px;
  background: #000;
  color: #fff;
  border: 2px solid #20dcff;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(32,220,255,0.42), 0 0 0 0 rgba(32,220,255,0.7);
  overflow: visible;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font: 700 20px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.3px;
  z-index: 9998;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  animation: orbiLauncherGlow 2.4s ease-in-out infinite;
  bottom: max(24px, env(safe-area-inset-bottom));
}
@keyframes orbiLauncherGlow {
  0%,100% { box-shadow: 0 10px 28px rgba(32,220,255,0.42), 0 0 0 0 rgba(32,220,255,0.62); border-color: #20dcff; }
  50% { box-shadow: 0 14px 42px rgba(32,220,255,0.88), 0 0 0 18px rgba(32,220,255,0); border-color: #7d4dff; }
}
.orbi-launcher:hover {
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 16px 42px rgba(32,220,255,0.65), 0 0 28px rgba(125,77,255,0.32);
}
.orbi-launcher .launcher-avatar {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: #000 url('/static/myorbi-icon.png?v=20260716-blue-orby') center/cover no-repeat;
  flex: 0 0 auto;
  box-shadow: 0 0 16px rgba(32,220,255,0.48);
}
.orbi-launcher .launcher-label { white-space: nowrap; }
.orbi-launcher .launcher-icon-close { display: none; }
.orbi-launcher.open {
  background: #000;
  color: #eaf7ff;
  padding: 12px 14px;
  min-height: 0;
  border-radius: 50%;
  box-shadow: 0 0 22px rgba(32,220,255,0.45);
  animation: none;
}
.orbi-launcher.open .launcher-avatar { display: none; }
.orbi-launcher.open .launcher-label { display: none; }
.orbi-launcher.open .launcher-icon-close { display: block; color: #eaf7ff; }

.launcher-badge {
  position: absolute;
  top: -2px; right: -2px;
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-page);
}

/* --------------------------------------------------------------
   PANEL
   -------------------------------------------------------------- */
.orbi-panel {
  position: fixed;
  bottom: 92px; right: 20px;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--bg-panel);
  color: var(--text);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.orbi-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
/* On mobile, the panel goes full-screen */
@media (max-width: 480px) {
  .orbi-panel {
    bottom: 0; right: 0; left: 0; top: 0;
    width: 100vw; height: 100vh; max-height: 100vh; max-width: none;
    border-radius: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .orbi-launcher.open { opacity: 0; pointer-events: none; }
}

/* --------------------------------------------------------------
   PANEL HEADER
   -------------------------------------------------------------- */
.orbi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #111728;
  border-bottom: 1px solid #1f2942;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.avatar {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: #000 url('/static/myorbi-icon.png?v=20260716-blue-orby') center/cover no-repeat;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 0 12px rgba(32,220,255,0.42);
}
.avatar.speaking::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: ring 1.4s infinite ease-out;
}
@keyframes ring {
  0%   { opacity: 1; transform: scale(0.9); }
  100% { opacity: 0; transform: scale(1.5); }
}
.brand-text {
  min-width: 0;
}
.business {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.status {
  font-size: 11px;
  color: #20dcff;
  margin-top: 2px;
  text-shadow: 0 0 8px rgba(32,220,255,0.38);
}
.status.degraded { color: #9fb6ff; }
.status.offline { color: var(--bad); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.toggle-btn, .icon-btn {
  background: rgba(6,152,255,0.08);
  border: 1px solid rgba(6,152,255,0.4);
  color: #20dcff;
  width: 48px; height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.toggle-btn svg, .icon-btn svg {
  width: 28px;
  height: 28px;
}
.toggle-btn:hover, .icon-btn:hover {
  background: var(--bg-card-2);
  color: var(--text);
}
.toggle-btn[aria-pressed="true"] {
  background: rgba(125,77,255,0.18);
  color: var(--accent);
  border-color: rgba(125,77,255,0.4);
}
/* Icon swap */
.toggle-btn .icon-mic-off, .toggle-btn .icon-speaker-off { display: block; }
.toggle-btn .icon-mic-on,  .toggle-btn .icon-speaker-on  { display: none; }
.toggle-btn[aria-pressed="true"] .icon-mic-off,
.toggle-btn[aria-pressed="true"] .icon-speaker-off { display: none; }
.toggle-btn[aria-pressed="true"] .icon-mic-on,
.toggle-btn[aria-pressed="true"] .icon-speaker-on  { display: block; }
/* Frank 2026-06-23: brand teal instead of red. Red reads as 'stop' —
   the mic-is-listening state is GOOD (she's hearing you), so a friendly
   teal pulse matches the myOrbi brand and the favicon. */
.toggle-btn#mic-toggle.listening {
  background: rgba(6,152,255,0.18);
  color: #20dcff;
  border-color: rgba(6,152,255,0.55);
  animation: micPulse 1.6s infinite ease-in-out;
}
/* ── BIG MIC PILL ───────────────────────────────────────────────── */
.mic-bar {
  display: flex;
  justify-content: center;
  padding: 6px 16px 10px;
  background: var(--bg-panel);
}
.mic-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 36px;
  border-radius: 999px;
  border: 2px solid rgba(32,220,255,0.68);
  background: linear-gradient(135deg, rgba(6,152,255,0.18), rgba(125,77,255,0.12));
  color: #dffaff;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  animation: micIdleGlow 2.4s ease-in-out infinite;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.mic-pill-label { letter-spacing: 0.02em; }
@keyframes micIdleGlow {
  0%,100% { box-shadow: 0 0 10px rgba(32,220,255,0.45), 0 0 24px rgba(6,152,255,0.22), 0 0 0 0px rgba(32,220,255,0.48); }
  50%     { box-shadow: 0 0 26px rgba(32,220,255,0.95), 0 0 44px rgba(125,77,255,0.35), 0 0 0 14px rgba(32,220,255,0); }
}
.mic-pill.listening {
  background: linear-gradient(135deg, rgba(32,220,255,0.30), rgba(125,77,255,0.18));
  border-color: #20dcff;
  animation: micActiveGlow 1.2s ease-in-out infinite;
}
.mic-pill.listening .mic-pill-label::after { content: '…'; }
.mic-pill.listening .mic-pill-label { content: 'Listening'; }
@keyframes micActiveGlow {
  0%,100% { box-shadow: 0 0 16px rgba(32,220,255,0.78), 0 0 30px rgba(6,152,255,0.38), 0 0 0 0px rgba(32,220,255,0.78); }
  50%     { box-shadow: 0 0 34px rgba(32,220,255,1.0), 0 0 56px rgba(125,77,255,0.48), 0 0 0 18px rgba(32,220,255,0); }
}
.mic-pill.muted-while-speaking {
  background: linear-gradient(135deg, rgba(6,152,255,0.22), rgba(125,77,255,0.18));
  border-color: rgba(32,220,255,0.62);
  color: #dffaff;
  box-shadow: 0 0 18px rgba(32,220,255,0.58), 0 0 38px rgba(125,77,255,0.28);
  animation: none;
}

.toggle-btn#mic-toggle.muted-while-speaking {
  background: rgba(6,152,255,0.18);
  color: #20dcff;
  border-color: rgba(32,220,255,0.55);
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(32,220,255,0.5); }
  50%      { box-shadow: 0 0 0 10px rgba(32,220,255,0); }
}

/* --------------------------------------------------------------
   STATE BAR (shows what Orbi is doing — listening / thinking / speaking)
   -------------------------------------------------------------- */
.orbi-state-bar {
  padding: 6px 16px;
  font-size: 12px;
  text-align: center;
  background: rgba(125,77,255,0.08);
  color: var(--text-soft);
  border-bottom: 1px solid var(--border);
}
.orbi-state-bar.listening { background: rgba(6,152,255,0.10); color: #5eead4; }
.orbi-state-bar.thinking  { background: rgba(139,92,246,0.10); color: #c4b3ff; }
.orbi-state-bar.speaking  { background: rgba(125,77,255,0.10); color: #8eb6ff; }

/* --------------------------------------------------------------
   CHAT AREA
   -------------------------------------------------------------- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.welcome {
  margin: auto;
  text-align: center;
  padding: 12px;
  max-width: 360px;
}
.welcome-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 16px;
  margin-bottom: 14px;
}
.welcome-bubble h2 {
  margin: 0 0 6px;
  font-size: 18px;
}
.welcome-bubble p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.quick-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.quick-chip:hover { background: var(--bg-card-2); color: var(--text); }

/* MESSAGES */
.message {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #000;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.message.assistant.degraded { border-color: rgba(125,77,255,0.48); }
.message-tier-hint {
  font-size: 10.5px;
  color: var(--text-soft);
  margin-top: 4px;
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing span {
  width: 7px; height: 7px;
  background: var(--text-soft);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* INTERIM TRANSCRIPT bubble (preview of what mic is hearing right now) */
.interim {
  align-self: flex-end;
  background: rgba(125,77,255,0.18);
  color: var(--accent);
  border: 1px dashed rgba(125,77,255,0.4);
  font-style: italic;
  opacity: 0.9;
}

/* --------------------------------------------------------------
   COMPOSER
   -------------------------------------------------------------- */
.powered-by-orby {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 12px 2px;
  background: #0e1422;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.powered-by-orby a { color: #4f8cff; text-decoration: none; }
.powered-by-orby a:hover { text-decoration: underline; }

.ai-disclaimer {
  text-align: center;
  font-size: 11px;
  color: #5a6a8a;
  padding: 3px 12px 5px;
  background: #0e1422;
  flex-shrink: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: #0e1422;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer textarea {
  flex: 1;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 16px;  /* >= 16px prevents iOS Safari zoom on focus */
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  outline: none;
  -webkit-appearance: none;  /* prevent iOS rounded styling */
}
@media (min-width: 481px) { .composer textarea { font-size: 14.5px; } }
.composer textarea:focus { border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: white;
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hov); }
.send-btn:disabled { background: var(--border); cursor: not-allowed; opacity: 0.6; }

/* MESSAGE TIMESTAMP (visible on hover) */
.message-time {
  display: block;
  font-size: 10.5px;
  color: var(--text-soft);
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.message:hover .message-time { opacity: 0.7; }

/* COPY BUTTON on assistant messages */
.message-copy-btn {
  position: absolute;
  top: 6px; right: 6px;
  width: 24px; height: 24px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 4px;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.message:hover .message-copy-btn { opacity: 1; }
.message-copy-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.message.assistant {
  position: relative;
  padding-right: 32px;
}
.message-copy-btn.copied {
  color: var(--good);
  opacity: 1;
}

/* SCROLL-TO-BOTTOM BUTTON */
.scroll-to-bottom {
  position: absolute;
  right: 14px;
  bottom: 76px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fadeIn 0.2s ease;
}
.scroll-to-bottom:hover { background: var(--accent-hov); }
.scroll-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-panel);
}

/* OFFLINE BANNER */
.offline-banner {
  background: rgba(255,90,90,0.12);
  color: var(--bad);
  border-bottom: 1px solid rgba(255,90,90,0.3);
  padding: 7px 14px;
  font-size: 12px;
  text-align: center;
}
