/* ============================================
   Flowi Support Widget
   ============================================ */

/* Launcher button */
.flowi-launcher {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 38;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 9999px;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.flowi-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

.flowi-launcher.has-unread {
  animation: flowi-pulse 2s infinite;
}

/* Unread badge */
.flowi-unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  background: #e53e3e;
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-primary);
}

/* Popup panel */
.flowi-popup {
  position: fixed;
  bottom: 6rem;
  right: 1.5rem;
  z-index: 42;
  width: 380px;
  max-height: 520px;
  border-radius: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.flowi-popup.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.flowi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: var(--accent-contrast) !important;
  flex-shrink: 0;
}

.flowi-header span,
.flowi-header svg {
  color: var(--accent-contrast) !important;
}

.flowi-header-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.9375rem;
}

.flowi-header-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}

.flowi-header-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Tab bar */
.flowi-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}

.flowi-tab {
  flex: 1;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.flowi-tab:hover {
  color: var(--text-primary);
}

.flowi-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Messages area */
.flowi-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  min-height: 0;
}

/* Message bubbles */
.flowi-msg {
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.flowi-msg.ai {
  align-self: flex-start;
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.flowi-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-contrast) !important;
  border-bottom-right-radius: 4px;
}

/* Force accent-contrast on ALL children inside user bubbles.
   Must beat design_tokens.css p:not(...)... which has specificity (0,5,1).
   Using .user.user repetition trick to reach (0,5,1), wins by source order
   since flowi_widget.css loads after design_tokens.css. */
.flowi-popup .flowi-messages .flowi-msg.user.user p,
.flowi-popup .flowi-messages .flowi-msg.user.user li,
.flowi-popup .flowi-messages .flowi-msg.user.user td,
.flowi-popup .flowi-messages .flowi-msg.user.user th {
  color: var(--accent-contrast) !important;
}

.flowi-msg.user span,
.flowi-msg.user a,
.flowi-msg.user strong,
.flowi-msg.user code,
.flowi-msg.user div {
  color: var(--accent-contrast) !important;
}

.flowi-msg.agent {
  align-self: flex-start;
  background: var(--accent-10);
  color: var(--text-primary);
  border: 1px solid var(--accent-20);
  border-bottom-left-radius: 4px;
}

.flowi-msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 0.75rem;
  font-style: italic;
  text-align: center;
  max-width: 100%;
  padding: 0.25rem 0;
}

/* Markdown inside messages */
.flowi-msg p { margin: 0 0 0.375rem; }
.flowi-msg p:last-child { margin-bottom: 0; }
.flowi-msg strong { font-weight: 600; }
.flowi-msg ul, .flowi-msg ol { margin: 0.25rem 0; padding-left: 1.25rem; }
.flowi-msg li { margin-bottom: 0.125rem; }
.flowi-msg code {
  background: rgba(0,0,0,0.06);
  padding: 0.125rem 0.25rem;
  border-radius: 3px;
  font-size: 0.75rem;
}

/* Status banner */
.flowi-status {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.375rem;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

.flowi-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  flex-shrink: 0;
}

.flowi-status-dot.ai { background: var(--accent); }
.flowi-status-dot.waiting { background: #eab308; animation: flowi-blink 1.5s infinite; }
.flowi-status-dot.agent { background: #22c55e; }

/* Typing indicator */
.flowi-typing {
  display: flex;
  gap: 4px;
  padding: 0.5rem 0.75rem;
  align-self: flex-start;
}

.flowi-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: var(--text-tertiary);
  animation: flowi-typing-bounce 1.2s infinite;
}

.flowi-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.flowi-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Input area */
.flowi-input-area {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border-default);
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
}

.flowi-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-default);
  border-radius: 0.625rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.4;
  max-height: 100px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.flowi-input:focus {
  border-color: var(--accent);
}

.flowi-input::placeholder {
  color: var(--text-tertiary);
}

.flowi-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.flowi-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Escalate link */
.flowi-escalate {
  display: block;
  text-align: center;
  padding: 0.25rem;
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  transition: color 0.15s;
}

.flowi-escalate:hover {
  color: var(--text-secondary);
}

/* Feedback tab content */
.flowi-feedback-tab {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

/* Animations */
@keyframes flowi-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); }
  50% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15), 0 0 0 8px var(--accent-20); }
}

@keyframes flowi-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

@keyframes flowi-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Mobile: full screen */
@media (max-width: 767px) {
  .flowi-popup {
    position: fixed;
    inset: 0;
    width: 100%;
    max-height: 100%;
    border-radius: 0;
    z-index: 42;
  }

  .flowi-launcher {
    bottom: 1rem;
    right: 1rem;
  }
}
