/**
 * Live Chat floating widget styles.
 *
 * Goals: Intercom/Crisp-like polish, CSS-variable theming, a11y focus,
 * responsive + iOS safe areas. No animation libraries.
 *
 * Theme inherits prefers-color-scheme and optional project tokens:
 *   --ic-theme-bg / --ic-theme-text / --ic-theme-primary (if present)
 */

:root {
  /* Public aliases (requested naming) */
  --chat-primary: var(--ic-theme-primary, #0d6efd);
  --chat-background: var(--ic-theme-bg, #ffffff);
  --chat-radius: 20px;
  --chat-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
  --chat-header-height: 76px;

  /* Internal tokens */
  --ic-chat-primary: var(--chat-primary);
  --ic-chat-primary-contrast: #ffffff;
  --ic-chat-surface: var(--chat-background);
  --ic-chat-surface-muted: #f4f6f8;
  --ic-chat-text: var(--ic-theme-text, #1a1d21);
  --ic-chat-text-muted: #6b7280;
  --ic-chat-border: rgba(15, 23, 42, 0.05);
  --ic-chat-shadow: var(--chat-shadow);
  --ic-chat-radius: var(--chat-radius);
  --ic-chat-header-height: var(--chat-header-height);
  --ic-chat-z: 99980;
  --ic-chat-launcher-size: 60px;
  --ic-chat-offset: 24px;
  --ic-chat-offset-mobile: 16px;
  --ic-chat-panel-width: 380px;
  --ic-chat-panel-max-height: min(560px, calc(100dvh - 100px));
  --ic-chat-anim-ms: 220ms;
  --ic-chat-safe-bottom: env(safe-area-inset-bottom, 0px);
  --ic-chat-safe-right: env(safe-area-inset-right, 0px);
  --ic-chat-safe-left: env(safe-area-inset-left, 0px);
  --ic-chat-online: #22c55e;
  --ic-chat-busy: #eab308;
  --ic-chat-offline: #9ca3af;
  --ic-chat-checking: #60a5fa;
  --ic-chat-error: #ef4444;
  --ic-chat-focus-ring: 0 0 0 3px rgba(255, 255, 255, 0.95), 0 0 0 6px var(--ic-chat-primary);
}

@media (prefers-color-scheme: dark) {
  :root {
    --chat-background: var(--ic-theme-bg, #1f2430);
    --chat-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
    --ic-chat-surface: var(--chat-background);
    --ic-chat-surface-muted: #2a3140;
    --ic-chat-text: var(--ic-theme-text, #f3f4f6);
    --ic-chat-text-muted: #9ca3af;
    --ic-chat-border: rgba(255, 255, 255, 0.1);
    --ic-chat-shadow: var(--chat-shadow);
  }
}

/* Project dark-theme class hooks (inherit if site sets these) */
html.dark .ic-chat-root,
html[data-theme="dark"] .ic-chat-root,
body.dark-mode .ic-chat-root,
body.theme-dark .ic-chat-root {
  --chat-background: var(--ic-theme-bg, #1f2430);
  --ic-chat-surface: var(--chat-background);
  --ic-chat-surface-muted: #2a3140;
  --ic-chat-text: var(--ic-theme-text, #f3f4f6);
  --ic-chat-text-muted: #9ca3af;
  --ic-chat-border: rgba(255, 255, 255, 0.1);
  --ic-chat-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}

html.light .ic-chat-root,
html[data-theme="light"] .ic-chat-root,
body.theme-light .ic-chat-root {
  --chat-background: var(--ic-theme-bg, #ffffff);
  --ic-chat-surface: var(--chat-background);
  --ic-chat-surface-muted: #f4f6f8;
  --ic-chat-text: var(--ic-theme-text, #1a1d21);
  --ic-chat-text-muted: #6b7280;
  --ic-chat-border: rgba(15, 23, 42, 0.08);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --ic-chat-anim-ms: 1ms;
  }

  .ic-chat-launcher__pulse,
  .ic-chat-root--pulse .ic-chat-launcher__pulse {
    animation: none !important;
  }

  .ic-chat-skeleton__block {
    animation: none !important;
  }
}

/* ---------- Root shell ---------- */

.ic-chat-root {
  position: fixed;
  right: calc(var(--ic-chat-offset) + var(--ic-chat-safe-right));
  bottom: calc(var(--ic-chat-offset) + var(--ic-chat-safe-bottom));
  left: auto;
  z-index: var(--ic-chat-z);
  font-family: inherit;
  color: var(--ic-chat-text);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none; /* Allow clicks to pass through the empty zones of the invisible panel */
}

.ic-chat-root[data-position="bottom-left"] {
  right: auto;
  left: calc(var(--ic-chat-offset) + var(--ic-chat-safe-left));
  align-items: flex-start;
}

.ic-chat-root *,
.ic-chat-root *::before,
.ic-chat-root *::after {
  box-sizing: border-box;
}

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

.ic-chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Launcher ---------- */

.ic-chat-launcher {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--ic-chat-launcher-size);
  min-width: var(--ic-chat-launcher-size);
  padding: 0 18px 0 8px;
  border-radius: 999px !important;
  background: var(--ic-chat-primary);
  color: var(--ic-chat-primary-contrast);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15) !important;
  transition:
    transform var(--ic-chat-anim-ms) ease,
    box-shadow var(--ic-chat-anim-ms) ease,
    opacity var(--ic-chat-anim-ms) ease,
    background-color var(--ic-chat-anim-ms) ease;
  position: relative;
  z-index: 2;
  isolation: isolate;
  pointer-events: auto; /* Catch clicks on the launcher itself */
}

.ic-chat-launcher:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 18px 40px color-mix(in srgb, var(--ic-chat-primary) 40%, transparent);
}

.ic-chat-launcher:active {
  transform: translateY(-1px) scale(0.98);
}

.ic-chat-launcher:focus {
  outline: none;
}

.ic-chat-launcher:focus-visible {
  box-shadow: var(--ic-chat-focus-ring);
  transform: translateY(-2px);
}

/* Desktop tooltip via data-tooltip (native title also set) */
@media (hover: hover) and (pointer: fine) {
  .ic-chat-launcher::after {
    content: attr(data-tooltip);
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%) translateX(4px);
    background: var(--ic-chat-text);
    color: var(--ic-chat-surface);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    padding: 8px 12px;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  }

  .ic-chat-root[data-position="bottom-left"] .ic-chat-launcher::after {
    right: auto;
    left: calc(100% + 12px);
    transform: translateY(-50%) translateX(-4px);
  }

  .ic-chat-launcher:hover::after,
  .ic-chat-launcher:focus-visible::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }
}

.ic-chat-launcher__pulse {
  display: none;
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--ic-chat-primary);
  z-index: -1;
  pointer-events: none;
}

.ic-chat-root--pulse:not(.is-open) .ic-chat-launcher__pulse {
  display: block;
  animation: ic-chat-pulse 2.4s ease-out infinite;
}

@keyframes ic-chat-pulse {
  0% {
    transform: scale(1);
    opacity: 0.45;
  }
  70% {
    transform: scale(1.35);
    opacity: 0;
  }
  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

.ic-chat-launcher__icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.18);
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.ic-chat-launcher__label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding-right: 4px;
}

.ic-chat-launcher__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  display: none;
}

