:root {
  --cm-red: #ed1b34;
  --cm-red-dark: #c9162c;
  --cm-black: #171717;
  --cm-white: #ffffff;
  --cm-border: #e2e2e2;
  --cm-text: #202020;
  --cm-muted: #666666;
}

* { box-sizing: border-box; }

body {
  font-family: Arial, sans-serif;
  padding: 40px;
  margin: 0;
  background: #fafafa;
}

#chatButton {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--cm-red);
  color: white;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0,0,0,.28);
  z-index: 9997;
}

#chatButton:hover {
  background: var(--cm-red-dark);
  transform: translateY(-1px);
}

#chatBox {
  position: fixed;
  right: 20px;
  bottom: 90px;
  width: 410px;
  height: 620px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 110px);
  border-radius: 20px;
  background: var(--cm-white);
  box-shadow: 0 12px 38px rgba(0,0,0,.30);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #2b2b2b;
  z-index: 9998;
}

#chatHeader {
  position: relative;
  background: var(--cm-black);
  color: white;
  padding: 18px 18px 18px 22px;
  font-weight: bold;
  font-size: 18px;
  min-height: 86px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
}

#chatHeader::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 78%;
  height: 100%;
  background: var(--cm-red);
  clip-path: polygon(0 0, 88% 0, 68% 100%, 0% 100%);
  z-index: 0;
}

.agentProfile {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
}

.agentPhoto {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid white;
  flex-shrink: 0;
}

.agentInfo {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.agentName {
  font-size: 18px;
  font-weight: 700;
  color: white;
}

.agentRole {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 400;
  color: white;
  opacity: 0.95;
}

#closeBtn {
  position: relative;
  z-index: 2;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 44px;
  height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .2s ease;
}

#closeBtn:hover { background: rgba(255,255,255,0.14); }

#messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: linear-gradient(180deg, #ffffff 0%, #f6f6f6 100%);
  font-size: 14px;
}

.msg {
  max-width: 88%;
  padding: 12px 14px;
  margin: 9px 0;
  border-radius: 18px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}

.user {
  background: var(--cm-red);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 5px;
  border: 1px solid var(--cm-red);
}

.bot {
  background: var(--cm-white);
  color: var(--cm-text);
  margin-right: auto;
  border-bottom-left-radius: 5px;
  border: 1px solid var(--cm-border);
}

.optionWrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0 16px 0;
  max-width: 100%;
}

.choiceBtn {
  width: 100%;
  text-align: left;
  border: 1.5px solid var(--cm-red);
  background: white;
  color: var(--cm-text);
  border-radius: 14px;
  padding: 13px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all .18s ease;
}

/* U+27BA DRAFTING POINT RIGHTWARDS ARROW, written as a CSS escape rather than
   the literal glyph so it survives any editor or pipeline that is careless
   about encoding - which is exactly how it reached this repo mangled, as
   "\00E2\00BA". Same for U+27A4 on the send button below. */
.choiceBtn::after {
  content: "\27BA";
  color: var(--cm-black);
  font-size: 24px;
  line-height: 1;
  font-weight: 700;
}

.choiceBtn:hover {
  background: #fff5f6;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(237, 27, 52, .12);
}

.choiceBtn.selected {
  background: var(--cm-red);
  color: white;
}

.choiceBtn.selected::after {
  color: white;
}

.choiceBtn:disabled {
  opacity: .75;
  cursor: default;
  transform: none;
}

.helperText {
  font-size: 12px;
  color: var(--cm-muted);
  margin: 0 0 8px 2px;
}

#inputArea {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--cm-border);
  background: white;
  min-height: 62px;
  padding: 10px;
  gap: 8px;
  position: relative;
  z-index: 10000;
}

#msg {
  flex: 1;
  min-width: 0;
  padding: 14px 14px;
  border: 1px solid var(--cm-border);
  outline: none;
  font-size: 14px;
  border-radius: 14px;
  background: white;
}

#msg:focus {
  border-color: var(--cm-red);
  box-shadow: 0 0 0 3px rgba(237,27,52,.10);
}

mapbox-address-autofill {
  flex: 1;
  min-width: 0;
  display: block;
  position: relative;
  z-index: 10000;
}

mapbox-address-autofill #msg {
  width: 100%;
}

mapbox-search-listbox {
  position: fixed !important;
  z-index: 20000 !important;
}

#imagePreviewBar {
  display: none;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px;
  background: white;
  border-top: 1px solid var(--cm-border);
  scrollbar-width: thin;
}

.imagePreviewItem {
  position: relative;
  flex: 0 0 auto;
  width: 74px;
  height: 74px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--cm-border);
  background: #f4f4f4;
}

.imagePreviewItem img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.imagePreviewRemove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.72);
  color: white;
  cursor: pointer;
  font-size: 14px;
  line-height: 22px;
  padding: 0;
}

#files { display: none; }

#uploadBtn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  background: white;
  border: 1px solid var(--cm-border);
  border-radius: 14px;
  color: var(--cm-red);
}

#uploadBtn:hover { background: #fff5f6; }

#sendBtn {
  height: 44px;
  min-width: 54px;
  padding: 0 16px;
  border: none;
  border-radius: 14px;
  background: var(--cm-red);
  color: white;
  cursor: pointer;
  font-weight: bold;
  font-size: 0;
}

#sendBtn::before {
  content: "\27A4";
  font-size: 18px;
}

#sendBtn:hover {
  background: var(--cm-red-dark);
}

#sendBtn:disabled {
  background: #d9d9d9;
  cursor: default;
}

.poweredBy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-align: center;
  font-size: 12px;
  color: #777;
  padding: 0 0 12px 0;
  background: white;
}

.poweredBy svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  flex: 0 0 auto;
}

.poweredBy strong {
  color: var(--cm-red);
  font-weight: 700;
}

.typingBubble {
  width: fit-content;
  min-width: 58px;
  padding: 13px 16px;
}

.typingDots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.typingDots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #888;
  animation: cmTypingBounce 1.2s infinite;
}

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

.typingDots span:nth-child(3) {
  animation-delay: .4s;
}

@keyframes cmTypingBounce {
  0%, 80%, 100% {
    transform: scale(0.75);
    opacity: .45;
  }

  40% {
    transform: scale(1.15);
    opacity: 1;
  }
}

@media (max-width: 600px) {
  body { padding: 0; }

  #chatBox {
    right: 0;
    bottom: 0;
    top: env(safe-area-inset-top);
    left: 0;
    width: 100vw;
    height: calc(100dvh - env(safe-area-inset-top));
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }

  #chatHeader {
    min-height: 88px;
    padding: calc(env(safe-area-inset-top) + 12px) 16px 14px 18px;
  }

  #messages {
    font-size: 15px;
    padding: 14px;
    padding-bottom: 16px;
  }

  .msg {
    max-width: 90%;
    font-size: 15px;
  }

  .choiceBtn {
    font-size: 15px;
    padding: 14px 16px;
  }

  #inputArea {
    min-height: 66px;
    padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
  }

  #msg {
    font-size: 16px;
  }

  #chatButton {
    right: 16px;
    bottom: 16px;
  }
}
