/* chat-widget.css - every style the floating chat widget needs, and nothing else.
   Link this file on any page that embeds the widget. It does not style the host page:
   all rules are scoped to the launcher (.chat-toggle) and the chat window (.chat-panel).
   The demo page's own styles live in styles.css. */

:root {
  --surface: #ffffff;
  --surface-muted: #f5f7fb;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --ring: rgba(59, 138, 217, 0.35);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.16);
  --shadow-md: 0 10px 24px rgba(0, 34, 68, 0.16);
  --radius: 16px;
  /* chat widget palette */
  --accent: #3b8ad9;
  --accent-dark: #2a6db5;
  --accent-soft: #eaf3fc;
  --accent-border: #c5dcf3;
  --border: #e1dfdd;
  --border-strong: #c8c6c4;
  --text-muted: #6b6b6b;
  /* extra distance from the corner; set from launcherOffsetUp / launcherOffsetLeft in config.js */
  --launcher-offset-up: 0px;
  --launcher-offset-left: 0px;
  /* added to every widget font size; set from fontSizeAdjust in config.js */
  --chat-font-adjust: 0px;
  /* displayMode "sidecar": width, set from sidecarWidth in config.js (and by dragging) */
  --sidecar-width: 420px;
  /* displayMode "fullscreen": size, set from fullscreenWidth / fullscreenHeight in config.js */
  --fullscreen-width: 100%;
  --fullscreen-height: 100%;
  /* width the page is pushed by an open sidecar when sidecarPushPage is true (else 0px) */
  --chat-sidecar-push: 0px;
}

/* Only the widget's own elements use border-box, so the host page's layout is untouched. */
.chat-toggle,
.chat-toggle *,
.chat-panel,
.chat-panel * {
  box-sizing: border-box;
}

/* Segoe UI, resolved in this order for each weight:
   1. Segoe UI installed locally (Windows)
   2. Segoe UI web font hot-linked from Microsoft's Fluent UI CDN
   3. Selawik (Microsoft's open-source Segoe UI stand-in) self-hosted in ./fonts (next to
      this file), used automatically if the CDN request fails */
@font-face {
  font-family: "Segoe UI Web";
  font-weight: 350;
  font-style: normal;
  font-display: swap;
  src: local("Segoe UI Semilight"),
       url("https://static2.sharepointonline.com/files/fabric/assets/fonts/segoeui-westeuropean/segoeui-semilight.woff2") format("woff2"),
       url("./fonts/selawksl.woff2") format("woff2");
}

@font-face {
  font-family: "Segoe UI Web";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: local("Segoe UI"),
       url("https://static2.sharepointonline.com/files/fabric/assets/fonts/segoeui-westeuropean/segoeui-regular.woff2") format("woff2"),
       url("./fonts/selawk.woff2") format("woff2");
}

@font-face {
  font-family: "Segoe UI Web";
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  src: local("Segoe UI Semibold"),
       url("https://static2.sharepointonline.com/files/fabric/assets/fonts/segoeui-westeuropean/segoeui-semibold.woff2") format("woff2"),
       url("./fonts/selawksb.woff2") format("woff2");
}

/* The widget always uses this font stack, whatever the host page uses. */
.chat-toggle,
.chat-panel {
  font-family: "Segoe UI Web", "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ===== Chat widget: clean light style (white panel, blue accent) ===== */
.chat-toggle {
  position: fixed;
  right: calc(1.1rem + var(--launcher-offset-left));
  bottom: calc(1.1rem + var(--launcher-offset-up));
  border: 0;
  border-radius: 999px;
  --launcher-color: var(--accent); /* overridden by launcherColor in config.js */
  background: linear-gradient(135deg, var(--launcher-color), color-mix(in srgb, var(--launcher-color) 72%, #000));
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.95rem 0.6rem 0.65rem;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22), 0 14px 32px rgba(0, 0, 0, 0.16);
  cursor: pointer;
  z-index: 1000;
}

/* launcherStyle: "fulltext" / "compacttext" - label only, no icon */
.chat-toggle--fulltext .chat-toggle__icon,
.chat-toggle--compacttext .chat-toggle__icon {
  display: none;
}

.chat-toggle--fulltext,
.chat-toggle--compacttext {
  padding: 0.85rem 1.1rem;
}

/* launcherStyle: "icon" - round button with the icon only (X when open) */
.chat-toggle--icon {
  padding: 0.45rem;
}

.chat-toggle--icon .chat-toggle__icon {
  width: 2.5rem;
  height: 2.5rem;
}

.chat-toggle--icon #chatToggleLabel {
  display: none;
}

/* Higher specificity than .chat-toggle[aria-expanded="true"] below, which adds left padding */
.chat-toggle.chat-toggle--icon[aria-expanded="true"] {
  padding: 0;
  gap: 0;
  width: 3.4rem;
  height: 3.4rem;
  justify-content: center;
}

.chat-toggle--icon .chat-toggle__close {
  width: 1.3rem;
  height: 1.3rem;
}

.chat-toggle:focus-visible,
.chat-close:focus-visible,
.chat-restart:focus-visible,
.chat-input button:focus-visible,
.chat-input:focus-within,
.suggested-actions button:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.chat-toggle__icon {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  overflow: hidden;
  display: inline-flex;
}

.chat-toggle__icon svg,
.chat-toggle__icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#chatToggleLabel {
  font-weight: 600;
  font-size: calc(0.9rem + var(--chat-font-adjust));
}

