/* ══════════════════════════════════════════════════════════════════
   Convozent Voice Agent — Full Design System
   Matching fe-platform exactly
   ══════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  --bg:           #ffffff;
  --fg:           #0a0a0a;
  --muted:        #f5f5f5;
  --muted-fg:     #737373;
  --border:       #e5e5e5;
  --brand-color:  #EE3275;
  --text-color:   #ffffff;
  --radius:       0.625rem;
  --font:         'Public Sans', ui-sans-serif, system-ui, sans-serif;
  --shadow-sm:    0 1px 4px rgba(0,0,0,0.06);
  --shadow-md:    0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg:    0 12px 40px rgba(0,0,0,0.12);
  --connecting-gradient: linear-gradient(90deg, #000 0%, #000 40%, #fff 50%, #000 60%, #000 100%);
  --connecting-glow: rgba(0,0,0,0.06);
}

[data-theme="dark"] {
  --bg:           #0a0a0a;
  --fg:           #fafafa;
  --muted:        #1f1f1f;
  --muted-fg:     #a3a3a3;
  --border:       rgba(255,255,255,0.1);
  --shadow-sm:    0 1px 4px rgba(0,0,0,0.4);
  --shadow-md:    0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg:    0 12px 40px rgba(0,0,0,0.6);
  --connecting-gradient: linear-gradient(90deg, #333 0%, #333 40%, #fff 50%, #333 60%, #333 100%);
  --connecting-glow: rgba(255,255,255,0.04);
}

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  font-family:    var(--font);
  background:     var(--bg);
  color:          var(--fg);
  height:         100vh;
  width:          100vw;
  overflow:       hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* ══════════════════════════════════════════════════════════════════
   VIEWS — only .active is visible
   ══════════════════════════════════════════════════════════════════ */
.view {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s;
}
.view.active { display: flex; }

/* ══════════════════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════════════════ */
#app-header {
  position: fixed; top: 0; left: 0; width: 100%; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px 4px 16px;
}
.header-logo-wrap {
  position: relative;
  min-width: 64px; min-height: 56px;
  display: flex; align-items: center; justify-content: center;
}
.header-logo {
  height: 48px; width: auto; object-fit: contain; border-radius: 6px;
  opacity: 0; transition: opacity 0.5s;
}
.header-logo.loaded { opacity: 1; }
.spinner {
  position: absolute; z-index: 20;
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--muted-fg);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.header-right { display: flex; align-items: center; gap: 16px; }
.header-brand {
  font-family: var(--font);
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.2em; color: var(--fg);
  text-transform: uppercase;
}
@media (min-width: 640px) { .header-brand { font-size: 12px; } }
.brand-hidden-sm { display: none; }
@media (min-width: 640px) { .brand-hidden-sm { display: inline; } }
.brand-link {
  color: inherit; text-decoration: none; position: relative;
}
.brand-link::after {
  content: ''; position: absolute; width: 100%; height: 1px;
  bottom: -1px; left: 0; background: currentColor;
  transform: scaleX(0); transform-origin: right; transition: transform 0.3s;
}
.brand-link:hover::after { transform: scaleX(1); transform-origin: left; }

/* Theme Toggle */
.theme-toggle-group {
  display: flex; align-items: center; gap: 4px;
  padding: 4px; background: var(--muted); border-radius: 20px; border: 1px solid var(--border);
}
.theme-btn {
  background: none; border: none; padding: 5px 6px; cursor: pointer;
  border-radius: 50%; display: flex; align-items: center;
  color: var(--muted-fg); transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.theme-btn.active { background: var(--bg); color: var(--fg); box-shadow: var(--shadow-sm); }

/* ══════════════════════════════════════════════════════════════════
   LOADING VIEW
   ══════════════════════════════════════════════════════════════════ */
.loading-content {
  display: flex; flex-direction: column; align-items: center; gap: 48px;
}

/* Sound Bars (shared between loading and session) */
.sound-bars {
  display: flex; align-items: flex-end; gap: 6px;
}
.loading-bars { height: 48px; }
.loading-bars .bar {
  width: 8px; border-radius: 9999px; background: var(--fg);
  animation: loadingBar 4s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.2s);
}
@keyframes loadingBar {
  0%,100% { height: 8px; opacity: 0.3; }
  25%     { height: 48px; opacity: 1; }
  50%     { height: 19px; opacity: 0.6; }
  75%     { height: 58px; opacity: 1; }
}

/* Shimmer text */
.shimmer-text {
  font-family: var(--font);
  font-size: 20px; font-weight: 900;
  letter-spacing: 0.2em; text-transform: uppercase;
  background-image: var(--connecting-gradient);
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 6s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -100% 0; } }

