/* Support AI Agent — Frontend Widget Stylesheet */
:host {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

:host,
.saia-widget-scope {
  --saia-primary: #4f46e5;
  --saia-accent: #6366f1;
  --saia-chat-bg: #ffffff;
  --saia-text: #0f172a;
  --saia-muted: #64748b;
  --saia-border: rgba(15, 23, 42, 0.1);
  --saia-surface: #f8fafc;
  --saia-btn-bg: #4f46e5;
  --saia-btn-icon: #ffffff;
  --saia-font: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --saia-shadow: 0 20px 50px rgba(15, 23, 42, 0.18), 0 4px 16px rgba(15, 23, 42, 0.08);
  font-family: var(--saia-font);
  color: var(--saia-text);
  box-sizing: border-box;
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.saia-widget-scope *,
.saia-widget-scope *::before,
.saia-widget-scope *::after {
  box-sizing: border-box;
  font-family: inherit;
}

/* Floating container */
.saia-floating-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}

.saia-floating-container.saia-pos-left {
  right: auto;
  left: 20px;
  align-items: flex-start;
}

.saia-floating-container > * {
  pointer-events: auto;
}

/* Greeting tooltip */
.saia-greeting-tooltip {
  position: relative;
  max-width: 280px;
  background: #ffffff;
  color: #0f172a;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  padding: 12px 34px 12px 14px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
  font-size: 13.5px;
  line-height: 1.45;
  cursor: pointer;
  animation: saia-pop-in 0.22s ease-out;
}

.saia-greeting-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.06);
  color: #475569;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.saia-greeting-close:hover {
  background: rgba(15, 23, 42, 0.12);
  color: #0f172a;
}

/* Launcher FAB */
.saia-fab-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.saia-fab {
  width: 60px;
  height: 60px;
  border-radius: 9999px;
  border: none;
  background: linear-gradient(135deg, var(--saia-btn-bg), var(--saia-accent));
  color: var(--saia-btn-icon);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.24);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  padding: 0;
  overflow: hidden;
  position: relative;
}

.saia-fab.saia-layout-minimal {
  width: auto;
  height: 48px;
  padding: 0 18px;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}

.saia-fab:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.28);
}

.saia-fab:focus-visible,
.saia-icon-btn:focus-visible,
.saia-send-btn:focus-visible,
.saia-starter-btn:focus-visible,
.saia-escalate-trigger:focus-visible {
  outline: 2px solid var(--saia-accent);
  outline-offset: 2px;
}

.saia-fab img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.saia-fab.saia-layout-minimal img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.saia-fab svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.saia-fab.saia-layout-minimal svg {
  width: 20px;
  height: 20px;
}

/* Chat Window */
.saia-window {
  width: 380px;
  height: 580px;
  max-height: calc(100vh - 104px);
  max-width: calc(100vw - 32px);
  background: var(--saia-chat-bg);
  color: var(--saia-text);
  border-radius: 18px;
  border: 1px solid var(--saia-border);
  box-shadow: var(--saia-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: saia-slide-up 0.2s ease-out;
}

.saia-window.saia-inline-window {
  width: 100%;
  max-width: 100%;
  height: 560px;
  max-height: none;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
  animation: none;
}

.saia-window.saia-hidden,
.saia-hidden {
  display: none !important;
}

/* Header */
.saia-header {
  background: linear-gradient(135deg, var(--saia-primary), var(--saia-accent));
  color: var(--saia-btn-icon);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.saia-header-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.saia-avatar-badge {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: var(--saia-btn-icon);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.saia-avatar-badge img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.saia-avatar-badge svg {
  width: 20px;
  height: 20px;
}

.saia-header-text {
  min-width: 0;
}

.saia-header-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.saia-agent-name {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saia-preview-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
  flex-shrink: 0;
}

.saia-agent-role {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.88;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saia-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.saia-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: var(--saia-btn-icon);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  padding: 0;
}

.saia-icon-btn:hover {
  background: rgba(255, 255, 255, 0.26);
}

.saia-icon-btn svg {
  width: 16px;
  height: 16px;
}

/* Messages area */
.saia-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--saia-chat-bg);
}

.saia-messages::-webkit-scrollbar {
  width: 6px;
}

.saia-messages::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.28);
  border-radius: 999px;
}

.saia-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  gap: 4px;
}

.saia-msg-row.saia-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.saia-msg-row.saia-msg-assistant,
.saia-msg-row.saia-msg-system {
  align-self: flex-start;
  align-items: flex-start;
}

.saia-msg-assistant-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}

.saia-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--saia-primary), var(--saia-accent));
  color: var(--saia-btn-icon);
}

.saia-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.saia-msg-avatar svg {
  width: 15px;
  height: 15px;
}

.saia-msg-row.saia-msg-assistant .saia-citations {
  padding-left: 36px;
}

.saia-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.saia-msg-user .saia-msg-bubble {
  background: var(--saia-primary);
  color: var(--saia-btn-icon);
  border-bottom-right-radius: 4px;
}

