.support-chat {
  --support-gap: 24px;
  position: fixed;
  right: max(var(--support-gap), env(safe-area-inset-right, 0px));
  bottom: calc(max(var(--support-gap), env(safe-area-inset-bottom, 0px)) + var(--mobile-viewport-bottom, 0px));
  z-index: 45;
  color: var(--ui-text);
  font-family: inherit;
}

.support-chat [hidden], .support-chat[hidden] { display: none !important; }
.support-chat button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.support-chat button:disabled { cursor: default; }
.support-chat button:focus-visible, .support-chat-scroll:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 3px;
}

.support-chat-launcher {
  position: relative;
  top: 0;
  transition: top 180ms ease;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: var(--ui-button-radius, 12px);
  background: transparent;
  color: inherit;
}
.support-chat-launcher .support-chat-avatar { width: calc(100% - 4px); height: calc(100% - 4px); padding: 1.5px; box-shadow: 0 4px 16px #70266c1f, 0 1px 3px #24102c12; }
/* Move with relative positioning to avoid rerasterizing the thin ring in a transform layer. */
.support-chat-launcher .support-chat-avatar img { border-width: 4px; }
@media (hover: hover) and (pointer: fine) {
  .support-chat-launcher:hover { top: -3px; }
  .support-chat-launcher:active { top: -1px; }
}
.support-chat-launcher-status { position: absolute; right: 0; bottom: 0; width: 20px; height: 20px; border: 4px solid var(--ui-canvas); border-radius: 50%; background: var(--ui-online); }
.support-chat-unread { position: absolute; top: -3px; right: -4px; display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border: 3px solid var(--ui-canvas); border-radius: calc(var(--ui-notification-radius, 6px) + 3px); background: var(--ui-notification); color: var(--ui-on-notification); font-size: 10px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; box-sizing: border-box; }
.support-chat-notification { position: absolute; right: 0; bottom: calc(100% + 12px); width: min(312px, calc(100vw - 48px)); border: 1px solid var(--ui-border); border-radius: 18px; background: var(--ui-surface); box-shadow: 0 12px 42px -12px rgb(0 0 0 / .2); animation: support-chat-enter 180ms ease-out; transform-origin: bottom right; }
.support-chat-notification-open { display: flex; flex-direction: column; gap: 7px; width: 100%; padding: 18px 40px 17px 18px; border: 0; border-radius: var(--ui-button-radius, 12px); background: transparent; color: var(--ui-text); text-align: left; }
.support-chat-notification-label { color: var(--ui-text-secondary); font-size: 10px; font-weight: 600; line-height: 1.5; }
.support-chat-notification-body { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 13px; font-weight: 550; line-height: 1.55; overflow-wrap: anywhere; }
.support-chat-notification-cta { display: flex; align-items: center; gap: 5px; margin-top: 3px; color: var(--campus-accent, var(--ui-accent)); font-size: 11px; font-weight: 600; line-height: 1.4; }
.support-chat-notification-cta .icon { width: 13px; height: 13px; transition: transform 150ms ease; }
.support-chat-notification-open:hover .support-chat-notification-cta .icon { transform: translateX(3px); }
.support-chat-notification-dismiss { position: absolute; top: 6px; right: 6px; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: var(--ui-button-radius, 12px); background: transparent; color: var(--ui-text-muted); }
.support-chat-notification-dismiss:hover { background: var(--ui-surface-hover); color: var(--ui-text); }
.support-chat-notification-dismiss .icon { width: 14px; height: 14px; }

.support-chat-panel {
  display: flex;
  flex-direction: column;
  width: 384px;
  height: 526px;
  max-height: calc(var(--mobile-viewport-height, 100dvh) - 48px - env(safe-area-inset-top, 0px));
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--ui-border) 65%, transparent);
  border-radius: 24px;
  background: var(--ui-surface);
  box-shadow: 0 18px 70px #24102c24, 0 4px 18px #24102c0a;
  animation: support-chat-enter 180ms ease-out;
  transform-origin: bottom right;
}
/* Light overlays stay distinct from the white dashboard. Keep dark elevation
   and system high-contrast colors under their existing theme rules. */
