/* TraceDat Voice Agent Widget — Phase 1 */

:root {
  --tracedat-blue:  #1a3c6e;
  --tracedat-green: #00a86b;
  --tracedat-light: #f4f7fb;
  --tracedat-text:  #1a1a2e;
  --tracedat-red:   #e53e3e;
  --tracedat-orange:#f6821f;
  --tracedat-shadow:0 8px 40px rgba(0,0,0,0.18);
  --tracedat-radius:16px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
#tracedat-voice-agent-root *,
#tracedat-voice-agent-root *::before,
#tracedat-voice-agent-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Root container ─────────────────────────────────────────────────────────── */
#tracedat-voice-agent-root {
  position: fixed;
  z-index: 9999;
  bottom: 0;
  right: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--tracedat-text);
}

/* ─── Floating button ────────────────────────────────────────────────────────── */
.tracedat-widget__button {
  position: fixed;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--tracedat-blue);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.22);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 9999;
}

.tracedat-widget__button:hover {
  transform: scale(1.07);
  box-shadow: 0 6px 28px rgba(0,0,0,0.28);
}

.tracedat-widget__button:focus-visible {
  outline: 3px solid var(--tracedat-green);
  outline-offset: 3px;
}

.tracedat-widget__button.bottom-right { right: 24px; }
.tracedat-widget__button.bottom-left  { left: 24px; }

/* ─── Unread badge ───────────────────────────────────────────────────────────── */
.tracedat-widget__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--tracedat-orange);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  transition: opacity 0.2s, transform 0.2s;
}

.tracedat-widget__badge--hidden {
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
}

/* ─── Chat panel ─────────────────────────────────────────────────────────────── */
.tracedat-widget__panel {
  position: fixed;
  bottom: 96px;
  width: 380px;
  height: 540px;
  background: #fff;
  border-radius: var(--tracedat-radius);
  box-shadow: var(--tracedat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  transform-origin: bottom right;
}

.tracedat-widget__panel.bottom-right { right: 24px; }
.tracedat-widget__panel.bottom-left  { left: 24px; transform-origin: bottom left; }

/* ─── Panel open/close animations ───────────────────────────────────────────── */
.tracedat-widget__panel--hidden {
  opacity: 0;
  transform: scale(0.92) translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tracedat-widget__panel--visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
  transition: opacity 0.2s ease, transform 0.2s ease;
  animation: tracedatSlideUp 0.2s ease-out;
}

@keyframes tracedatSlideUp {
  from { opacity: 0; transform: scale(0.92) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.tracedat-widget__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 52px;
  background: var(--tracedat-blue);
  flex-shrink: 0;
}

.tracedat-widget__logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.tracedat-widget__title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tracedat-widget__close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.tracedat-widget__close:hover { color: #fff; background: rgba(255,255,255,0.15); }
.tracedat-widget__close:focus-visible { outline: 2px solid var(--tracedat-green); outline-offset: 2px; }

/* ─── Message list ───────────────────────────────────────────────────────────── */
.tracedat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--tracedat-light);
  scroll-behavior: smooth;
}

.tracedat-widget__messages::-webkit-scrollbar { width: 5px; }
.tracedat-widget__messages::-webkit-scrollbar-track { background: transparent; }
.tracedat-widget__messages::-webkit-scrollbar-thumb { background: #cdd5e0; border-radius: 3px; }

/* ─── Message bubbles ────────────────────────────────────────────────────────── */
.tracedat-widget__bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  animation: tracedatFadeIn 0.15s ease-out;
}

@keyframes tracedatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tracedat-widget__bubble--agent {
  background: #fff;
  color: var(--tracedat-text);
  border-left: 3px solid var(--tracedat-green);
  align-self: flex-start;
  border-radius: 2px 12px 12px 2px;
}

.tracedat-widget__bubble--user {
  background: var(--tracedat-blue);
  color: #fff;
  align-self: flex-end;
  border-radius: 12px 12px 2px 12px;
}

/* ─── Action button (product redirect) ──────────────────────────────────────── */
.tracedat-widget__action-wrapper {
  align-self: flex-start;
  animation: tracedatFadeIn 0.15s ease-out;
}

.tracedat-widget__action-btn {
  display: inline-block;
  background: var(--tracedat-green);
  color: #fff;
  text-decoration: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.tracedat-widget__action-btn:hover {
  background: #009060;
  transform: translateY(-1px);
  color: #fff;
  text-decoration: none;
}

.tracedat-widget__action-btn:focus-visible {
  outline: 3px solid var(--tracedat-blue);
  outline-offset: 2px;
}

/* ─── Typing indicator ───────────────────────────────────────────────────────── */
.tracedat-widget__typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px 2px;
  background: var(--tracedat-light);
  flex-shrink: 0;
}

.tracedat-widget__typing--hidden { display: none; }

.tracedat-widget__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aab4c4;
  animation: tracedatBounce 1.1s infinite ease-in-out;
}