.ic-chat-launcher__badge.is-visible {
  display: block;
}

/* Hide launcher label/compact when panel is open */
.ic-chat-root.is-open .ic-chat-launcher {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

/* ---------- Panel ---------- */

.ic-chat-panel {
  width: var(--ic-chat-panel-width);
  max-width: calc(100vw - 32px);
  max-height: var(--ic-chat-panel-max-height);
  background: var(--ic-chat-surface);
  border-radius: 20px !important; /* Force premium rounding */
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12) !important; /* Force premium shadow */
  border: 1px solid rgba(15, 23, 42, 0.05) !important; /* Force clean border */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px) scale(0.94);
  transform-origin: bottom right;
  transition:
    opacity var(--ic-chat-anim-ms) ease,
    transform var(--ic-chat-anim-ms) cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear var(--ic-chat-anim-ms);
  z-index: 1;
}

.ic-chat-root[data-position="bottom-left"] .ic-chat-panel {
  transform-origin: bottom left;
}

.ic-chat-root.is-open .ic-chat-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition:
    opacity var(--ic-chat-anim-ms) ease,
    transform var(--ic-chat-anim-ms) cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 0s;
}

.ic-chat-root.is-closing .ic-chat-panel {
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition:
    opacity calc(var(--ic-chat-anim-ms) * 0.85) ease,
    transform calc(var(--ic-chat-anim-ms) * 0.85) ease,
    visibility 0s linear var(--ic-chat-anim-ms);
}

/* ---------- Header ---------- */

