:root {
  --bg: #dfe9e1;
  --bg-accent: #c9d8cb;
  --card: rgba(247, 251, 248, 0.88);
  --card-strong: #fdfefd;
  --line: rgba(30, 71, 52, 0.14);
  --text: #15241c;
  --muted: #5c7267;
  --green: #1f5a43;
  --green-deep: #123c2c;
  --gold: #c69b58;
  --gold-deep: #a57c3f;
  --assistant: #e3efe7;
  --user: #173f30;
  --user-text: #f4fbf7;
  --shadow: 0 24px 80px rgba(18, 60, 44, 0.18);
  --radius-xl: 32px;
  --radius-lg: 22px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.8), transparent 30%),
    radial-gradient(circle at top right, rgba(31, 90, 67, 0.18), transparent 22%),
    radial-gradient(circle at bottom right, rgba(198, 155, 88, 0.14), transparent 24%),
    linear-gradient(160deg, var(--bg) 0%, #c8d9cb 100%);
}

.widget-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  padding: 16px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  overflow: hidden;
}

.chat-launcher {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--green), var(--green-deep));
  color: white;
  font: inherit;
  font-weight: 700;
  box-shadow: 0 18px 40px rgba(18, 60, 44, 0.28);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.chat-launcher:hover,
.chat-launcher:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 22px 46px rgba(18, 60, 44, 0.33);
}

.chat-launcher-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.chat-launcher-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.chat-launcher-label {
  white-space: nowrap;
}

.chat-card {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  width: min(380px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 32px));
  background: var(--card);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

.widget-shell-closed .chat-card {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px) scale(0.96);
}

.widget-shell-open .chat-card {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.widget-shell-open .chat-launcher {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(250, 253, 251, 0.96), rgba(239, 247, 242, 0.8));
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--green), var(--green-deep));
  color: white;
  font-family: "Outfit", sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(18, 60, 44, 0.3);
}

.brand-copy {
  flex: 1;
  min-width: 0;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.send-button {
  border: 0;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.icon-button {
  background: rgba(18, 60, 44, 0.07);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  font-size: 1.25rem;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible,
.send-button:hover,
.send-button:focus-visible {
  transform: translateY(-1px);
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 10px 12px 10px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chat-thread::-webkit-scrollbar {
  display: none;
}

.message {
  display: flex;
  animation: rise-in 260ms ease;
}

.message-assistant {
  justify-content: flex-start;
}

.message-user {
  justify-content: flex-end;
}

.message-bubble {
  display: inline-block;
  max-width: 88%;
  padding: 11px 13px;
  border-radius: var(--radius-md);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: start;
  unicode-bidi: plaintext;
  font-size: 0.94rem;
}

.message-assistant .message-bubble {
  background: var(--assistant);
  color: var(--text);
  border-bottom-left-radius: 8px;
  direction: ltr;
}

.chat-thread > .message:first-child .message-bubble {
  max-width: 88%;
}

.message-user .message-bubble {
  background: var(--user);
  color: var(--user-text);
  border-bottom-right-radius: 8px;
}

.message-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(18, 60, 44, 0.06);
  color: var(--muted);
  font-size: 0.95rem;
}

.message-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(31, 90, 67, 0.12);
  animation: pulse 1.1s infinite;
}

.chat-composer {
  display: grid;
  gap: 8px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--line);
  background: rgba(247, 251, 248, 0.88);
  align-self: end;
}

.composer-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
}

.chat-composer textarea {
  width: 100%;
  min-height: 38px;
  max-height: 120px;
  resize: none;
  padding: 8px 11px;
  border: 1px solid rgba(30, 71, 52, 0.18);
  border-radius: 12px;
  background: var(--card-strong);
  color: var(--text);
  font: inherit;
  line-height: 1.35;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chat-composer textarea::-webkit-scrollbar {
  display: none;
}

.chat-composer textarea:focus {
  border-color: rgba(31, 90, 67, 0.5);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 0 0 4px rgba(31, 90, 67, 0.14);
}

.composer-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  padding-left: 2px;
}

.send-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--green), var(--green-deep));
  color: white;
  box-shadow: 0 18px 30px rgba(18, 60, 44, 0.24);
}

.send-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  transform: translateX(1px);
}

.send-button:disabled,
.icon-button:disabled {
  cursor: wait;
  opacity: 0.7;
  transform: none;
}

.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;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.8;
  }
}

@media (max-width: 720px) {
  .widget-shell {
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .chat-card {
    width: 100%;
    max-width: 420px;
    height: min(100%, 620px);
    border-radius: 22px;
  }

  .chat-header {
    gap: 10px;
    align-items: center;
    flex-wrap: nowrap;
  }

  .chat-launcher {
    right: 12px;
    bottom: 12px;
    padding: 14px;
  }

  .chat-launcher-label {
    display: none;
  }

  .composer-bar {
    grid-template-columns: 1fr auto;
  }

  .icon-button {
    width: 38px;
  }
}

@media (max-width: 560px), (max-height: 720px) {
  html,
  body,
  .widget-shell {
    min-height: 100svh;
  }

  .widget-shell {
    align-items: stretch;
    justify-content: stretch;
  }

  .chat-card {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 20px;
    transform-origin: bottom center;
  }

  .widget-shell-closed .chat-card {
    transform: translateY(20px) scale(0.98);
  }

  .chat-header {
    padding: 16px 16px 12px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .chat-thread {
    padding: 10px 10px 8px;
  }

  .message-bubble {
    max-width: 92%;
    font-size: 0.92rem;
  }

  .chat-composer {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }
}