/* Typing status text */
.typing-text {
  font-family: var(--font);
  font-size: 12px; font-weight: 500;
  color: var(--muted-fg);
  letter-spacing: 0.05em;
  min-height: 18px;
  text-align: center;
}

/* ══════════════════════════════════════════════════════════════════
   WELCOME VIEW
   ══════════════════════════════════════════════════════════════════ */
.welcome-content {
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.welcome-icon { color: var(--fg); margin-bottom: 16px; }
.intro-text {
  font-size: 16px; font-weight: 500; line-height: 1.6;
  color: var(--fg); max-width: 420px; padding: 0 16px;
}
.start-btn {
  margin-top: 24px; width: 256px;
  padding: 14px 32px;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  border: none; border-radius: 8px; cursor: pointer;
  background: var(--brand-color); color: var(--text-color);
  transition: filter 0.2s, transform 0.15s;
}
.start-btn:hover { filter: brightness(0.9); }
.start-btn:active { transform: scale(0.97); }
.start-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.welcome-footer {
  position: fixed; bottom: 20px; left: 0; width: 100%;
  text-align: center;
  font-size: 12px; color: var(--muted-fg);
}
@media (min-width: 640px) { .welcome-footer { font-size: 14px; } }

/* ══════════════════════════════════════════════════════════════════
   ERROR VIEW
   ══════════════════════════════════════════════════════════════════ */
.error-card {
  width: 90%; max-width: 512px;
  padding: 48px 24px;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}
.error-code {
  font-size: 120px; line-height: 1; font-weight: 700;
  letter-spacing: -0.04em;
  color: #d1d5db;
}
[data-theme="dark"] .error-code { color: #27272a; }
.error-title {
  margin-top: 8px;
  font-family: var(--font); font-size: 24px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase; color: #4b5563;
}
[data-theme="dark"] .error-title { color: #e4e4e7; }
.error-desc {
  margin-top: 16px;
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: #9ca3af; max-width: 320px; margin-left: auto; margin-right: auto; line-height: 1.7;
}
@media (min-width: 640px) { .error-desc { font-size: 12px; } }

/* ══════════════════════════════════════════════════════════════════
   POPUP FORM
   ══════════════════════════════════════════════════════════════════ */
.popup-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5);
}
.popup-overlay.open { display: flex; }
.popup-card {
  width: 100%; max-width: 448px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  animation: popupIn 0.25s ease-out;
}
@keyframes popupIn {
  from { opacity: 0; transform: scale(0.95) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.popup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.popup-header h2 { font-size: 14px; font-weight: 600; }
.popup-close {
  background: none; border: none; font-size: 20px;
  cursor: pointer; color: var(--muted-fg); padding: 4px;
  border-radius: 6px; transition: background 0.2s;
}
.popup-close:hover { background: var(--muted); }
.popup-body { padding: 24px; }
.popup-body label {
  display: block; margin-bottom: 4px;
  font-size: 14px; font-weight: 500; color: var(--fg);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.popup-body input {
  width: 100%; padding: 10px 12px;
  font-family: var(--font); font-size: 14px; font-weight: 500;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 16px; transition: box-shadow 0.2s, border-color 0.2s;
  outline: none;
}
.popup-body input:focus { border-color: var(--brand-color); box-shadow: 0 0 0 3px rgba(238,50,117,0.12); }
.popup-body input::placeholder { color: var(--muted-fg); }
.popup-submit {
  width: 100%; padding: 12px;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  border: none; border-radius: 8px; cursor: pointer;
  background: var(--brand-color); color: var(--text-color);
  transition: filter 0.2s, transform 0.1s;
}
.popup-submit:hover:not(:disabled) { filter: brightness(0.9); }
.popup-submit:active:not(:disabled) { transform: scale(0.97); }
.popup-submit:disabled { background: #e5e7eb; color: #9ca3af; cursor: not-allowed; }

/* ══════════════════════════════════════════════════════════════════
   SESSION VIEW
   ══════════════════════════════════════════════════════════════════ */
#session-view { overflow: hidden; }

/* Connecting overlay */
.connecting-overlay {
  position: absolute; inset: 0; z-index: 120;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.01);
  backdrop-filter: blur(64px);
  transition: opacity 0.4s;
}
.connecting-overlay.hidden { opacity: 0; pointer-events: none; }
[data-theme="dark"] .connecting-overlay { background: rgba(0,0,0,0.5); }

/* Session center */
.session-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; position: relative; z-index: 10;
}

/* Session sound bars */
.session-bars { height: 56px; }
.session-bars .bar {
  width: 8px; height: 8px;
  border-radius: 9999px; background: var(--fg);
  opacity: 0.2; transition: height 0.2s, opacity 0.2s, background 0.3s;
  transform-origin: bottom center;
}

/* States */
#session-view.listening .session-bars .bar {
  opacity: 0.45;
  animation: barBreathe 2s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.18s);
}
@keyframes barBreathe { 0%,100% { height: 8px; } 50% { height: 22px; } }

#session-view.thinking .session-bars .bar {
  opacity: 0.7;
  animation: barThink 1.4s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.14s);
}
@keyframes barThink { 0%,100% { height: 8px; } 40% { height: 46px; } 60% { height: 36px; } }

