/* AI support chat widget — launcher + panel. Tokens from app.css; every
   colour has a light fallback and the dark theme swaps through the same
   tokens, so the widget follows the page it sits on. */
.sc-launcher {
  position: fixed; right: 16px; bottom: 20px; z-index: 1029;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border: 0; border-radius: 999px;
  background: #4F46E5; color: #fff;
  font: 600 var(--text-sm, .835rem) system-ui, -apple-system, "Segoe UI", sans-serif;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .22); cursor: pointer;
}
.sc-launcher:hover { background: #4338CA; }
.sc-launcher:focus-visible { outline: 3px solid var(--brand-ink, #4F46E5); outline-offset: 2px; }
.sc-launcher .sc-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #4ADE80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, .28);
}
.sc-launcher[hidden] { display: none; }

.sc-panel {
  position: fixed; right: 16px; bottom: 20px; z-index: 1031;
  width: min(400px, calc(100vw - 24px)); height: min(640px, calc(100vh - 40px));
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: 16px; border: 1px solid var(--border-primary, #e5e7eb);
  background: var(--surface-elevated, #fff); color: var(--text-primary, #0f172a);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.sc-panel[hidden] { display: none; }
.sc-panel.sc-standalone {
  position: static; width: 100%; height: min(720px, calc(100vh - 220px));
  min-height: 480px; box-shadow: none;
}
.sc-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: #4F46E5; color: #fff;
}
.sc-head .sc-avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, .18); font-size: var(--text-md, 1rem);
}
.sc-head .sc-title { font-weight: 700; font-size: var(--text-base, .9rem); line-height: 1.2; }
.sc-head .sc-sub { font-size: var(--text-xs, .75rem); opacity: .9; }
.sc-head .sc-close {
  margin-left: auto; border: 0; background: transparent; color: #fff;
  font-size: var(--text-lg, 1.2rem); line-height: 1; cursor: pointer; padding: 4px 6px;
}
.sc-body { flex: 1; overflow-y: auto; padding: 14px; background: var(--surface-sunken, #f8fafc); }
.sc-note {
  font-size: var(--text-xs, .75rem); color: var(--text-secondary, #475569);
  padding: 8px 10px; border-radius: 8px; margin-bottom: 12px;
  background: var(--surface-primary, #fff); border: 1px dashed var(--border-primary, #e5e7eb);
}
.sc-form label { display: block; font-size: var(--text-sm, .835rem); font-weight: 600; margin: 10px 0 4px; }
.sc-form input {
  width: 100%; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--border-primary, #cbd5e1);
  background: var(--surface-primary, #fff); color: var(--text-primary, #0f172a);
  font-size: var(--text-base, .9rem);
}
.sc-form .sc-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.sc-form .sc-error { color: var(--danger, #B91C1C); font-size: var(--text-sm, .835rem); margin-top: 6px; min-height: 1.2em; }
.sc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  font-weight: 600; font-size: var(--text-sm, .835rem);
  background: #4F46E5; color: #fff;
}
.sc-btn.sc-btn-outline { background: transparent; color: var(--brand-ink, #4F46E5); border-color: currentColor; }
.sc-btn:disabled { opacity: .6; cursor: default; }
.sc-btn.sc-block { width: 100%; margin-top: 14px; }

.sc-msg { display: flex; margin-bottom: 10px; }
.sc-msg.sc-user { justify-content: flex-end; }
.sc-bubble {
  max-width: 88%; padding: 10px 12px; border-radius: 14px;
  font-size: var(--text-base, .9rem); line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  background: var(--surface-primary, #fff); color: var(--text-primary, #0f172a);
  border: 1px solid var(--border-primary, #e5e7eb);
}
.sc-user .sc-bubble { background: #4F46E5; color: #fff; border-color: transparent; border-bottom-right-radius: 4px; }
.sc-assistant .sc-bubble, .sc-agent .sc-bubble { border-bottom-left-radius: 4px; }
.sc-agent .sc-bubble { border-left: 3px solid #4ADE80; }
.sc-bubble a { color: inherit; text-decoration: underline; }
.sc-bubble ul { margin: 6px 0 0 18px; padding: 0; }
.sc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 0 4px; font-size: var(--text-2xs, .7rem); color: var(--text-secondary, #475569); }
.sc-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.sc-badge.sc-ok { background: rgba(74, 222, 128, .18); color: var(--success, #166534); }
.sc-badge.sc-warn { background: rgba(251, 191, 36, .2); color: var(--warning, #92400E); }
.sc-badge.sc-agent-badge { background: rgba(99, 102, 241, .14); color: var(--brand-ink, #4F46E5); }
.sc-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.sc-sources a {
  font-size: var(--text-xs, .75rem); padding: 3px 9px; border-radius: 999px; text-decoration: none;
  background: rgba(99, 102, 241, .1); color: var(--brand-ink, #4F46E5); border: 1px solid rgba(99, 102, 241, .25);
}
.sc-fb { display: inline-flex; gap: 2px; }
.sc-fb button { border: 0; background: transparent; cursor: pointer; padding: 0 4px; color: inherit; font-size: var(--text-sm, .835rem); line-height: 1; }
.sc-fb button.on { color: var(--brand-ink, #4F46E5); }
.sc-manager-cta { margin: 4px 0 12px 4px; }
.sc-typing { color: var(--text-secondary, #475569); font-size: var(--text-sm, .835rem); margin: 4px 0 10px 4px; }

.sc-foot { padding: 10px 12px; border-top: 1px solid var(--border-primary, #e5e7eb); background: var(--surface-primary, #fff); }
.sc-foot form { display: flex; gap: 8px; align-items: flex-end; }
.sc-foot textarea {
  flex: 1; resize: none; min-height: 40px; max-height: 120px; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--border-primary, #cbd5e1); background: var(--surface-primary, #fff);
  color: var(--text-primary, #0f172a); font: inherit; font-size: var(--text-base, .9rem);
}
.sc-foot .sc-tools { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 8px; }
.sc-foot .sc-tools .sc-link { background: none; border: 0; padding: 0; color: var(--brand-ink, #4F46E5); font-size: var(--text-xs, .75rem); cursor: pointer; text-decoration: underline; }
.sc-foot .sc-disclaimer { font-size: var(--text-2xs, .7rem); color: var(--text-secondary, #475569); }

@media (max-width: 767.98px) {
  .sc-launcher { right: 10px; bottom: calc(var(--mobile-tabbar-height, 56px) + env(safe-area-inset-bottom, 0px) + 12px); }
  .sc-panel:not(.sc-standalone) { right: 0; bottom: 0; width: 100vw; height: 100dvh; border-radius: 0; }
  .sc-panel.sc-standalone { height: calc(100dvh - 160px); }
}