/* Close (X) icon: only shown while the chat is open, replacing the launcher icon */
.chat-toggle__close {
  display: none;
  width: 1.05rem;
  height: 1.05rem;
}

.chat-toggle[aria-expanded="true"] .chat-toggle__icon {
  display: none;
}

.chat-toggle[aria-expanded="true"] .chat-toggle__close {
  display: block;
}

.chat-toggle[aria-expanded="true"] {
  padding-left: 1.1rem;
}

/* launcherPosition: "top-right" - pinned to the top edge; launcherOffsetUp then moves it down */
.chat-toggle--top {
  bottom: auto;
  top: calc(1.1rem + var(--launcher-offset-up));
}

/* Sidecar / fullscreen hide the launcher while the window is open (it has its own X). */
.chat-toggle[hidden] {
  display: none;
}

.chat-panel {
  position: fixed;
  right: calc(1.1rem + var(--launcher-offset-left));
  bottom: calc(5.3rem + var(--launcher-offset-up));
  width: min(390px, calc(100vw - 1rem));
  height: min(680px, 74vh);
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  border: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 999;
}

.chat-panel.is-open {
  display: flex;
}

.chat-panel[hidden] {
  display: none !important;
}

/* launcherPosition: "top-right" - the floating window hangs below the launcher */
.chat-panel--floating.chat-panel--launcher-top {
  bottom: auto;
  top: calc(5.3rem + var(--launcher-offset-up));
}

/* ===== displayMode: "sidecar" - docked to the right edge, full height of the window =====
   Width comes from --sidecar-width (sidecarWidth in config.js; dragging the left edge
   changes it). Shadow and border match the "Try it yourself" drawer on the demo page. */
.chat-panel--sidecar {
  top: 0;
  right: 0;
  bottom: 0;
  width: clamp(300px, var(--sidecar-width), 100vw);
  height: auto;
  border-radius: 0;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.12);
}

/* Drag handle on the sidecar's left edge (added by app.js when sidecarResizable is true) */
.chat-panel__resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 8px;
  cursor: ew-resize;
  touch-action: none;
  z-index: 1;
}

.chat-panel__resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: 4px;
  height: 2.6rem;
  margin-top: -1.3rem;
  border-radius: 999px;
  background: var(--border-strong);
  opacity: 0;
  transition: opacity 0.15s;
}

.chat-panel__resizer:hover::after,
.chat-panel__resizer:focus-visible::after,
.chat-panel.is-resizing .chat-panel__resizer::after {
  opacity: 1;
  background: var(--accent);
}

.chat-panel__resizer:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: -3px;
}

.chat-panel.is-resizing {
  user-select: none;
}

/* closeButton: false in sidecar / fullscreen mode: the launcher stays visible in the corner,
   so the message box moves up to leave it room. */
.chat-panel--launcher-visible:not(.chat-panel--launcher-top) .chat-input {
  margin-bottom: calc(4.6rem + var(--launcher-offset-up));
}

/* ... and with the launcher pinned top-right, the title bar moves down instead. */
.chat-panel--launcher-visible.chat-panel--launcher-top .chat-panel__header {
  padding-top: calc(4.8rem + var(--launcher-offset-up));
}

