/* QABash AI Architect — Widget Styles */

:root {
  --qbai-w-primary:   #18181b;
  --qbai-w-primary-d: #09090b;
  --qbai-w-accent:    #1db954;
  --qbai-w-surface:   #ffffff;
  --qbai-w-bg:        #f4f4f5;
  --qbai-w-border:    #e4e4e7;
  --qbai-w-text:      #09090b;
  --qbai-w-muted:     #71717a;
  --qbai-w-shadow:    0 20px 56px rgba(0,0,0,.14), 0 6px 20px rgba(0,0,0,.08);
  --qbai-w-radius:    14px;
  --qbai-w-z:         2147483647;
  --qbai-w-nav:       var(--nav-height, 52px);
}

/* ── Reset scope ───────────────────────────────────────────────────────────── */
.qbai-widget *,
.qbai-widget *::before,
.qbai-widget *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Launcher ──────────────────────────────────────────────────────────────── */
.qbai-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--qbai-w-z);
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a0a3c 0%, #0d1a40 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(26,10,60,.45);
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
  color: #fff;
  overflow: hidden;
}
.qbai-launcher:hover {
  transform: scale(1.07);
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.qbai-launcher--left { right: auto; left: 24px; }

.qbai-launcher__icon { width: 32px; height: 32px; transition: opacity .2s; object-fit: cover; }
.qbai-launcher__icon--open { display: none; }
.qbai-launcher--open .qbai-launcher__icon--default { display: none; }
.qbai-launcher--open .qbai-launcher__icon--open { display: block; }

.qbai-launcher__pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  animation: qbai-pulse 2.8s ease-out infinite;
  background: rgba(29,185,84,.4);
  pointer-events: none;
}
@keyframes qbai-pulse {
  0%   { transform: scale(1);   opacity: .55; }
  100% { transform: scale(1.75); opacity: 0;  }
}
.qbai-launcher--open .qbai-launcher__pulse { display: none; }

/* ── Chat Panel ────────────────────────────────────────────────────────────── */
.qbai-panel-wrap {
  position: fixed;
  bottom: 88px;
  right: 24px;
  z-index: var(--qbai-w-z);
  width: 376px;
  max-width: calc(100vw - 32px);
  border-radius: var(--qbai-w-radius);
  background: var(--qbai-w-surface);
  box-shadow: var(--qbai-w-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(.93) translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
  /* Never overlap the navbar */
  max-height: calc(100dvh - var(--qbai-w-nav) - 96px);
}
.qbai-panel-wrap--left { right: auto; left: 24px; transform-origin: bottom left; }
.qbai-panel-wrap--open { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }

/* ── Embedded mode ─────────────────────────────────────────────────────────── */
.qbai-embed {
  position: relative;
  width: 100%;
  border-radius: var(--qbai-w-radius);
  overflow: hidden;
  box-shadow: var(--qbai-w-shadow);
}
.qbai-embed .qbai-panel-wrap {
  position: static;
  transform: none;
  opacity: 1;
  pointer-events: all;
  max-height: 100%;
  height: 100%;
  width: 100%;
  bottom: auto;
  right: auto;
  border-radius: 0;
}

/* ── Panel Header ──────────────────────────────────────────────────────────── */
.qbai-panel-header {
  display: flex;
  align-items: center;
  padding: 11px 14px;
  background: var(--qbai-w-primary);
  color: #fff;
  flex-shrink: 0;
  gap: 9px;
}
.qbai-panel-header__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.qbai-panel-header__avatar img { width: 100%; height: 100%; object-fit: cover; }
.qbai-panel-header__info { flex: 1; min-width: 0; }
.qbai-panel-header__title { font-size: .8rem; font-weight: 700; letter-spacing: -.01em; }
.qbai-panel-header__sub {
  font-size: .67rem;
  opacity: .65;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
}
.qbai-panel-header__sub::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--qbai-w-accent);
  flex-shrink: 0;
  opacity: 1;
}
.qbai-panel-header__close {
  background: rgba(255,255,255,.12);
  border: none;
  color: rgba(255,255,255,.8);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: .78rem;
  flex-shrink: 0;
  transition: background .15s;
}
.qbai-panel-header__close:hover { background: rgba(255,255,255,.2); color: #fff; }

/* ── Messages Area ─────────────────────────────────────────────────────────── */
.qbai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--qbai-w-bg);
  scroll-behavior: smooth;
}
.qbai-messages::-webkit-scrollbar { width: 3px; }
.qbai-messages::-webkit-scrollbar-track { background: transparent; }
.qbai-messages::-webkit-scrollbar-thumb { background: #d4d4d8; border-radius: 999px; }

/* ── Message Bubbles ───────────────────────────────────────────────────────── */
.qbai-msg { display: flex; gap: 8px; max-width: 100%; }
.qbai-msg--user { flex-direction: row-reverse; }

.qbai-msg__avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .68rem;
  font-weight: 700;
  flex-shrink: 0;
  align-self: flex-end;
  overflow: hidden;
}
.qbai-msg--assistant .qbai-msg__avatar {
  background: linear-gradient(135deg, #1a0a3c 0%, #0d1a40 100%);
  color: #fff;
}
.qbai-msg--user .qbai-msg__avatar {
  background: #e4e4e7;
  color: #52525b;
}
.qbai-msg__avatar img { width: 100%; height: 100%; object-fit: cover; }

.qbai-msg__bubble {
  max-width: 84%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: .8rem;
  line-height: 1.55;
  color: var(--qbai-w-text);
  word-break: break-word;
}
.qbai-msg--assistant .qbai-msg__bubble {
  background: #ffffff;
  border: 1px solid var(--qbai-w-border);
  border-bottom-left-radius: 3px;
}
.qbai-msg--user .qbai-msg__bubble {
  background: var(--qbai-w-primary);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.qbai-msg__content { white-space: pre-wrap; }
.qbai-msg__content code {
  background: rgba(0,0,0,.06);
  border-radius: 3px;
  padding: 1px 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: .78em;
}
.qbai-msg--user .qbai-msg__content code { background: rgba(255,255,255,.18); }

/* ── Typing Indicator ──────────────────────────────────────────────────────── */
.qbai-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 12px;
}
.qbai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a1a1aa;
  animation: qbai-bounce .85s infinite;
}
.qbai-typing span:nth-child(2) { animation-delay: .16s; }
.qbai-typing span:nth-child(3) { animation-delay: .32s; }
@keyframes qbai-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-5px); }
}

