.cb-chat-root {
  --chat-navy: #0c1a34;
  --chat-navy-deep: #071124;
  --chat-blue: #2563eb;
  --chat-cyan: #22d3ee;
  --chat-bg: #f4f7fb;
  --chat-surface: #ffffff;
  --chat-text: #0a1628;
  --chat-muted: #64748b;
  --chat-border: rgba(10, 22, 40, 0.12);
  --chat-shadow: 0 18px 48px rgba(7, 17, 36, 0.22);

  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  color: var(--chat-text);
}

.chat-launcher {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 9998;
  width: 72px;
  height: 72px;
  padding: 4px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--chat-navy);
  box-shadow: 0 12px 32px rgba(7, 17, 36, 0.28);
  cursor: pointer;
  isolation: isolate;
}

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

.chat-launcher-badge {
  position: absolute;
  right: -5px;
  bottom: -5px;
  z-index: 1;
  padding: 4px 8px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--chat-cyan), var(--chat-blue));
  color: #061426;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.02em;
}

.chat-panel[hidden],
.chat-launcher[hidden] {
  display: none;
}

.chat-panel {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 9999;
  width: min(430px, calc(100vw - 28px));
  height: min(680px, calc(100dvh - 36px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  background: var(--chat-surface);
  box-shadow: var(--chat-shadow);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 78px;
  padding: 14px 16px 14px 18px;
  background: var(--chat-navy);
  color: #fff;
}

.chat-brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

.chat-brand-logo {
  display: block;
  width: min(178px, 48vw);
  max-height: 46px;
  object-fit: contain;
  object-position: left center;
}

.chat-brand-fallback strong,
.chat-brand-fallback small {
  display: block;
}

.chat-brand-fallback small {
  margin-top: 2px;
  color: #c4d2e8;
  font-size: 12px;
}

.chat-close {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
}

.chat-close:hover {
  background: rgba(255,255,255,.14);
}

.chat-context {
  padding: 9px 16px;
  border-bottom: 1px solid var(--chat-border);
  background: #edf3fa;
  color: #4b5e78;
  font-size: 12px;
  font-weight: 650;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: var(--chat-bg);
}

.chat-message {
  max-width: 88%;
  margin: 0 0 12px;
  padding: 11px 13px;
  border-radius: 12px;
  line-height: 1.48;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-message.assistant {
  border: 1px solid var(--chat-border);
  background: #fff;
}

.chat-message.user {
  margin-left: auto;
  background: linear-gradient(135deg, var(--chat-cyan), var(--chat-blue));
  color: #061426;
  font-weight: 540;
}

.chat-message.pending {
  color: #667386;
}

.chat-message.error {
  border-color: #e6b7b2;
  color: #8d2923;
  background: #fff8f7;
}

.chat-message.summary {
  max-width: 100%;
  border-left: 4px solid var(--chat-cyan);
  background: #fff;
}

.chat-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px 0 16px;
}

.chat-choices button,
.chat-confirmation button {
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--chat-blue);
  border-radius: 12px;
  background: #fff;
  color: #15335e;
  text-align: left;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
  transition: background-color .16s ease, transform .16s ease, box-shadow .16s ease;
}

.chat-choices button:hover,
.chat-confirmation button:hover {
  background: #eaf2ff;
}

.chat-choices button:active,
.chat-confirmation button:active {
  transform: translateY(1px);
}

.chat-choices button:disabled {
  opacity: 0.52;
  cursor: wait;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--chat-border);
  background: #fff;
}

.chat-input {
  flex: 1;
  min-width: 0;
  max-height: 110px;
  padding: 11px 12px;
  border: 1px solid #a9b8cc;
  border-radius: 12px;
  resize: vertical;
  font: inherit;
  font-size: 16px;
  color: var(--chat-text);
}

.chat-send {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chat-cyan), var(--chat-blue));
  color: #061426;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.chat-send:disabled {
  opacity: 0.55;
  cursor: wait;
}

.chat-note {
  padding: 0 12px 11px;
  background: #fff;
  text-align: center;
  color: var(--chat-muted);
  font-size: 11px;
  line-height: 1.4;
}

.chat-confirmation {
  margin: 4px 0 16px;
  padding: 13px;
  border: 1px solid #b6c8df;
  border-radius: 12px;
  background: #eef4fb;
  font-size: 0.84rem;
}

.chat-confirmation p {
  margin: 0 0 10px;
  line-height: 1.45;
}

.chat-confirmation div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-confirmation .chat-confirm-send {
  border-color: transparent;
  background: linear-gradient(135deg, var(--chat-cyan), var(--chat-blue));
  color: #061426;
}

.chat-confirmation .chat-confirm-edit {
  border-color: #76869b;
}

.chat-launcher:focus-visible,
.chat-close:focus-visible,
.chat-send:focus-visible,
.chat-choices button:focus-visible,
.chat-confirmation button:focus-visible,
.chat-input:focus-visible {
  outline: 3px solid var(--chat-cyan);
  outline-offset: 2px;
}

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

@media (max-width: 520px) {
  .chat-panel {
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .chat-brand-logo {
    width: min(168px, 52vw);
  }

  .chat-choices {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 360px) {
  .chat-header {
    padding-inline: 13px;
  }

  .chat-brand-logo {
    width: 145px;
  }

  .chat-send {
    padding-inline: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-choices button,
  .chat-confirmation button {
    transition: none;
  }
}