.tracedat-widget__typing span:nth-child(1) { animation-delay: 0s; }
.tracedat-widget__typing span:nth-child(2) { animation-delay: 0.18s; }
.tracedat-widget__typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes tracedatBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* ─── Bottom bar ─────────────────────────────────────────────────────────────── */
.tracedat-widget__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e8edf4;
  background: #fff;
  flex-shrink: 0;
}

.tracedat-widget__input {
  flex: 1;
  border: 1px solid #d0d8e6;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--tracedat-text);
  background: var(--tracedat-light);
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.tracedat-widget__input:focus { border-color: var(--tracedat-blue); }
.tracedat-widget__input::placeholder { color: #94a3b8; }

/* ─── Mic button ─────────────────────────────────────────────────────────────── */
.tracedat-widget__mic {
  background: none;
  border: 1px solid #d0d8e6;
  border-radius: 8px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #6b7a8d;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  position: relative;
}

.tracedat-widget__mic:hover { border-color: var(--tracedat-blue); color: var(--tracedat-blue); }
.tracedat-widget__mic:focus-visible { outline: 2px solid var(--tracedat-blue); outline-offset: 2px; }

.tracedat-widget__mic--listening {
  border-color: var(--tracedat-red);
  color: var(--tracedat-red);
  background: #fff5f5;
}

/* Pulse ring when listening */
.tracedat-widget__mic--listening::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 10px;
  border: 2px solid var(--tracedat-red);
  animation: tracedatPulse 1.2s infinite ease-out;
  pointer-events: none;
}

@keyframes tracedatPulse {
  0%   { opacity: 0.8; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.5); }
}

/* ─── Send button ────────────────────────────────────────────────────────────── */
.tracedat-widget__send {
  background: var(--tracedat-blue);
  border: none;
  border-radius: 8px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.tracedat-widget__send:hover { background: #14305a; transform: scale(1.05); }
.tracedat-widget__send:focus-visible { outline: 2px solid var(--tracedat-green); outline-offset: 2px; }

/* ─── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 440px) {
  .tracedat-widget__panel {
    width: 95vw;
    height: 80vh;
    bottom: 82px;
    right: 2.5vw;
    left: auto;
  }

  .tracedat-widget__panel.bottom-left {
    left: 2.5vw;
    right: auto;
  }

  .tracedat-widget__button.bottom-right { right: 16px; }
  .tracedat-widget__button.bottom-left  { left: 16px; }
}

/* ─── Reduced motion ─────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .tracedat-widget__panel--hidden,
  .tracedat-widget__panel--visible,
  .tracedat-widget__bubble,
  .tracedat-widget__action-wrapper {
    animation: none;
    transition: opacity 0.1s;
  }

  .tracedat-widget__typing span,
  .tracedat-widget__mic--listening::before {
    animation: none;
  }
}