/* ── Welcome Message ───────────────────────────────────────────────────────── */
.qbai-welcome {
  text-align: center;
  padding: 20px 14px 10px;
}
.qbai-welcome__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
  background: linear-gradient(135deg, #1a0a3c 0%, #0d1a40 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  overflow: hidden;
}
.qbai-welcome__icon img { width: 100%; height: 100%; object-fit: cover; }
.qbai-welcome__title { font-size: .84rem; font-weight: 700; color: var(--qbai-w-text); margin-bottom: 5px; }
.qbai-welcome__body  { font-size: .75rem; color: var(--qbai-w-muted); line-height: 1.55; }
.qbai-welcome__text  { font-size: .79rem; color: var(--qbai-w-muted); line-height: 1.5; }

/* ── Suggestions ───────────────────────────────────────────────────────────── */
.qbai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 14px 10px;
}
.qbai-suggestion-chip {
  background: #fff;
  color: #3f3f46;
  border: 1px solid var(--qbai-w-border);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: .73rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.qbai-suggestion-chip:hover { background: #f4f4f5; border-color: #a1a1aa; }

/* ── Recommendations ───────────────────────────────────────────────────────── */
.qbai-recs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.qbai-recs__label {
  font-size: .67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--qbai-w-muted);
  margin-bottom: 2px;
}
.qbai-rec-card {
  background: #fafafa;
  border: 1px solid var(--qbai-w-border);
  border-left: 2px solid var(--qbai-w-accent);
  border-radius: 7px;
  padding: 8px 10px;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: background .12s;
}
.qbai-rec-card:hover { background: #f0fdf4; }
.qbai-rec-card__title {
  font-size: .76rem;
  font-weight: 600;
  color: var(--qbai-w-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.qbai-rec-card__arrow { font-size: .7rem; opacity: .5; flex-shrink: 0; }
.qbai-rec-card__excerpt { font-size: .71rem; color: var(--qbai-w-muted); margin-top: 2px; line-height: 1.4; }
.qbai-rec-card__score {
  font-size: .66rem;
  color: var(--qbai-w-accent);
  font-weight: 600;
  margin-top: 3px;
}

/* ── Input Area ────────────────────────────────────────────────────────────── */
.qbai-input-area {
  padding: 10px;
  background: var(--qbai-w-surface);
  border-top: 1px solid var(--qbai-w-border);
  display: flex;
  gap: 7px;
  align-items: flex-end;
  flex-shrink: 0;
}
.qbai-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--qbai-w-border);
  border-radius: 8px;
  font-size: .8rem;
  line-height: 1.4;
  resize: none;
  max-height: 100px;
  min-height: 36px;
  color: var(--qbai-w-text);
  background: var(--qbai-w-bg);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.qbai-input:focus {
  outline: none;
  border-color: #52525b;
  box-shadow: 0 0 0 2px rgba(24,24,27,.08);
  background: #fff;
}
.qbai-input::placeholder { color: #a1a1aa; font-size: .77rem; }

.qbai-send {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--qbai-w-primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .12s, opacity .15s;
}
.qbai-send:hover { transform: scale(1.05); }
.qbai-send:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.qbai-send svg { width: 15px; height: 15px; }

/* ── Footer ────────────────────────────────────────────────────────────────── */
.qbai-footer {
  padding: 5px 10px;
  text-align: center;
  font-size: .63rem;
  color: #a1a1aa;
  border-top: 1px solid var(--qbai-w-border);
  background: var(--qbai-w-surface);
  flex-shrink: 0;
}
.qbai-footer a { color: var(--qbai-w-accent); text-decoration: none; }

/* ── Error ─────────────────────────────────────────────────────────────────── */
.qbai-msg--error .qbai-msg__bubble {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  /* QABash mobile bottom nav is 64px (pb-16 in layout) */
  --qbai-mobile-nav: 64px;

  /* Sheet slides up from above the bottom nav */
  .qbai-panel-wrap {
    position: fixed;
    bottom: var(--qbai-mobile-nav, 64px);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: calc(100dvh - var(--qbai-w-nav) - var(--qbai-mobile-nav, 64px));
    transform-origin: bottom center;
    /* Slide animation on mobile (no scale) */
    transform: translateY(105%);
    opacity: 1;
    transition: transform .28s cubic-bezier(.32,0,.67,0);
  }
  .qbai-panel-wrap--open {
    transform: translateY(0);
    opacity: 1;
    transition: transform .3s cubic-bezier(.34,1.2,.64,1);
  }

  /* Launcher sits above bottom nav with breathing room */
  .qbai-launcher {
    bottom: calc(var(--qbai-mobile-nav, 64px) + 12px);
    right: 16px;
    width: 50px;
    height: 50px;
  }

  /* Suggestions: single-row horizontal scroll */
  .qbai-suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 12px 10px;
    gap: 6px;
  }
  .qbai-suggestions::-webkit-scrollbar { display: none; }
  .qbai-suggestion-chip { flex-shrink: 0; }

  /* Prevent iOS auto-zoom on input focus (needs ≥16px) */
  .qbai-input { font-size: 16px; }

  /* Larger touch targets */
  .qbai-panel-header__close {
    width: 36px;
    height: 36px;
  }
  .qbai-send {
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }

  /* Tighter header padding */
  .qbai-panel-header { padding: 10px 12px; }

  /* Messages area slightly more compact */
  .qbai-messages { padding: 10px 12px; }
  .qbai-input-area { padding: 8px 10px; }
}

/* ── Dark mode ─────────────────────────────────────────────────────────────── */
.dark .qbai-panel-wrap,
@media (prefers-color-scheme: dark) {
  .qbai-panel-wrap {
    --qbai-w-surface: #18181b;
    --qbai-w-bg:      #09090b;
    --qbai-w-border:  #27272a;
    --qbai-w-text:    #fafafa;
    --qbai-w-muted:   #a1a1aa;
  }
  .qbai-messages { background: #09090b; }
  .qbai-msg--assistant .qbai-msg__bubble { background: #18181b; border-color: #27272a; }
  .qbai-msg--user .qbai-msg__avatar { background: #27272a; color: #a1a1aa; }
  .qbai-input { background: #18181b; color: #fafafa; border-color: #27272a; }
  .qbai-input:focus { background: #09090b; border-color: #52525b; }
  .qbai-input-area, .qbai-footer { background: #18181b; border-color: #27272a; }
  .qbai-suggestion-chip { background: #18181b; border-color: #3f3f46; color: #d4d4d8; }
  .qbai-suggestion-chip:hover { background: #27272a; border-color: #52525b; }
  .qbai-rec-card { background: #18181b; border-color: #27272a; }
  .qbai-rec-card:hover { background: #052e16; }
  .qbai-rec-card__title { color: #fafafa; }
  .qbai-welcome__text { color: #71717a; }
}
