/* Echo Chat Widget - v1.0
   Scoped under .echo-widget to avoid collisions. */

.echo-widget {
  --ew-bg: #121118;
  --ew-surface: #1A0F3D;
  --ew-header: #2D1B69;
  --ew-msg-echo: #3D2B7A;
  --ew-ember: #E05A2B;
  --ew-ember-15: rgba(224, 90, 43, 0.15);
  --ew-white: #F0EBE3;
  --ew-muted: #6E6A7A;
  --ew-border: #2A2640;
  --ew-input-bg: #000000;
  --ew-placeholder: #B8A9D4;
  --ew-font-display: 'Space Grotesk', system-ui, sans-serif;
  --ew-font-body: 'Inter', system-ui, sans-serif;
  --ew-font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --ew-radius: 12px;
  --ew-z: 9999;
}

/* ---- Bubble ---- */

.echo-widget-bubble {
  position: fixed;
  bottom: 48px;
  right: 48px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid rgba(224, 90, 43, 0.6);
  background: var(--ew-bg);
  cursor: pointer;
  z-index: var(--ew-z);
  padding: 0;
  overflow: hidden;
  transition: transform 200ms ease-out;
  box-shadow: 0 0 12px 4px rgba(224, 90, 43, 0.45), 0 0 24px 8px rgba(224, 90, 43, 0.15);
}

.echo-widget-bubble:hover {
  transform: scale(1.05);
}

.echo-widget-bubble img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.echo-widget-bubble[aria-expanded="true"] {
  display: block;
}

/* ---- Panel ---- */

.echo-widget-panel {
  position: fixed;
  bottom: 48px;
  right: 48px;
  width: 380px;
  max-height: 520px;
  display: none;
  flex-direction: column;
  border-radius: var(--ew-radius);
  border: 1px solid var(--ew-border);
  background: var(--ew-surface);
  z-index: var(--ew-z);
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  font-family: var(--ew-font-body);
  color: var(--ew-white);
  font-size: 0.875rem;
  line-height: 1.5;
}

.echo-widget-panel.open {
  display: flex;
}

/* ---- Header ---- */

.echo-widget-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--ew-header);
  border-bottom: 1px solid var(--ew-border);
  flex-shrink: 0;
}

.echo-widget-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--ew-ember);
  flex-shrink: 0;
}

.echo-widget-header-info {
  flex: 1;
  min-width: 0;
}

.echo-widget-header-name {
  font-family: var(--ew-font-display);
  font-weight: 700;
  font-size: 0.9375rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.echo-widget-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ew-ember);
  flex-shrink: 0;
}

.echo-widget-header-sub {
  font-size: 0.6875rem;
  color: var(--ew-muted);
  letter-spacing: 0.02em;
}

.echo-widget-close {
  background: none;
  border: none;
  color: var(--ew-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 1.25rem;
  line-height: 1;
  transition: color 200ms;
  flex-shrink: 0;
}

.echo-widget-close:hover {
  color: var(--ew-white);
}

/* ---- Messages ---- */

.echo-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.echo-widget-messages::-webkit-scrollbar {
  width: 4px;
}

.echo-widget-messages::-webkit-scrollbar-track {
  background: transparent;
}

.echo-widget-messages::-webkit-scrollbar-thumb {
  background: var(--ew-border);
  border-radius: 2px;
}

.echo-widget-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--ew-radius);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.echo-widget-msg-echo {
  background: var(--ew-msg-echo);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.echo-widget-msg-user {
  background: var(--ew-ember-15);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.echo-widget-msg code {
  font-family: var(--ew-font-mono);
  font-size: 0.8125rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 3px;
}

.echo-widget-msg strong {
  font-weight: 600;
}

.echo-widget-msg em {
  font-style: italic;
}

/* ---- Sources ---- */

.echo-widget-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.echo-widget-source {
  display: inline-block;
  font-family: var(--ew-font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 9999px;
  background: rgba(139, 92, 246, 0.15);
  color: #B8A9D4;
  text-decoration: none;
  transition: background 200ms;
}

.echo-widget-source:hover {
  background: rgba(139, 92, 246, 0.3);
}

/* ---- Greeting + Chips ---- */

.echo-widget-greeting {
  font-size: 0.875rem;
  line-height: 1.6;
}

.echo-widget-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.echo-widget-chip {
  display: inline-block;
  padding: 6px 12px;
  font-family: var(--ew-font-body);
  font-size: 0.75rem;
  color: var(--ew-white);
  background: rgba(224, 90, 43, 0.1);
  border: 1px solid rgba(224, 90, 43, 0.3);
  border-radius: 9999px;
  cursor: pointer;
  transition: background 200ms, border-color 200ms;
}

.echo-widget-chip:hover {
  background: rgba(224, 90, 43, 0.2);
  border-color: rgba(224, 90, 43, 0.5);
}

/* ---- Loading ---- */

.echo-widget-loading {
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--ew-msg-echo);
  border-radius: var(--ew-radius);
  border-bottom-left-radius: 4px;
  font-size: 0.8125rem;
  color: var(--ew-muted);
}

.echo-widget-loading-dots::after {
  content: '';
  animation: ew-dots 1.2s steps(4, end) infinite;
}

@keyframes ew-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ---- Input ---- */

.echo-widget-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--ew-border);
  background: var(--ew-input-bg);
  flex-shrink: 0;
}

.echo-widget-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--ew-white);
  font-family: var(--ew-font-body);
  font-size: 1rem;
  outline: none;
  min-width: 0;
}

.echo-widget-input::placeholder {
  color: var(--ew-placeholder);
}

.echo-widget-send {
  background: none;
  border: none;
  color: var(--ew-muted);
  cursor: pointer;
  padding: 4px;
  transition: color 200ms;
  flex-shrink: 0;
}

.echo-widget-send:hover {
  color: var(--ew-ember);
}

.echo-widget-send:disabled {
  opacity: 0.3;
  cursor: default;
}

.echo-widget-send svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* ---- Footer ---- */

.echo-widget-footer {
  padding: 6px 16px;
  text-align: center;
  font-size: 0.5625rem;
  font-family: var(--ew-font-mono);
  color: var(--ew-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-top: 1px solid var(--ew-border);
  background: var(--ew-input-bg);
  flex-shrink: 0;
}

/* ---- Mobile ---- */

@media (max-width: 480px) {
  .echo-widget-panel {
    width: 100%;
    height: calc(100% - 60px);
    max-height: none;
    bottom: 0;
    right: 0;
    border-radius: var(--ew-radius) var(--ew-radius) 0 0;
  }

  .echo-widget-panel.open + .echo-widget-bubble {
    display: none;
  }

  .echo-widget-bubble {
    bottom: 16px;
    right: 16px;
  }
}