.saia-msg-assistant .saia-msg-bubble {
  background: rgba(148, 163, 184, 0.14);
  color: var(--saia-text);
  border: 1px solid var(--saia-border);
  border-bottom-left-radius: 4px;
}

.saia-msg-system .saia-msg-bubble {
  background: rgba(245, 158, 11, 0.14);
  color: var(--saia-text);
  border: 1px solid rgba(245, 158, 11, 0.35);
  font-size: 12.5px;
}

/* Safe markdown typography inside bubbles */
.saia-msg-bubble p {
  margin: 0 0 8px;
}

.saia-msg-bubble p:last-child {
  margin-bottom: 0;
}

.saia-msg-bubble ul,
.saia-msg-bubble ol {
  margin: 6px 0;
  padding-left: 18px;
}

.saia-msg-bubble li {
  margin-bottom: 3px;
}

.saia-msg-bubble a {
  color: var(--saia-accent);
  text-decoration: underline;
  font-weight: 500;
}

.saia-msg-user .saia-msg-bubble a {
  color: inherit;
}

.saia-inline-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  background: rgba(15, 23, 42, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

.saia-code-block {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  background: #0f172a;
  color: #f8fafc;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
  white-space: pre-wrap;
}

.saia-md-heading {
  font-weight: 700;
  margin: 6px 0 4px;
}

/* Citations */
.saia-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.saia-citation-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.1);
  color: var(--saia-primary);
  border: 1px solid rgba(99, 102, 241, 0.22);
  text-decoration: none;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

a.saia-citation-chip:hover {
  background: rgba(99, 102, 241, 0.18);
}

/* Starter prompts */
.saia-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.saia-starter-btn {
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.07);
  color: var(--saia-primary);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, transform 0.1s ease;
}

.saia-starter-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  transform: translateY(-1px);
}

/* Typing indicator */
.saia-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid var(--saia-border);
}

.saia-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--saia-muted);
  animation: saia-bounce 1.2s infinite ease-in-out;
}

.saia-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.saia-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

/* Escalation bar & form */
.saia-escalate-bar {
  padding: 8px 14px;
  border-top: 1px solid var(--saia-border);
  background: rgba(148, 163, 184, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.saia-escalate-trigger {
  border: 1px solid var(--saia-border);
  background: transparent;
  color: var(--saia-text);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.saia-escalate-trigger:hover {
  background: rgba(148, 163, 184, 0.14);
}

.saia-escalate-link {
  font-size: 12px;
  color: var(--saia-primary);
  text-decoration: none;
  font-weight: 600;
}

.saia-escalate-link:hover {
  text-decoration: underline;
}

.saia-escalate-panel {
  border-top: 1px solid var(--saia-border);
  padding: 12px 14px;
  background: rgba(248, 250, 252, 0.96);
  color: #0f172a;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.saia-escalate-panel.saia-hidden {
  display: none;
}

.saia-escalate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
}

.saia-escalate-close {
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
}

.saia-field-input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  background: #ffffff;
  color: #0f172a;
}

.saia-field-input:focus {
  outline: 2px solid var(--saia-accent);
  border-color: transparent;
}

.saia-escalate-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.saia-btn-primary {
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--saia-btn-bg);
  color: var(--saia-btn-icon);
}

.saia-btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.saia-escalate-feedback {
  font-size: 12px;
  color: #047857;
}

.saia-escalate-feedback.saia-error {
  color: #b91c1c;
}

/* Composer */
.saia-composer {
  border-top: 1px solid var(--saia-border);
  padding: 10px 12px;
  background: var(--saia-chat-bg);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.saia-composer-input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.saia-input {
  width: 100%;
  min-height: 38px;
  max-height: 110px;
  resize: none;
  border: 1px solid var(--saia-border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13.5px;
  line-height: 1.4;
  background: rgba(148, 163, 184, 0.08);
  color: var(--saia-text);
  overflow-y: auto;
}

.saia-input:focus {
  outline: 2px solid var(--saia-accent);
  border-color: transparent;
  background: var(--saia-chat-bg);
}

.saia-char-count {
  font-size: 11px;
  color: var(--saia-muted);
  text-align: right;
}

.saia-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--saia-btn-bg);
  color: var(--saia-btn-icon);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.saia-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.saia-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.saia-send-btn svg {
  width: 18px;
  height: 18px;
}

/* Mobile fullscreen chat */
@media (max-width: 639px) {
  .saia-floating-container {
    bottom: 14px;
    right: 14px;
    left: auto;
  }

  .saia-floating-container.saia-pos-left {
    left: 14px;
    right: auto;
  }

  .saia-floating-container.saia-is-open {
    inset: 0;
    padding: 0;
    align-items: stretch;
  }

  .saia-floating-container.saia-is-open .saia-window {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }

  .saia-floating-container.saia-is-open .saia-fab-row,
  .saia-floating-container.saia-is-open .saia-greeting-tooltip {
    display: none;
  }
}

@keyframes saia-slide-up {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes saia-pop-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes saia-bounce {
  0%, 80%, 100% {
    transform: scale(0.65);
    opacity: 0.45;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}
