/**
 * Flowbie Chat Widget – Dark Glassmorphism Design
 *
 * All rules scoped under `.flowbie-chat-widget`.
 * Uses CSS custom properties for theming with `--fcw-accent` set by JS.
 */

/* Thinking / loading checklist */
.flowbie-chat-widget .fcw-thinking-steps {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flowbie-chat-widget .fcw-thinking-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--fcw-text-secondary);
}

.flowbie-chat-widget .fcw-card--thinking-active {
  border-color: rgba(34, 211, 238, 0.35);
  animation: fcwThinkingBreathe 2.8s ease-in-out infinite;
}

@keyframes fcwThinkingBreathe {
  0%,
  100% {
    border-color: rgba(34, 211, 238, 0.25);
    box-shadow: 0 0 0 rgba(34, 211, 238, 0);
  }
  50% {
    border-color: rgba(34, 211, 238, 0.45);
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.12);
  }
}

/* ── Reset scope ────────────────────────────────────────────── */
.flowbie-chat-widget,
.flowbie-chat-widget *,
.flowbie-chat-widget *::before,
.flowbie-chat-widget *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
}

/* ── Root container ─────────────────────────────────────────── */
.flowbie-chat-widget {
  --fcw-bg: #0f0f11;
  --fcw-bg-elevated: rgba(255, 255, 255, 0.04);
  --fcw-text: #e5e5e5;
  --fcw-text-secondary: rgba(229, 229, 229, 0.65);
  --fcw-text-muted: rgba(255, 255, 255, 0.35);
  --fcw-border: rgba(255, 255, 255, 0.08);
  --fcw-border-hover: rgba(255, 255, 255, 0.15);
  --fcw-card-bg: rgba(255, 255, 255, 0.04);
  --fcw-radius: 16px;
  --fcw-shadow: 0 8px 40px rgba(0, 0, 0, 0.5), 0 2px 12px rgba(0, 0, 0, 0.3);
  --fcw-bubble-size: 56px;

  position: fixed;
  z-index: 999999;
  font-size: 14px;
  line-height: 1.5;
  color: var(--fcw-text);
}

.flowbie-chat--bottom-right {
  bottom: 20px;
  right: 20px;
}
.flowbie-chat--bottom-left {
  bottom: 20px;
  left: 20px;
}

/* ── Floating bubble ────────────────────────────────────────── */
.fcw-bubble {
  width: var(--fcw-bubble-size);
  height: var(--fcw-bubble-size);
  border-radius: 50%;
  border: none;
  background: #2a2a2a;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.fcw-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.35);
}
.fcw-bubble--hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* ── Panel ──────────────────────────────────────────────────── */
.fcw-panel {
  position: absolute;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 100px);
  border-radius: var(--fcw-radius);
  background: var(--fcw-bg);
  border: 1px solid var(--fcw-border);
  box-shadow: var(--fcw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.flowbie-chat--bottom-right .fcw-panel {
  bottom: calc(var(--fcw-bubble-size) + 12px);
  right: 0;
}
.flowbie-chat--bottom-left .fcw-panel {
  bottom: calc(var(--fcw-bubble-size) + 12px);
  left: 0;
}

.fcw-panel--hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.97);
}

/* ── Header ─────────────────────────────────────────────────── */
.fcw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: #181818;
  border-bottom: 1px solid var(--fcw-border);
  flex-shrink: 0;
}
.fcw-header__title {
  font-weight: 600;
  font-size: 14px;
  color: var(--fcw-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fcw-header__close {
  background: none;
  border: none;
  color: var(--fcw-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 6px;
  transition: color 0.15s, background 0.15s;
}
.fcw-header__close:hover {
  color: var(--fcw-text);
  background: rgba(255, 255, 255, 0.08);
}

/* ── Messages area ──────────────────────────────────────────── */
.fcw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}
.fcw-messages::-webkit-scrollbar {
  width: 5px;
}
.fcw-messages::-webkit-scrollbar-track {
  background: transparent;
}
.fcw-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.fcw-msg {
  display: flex;
}
.fcw-msg--user {
  justify-content: flex-end;
}
.fcw-msg--assistant {
  justify-content: flex-start;
}

/* User bubble */
.fcw-user-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  background: #2a2a2a;
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  animation: fcw-fadeIn 0.25s ease;
}

/* ── Semantic Card (Glassmorphism) ──────────────────────────── */
.fcw-card {
  max-width: 100%;
  width: 100%;
  border-radius: 12px;
  padding: 16px 18px;
  background: var(--fcw-card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--fcw-border);
  animation: fcw-slideIn 0.3s ease;
}

/* Card type badge */
.fcw-card__type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.5);
}

/* Title row */
.fcw-card__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.fcw-card__title {
  font-weight: 600;
  font-size: 14px;
  color: #f5f5f5;
  line-height: 1.3;
}
.fcw-card__title strong {
  font-weight: 700;
  color: #fff;
}