.ic-chat-panel__header {
  min-height: var(--ic-chat-header-height);
  padding: 14px 14px 14px 16px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  background: linear-gradient(
    135deg,
    var(--ic-chat-primary) 0%,
    color-mix(in srgb, var(--ic-chat-primary) 82%, #000) 100%
  );
  color: var(--ic-chat-primary-contrast);
}

.ic-chat-panel__avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.35);
  line-height: 1;
  overflow: hidden;
}

.ic-chat-panel__avatar img,
.ic-chat-panel__avatar--image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ic-chat-launcher__avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.ic-chat-panel__powered {
  padding: 8px 16px 12px;
  text-align: center;
  font-size: 11px;
  color: var(--ic-chat-text-muted);
  border-top: 1px solid var(--ic-chat-border);
  background: var(--ic-chat-surface);
}

/* Disable CSS tooltip when admin turns tooltips off */
.ic-chat-root[data-show-tooltip="false"] .ic-chat-launcher::after {
  display: none !important;
}

/* When dark mode support is disabled, ignore prefers-color-scheme overrides */
.ic-chat-root--no-dark {
  --chat-background: var(--chat-bg, #ffffff);
  --ic-chat-surface: var(--chat-bg, #ffffff);
  --ic-chat-surface-muted: #f4f6f8;
  --ic-chat-text: #1a1d21;
  --ic-chat-text-muted: #6b7280;
  --ic-chat-border: rgba(15, 23, 42, 0.08);
}

.ic-chat-panel__heading {
  grid-column: 2;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.ic-chat-panel__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.01em;
  margin-bottom:0px !important;
}

.ic-chat-panel__status {
  margin: 4px 0 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  opacity: 0.98;
}

.ic-chat-panel__status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ic-chat-checking);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
}

.ic-chat-panel__status[data-state="online"] .ic-chat-panel__status-dot {
  background: var(--ic-chat-online);
}

.ic-chat-panel__status[data-state="busy"] .ic-chat-panel__status-dot {
  background: var(--ic-chat-busy);
}

.ic-chat-panel__status[data-state="offline"] .ic-chat-panel__status-dot {
  background: var(--ic-chat-offline);
}

.ic-chat-panel__status[data-state="error"] .ic-chat-panel__status-dot {
  background: var(--ic-chat-error);
}

.ic-chat-panel__status[data-state="checking"] .ic-chat-panel__status-dot {
  animation: ic-chat-dot-pulse 1.2s ease-in-out infinite;
}

@keyframes ic-chat-dot-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.ic-chat-panel__status-detail {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  opacity: 0.88;
}

.ic-chat-panel__close {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.15);
  color: inherit;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 150ms ease, transform 150ms ease;
  align-self: center;
}

.ic-chat-panel__close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.ic-chat-panel__close:focus {
  outline: none;
}

.ic-chat-panel__close:focus-visible {
  box-shadow: var(--ic-chat-focus-ring);
}

/* ---------- Body ---------- */

.ic-chat-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 20px;
  background: var(--ic-chat-surface);
  -webkit-overflow-scrolling: touch;
}

/* ---------- Welcome panel ---------- */

.ic-chat-welcome {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px 4px;
  animation: ic-chat-fade-in var(--ic-chat-anim-ms) ease;
}

.ic-chat-welcome__emoji {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 8px;
}

.ic-chat-welcome__title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--ic-chat-text);
  letter-spacing: -0.01em;
}

.ic-chat-welcome__subtitle {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ic-chat-text);
}

.ic-chat-welcome__message {
  margin: 4px 0 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ic-chat-text-muted);
  max-width: 28ch;
  white-space: pre-line;
}

/* ---------- Help-type / routing groups ---------- */

.ic-chat-groups {
  width: 100%;
  margin: 0 0 14px;
  text-align: left;
}

.ic-chat-groups__label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ic-chat-text-muted);
}

.ic-chat-groups__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 168px;
  overflow-y: auto;
}

