:root {
  --chatfos-brand: #124a72;
  --chatfos-button-text: #ffffff;
  --chatfos-panel-bg: #ffffff;
  --chatfos-assistant-bg: #ffffff;
  --chatfos-assistant-text: #111827;
  --chatfos-user-bg: #124a72;
  --chatfos-user-text: #ffffff;
  --chatfos-shadow: 0 16px 44px rgba(0, 0, 0, .16);
  --chatfos-kb-offset: 0px;
  --chatfos-vv-height: 100vh;
  --chatfos-fab-offset: 84px;
}

#chatfos-root {
  position: fixed;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--chatfos-kb-offset, 0px));
  z-index: 2147483646;
  font-family: inherit;
  line-height: 1.45;
}

#chatfos-root:not(.chatfos-ready) {
  display: none;
}

#chatfos-fab {
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 18px;
  background: var(--chatfos-brand);
  color: var(--chatfos-button-text);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--chatfos-shadow);
  cursor: pointer;
  padding: 0;
}

#chatfos-fab svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

#chatfos-fab .chatfos-fab-img {
  display: none;
  max-width: 95px;
  max-height: 90px;
  width: auto;
  height: auto;
  object-fit: contain;
}

#chatfos-fab.chatfos-fab--img {
  width: auto;
  height: auto;
  min-width: 54px;
  min-height: 54px;
  background: transparent;
  box-shadow: none;
}

#chatfos-fab.chatfos-fab--img-ready svg {
  display: none;
}

#chatfos-fab.chatfos-fab--img-ready .chatfos-fab-img {
  display: block;
  filter: drop-shadow(0 16px 44px rgba(0, 0, 0, .16));
}

#chatfos-panel {
  position: fixed;
  left: 16px;
  bottom: calc(var(--chatfos-fab-offset, 84px) + env(safe-area-inset-bottom, 0px) + var(--chatfos-kb-offset, 0px));
  width: min(380px, calc(100vw - 32px));
  height: 420px;
  max-height: calc(var(--chatfos-vv-height, 100vh) - 120px);
  background: var(--chatfos-panel-bg);
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 16px;
  box-shadow: var(--chatfos-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#chatfos-panel[aria-hidden="true"] {
  display: none;
}

.chatfos-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, .08);
}

.chatfos-hd-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.chatfos-title {
  font-weight: 800;
  font-size: 14px;
  color: var(--chatfos-assistant-text);
}

.chatfos-subtitle {
  font-size: 13px;
  line-height: 1.4;
  color: #4b5563;
}

.chatfos-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: rgba(0, 0, 0, .06);
  color: var(--chatfos-assistant-text);
  cursor: pointer;
  font-size: 18px;
  line-height: 36px;
  padding: 0;
  flex: 0 0 auto;
}

.chatfos-messages {
  flex: 1 1 auto;
  min-height: 160px;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.chatfos-msg {
  display: flex;
}

.chatfos-msg--assistant {
  justify-content: flex-start;
}

.chatfos-msg--user {
  justify-content: flex-end;
}

.chatfos-bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, .06);
  background: var(--chatfos-assistant-bg);
  color: var(--chatfos-assistant-text);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.chatfos-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chatfos-msg--user .chatfos-bubble {
  background: var(--chatfos-user-bg);
  border-color: transparent;
  color: var(--chatfos-user-text);
}

.chatfos-bubble--typing {
  opacity: .8;
}

.chatfos-form {
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(0, 0, 0, .08);
}

.chatfos-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#chatfos-input {
  flex: 1 1 auto;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, .18);
  background: #fff;
  color: #111827;
  outline: none;
  font: inherit;
}

#chatfos-input:focus {
  border-color: var(--chatfos-brand);
  box-shadow: 0 0 0 2px rgba(18, 74, 114, .18);
}

.chatfos-send {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--chatfos-brand);
  color: var(--chatfos-button-text);
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
  font: inherit;
}

.chatfos-send:disabled {
  cursor: wait;
  opacity: .7;
}

.chatfos-hint {
  margin-top: 6px;
  font-size: 12px;
  text-align: right;
  color: #64748b;
}

.chatfos-hint.is-error {
  color: #a00000;
}

@media (max-width: 480px) {
  #chatfos-root {
    left: 12px;
    right: auto;
  }

  #chatfos-panel {
    width: min(360px, calc(100vw - 24px));
    left: 12px;
    right: auto;
  }
}