/* ===== displayMode: "fullscreen" - covers the browser window =====
   Size comes from --fullscreen-width / --fullscreen-height (config.js). Anything smaller
   than the window is centred over a dimmed page. --chat-inset-left lets a host page keep
   a strip on the left free (the demo's settings drawer uses it); it is 0 elsewhere. */
.chat-panel--fullscreen {
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--chat-inset-left, 0px);
  margin: auto;
  width: min(var(--fullscreen-width), calc(100vw - var(--chat-inset-left, 0px)));
  height: min(var(--fullscreen-height), 100%);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}

.chat-panel--fullscreen.chat-panel--edge-to-edge {
  border-radius: 0;
  box-shadow: none;
}

/* Dimmed, click-absorbing backdrop behind the fullscreen window (added by app.js).
   Clicking it closes the chat. Sits under the panel (999) and the launcher (1000). */
.chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 998;
}

.chat-backdrop[hidden] {
  display: none;
}

.chat-panel__header {
  background: #fff;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
}

.chat-panel__title-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chat-panel__title-wrap h3 {
  margin: 0;
  font-size: calc(1rem + var(--chat-font-adjust));
  font-weight: 600;
}

.chat-panel__title-wrap p {
  margin: 0;
  font-size: calc(0.74rem + var(--chat-font-adjust));
  color: var(--text-muted);
}

.chat-panel__icon {
  width: 2rem;
  height: 2rem;
  flex: none;
  border-radius: 999px;
  overflow: hidden;
  display: inline-flex;
}

.chat-panel__icon svg,
.chat-panel__icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-panel__status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.1rem;
}

.chat-panel__status p {
  margin: 0;
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #facc15;
}

.connection-dot.online {
  background: #16a34a;
}

.chat-panel__actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.chat-close,
.chat-restart {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: calc(1.05rem + var(--chat-font-adjust));
  cursor: pointer;
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-restart svg {
  width: 1.15rem;
  height: 1.15rem;
}

/* closeButton: false in config.js sets the hidden attribute; it must beat the display rule above. */
.chat-close[hidden] {
  display: none;
}

.chat-close:hover,
.chat-restart:hover {
  color: var(--text-primary);
  background: #f3f2f1;
}

.chat-restart:disabled {
  opacity: 0.5;
  cursor: wait;
}

.chat-status {
  display: none;
  background: #fff5d6;
  color: #7c5600;
  border-bottom: 1px solid #f1dfab;
  font-size: calc(0.8rem + var(--chat-font-adjust));
  padding: 0.55rem 0.8rem;
}

.chat-status.error {
  background: #ffe4e6;
  color: #9f1239;
  border-bottom-color: #fecdd3;
}

.chat-status.visible {
  display: block;
}

.messages {
  flex: 1;
  overflow-y: auto;
  background: #fff;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.message {
  max-width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  line-height: 1.45;
  font-size: calc(0.9rem + var(--chat-font-adjust));
  animation: pop-in 0.16s ease;
}

.message.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--accent-soft);
  color: var(--text-primary);
  border: 1px solid var(--accent-border);
}

.message.agent {
  align-self: stretch;
  background: #fff;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.message.agent a {
  color: var(--accent-dark);
}

.message.agent p {
  margin: 0 0 0.45rem;
}

.message.agent p:last-child {
  margin-bottom: 0;
}

.message.agent ul,
.message.agent ol {
  margin: 0.32rem 0;
  padding-left: 1.2rem;
}

.message.agent code {
  background: #f1f3f5;
  border-radius: 4px;
  padding: 0.05rem 0.25rem;
}

.sources {
  border-top: 1px solid var(--border);
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.7rem;
  font-size: calc(0.75rem + var(--chat-font-adjust));
}

.sources b {
  width: 100%;
  color: var(--text-secondary);
}

.typing {
  align-self: flex-start;
  display: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  gap: 0.3rem;
}

.typing.visible {
  display: inline-flex;
}

.typing span {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 999px;
  background: #8a8886;
  animation: pulse 1.2s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

.suggested-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem;
  background: #fff;
}

.suggested-actions:not(:empty) {
  padding: 0.5rem 1rem;
}

.suggested-actions button {
  border: 1px solid var(--accent-border);
  background: #fff;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 0.32rem 0.7rem;
  cursor: pointer;
  font-size: calc(0.78rem + var(--chat-font-adjust));
}

.suggested-actions button:hover {
  background: var(--accent-soft);
}