.ic-chat-groups__option {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--ic-chat-border, #e2e8f0);
  border-radius: 10px;
  background: var(--ic-chat-surface, #fff);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.ic-chat-groups__option:hover {
  border-color: var(--ic-chat-primary, #2563eb);
}

.ic-chat-groups__option:focus-visible {
  outline: none;
  box-shadow: var(--ic-chat-focus-ring);
}

.ic-chat-groups__option[aria-checked="true"] {
  border-color: var(--ic-chat-primary, #2563eb);
  box-shadow: inset 0 0 0 1px var(--ic-chat-primary, #2563eb);
  background: color-mix(in srgb, var(--ic-chat-primary, #2563eb) 8%, transparent);
}

.ic-chat-groups__swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--ic-chat-group-color, #2563eb);
}

.ic-chat-groups__meta {
  min-width: 0;
  flex: 1 1 auto;
}

.ic-chat-groups__name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ic-chat-text, #0f172a);
}

.ic-chat-groups__desc {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ic-chat-text-muted);
}

/* ---------- Buttons ---------- */

.ic-chat-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 22px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background-color 150ms ease,
    opacity 150ms ease;
}

.ic-chat-btn:focus {
  outline: none;
}

.ic-chat-btn:focus-visible {
  box-shadow: var(--ic-chat-focus-ring);
}

.ic-chat-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.ic-chat-btn--primary {
  background: var(--ic-chat-primary);
  color: var(--ic-chat-primary-contrast);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--ic-chat-primary) 35%, transparent);
  width: 100%;
  max-width: 260px;
}

.ic-chat-btn--primary:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.ic-chat-btn--secondary {
  background: var(--ic-chat-surface-muted);
  color: var(--ic-chat-text);
  border: 1px solid var(--ic-chat-border);
}

.ic-chat-btn--secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ic-chat-surface-muted) 80%, var(--ic-chat-primary) 20%);
}

/* ---------- Skeleton ---------- */

.ic-chat-skeleton {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 8px;
}

.ic-chat-skeleton__block {
  border-radius: 10px;
  background: linear-gradient(
    90deg,
    var(--ic-chat-surface-muted) 0%,
    color-mix(in srgb, var(--ic-chat-surface-muted) 60%, #fff) 50%,
    var(--ic-chat-surface-muted) 100%
  );
  background-size: 200% 100%;
  animation: ic-chat-shimmer 1.2s ease-in-out infinite;
}

.ic-chat-skeleton__block--emoji {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.ic-chat-skeleton__block--title {
  width: 140px;
  height: 22px;
}

.ic-chat-skeleton__block--line {
  width: 220px;
  height: 12px;
}

.ic-chat-skeleton__block--short {
  width: 160px;
}

.ic-chat-skeleton__block--btn {
  width: 200px;
  height: 44px;
  margin-top: 12px;
  border-radius: 12px;
}

@keyframes ic-chat-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

@keyframes ic-chat-fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Error ---------- */

.ic-chat-error {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 8px;
  animation: ic-chat-fade-in var(--ic-chat-anim-ms) ease;
}

.ic-chat-error__icon {
  font-size: 28px;
  margin-bottom: 4px;
}

.ic-chat-error__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ic-chat-text);
}

.ic-chat-error__detail {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ic-chat-text-muted);
  line-height: 1.45;
}

/* View panels: JS toggles [hidden]; flex when visible */
.ic-chat-guest {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 4px;
  animation: ic-chat-fade-in var(--ic-chat-anim-ms) ease;
}

.ic-chat-guest__form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
}

.ic-chat-guest__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ic-chat-text-muted);
  text-align: left;
}

.ic-chat-guest__input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--ic-chat-border);
  background: var(--ic-chat-surface);
  color: var(--ic-chat-text);
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ic-chat-guest__input:focus {
  border-color: var(--ic-chat-primary) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
  outline: none !important;
}

.ic-chat-guest__error {
  margin: 0;
  color: #ef4444;
  font-size: 12px;
  text-align: left;
}

.ic-chat-session {
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  width: 100%;
}