@media (forced-colors: none) {
  html:not([data-theme="dark"]) :is(.support-chat-panel, .support-chat-notification) {
    border-color: var(--ui-border-floating);
    background: var(--ui-surface-floating);
    box-shadow: var(--ui-shadow-floating);
  }
}
.support-chat-header {
  display: flex;
  align-items: center;
  flex: none;
  gap: 12px;
  padding: 22px 18px 20px 22px;
  background: linear-gradient(130deg, color-mix(in srgb, var(--ui-accent-soft) 75%, var(--ui-surface)), var(--ui-surface) 90%);
}
.support-chat-avatar {
  --support-avatar-ring: linear-gradient(145deg, #8b47ed 5%, #cf38c4 47%, #fa8a53 82%, #f4b76a 100%);
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 1.5px;
  border-radius: 50%;
  background: var(--support-avatar-ring);
}
/* Portrait spacing and badge cutouts match the page canvas, not the raised chat. */
.support-chat-avatar img { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; border: 1.5px solid var(--ui-canvas); border-radius: 50%; object-fit: cover; object-position: center; }
/* Rounded mask boxes draw the same smooth 1.5px story ring in both themes.
   Portrait spacing and the status border retain the page canvas color. */
@supports (mask-composite: exclude) or (-webkit-mask-composite: xor) {
  @media (forced-colors: none) {
    html .support-chat-avatar { position: relative; background: transparent; }
    html .support-chat-avatar::before {
      content: "";
      position: absolute;
      inset: 0;
      box-sizing: border-box;
      padding: 1.5px;
      border-radius: inherit;
      background: var(--support-avatar-ring);
      pointer-events: none;
      -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0) border-box;
      -webkit-mask-composite: xor;
      mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0) border-box;
      mask-composite: exclude;
    }
  }
}
.support-chat-identity { min-width: 0; flex: 1; }
.support-chat-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 5px 10px; margin-bottom: 3px; }
.support-chat-identity h2 { margin: 0; color: var(--ui-text); font-size: 16px; font-weight: 650; line-height: 1.3; letter-spacing: -.3px; }
.support-chat-identity p { margin: 0; color: var(--ui-text-secondary); font-size: 12px; line-height: 1.4; }
.support-chat-status { display: inline-flex; align-items: center; gap: 5px; color: var(--ui-online-text); font-size: 11px; line-height: 1.4; }
.support-chat-status > span { width: 8px; height: 8px; border-radius: 50%; background: var(--ui-online); }
.support-chat-close {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--ui-button-radius, 12px);
  background: transparent;
  color: var(--ui-text-secondary);
  transition: background 150ms ease, color 150ms ease;
}
.support-chat-close:hover { background: var(--ui-accent-soft); color: var(--campus-accent, var(--ui-accent)); }
.support-chat-scroll { min-height: 0; flex: 1; padding: 12px 20px 18px; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--ui-border-strong) transparent; }
.support-chat-intro { display: flex; flex-direction: column; align-items: center; padding: 36px 8px 28px; text-align: center; }
.support-chat-intro-icon { display: grid; place-items: center; width: 54px; height: 54px; margin-bottom: 18px; border-radius: 18px; background: var(--ui-accent-soft); color: var(--campus-accent, var(--ui-accent)); transform: rotate(-6deg); }
.support-chat-intro-icon .icon { width: 25px; height: 25px; transform: rotate(6deg); }
.support-chat-intro h3 { margin: 0 0 9px; font-size: 17px; font-weight: 600; letter-spacing: -.35px; line-height: 1.4; }
.support-chat-intro p { max-width: 260px; margin: 0; color: var(--ui-text-secondary); font-size: 13px; line-height: 1.7; }
.support-chat-messages { display: flex; flex-direction: column; gap: 18px; }
.support-chat-message { align-self: flex-start; max-width: 88%; min-width: 0; }
.support-chat-message.is-mine { align-self: flex-end; }
.support-chat-bubble { margin: 0; padding: 12px 15px; border-radius: 16px 16px 16px 5px; background: var(--ui-surface-muted); color: var(--ui-text); font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.support-chat-message.is-mine .support-chat-bubble { border-radius: 16px 16px 5px 16px; background: var(--ui-accent-soft); color: var(--campus-accent, var(--ui-accent)); }
.support-chat-message-meta { display: flex; flex-wrap: wrap; gap: 7px; margin: 6px 3px 0; color: var(--ui-text-muted); font-size: 10px; line-height: 1.5; }
.support-chat-message.is-mine .support-chat-message-meta { justify-content: flex-end; }
.support-chat-history-control { padding: 0 0 20px; text-align: center; }
.support-chat-text-button { padding: 7px 10px; border: 0; border-radius: var(--ui-button-radius, 12px); background: transparent; color: var(--campus-accent, var(--ui-accent)); font-size: 12px !important; font-weight: 550 !important; }
.support-chat-text-button:hover { background: var(--ui-accent-soft); }
.support-chat-text-button:disabled { opacity: .6; }
.support-chat-older-error { margin: 5px 0 0; color: var(--ui-text-secondary); font-size: 12px; line-height: 1.5; }
.support-chat-load-state { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 8px; color: var(--ui-text-secondary); font-size: 12px; line-height: 1.6; text-align: center; }
.support-chat-latest { display: flex; align-items: center; justify-content: center; align-self: center; flex: none; gap: 6px; margin: -7px 0 4px; padding: 7px 12px; border: 0; border-radius: var(--ui-button-radius, 12px); background: var(--ui-accent-soft); color: var(--campus-accent, var(--ui-accent)); font-size: 11px !important; }
.support-chat-latest .icon { width: 13px; height: 13px; }
.support-chat-form { flex: none; padding: 10px 18px 18px; margin: 0; }
.support-chat-composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px; border: 1px solid transparent; border-radius: 16px; background: var(--ui-surface-muted); transition: border-color 150ms ease, box-shadow 150ms ease; }
.support-chat-composer:focus-within { border-color: color-mix(in srgb, var(--ui-accent) 35%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ui-accent-soft) 60%, transparent); }
.support-chat-composer textarea { display: block; flex: 1; min-width: 0; min-height: 36px; max-height: 112px; padding: 8px 4px 7px 6px; border: 0; border-radius: 0; outline: 0; background: transparent; color: var(--ui-text); font: inherit; font-size: 13px; line-height: 21px; resize: none; scrollbar-width: thin; }
.support-chat-composer textarea::placeholder { color: var(--ui-text-muted); opacity: 1; }
.support-chat-send { display: grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0; border: 0; border-radius: var(--ui-button-radius, 12px); background: var(--campus-accent, var(--ui-accent)); color: #fff; transition: background 150ms ease, transform 150ms ease; }
.support-chat-send .icon { width: 19px; height: 19px; }
.support-chat-send:hover:not(:disabled) { transform: translateY(-1px); background: #ad2cc7; }
.support-chat-send:disabled { background: var(--ui-accent-soft); color: color-mix(in srgb, var(--campus-accent, var(--ui-accent)) 40%, var(--ui-surface)); }
.support-chat-send.is-sending .icon { animation: support-chat-sending 900ms ease-in-out infinite alternate; }
.support-chat-composer-meta { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 8px 3px 0; color: var(--ui-text-muted); font-size: 11px; line-height: 1.5; }
.support-chat-composer-meta p { margin: 0; }
.support-chat-composer-meta.has-error p { color: var(--ui-danger); }
.support-chat-count { flex: none; font-variant-numeric: tabular-nums; }
html[data-theme='dark'] .support-chat-panel { background: var(--ui-surface-floating); box-shadow: none; }
html[data-theme='dark'] .support-chat-send:not(:disabled) { background: #b633d6; }

@keyframes support-chat-enter { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes support-chat-sending { from { opacity: .45; transform: translateY(2px); } to { opacity: 1; transform: translateY(-2px); } }

@media (max-width: 760px) {
  .support-chat { --support-gap: 12px; --support-navigation-space: var(--campus-bottom-nav, 68px); bottom: calc(var(--support-navigation-space) + 12px + var(--mobile-viewport-bottom, 0px)); }
  .support-chat-launcher { width: 54px; height: 54px; }
  .support-chat-panel { width: min(384px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))); height: 510px; max-height: calc(var(--mobile-viewport-height, 100dvh) - var(--support-navigation-space) - 28px - env(safe-area-inset-top, 0px)); border-radius: 22px; }
  .support-chat-header { padding: 17px 15px 17px 19px; }
  .support-chat-scroll { padding: 10px 16px 16px; }
  .support-chat-form { padding: 8px 13px 13px; }
  .support-chat-composer textarea { font-size: 16px; }
  .support-chat-intro { padding-top: 28px; }
}

@media (max-height: 520px) {
  .support-chat-header { padding-top: 10px; padding-bottom: 10px; }
  .support-chat-header .support-chat-avatar { width: 36px; height: 36px; }
  .support-chat-intro { padding: 14px 8px; }
  .support-chat-intro-icon { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .support-chat *, .support-chat *::before, .support-chat *::after { animation: none !important; transition: none !important; }
}

@media (forced-colors: active) {
  .support-chat-avatar img, .support-chat-launcher-status { border-color: Canvas; }
  .support-chat-unread { background: Highlight; color: HighlightText; border-color: Canvas; forced-color-adjust: none; }
  .support-chat-notification { background: Canvas; color: CanvasText; border-color: CanvasText; box-shadow: none; }
}

