.terrenate-chat {
  --chat-ink: #102217;
  --chat-muted: #65736c;
  --chat-green: #07543d;
  --chat-green-dark: #053426;
  --chat-mint: #2bee79;
  --chat-bone: #f1f0e8;
  --chat-paper: #fbfcfa;
  --chat-line: #bdcbc3;
  --chat-blue: #315d73;
  --chat-burgundy: #641d35;
  --chat-gold: #d3b66f;
  position: fixed;
  z-index: 170;
  right: 20px;
  bottom: 20px;
  color: var(--chat-ink);
  font-family: var(--body, "Instrument Sans", sans-serif);
}

.terrenate-chat * { box-sizing: border-box; }
.terrenate-chat [hidden] { display: none !important; }

.terrenate-chat-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  padding: 0;
  border: 2px solid white;
  border-radius: 50%;
  color: white;
  background: var(--chat-green);
  box-shadow: 0 0 0 1px var(--chat-green-dark), 0 15px 34px rgba(8, 35, 24, .3);
  cursor: pointer;
  animation: terrenate-chat-launcher-in .45s ease both;
}

.terrenate-chat-launcher::before {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 3px;
  width: 13px;
  height: 13px;
  transform: rotate(25deg);
  border-right: 2px solid white;
  border-bottom: 2px solid white;
  background: var(--chat-green);
}

.terrenate-chat-launcher img { position: relative; z-index: 1; width: 54px; height: 54px; border-radius: 50%; object-fit: cover; object-position: center 24%; background: white; }
.terrenate-chat-notification { position: absolute; z-index: 2; top: -4px; right: -3px; display: grid; place-items: center; width: 20px; height: 20px; border: 2px solid white; border-radius: 50%; color: white; background: var(--chat-burgundy); font-family: var(--mono, monospace); font-size: .55rem; font-weight: 700; }
.terrenate-chat-launcher:focus-visible, .terrenate-chat button:focus-visible, .terrenate-chat textarea:focus-visible, .terrenate-chat a:focus-visible { outline: 3px solid var(--chat-mint); outline-offset: 2px; }

.terrenate-chat-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(410px, calc(100vw - 28px));
  height: min(650px, calc(100dvh - 118px));
  overflow: hidden;
  border: 1px solid var(--chat-green-dark);
  border-top: 4px solid var(--chat-gold);
  border-radius: 7px;
  background: var(--chat-paper);
  box-shadow: 0 28px 70px rgba(8, 35, 24, .34);
  animation: terrenate-chat-panel-in .22s ease both;
}