.ic-chat-conv-root {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.ic-chat-conv-root .ic-conv {
  border: 0;
  border-radius: 0;
  height: 100%;
  min-height: 0;
}

.ic-chat-session__meta {
  margin: 0;
  font-size: 11px;
  color: var(--ic-chat-text-muted);
}

.ic-chat-skeleton:not([hidden]),
.ic-chat-welcome:not([hidden]),
.ic-chat-error:not([hidden]),
.ic-chat-guest:not([hidden]),
.ic-chat-session:not([hidden]) {
  display: flex;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .ic-chat-root {
    right: calc(var(--ic-chat-offset-mobile) + var(--ic-chat-safe-right));
    bottom: calc(var(--ic-chat-offset-mobile) + var(--ic-chat-safe-bottom));
  }

  .ic-chat-root[data-position="bottom-left"] {
    left: calc(var(--ic-chat-offset-mobile) + var(--ic-chat-safe-left));
  }

  .ic-chat-panel {
    width: min(380px, calc(100vw - 24px));
    max-height: min(520px, calc(100dvh - 88px - var(--ic-chat-safe-bottom)));
  }

  .ic-chat-launcher__label {
    display: none;
  }

  .ic-chat-launcher {
    padding: 0;
    width: var(--ic-chat-launcher-size);
    justify-content: center;
  }

  .ic-chat-launcher__icon {
    width: 100%;
    height: 100%;
    background: transparent;
  }

  /* No hover tooltips crowding mobile */
  .ic-chat-launcher::after {
    display: none !important;
  }
}

@media (max-width: 420px) {
  .ic-chat-root {
    left: calc(10px + var(--ic-chat-safe-left));
    right: calc(10px + var(--ic-chat-safe-right));
    width: auto;
    align-items: stretch;
  }

  .ic-chat-root[data-position="bottom-left"] {
    left: calc(10px + var(--ic-chat-safe-left));
    right: calc(10px + var(--ic-chat-safe-right));
  }

  .ic-chat-panel {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 84px - var(--ic-chat-safe-bottom));
    border-radius: 14px;
  }

  .ic-chat-launcher {
    align-self: flex-end;
  }

  .ic-chat-root[data-position="bottom-left"] .ic-chat-launcher {
    align-self: flex-start;
  }
}

/* ------------------------------------------------------------------ */
/* Conversation Timeline UI (ConversationEngine mount)                */
/* ------------------------------------------------------------------ */

.ic-chat-session {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  gap: 0;
}

.ic-chat-conv-root {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.ic-chat-conv-root .ic-conv {
  border: 0;
  border-radius: 0;
  min-height: 0;
  height: 100%;
}

.ic-chat-event--right {
  align-self: flex-end;
}

.ic-chat-event--center,
.ic-chat-event--system {
  align-self: center;
  max-width: 95%;
  text-align: center;
}

.ic-chat-bubble__body {
  background: rgba(37, 99, 235, 0.1);
  color: inherit;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
}

.ic-chat-event--right .ic-chat-bubble__body {
  background: var(--ic-chat-primary, #2563eb);
  color: #fff;
}

.ic-chat-system__label {
  font-size: 12px;
  color: #64748b;
  padding: 4px 10px;
  background: rgba(100, 116, 139, 0.12);
  border-radius: 999px;
  display: inline-block;
}

.ic-chat-unread-divider {
  align-self: stretch;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #b91c1c;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 4px 0;
  position: relative;
}

.ic-chat-unread-divider::before,
.ic-chat-unread-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 32%;
  height: 1px;
  background: rgba(185, 28, 28, 0.35);
}

.ic-chat-unread-divider::before {
  left: 0;
}

.ic-chat-unread-divider::after {
  right: 0;
}

.ic-chat-composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex: 0 0 auto;
  padding-top: 4px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.ic-chat-composer__input {
  flex: 1;
  resize: none;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  min-height: 40px;
  max-height: 96px;
  background: #fff;
  color: inherit;
}

.ic-chat-composer__send {
  flex: 0 0 auto;
  white-space: nowrap;
}

.ic-chat-bubble__body--image img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
}

/* Widget-specific composer alignment (ConversationEngine Composer) */
.ic-chat-conv-root .ic-comp__form {
  align-items: end;
}

.ic-chat-conv-root .ic-comp__attach,
.ic-chat-conv-root .ic-comp__send {
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
}

.ic-chat-conv-root .ic-comp__input {
  min-height: 2.5rem;
}

/* Template layout alignment overrides */
#back-to-top {
  bottom: 100px !important;
  right: 36px !important;
  transition: bottom 0.2s ease, right 0.2s ease, opacity 0.2s ease, background-color 0.2s ease !important;
}

.ic-chat-panel__heading h2,.ic-chat-panel__status,.ic-chat-panel__status-detail {
  color : #fff !important;
}

/* AppConfirm-compatible overlay (pages without custom.css / common.js) */
.app-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  animation: ic-chat-confirm-fade-in 0.2s ease;
}

.app-confirm-box {
  width: min(420px, calc(100vw - 32px));
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
  padding: 24px;
  font-family: system-ui, -apple-system, sans-serif;
  color: #0f172a;
}

.app-confirm-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.app-confirm-message {
  font-size: 14px;
  color: #555;
  margin-bottom: 20px;
  line-height: 1.45;
}

.app-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.app-confirm-overlay .app-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
}

.app-confirm-overlay .app-btn-cancel {
  background: #eee;
  color: #111;
}

.app-confirm-overlay .app-btn-confirm {
  background: #2563eb;
  color: #fff;
}

@keyframes ic-chat-confirm-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
