/* ── StealthCo Chat Widget ─────────────────────────────────────────── */
/* Theme-aware: inherits CSS variables from main layout                */

/* ── Chat Bubble (trigger) ──────────────────────────────────────── */
.sc-chat-bubble {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 55;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-panel-strong);
  border: 1px solid var(--border-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.5s ease, transform 0.5s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.sc-chat-bubble.sc-visible {
  opacity: 1;
  transform: scale(1);
}

.sc-chat-bubble:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--text-faint);
}

.sc-chat-bubble svg {
  width: 22px;
  height: 22px;
  color: var(--text-medium);
  transition: color 0.2s ease;
}

.sc-chat-bubble:hover svg {
  color: var(--text-strong);
}

/* ── Teaser Tooltip ────────────────────────────────────────────── */
.sc-chat-teaser {
  position: fixed;
  bottom: 4.5rem;
  right: 1.5rem;
  z-index: 55;
  max-width: 260px;
  padding: 0.6rem 0.85rem;
  background: var(--bg-panel-strong);
  border: 1px solid var(--border-soft);
  border-radius: 12px 12px 4px 12px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.sc-chat-teaser.sc-teaser-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.sc-chat-teaser-text {
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-medium);
}

.sc-chat-teaser-text strong {
  color: var(--text-strong);
  font-weight: 600;
}

.sc-chat-teaser-dismiss {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-soft);
  background: var(--bg-primary);
  color: var(--text-faint);
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.sc-chat-teaser:hover .sc-chat-teaser-dismiss {
  opacity: 1;
}

.sc-chat-teaser-dismiss:hover {
  color: var(--text-medium);
}

@media (max-width: 639px) {
  .sc-chat-teaser {
    right: 1rem;
    bottom: 4rem;
    max-width: 240px;
  }
}

/* ── Chat Panel ─────────────────────────────────────────────────── */
.sc-chat-panel {
  position: fixed;
  z-index: 56;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease, width 0.2s ease, height 0.2s ease;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.sc-chat-panel.sc-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Size modes */
.sc-chat-panel.sc-size-compact {
  width: 360px;
  height: 420px;
}

.sc-chat-panel.sc-size-standard {
  width: 420px;
  height: 560px;
}

.sc-chat-panel.sc-size-large {
  width: 560px;
  height: 680px;
}

/* Default position: bottom-right, above bubble */
.sc-chat-panel.sc-pos-br {
  bottom: 5rem;
  right: 1.5rem;
}

.sc-chat-panel.sc-pos-bl {
  bottom: 5rem;
  left: 1.5rem;
}

.sc-chat-panel.sc-pos-tr {
  top: 5rem;
  right: 1.5rem;
}

.sc-chat-panel.sc-pos-tl {
  top: 5rem;
  left: 1.5rem;
}

/* ── Header ─────────────────────────────────────────────────────── */
.sc-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-soft);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.sc-chat-header:active {
  cursor: grabbing;
}

.sc-chat-header-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-medium);
}

.sc-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.sc-chat-header-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
}

.sc-chat-header-btn:hover {
  background: var(--bg-panel-strong);
  color: var(--text-medium);
}

.sc-chat-header-btn svg {
  width: 14px;
  height: 14px;
}

/* ── Messages area ──────────────────────────────────────────────── */
.sc-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-soft) transparent;
}

.sc-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.sc-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.sc-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-soft);
  border-radius: 2px;
}

/* ── Welcome message ────────────────────────────────────────────── */
.sc-chat-welcome {
  text-align: center;
  padding: 0.5rem 0 0.25rem;
}

.sc-chat-welcome-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: 0.35rem;
}

.sc-chat-welcome-sub {
  font-size: 0.78rem;
  color: var(--text-soft);
  line-height: 1.5;
}

/* ── Conversation starters ──────────────────────────────────────── */
.sc-chat-starters {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.25rem 0 0.5rem;
}

.sc-chat-starter {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-size: 0.78rem;
  color: var(--text-medium);
  cursor: pointer;
  text-align: left;
  font-family: 'Inter', sans-serif;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  line-height: 1.4;
}

.sc-chat-starter:hover {
  background: var(--bg-panel-strong);
  border-color: var(--text-faint);
  color: var(--text-strong);
}

/* ── Message bubbles ────────────────────────────────────────────── */
.sc-msg {
  max-width: 88%;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.6;
  word-break: break-word;
}

