/* ═══════════════════════════════════════════════
   Quematics Q Widget — v3
   Clean scoped CSS, no blanket resets
   ═══════════════════════════════════════════════ */

#q-widget-root {
  position: fixed !important;
  bottom: 28px !important;
  right: 28px !important;
  z-index: 999999 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
  gap: 12px !important;
  width: auto !important;
  max-width: none !important;
  pointer-events: none !important;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif !important;
}

/* All direct children get pointer events back */
#q-widget-root > * {
  pointer-events: all !important;
}

/* ── Scoped font reset (gentle) ── */
#q-widget-root * {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════
   LAUNCHER
   ═══════════════════════════════════════════════ */

#q-launcher {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-direction: row-reverse;
}

#q-btn {
  width: 60px !important;
  height: 60px !important;
  min-width: 60px !important;
  border-radius: 14px !important;
  background: #1a2d5a !important;
  border: none !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: 0 4px 24px rgba(26,45,90,0.55), 0 2px 8px rgba(0,0,0,0.25) !important;
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s ease !important;
  position: relative !important;
  flex-shrink: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}

#q-btn:hover {
  transform: scale(1.08) !important;
  background: #1e3468 !important;
  box-shadow: 0 6px 32px rgba(26,45,90,0.7) !important;
}

#q-btn:active {
  transform: scale(0.96) !important;
}

#q-btn svg {
  width: 26px;
  height: 26px;
  color: #ffffff;
  display: block;
}

#q-btn .q-icon-close { display: none; }
#q-widget-root.q-open #q-btn .q-icon-chat  { display: none; }
#q-widget-root.q-open #q-btn .q-icon-close { display: block; }

/* Badge */
#q-badge {
  position: absolute !important;
  top: -6px !important;
  right: -6px !important;
  width: 20px !important;
  height: 20px !important;
  background: #ef4444 !important;
  color: #fff !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border: 2px solid #fff !important;
  padding: 0 !important;
  margin: 0 !important;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s;
}

#q-badge.q-hidden {
  transform: scale(0) !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* CTA bubble */
#q-cta {
  background: #1a2d5a !important;
  color: #ffffff !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  padding: 12px 18px !important;
  border-radius: 14px !important;
  white-space: nowrap !important;
  box-shadow: 0 4px 18px rgba(26,45,90,0.5) !important;
  cursor: pointer !important;
  border: none !important;
  display: inline-block !important;
  animation: q-cta-bounce 0.5s cubic-bezier(0.34,1.56,0.64,1) 1.4s both;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform-origin: right center;
}

@keyframes q-cta-bounce {
  from { opacity: 0; transform: scale(0.8) translateX(10px); }
  to   { opacity: 1; transform: scale(1)   translateX(0); }
}

#q-cta.q-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.9) !important;
}

/* ═══════════════════════════════════════════════
   POPUP
   ═══════════════════════════════════════════════ */

#q-popup {
  width: 380px !important;
  max-width: calc(100vw - 56px) !important;
  background: #1a2d5a !important;
  border-radius: 18px !important;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35), 0 6px 20px rgba(0,0,0,0.2) !important;
  overflow: hidden !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  transform-origin: bottom right;
  transform: scale(0.88) translateY(14px);
  opacity: 0;
  pointer-events: none !important;
  transition: transform 0.28s cubic-bezier(0.34,1.4,0.64,1), opacity 0.2s ease;
}

#q-widget-root.q-open #q-popup {
  transform: scale(1) translateY(0) !important;
  opacity: 1 !important;
  pointer-events: all !important;
}

/* Header */
.q-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: #141f3d;
}

.q-header-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 10px;
  background: #1e3468;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
}

.q-header-text strong {
  display: block;
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 3px;
}

.q-header-text span {
  font-size: 12px;
  color: #a8bfe0;
}

.q-header-dot {
  width: 9px;
  height: 9px;
  min-width: 9px;
  background: #22c55e;
  border-radius: 50%;
  margin-left: auto;
  box-shadow: 0 0 8px rgba(34,197,94,0.6);
  animation: q-pulse 2.5s infinite;
}

@keyframes q-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Welcome */
.q-welcome {
  padding: 18px 20px 12px;
  font-size: 14px;
  color: #ffffff;
  line-height: 1.6;
}

/* Channels */
.q-channels {
  padding: 4px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.q-channel-btn {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 15px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.09) !important;
  border-radius: 11px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  transition: background 0.15s ease, transform 0.15s ease;
}

.q-channel-btn:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.18) !important;
  transform: translateX(3px);
}