/* Input: one bordered box, borderless field, icon send button */
.chat-input {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.5rem 1rem 1rem;
  padding: 0.35rem 0.4rem 0.35rem 0.8rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  --input-box-color: #fff; /* overridden by inputBoxColor in config.js */
  background: var(--input-box-color);
}

.chat-input input {
  border: 0;
  outline: 0;
  background: transparent;
  padding: 0.5rem 0;
  flex: 1;
  font: inherit;
  font-size: calc(0.9rem + var(--chat-font-adjust));
  color: var(--text-primary);
}

.chat-input input::placeholder {
  color: var(--text-muted);
}

.chat-input input:disabled,
.chat-input button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-input button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  width: 2.1rem;
  height: 2.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* fileUploads: false sets the hidden attribute; it must beat the display rule above. */
.chat-input button[hidden],
.chat-input__divider[hidden] {
  display: none;
}

.chat-input button:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.chat-input button svg {
  width: 1.25rem;
  height: 1.25rem;
}

.chat-input__divider {
  width: 1px;
  height: 1.4rem;
  background: var(--border);
}

/* Files queued for the next message */
.attachment-list {
  display: none;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 1rem 0;
  background: #fff;
}

.attachment-list.visible {
  display: flex;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.3rem 0.2rem 0.7rem;
  font-size: calc(0.8rem + var(--chat-font-adjust));
  background: var(--surface-muted);
}

.attachment-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 14rem;
}

.attachment-chip__remove {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: calc(0.75rem + var(--chat-font-adjust));
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 999px;
}

.attachment-chip__remove:hover {
  background: #e1dfdd;
  color: var(--text-primary);
}

/* Files shown inside a sent user message */
.message__files {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.message__file {
  border: 1px solid var(--accent-border);
  background: #fff;
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-size: calc(0.78rem + var(--chat-font-adjust));
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message__file::before {
  content: "📎 ";
}

/* Thumbs up / down under agent replies */
.feedback {
  margin-top: 0.55rem;
}

.feedback__bar {
  display: flex;
  gap: 0.25rem;
}

.feedback__btn {
  border: 0;
  background: transparent;
  color: var(--text-primary);
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.feedback__btn svg {
  width: 1.15rem;
  height: 1.15rem;
}

.feedback__btn--dislike svg {
  transform: rotate(180deg);
}

.feedback__btn:hover:not(:disabled) {
  background: var(--accent-soft);
}

.feedback__btn.is-selected {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.feedback__btn:disabled {
  cursor: default;
}

.feedback__btn:disabled:not(.is-selected) {
  opacity: 0.35;
}

.feedback__form {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.feedback__form[hidden] {
  display: none;
}

.feedback__form textarea {
  font: inherit;
  font-size: calc(0.85rem + var(--chat-font-adjust));
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  resize: vertical;
}

.feedback__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.feedback__actions button {
  font: inherit;
  font-size: calc(0.8rem + var(--chat-font-adjust));
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  border: 1px solid var(--accent-dark);
  background: var(--accent-dark);
  color: #fff;
}

.feedback__actions .feedback__skip {
  background: #fff;
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

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

@keyframes pulse {
  0%, 75%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-3px); opacity: 1; }
}

@media (max-width: 640px) {
  .chat-toggle {
    right: calc(0.7rem + var(--launcher-offset-left));
    bottom: calc(0.7rem + var(--launcher-offset-up));
  }

  .chat-toggle--full,
  .chat-toggle--compact {
    padding-right: 0.8rem;
  }

  #chatToggleLabel {
    font-size: calc(0.82rem + var(--chat-font-adjust));
  }

  .chat-panel {
    width: calc(100vw - 1rem - var(--launcher-offset-left));
    right: calc(0.5rem + var(--launcher-offset-left));
    bottom: calc(4.9rem + var(--launcher-offset-up));
    height: min(76vh, 700px);
    border-radius: 10px;
  }

  .chat-toggle--top {
    bottom: auto;
    top: calc(0.7rem + var(--launcher-offset-up));
  }

  .chat-panel--floating.chat-panel--launcher-top {
    bottom: auto;
    top: calc(4.9rem + var(--launcher-offset-up));
  }

  /* On phones the sidecar and the fullscreen window both fill the screen. */
  .chat-panel--sidecar,
  .chat-panel--fullscreen {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: auto;
    border-radius: 0;
    box-shadow: none;
  }

  .chat-panel__resizer {
    display: none;
  }
}