#session-view.speaking .session-bars .bar {
  opacity: 1; background: var(--brand-color);
  animation: barSpeak 0.55s ease-in-out infinite alternate;
  animation-delay: calc(var(--i) * 0.08s);
}
@keyframes barSpeak { from { height: 10px; } to { height: 56px; } }
#session-view.speaking .session-bars .bar:nth-child(1),
#session-view.speaking .session-bars .bar:nth-child(5) { animation-name: barSpeakShort; }
#session-view.speaking .session-bars .bar:nth-child(2),
#session-view.speaking .session-bars .bar:nth-child(4) { animation-name: barSpeakMid; }
@keyframes barSpeakShort { from { height: 10px; } to { height: 26px; } }
@keyframes barSpeakMid   { from { height: 10px; } to { height: 44px; } }

.status-text {
  font-size: 13px; font-weight: 500; letter-spacing: 0.03em;
  color: var(--muted-fg); text-align: center; height: 20px;
}

/* Mic speaking pulse */
.ctrl-btn.user-speaking {
  color: #16a34a; background: rgba(22,163,74,0.08);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.25);
  animation: micPulse 1s ease-in-out infinite;
}
@keyframes micPulse {
  0%,100% { box-shadow: 0 0 0 3px rgba(22,163,74,0.25); }
  50%      { box-shadow: 0 0 0 7px rgba(22,163,74,0.08); }
}

/* ══════════════════════════════════════════════════════════════════
   VIDEO PiP
   ══════════════════════════════════════════════════════════════════ */
.video-tile {
  position: fixed; bottom: 110px; right: 20px;
  width: 120px; height: 120px; border-radius: 12px;
  overflow: hidden; background: #000;
  border: 2px solid var(--border); box-shadow: var(--shadow-md); z-index: 40;
}
#local-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

/* ══════════════════════════════════════════════════════════════════
   CONTROL BAR — fe-platform pill design
   ══════════════════════════════════════════════════════════════════ */