.q-channel-btn svg {
  width: 19px;
  height: 19px;
  min-width: 19px;
  opacity: 0.85;
  flex-shrink: 0;
}

/* Spotlight — Q-Assist */
.q-channel-btn.q-spotlight {
  border-color: rgba(109,40,217,0.55) !important;
  background: rgba(109,40,217,0.12);
}

.q-channel-btn.q-spotlight:hover {
  background: rgba(109,40,217,0.22);
  border-color: #7c3aed !important;
}

/* Footer */
.q-footer {
  padding: 10px 20px;
  font-size: 11px;
  color: rgba(168,191,224,0.5);
  text-align: center;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: #141f3d;
}

.q-footer a { color: rgba(168,191,224,0.5); }

/* ═══════════════════════════════════════════════
   CHAT VIEW
   ═══════════════════════════════════════════════ */

#q-view-chat {
  display: none;
  flex-direction: column;
  height: 480px;
}

#q-view-chat.q-active { display: flex; }

#q-view-channels.q-hidden { display: none; }

.q-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: #141f3d;
}

#q-back-btn {
  background: rgba(255,255,255,0.1) !important;
  border: none !important;
  color: #ffffff !important;
  padding: 7px 12px !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  display: flex !important;
  align-items: center !important;
  gap: 5px !important;
  transition: background 0.15s;
  white-space: nowrap;
}

#q-back-btn:hover { background: rgba(255,255,255,0.18) !important; }

.q-chat-header-title {
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
}

.q-chat-header-sub {
  font-size: 12px;
  color: #a8bfe0;
  margin-left: auto;
}

#q-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

#q-messages::-webkit-scrollbar { width: 4px; }
#q-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
}

.q-msg {
  max-width: 86%;
  padding: 11px 14px;
  border-radius: 13px;
  font-size: 14px;
  line-height: 1.55;
  animation: q-msg-in 0.2s ease;
}

@keyframes q-msg-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.q-msg-q {
  background: rgba(255,255,255,0.09);
  color: #ffffff;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.q-msg-user {
  background: #6d28d9;
  color: #ffffff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

.q-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.09);
  border-radius: 13px;
  border-bottom-left-radius: 4px;
  width: 54px;
  align-self: flex-start;
}

.q-typing span {
  width: 7px;
  height: 7px;
  background: #a8bfe0;
  border-radius: 50%;
  animation: q-dot 1.2s infinite;
}
.q-typing span:nth-child(2) { animation-delay: 0.2s; }
.q-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes q-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

.q-input-area {
  display: flex;
  gap: 9px;
  padding: 12px 13px;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: #141f3d;
}

#q-input {
  flex: 1;
  background: rgba(255,255,255,0.09) !important;
  border: 1px solid rgba(255,255,255,0.14) !important;
  border-radius: 9px !important;
  padding: 11px 14px !important;
  color: #ffffff !important;
  font-size: 14px !important;
  outline: none !important;
  transition: border-color 0.15s;
}

#q-input::placeholder { color: rgba(168,191,224,0.5); }

#q-input:focus {
  border-color: rgba(109,40,217,0.6) !important;
  background: rgba(255,255,255,0.12) !important;
}

#q-send-btn {
  background: #6d28d9 !important;
  border: none !important;
  border-radius: 9px !important;
  padding: 11px 16px !important;
  color: #fff !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

#q-send-btn:hover  { background: #7c3aed !important; }
#q-send-btn:active { transform: scale(0.93); }
#q-send-btn:disabled { opacity: 0.45 !important; cursor: not-allowed !important; }

#q-send-btn svg { width: 17px; height: 17px; }

/* ── Suggestion chips ── */
.q-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 4px 0 2px;
  align-self: flex-start;
  max-width: 100%;
}

.q-chip {
  background: transparent;
  border: 1px solid rgba(168,191,224,0.35) !important;
  border-radius: 20px;
  color: #a8bfe0;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1.3;
}

.q-chip:hover {
  background: rgba(109,40,217,0.2);
  border-color: #7c3aed !important;
  color: #ffffff;
}

/* ═══════════════════════════════════════════════
   MOBILE
   ═══════════════════════════════════════════════ */

@media (max-width: 480px) {
  #q-widget-root {
    bottom: 18px !important;
    right: 18px !important;
    left: 18px !important;
  }

  #q-popup {
    width: 100% !important;
    max-width: calc(100vw - 36px) !important;
  }

  #q-cta {
    font-size: 13px !important;
    max-width: 200px !important;
    white-space: normal !important;
    text-align: right !important;
  }
}