.terrenate-chat-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 72px; padding: 11px 14px; color: white; background: var(--chat-green-dark); }
.terrenate-chat-identity { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 11px; min-width: 0; }
.terrenate-chat-avatar { position: relative; display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid rgba(255, 255, 255, .62); border-radius: 50%; background: white; }
.terrenate-chat-avatar img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; object-position: center 24%; }
.terrenate-chat-avatar::after { content: ""; position: absolute; right: -1px; bottom: 1px; width: 10px; height: 10px; border: 2px solid var(--chat-green-dark); border-radius: 50%; background: var(--chat-mint); }
.terrenate-chat-identity > span:last-child { display: grid; min-width: 0; }
.terrenate-chat-identity strong { font-family: var(--display, "Bricolage Grotesque", sans-serif); font-size: 1.08rem; }
.terrenate-chat-identity small { margin-top: 1px; color: #c9ded4; font-family: var(--mono, monospace); font-size: .52rem; text-transform: uppercase; }
.terrenate-chat-close { display: grid; place-items: center; flex: 0 0 auto; width: 39px; height: 39px; padding: 0; border: 1px solid rgba(255, 255, 255, .45); border-radius: 50%; color: white; background: transparent; font-size: 1.15rem; cursor: pointer; }
.terrenate-chat-close:hover { color: var(--chat-green-dark); background: white; }

.terrenate-chat-context { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 42px; padding: 8px 14px; border-bottom: 1px solid var(--chat-line); background: var(--chat-bone); }
.terrenate-chat-context span { display: flex; align-items: center; gap: 6px; color: var(--chat-green); font-family: var(--mono, monospace); font-size: .49rem; font-weight: 700; text-transform: uppercase; }
.terrenate-chat-context span i { width: 7px; height: 7px; border-radius: 50%; background: var(--chat-mint); box-shadow: 0 0 0 3px rgba(43, 238, 121, .16); }
.terrenate-chat-context strong { overflow: hidden; color: var(--chat-muted); font-size: .58rem; text-overflow: ellipsis; white-space: nowrap; }

.terrenate-chat-messages { position: relative; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 15px 12px; background: var(--chat-paper); scrollbar-color: #8da398 transparent; scrollbar-width: thin; }
.terrenate-chat-message { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: end; gap: 7px; margin-bottom: 14px; animation: terrenate-chat-message-in .18s ease both; }
.terrenate-chat-message.is-user { display: flex; justify-content: flex-end; }
.terrenate-chat-message-mark { display: grid; place-items: center; width: 28px; height: 28px; margin-bottom: 15px; overflow: hidden; border: 1px solid var(--chat-burgundy); border-radius: 50%; background: white; }
.terrenate-chat-message-mark img { width: 100%; height: 100%; object-fit: cover; object-position: center 24%; }
.terrenate-chat-message-content { display: grid; justify-items: start; min-width: 0; }
.is-user .terrenate-chat-message-content { justify-items: end; }
.terrenate-chat-bubble { max-width: 100%; padding: 11px 12px; border: 1px solid var(--chat-line); border-left: 3px solid var(--chat-blue); border-radius: 3px; color: var(--chat-ink); background: white; font-size: .78rem; line-height: 1.5; white-space: pre-line; }
.is-user .terrenate-chat-bubble { max-width: 88%; border-color: var(--chat-green); border-left-color: var(--chat-green); color: white; background: var(--chat-green); }
.terrenate-chat-message time { margin-top: 4px; color: var(--chat-muted); font-family: var(--mono, monospace); font-size: .45rem; }

.terrenate-chat-actions { display: grid; width: calc(100% - 32px); margin: 2px 0 17px 32px; border-top: 1px solid var(--chat-green); }
.terrenate-chat-action { display: grid; grid-template-columns: 27px minmax(0, 1fr) 18px; align-items: center; gap: 8px; min-height: 43px; padding: 6px 5px; border: 0; border-bottom: 1px solid var(--chat-line); border-radius: 0; color: var(--chat-ink); background: transparent; text-align: left; cursor: pointer; }
.terrenate-chat-action > span { color: var(--chat-blue); font-family: var(--mono, monospace); font-size: .49rem; }
.terrenate-chat-action > strong { overflow-wrap: anywhere; font-size: .7rem; }
.terrenate-chat-action > i { color: var(--chat-green); font-size: .85rem; font-style: normal; text-align: center; }
.terrenate-chat-action:hover { padding-inline: 8px 2px; color: white; background: var(--chat-green); }
.terrenate-chat-action:hover > span, .terrenate-chat-action:hover > i { color: white; }

.terrenate-chat-results { width: calc(100% - 32px); margin: 2px 0 16px 32px; border: 1px solid var(--chat-line); border-top: 0; background: white; animation: terrenate-chat-message-in .2s ease both; }
.terrenate-chat-results > p { margin: 0; padding: 9px 10px; border-top: 3px solid var(--chat-green); border-bottom: 1px solid var(--chat-line); color: var(--chat-muted); background: var(--chat-bone); font-family: var(--mono, monospace); font-size: .48rem; text-transform: uppercase; }
.terrenate-chat-offer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 12px 10px; border-top: 1px solid var(--chat-line); background: white; }
.terrenate-chat-offer:first-of-type { border-top: 0; }
.terrenate-chat-offer-status { grid-column: 1 / -1; width: max-content; margin-bottom: 3px; padding: 2px 5px; color: var(--chat-green); background: #e5f2eb; font-family: var(--mono, monospace); font-size: .43rem; font-weight: 700; text-transform: uppercase; }
.terrenate-chat-offer h3 { grid-column: 1; margin: 0; overflow-wrap: anywhere; font-family: var(--display, sans-serif); font-size: .76rem; line-height: 1.25; }
.terrenate-chat-offer p { grid-column: 1; margin: 0; color: var(--chat-muted); font-size: .59rem; }
.terrenate-chat-offer a { grid-column: 2; grid-row: 2 / span 2; align-self: center; min-height: 32px; padding: 7px 0; color: var(--chat-green); font-size: .61rem; font-weight: 800; text-underline-offset: 3px; }
.terrenate-chat-results-footer { display: flex; justify-content: space-between; gap: 10px; padding: 10px; border-top: 1px solid var(--chat-line); background: #e8efeb; }
.terrenate-chat-results-footer a, .terrenate-chat-results-footer button { padding: 0; border: 0; color: var(--chat-green); background: transparent; font-size: .59rem; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.terrenate-chat-sources { width: calc(100% - 32px); margin: 2px 0 16px 32px; border-top: 2px solid var(--chat-blue); background: #eef3f8; animation: terrenate-chat-message-in .2s ease both; }
.terrenate-chat-sources > p { margin: 0; padding: 8px 10px 5px; color: var(--chat-blue); font-family: var(--mono, monospace); font-size: .47rem; font-weight: 800; text-transform: uppercase; }
.terrenate-chat-sources ul { display: grid; gap: 0; margin: 0; padding: 0 10px 7px; list-style: none; }
.terrenate-chat-sources li { display: grid; gap: 2px; padding: 7px 0; border-top: 1px solid #ccd9e5; }
.terrenate-chat-sources a { color: var(--chat-ink); font-size: .62rem; font-weight: 800; overflow-wrap: anywhere; text-underline-offset: 3px; }
.terrenate-chat-sources span { color: var(--chat-muted); font-size: .5rem; }

.terrenate-chat-typing { display: flex; gap: 4px; width: max-content; margin: 0 0 13px 32px; padding: 10px 12px; border-left: 3px solid var(--chat-blue); background: white; }
.terrenate-chat-typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--chat-muted); animation: terrenate-chat-dot .85s ease-in-out infinite alternate; }
.terrenate-chat-typing i:nth-child(2) { animation-delay: .15s; }
.terrenate-chat-typing i:nth-child(3) { animation-delay: .3s; }

.terrenate-chat-compose { padding: 10px 11px 8px; border-top: 1px solid var(--chat-line); background: white; }
.terrenate-chat-form { display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: end; gap: 8px; }
.terrenate-chat-form textarea { width: 100%; min-height: 44px; max-height: 92px; padding: 11px 12px; resize: none; border: 1px solid #91a79c; border-radius: 4px; color: var(--chat-ink); background: var(--chat-paper); font: .75rem/1.35 var(--body, sans-serif); }
.terrenate-chat-form textarea::placeholder { color: #738179; }
.terrenate-chat-send { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--chat-green-dark); border-radius: 50%; color: white; background: var(--chat-green); font-size: 1rem; font-weight: 800; cursor: pointer; }
.terrenate-chat-send:hover { color: var(--chat-green-dark); background: var(--chat-mint); }
.terrenate-chat-privacy { display: block; margin-top: 5px; color: var(--chat-muted); font-family: var(--mono, monospace); font-size: .44rem; text-align: center; }

@keyframes terrenate-chat-launcher-in {
  from { transform: translateY(12px) scale(.92); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes terrenate-chat-panel-in {
  from { transform: translateY(10px) scale(.985); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes terrenate-chat-message-in {
  from { transform: translateY(5px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes terrenate-chat-dot {
  to { transform: translateY(-3px); opacity: .35; }
}

@media (max-width: 620px) {
  .terrenate-chat { right: 12px; bottom: 14px; }
  body:has(.sticky-cta.is-visible) .terrenate-chat { bottom: 82px; }
  .terrenate-chat-panel { position: fixed; inset: 8px; width: auto; height: auto; }
  .terrenate-chat-launcher { width: 56px; height: 56px; }
  .terrenate-chat-launcher img { width: 48px; height: 48px; }
  .terrenate-chat-head { min-height: 68px; }
  .terrenate-chat-context { min-height: 40px; }
  .terrenate-chat-messages { padding-inline: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .terrenate-chat-launcher, .terrenate-chat-panel, .terrenate-chat-message, .terrenate-chat-results, .terrenate-chat-sources, .terrenate-chat-typing i { animation: none; }
}