.control-bar-wrapper {
  position: fixed; bottom: 12px; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 16px; z-index: 60; padding: 0 12px;
  animation: slideUp 0.4s cubic-bezier(0.4,0,0.2,1) 0.5s both;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.control-bar-left {
  display: flex; align-items: center; gap: 6px;
}

/* ── Track Pill (mic / video) ── */
.track-pill {
  position: relative;
  display: flex; align-items: center;
  background: var(--muted); border-radius: 9999px;
  height: 44px;
  transition: background 0.25s, color 0.25s;
  color: var(--fg);
}
.track-pill.active {
  background: var(--fg); color: var(--bg);
}
.track-pill.muted {
  background: var(--muted); color: var(--muted-fg);
  opacity: 0.6;
}
[data-theme="dark"] .track-pill.active {
  background: var(--fg); color: var(--bg);
}

/* Toggle button (mic/video icon) */
.pill-toggle {
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px 0 14px; height: 100%; color: inherit;
  border-radius: 9999px 0 0 9999px;
  transition: background 0.2s;
}
.pill-toggle:hover { background: rgba(255,255,255,0.12); }
.track-pill:not(.active) .pill-toggle:hover { background: rgba(0,0,0,0.05); }

/* Audio level bars inside mic pill */
.pill-level-bars {
  display: flex; align-items: center; gap: 2px;
  height: 24px; padding: 0 4px;
}
.lvl-bar {
  width: 2.5px; height: 5px; border-radius: 9999px;
  background: currentColor; opacity: 0.5;
  transition: height 0.12s ease, opacity 0.12s;
  transform-origin: center center;
}
/* Animate level bars when mic is active & speaking */
.track-pill.active .lvl-bar {
  animation: lvlBounce 0.6s ease-in-out infinite alternate;
}
.lvl-bar:nth-child(1) { animation-delay: 0s; }
.lvl-bar:nth-child(2) { animation-delay: 0.15s; }
.lvl-bar:nth-child(3) { animation-delay: 0.3s; }
@keyframes lvlBounce {
  0% { height: 5px; opacity: 0.4; }
  100% { height: 18px; opacity: 1; }
}
.track-pill:not(.active) .lvl-bar { animation: none; height: 5px; }

/* Divider inside pill */
.pill-divider {
  display: block; width: 1px; height: 18px; margin: 0;
  border: none;
  background: currentColor; opacity: 0.25;
}

/* Chevron dropdown trigger */
.pill-chevron {
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0 10px 0 6px; height: 100%; color: inherit;
  border-radius: 0 9999px 9999px 0;
  transition: background 0.2s;
}
.pill-chevron:hover { background: rgba(255,255,255,0.12); }
.track-pill:not(.active) .pill-chevron:hover { background: rgba(0,0,0,0.05); }

/* Device Dropdown */
.device-dropdown {
  display: none; position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%);
  min-width: 240px; max-width: 320px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 8px 0; z-index: 200;
  animation: dropdownIn 0.2s ease-out;
}
@keyframes dropdownIn { from { opacity: 0; transform: translateX(-50%) translateY(6px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.device-dropdown.open { display: block; }
.dropdown-title {
  padding: 6px 16px 8px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted-fg);
}
.device-list { display: flex; flex-direction: column; }
.device-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; font-size: 13px; font-weight: 500;
  color: var(--fg); cursor: pointer; background: none; border: none;
  text-align: left; width: 100%; font-family: var(--font);
  transition: background 0.15s;
}
.device-item:hover { background: var(--muted); }
.device-item.active-device { color: var(--brand-color); font-weight: 600; }
.device-item .check-icon { width: 16px; flex-shrink: 0; }
.device-item .check-icon::before {
  content: '✓'; display: none;
  font-size: 14px; font-weight: 800; color: var(--brand-color);
}
.device-item.active-device .check-icon::before { display: inline; }

/* ── Chat Button ── */
.chat-btn {
  background: var(--muted); border: none; cursor: pointer;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--fg);
  transition: background 0.2s, color 0.2s, transform 0.15s;
}
.chat-btn:hover { background: var(--border); transform: scale(1.06); }
.chat-btn:active { transform: scale(0.95); }
.chat-btn.chat-active { background: var(--fg); color: var(--bg); }

/* ── END CALL ── */
.end-call-btn {
  display: flex; align-items: center; gap: 8px;
  background: #fff1f2; color: var(--brand-color);
  border: 1px solid #fecdd3; border-radius: 20px;
  padding: 10px 24px;
  font-family: var(--font); font-size: 11px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  cursor: pointer; white-space: nowrap;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}
.end-call-btn:hover { background: var(--brand-color); color: #fff; border-color: var(--brand-color); }
.end-call-btn:active { transform: scale(0.97); }
.end-text-full { display: none; }
.end-text-short { display: inline; }
@media (min-width: 768px) { .end-text-full { display: inline; } .end-text-short { display: none; } }
[data-theme="dark"] .end-call-btn { background: rgba(238,50,117,0.12); border-color: rgba(238,50,117,0.3); }
[data-theme="dark"] .end-call-btn:hover { background: var(--brand-color); color: #fff; }

/* Mic speaking pulse on the pill */
.track-pill.user-speaking {
  box-shadow: 0 0 0 3px rgba(22,163,74,0.3);
  animation: pillPulse 1s ease-in-out infinite;
}
@keyframes pillPulse {
  0%,100% { box-shadow: 0 0 0 3px rgba(22,163,74,0.3); }
  50%     { box-shadow: 0 0 0 7px rgba(22,163,74,0.08); }
}

/* ══════════════════════════════════════════════════════════════════
   CHAT PANEL
   ══════════════════════════════════════════════════════════════════ */
.chat-panel {
  position: fixed; top: 0; right: -420px; width: 400px; max-width: calc(100vw - 24px);
  height: 100%; background: var(--bg);
  border-left: 1px solid var(--border); z-index: 70;
  display: flex; flex-direction: column;
  transition: right 0.32s cubic-bezier(0.4,0,0.2,1);
  box-shadow: -8px 0 32px rgba(0,0,0,0.06);
}
.chat-panel.open { right: 0; }
.chat-panel-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.chat-panel-title { font-size: 14px; font-weight: 600; letter-spacing: 0.03em; }
.transcript-panel {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.msg {
  max-width: 80%; padding: 10px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.5; word-break: break-word;
  animation: msgIn 0.25s ease both;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.msg.agent { align-self: flex-start; background: var(--muted); color: var(--fg); border-bottom-left-radius: 4px; }
.msg.user { align-self: flex-end; background: var(--fg); color: var(--bg); border-bottom-right-radius: 4px; }

/* ══════════════════════════════════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