.sc-msg-user {
  align-self: flex-end;
  background: var(--bg-panel-strong);
  color: var(--text-strong);
  border: 1px solid var(--border-soft);
  border-bottom-right-radius: 4px;
}

.sc-msg-assistant {
  align-self: flex-start;
  background: transparent;
  color: var(--text-medium);
  border-bottom-left-radius: 4px;
}

/* Markdown styles inside assistant messages */
.sc-msg-assistant strong {
  color: var(--text-strong);
  font-weight: 600;
}

.sc-msg-assistant em {
  color: var(--text-soft);
  font-style: italic;
}

.sc-msg-assistant code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  background: var(--bg-panel);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  color: var(--text-strong);
}

.sc-msg-assistant a {
  color: var(--text-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sc-msg-assistant a:hover {
  color: var(--text-medium);
}

.sc-msg-assistant ul,
.sc-msg-assistant ol {
  padding-left: 1.2rem;
  margin: 0.3rem 0;
}

.sc-msg-assistant li {
  margin-bottom: 0.15rem;
}

.sc-msg-assistant p {
  margin: 0 0 0.4rem;
}

.sc-msg-assistant p:last-child {
  margin-bottom: 0;
}

.sc-msg-assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.4rem 0;
  font-size: 0.76rem;
}

.sc-msg-assistant th,
.sc-msg-assistant td {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border-soft);
  text-align: left;
}

.sc-msg-assistant th {
  background: var(--bg-panel);
  color: var(--text-strong);
  font-weight: 600;
}

/* Citations */
.sc-citation {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-faint);
  background: var(--bg-panel);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  white-space: nowrap;
}

/* ── Typing indicator ───────────────────────────────────────────── */
.sc-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.7rem 0.85rem;
}

.sc-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: sc-bounce 1.4s ease-in-out infinite;
}

.sc-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.sc-typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes sc-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* ── Input area ─────────────────────────────────────────────────── */
.sc-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.sc-chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text-strong);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  line-height: 1.5;
  max-height: 100px;
  min-height: 20px;
  scrollbar-width: none;
}

.sc-chat-textarea::-webkit-scrollbar {
  display: none;
}

.sc-chat-textarea::placeholder {
  color: var(--text-faint);
}

.sc-chat-send {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
  flex-shrink: 0;
}

.sc-chat-send:hover:not(:disabled) {
  background: var(--bg-panel-strong);
  color: var(--text-strong);
}

.sc-chat-send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.sc-chat-send svg {
  width: 16px;
  height: 16px;
}

/* ── Follow-up suggestions (progressive starters) ────────────── */
.sc-chat-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.15rem 0 0.3rem;
  align-self: flex-start;
  max-width: 92%;
}

.sc-chat-followup {
  background: transparent;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 0.3rem 0.65rem;
  font-size: 0.72rem;
  color: var(--text-soft);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.sc-chat-followup:hover {
  background: var(--bg-panel);
  border-color: var(--text-faint);
  color: var(--text-medium);
}

/* On compact size, allow wrapping and shrink chips */
.sc-size-compact .sc-chat-followup {
  white-space: normal;
  font-size: 0.7rem;
}

/* ── Error message ──────────────────────────────────────────────── */
.sc-msg-error {
  align-self: center;
  background: var(--bg-panel);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--text-soft);
  font-size: 0.76rem;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  text-align: center;
}

/* ── Rate limit message ─────────────────────────────────────────── */
.sc-msg-rate-limit {
  align-self: center;
  color: var(--text-faint);
  font-size: 0.72rem;
  padding: 0.3rem 0.6rem;
  text-align: center;
}

/* ── Mobile: bottom sheet pattern (< 640px) ─────────────────────── */
@media (max-width: 639px) {
  .sc-chat-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100% !important;
    height: 70vh !important;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }

  .sc-chat-panel.sc-open {
    transform: translateY(0);
  }

  /* Override position classes on mobile */
  .sc-chat-panel.sc-pos-br,
  .sc-chat-panel.sc-pos-bl,
  .sc-chat-panel.sc-pos-tr,
  .sc-chat-panel.sc-pos-tl {
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
  }

  .sc-chat-bubble {
    bottom: 1rem;
    right: 1rem;
  }
}

/* ── Reduced motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .sc-chat-bubble,
  .sc-chat-panel,
  .sc-typing-dot {
    transition: none;
    animation: none;
  }
}