/* Body */
.fcw-card__body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--fcw-text-secondary);
  word-break: break-word;
  margin-top: 4px;
}
.fcw-card__body a {
  color: #ccc;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.fcw-card__body a:hover {
  color: #fff;
}
.fcw-card__body strong {
  font-weight: 600;
  color: #f5f5f5;
}

/* Confidence label */
.fcw-card__confidence {
  font-size: 11px;
  color: var(--fcw-text-muted);
  margin-top: 6px;
  font-style: italic;
}

/* ── Link pills ─────────────────────────────────────────────── */
.fcw-card__links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.fcw-link-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--fcw-border);
  color: var(--fcw-text);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
  line-height: 1.3;
}
.fcw-link-pill:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  text-decoration: none;
}
.fcw-link-pill__icon {
  display: flex;
  align-items: center;
  color: var(--fcw-text-muted);
}

/* ── CTA button ─────────────────────────────────────────────── */
.fcw-card__cta-wrap {
  margin-top: 14px;
}

.fcw-cta-btn {
  display: inline-block;
  padding: 9px 20px;
  border-radius: 8px;
  background: #333;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s, transform 0.1s;
}
.fcw-cta-btn:hover {
  background: #444;
  transform: translateY(-1px);
  color: #fff;
  text-decoration: none;
}

/* ── Related topic chips ────────────────────────────────────── */
.fcw-card__topics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--fcw-border);
}

.fcw-topic-chip {
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid var(--fcw-border);
  background: transparent;
  color: #ccc;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.fcw-topic-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* ── Input area ─────────────────────────────────────────────── */
.fcw-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--fcw-border);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.fcw-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--fcw-border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--fcw-text);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
  transition: border-color 0.2s;
  min-height: 40px;
  max-height: 120px;
}
.fcw-textarea:focus {
  border-color: rgba(255, 255, 255, 0.3);
}
.fcw-textarea::placeholder {
  color: var(--fcw-text-muted);
}

.fcw-send {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: #333;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: none;
  user-select: none;
  transition: opacity 0.15s, transform 0.1s;
}
.fcw-send:hover {
  background: #444;
  transform: translateY(-1px);
}
.fcw-send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* ── Status indicator ───────────────────────────────────────── */
.fcw-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  font-style: italic;
  padding: 10px 18px;
  animation: fcw-pulse 1.8s ease-in-out infinite;
}

/* ── Animations ─────────────────────────────────────────────── */
@keyframes fcw-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

@keyframes fcw-fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fcw-slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  .fcw-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 80px);
    border-radius: 12px;
  }
  .flowbie-chat--bottom-right .fcw-panel,
  .flowbie-chat--bottom-left .fcw-panel {
    right: auto;
    left: 12px;
  }
}

/* ── Light mode override ────────────────────────────────────── */
@media (prefers-color-scheme: light) {
  .flowbie-chat-widget {
    --fcw-bg: #f5f5f5;
    --fcw-bg-elevated: rgba(0, 0, 0, 0.03);
    --fcw-text: #1a1a1a;
    --fcw-text-secondary: #4a4a4a;
    --fcw-text-muted: #888;
    --fcw-border: rgba(0, 0, 0, 0.08);
    --fcw-border-hover: rgba(0, 0, 0, 0.15);
    --fcw-card-bg: rgba(0, 0, 0, 0.02);
    --fcw-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
  }
  .fcw-header {
    background: #e8e8e8;
  }
  .fcw-bubble {
    background: #333;
  }
  .fcw-user-bubble {
    background: #ddd;
    color: #1a1a1a;
  }
  .fcw-card__title { color: #1a1a1a; }
  .fcw-card__title strong { color: #000; }
  .fcw-card__body strong { color: #1a1a1a; }
  .fcw-card__body a { color: #333; }
  .fcw-card__type-badge { background: rgba(0,0,0,.06); color: #666; }
  .fcw-link-pill {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.08);
    color: #1a1a1a;
  }
  .fcw-link-pill:hover {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.15);
  }
  .fcw-cta-btn { background: #333; }
  .fcw-cta-btn:hover { background: #222; }
  .fcw-topic-chip {
    border-color: rgba(0, 0, 0, 0.1);
    color: #333;
    background: #fff;
  }
  .fcw-topic-chip:hover {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.2);
  }
  .fcw-send { background: #333; }
  .fcw-send:hover { background: #222; }
  .fcw-textarea {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.1);
    color: #1a1a1a;
  }
  .fcw-textarea::placeholder { color: #9ca3af; }
  .fcw-textarea:focus { border-color: rgba(0,0,0,.3); }
  .fcw-status { color: rgba(0,0,0,.35); }
  .fcw-messages {
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
  }
  .fcw-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
  }
}
