/*
  "Ask about Setu" floating chatbot widget.

  Styled entirely from the existing design tokens (tokens.css) so it reads
  as native app furniture, not a bolted-on third-party bubble: same card
  surface, hairline borders, radii, soft olive-tinted shadows, Sora type,
  and the earthy palette. No new colours are introduced.

  Placement: fixed bottom-right, above everything (z-index above --z-toast).
  The only other fixed element in the app is #fabricBg at z-index -1, so
  there is no corner collision to offset around — but the launcher sits on
  its own layer well clear of any future toast, and the panel opens upward.

  Motion honours prefers-reduced-motion (durations already collapse via the
  motion tokens; we additionally drop transforms below).
*/

/* Layer above toast (90). Named locally; kept off the shared z-scale since
   this is an always-on overlay that must clear every in-app layer. */
.setu-chat-launcher,
.setu-chat-panel {
  position: fixed;
  right: var(--space-6);
  z-index: 1000;
  font-family: var(--font-sans);
}

/* ---------- Launcher bubble ---------- */
.setu-chat-launcher {
  bottom: var(--space-6);
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: var(--on-primary);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-float);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.setu-chat-launcher:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: var(--shadow-modal); }
.setu-chat-launcher:active { background: var(--primary-active); transform: translateY(0); }
.setu-chat-launcher:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.setu-chat-launcher svg { width: 24px; height: 24px; display: block; }
/* Swap icon glyphs based on open state (both live in the DOM). */
.setu-chat-launcher .ico-close { display: none; }
.setu-chat-launcher.is-open .ico-chat { display: none; }
.setu-chat-launcher.is-open .ico-close { display: block; }

/* Small "1" style unread/attention dot — used only to draw a first-time eye. */
.setu-chat-launcher .nudge-dot {
  position: absolute; top: 2px; right: 2px;
  width: 12px; height: 12px; border-radius: var(--radius-pill);
  background: var(--accent); border: 2px solid var(--card);
}

/* ---------- Panel ---------- */
.setu-chat-panel {
  bottom: calc(var(--space-6) + 56px + var(--space-3));
  width: 360px;
  max-width: calc(100vw - var(--space-6) * 2);
  height: 520px;
  max-height: calc(100vh - var(--space-10));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  /* hidden state */
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  pointer-events: none;
  transition: opacity var(--dur-med) var(--ease-out), transform var(--dur-med) var(--ease-out);
}
.setu-chat-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.setu-chat-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--primary);
  color: var(--on-primary);
}
.setu-chat-head .sc-avatar {
  width: 34px; height: 34px; flex: none;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.14);
  display: grid; place-items: center;
}
.setu-chat-head .sc-avatar svg { width: 18px; height: 18px; }
.setu-chat-head .sc-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.setu-chat-head .sc-title b { font-size: var(--text-base); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); }
.setu-chat-head .sc-title span { font-size: var(--text-xs); opacity: 0.8; }
.setu-chat-head .sc-action {
  flex: none; background: none; border: 0; color: var(--on-primary);
  opacity: 0.85; cursor: pointer; padding: 6px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  transition: opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.setu-chat-head .sc-action:hover { opacity: 1; background: rgba(255, 255, 255, 0.12); }
.setu-chat-head .sc-action:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.setu-chat-head .sc-action svg { width: 17px; height: 17px; }

/* Message scroll area */
.setu-chat-log {
  flex: 1; overflow-y: auto;
  padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--paper);
  scroll-behavior: smooth;
}
.sc-msg {
  max-width: 85%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm); line-height: var(--leading-sm);
  white-space: pre-wrap; word-wrap: break-word;
}
.sc-msg.bot {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: var(--radius-xs);
}
.sc-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: var(--on-primary);
  border-bottom-right-radius: var(--radius-xs);
}
.sc-msg.error {
  align-self: flex-start;
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-bottom-left-radius: var(--radius-xs);
}

/* Typing indicator (three dots) */
.sc-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: var(--space-3) var(--space-4); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md); border-bottom-left-radius: var(--radius-xs); }
.sc-typing i { width: 6px; height: 6px; border-radius: var(--radius-pill); background: var(--ink-muted); animation: sc-bounce 1.2s infinite ease-in-out; }
.sc-typing i:nth-child(2) { animation-delay: 0.15s; }
.sc-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes sc-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Quick-reply chips */
.sc-quick { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-1); }
.sc-chip {
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  padding: 7px var(--space-3);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.sc-chip:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.sc-chip:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* Input row */
.setu-chat-input {
  display: flex; align-items: flex-end; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--line);
  background: var(--card);
}
.setu-chat-input textarea {
  flex: 1; resize: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-family: var(--font-sans); font-size: var(--text-sm); line-height: var(--leading-sm);
  color: var(--ink); background: var(--paper);
  max-height: 96px; min-height: 40px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.setu-chat-input textarea::placeholder { color: var(--ink-muted); }
.setu-chat-input textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--shadow-focus); }
.setu-chat-send {
  flex: none; width: 40px; height: 40px;
  border: 0; border-radius: var(--radius-md);
  background: var(--primary); color: var(--on-primary);
  cursor: pointer; display: grid; place-items: center;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.setu-chat-send:hover { background: var(--primary-hover); }
.setu-chat-send:active { transform: scale(0.96); }
.setu-chat-send:disabled { background: var(--primary-disabled); cursor: not-allowed; }
.setu-chat-send:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.setu-chat-send svg { width: 18px; height: 18px; }

/* Small print under the input */
.setu-chat-foot { padding: 0 var(--space-4) var(--space-3); background: var(--card); }
.setu-chat-foot span { font-size: 10.5px; color: var(--ink-muted); }

@media (max-width: 480px) {
  .setu-chat-panel { width: calc(100vw - var(--space-4) * 2); right: var(--space-4); }
  .setu-chat-launcher { right: var(--space-4); }
}

@media (prefers-reduced-motion: reduce) {
  .setu-chat-panel { transition: opacity var(--dur-med) var(--ease-out); transform: none; }
  .setu-chat-panel.is-open { transform: none; }
  .setu-chat-launcher:hover { transform: none; }
  .sc-typing i { animation: none; }
}
