/* ==========================================================================
   Fortis Ecology — Chat Agent Widget
   ========================================================================== */

/* ---------- Variables ---------- */
:root {
  --chat-forest: #1B3A2D;
  --chat-moss: #2D6A4F;
  --chat-fern: #40916C;
  --chat-gold: #B5935A;
  --chat-offwhite: #FAFAF8;
  --chat-grey-light: #F0F0ED;
  --chat-grey-mid: #D4D4CE;
  --chat-shadow: 0 8px 32px rgba(27, 58, 45, .18);
  --chat-radius: 16px;
  --chat-width: 380px;
  --chat-height: 520px;
  --chat-z: 9990;        /* below cookie banner (9999) */
  --chat-bubble-z: 9991;
}

/* ---------- Toggle button ---------- */
.fe-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--chat-bubble-z);
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-moss), var(--chat-fern));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(27, 58, 45, .3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s ease, box-shadow .25s ease;
}

.fe-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(27, 58, 45, .4);
}

.fe-chat-toggle:focus-visible {
  outline: 3px solid var(--chat-gold);
  outline-offset: 3px;
}

.fe-chat-toggle svg {
  width: 28px;
  height: 28px;
  transition: transform .3s ease, opacity .3s ease;
}

.fe-chat-toggle .fe-chat-icon-close {
  position: absolute;
  transform: rotate(90deg) scale(0);
  opacity: 0;
}

.fe-chat-toggle[aria-expanded="true"] .fe-chat-icon-open {
  transform: rotate(-90deg) scale(0);
  opacity: 0;
}

.fe-chat-toggle[aria-expanded="true"] .fe-chat-icon-close {
  transform: rotate(0) scale(1);
  opacity: 1;
}

/* Notification dot */
.fe-chat-toggle__dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 14px;
  height: 14px;
  background: var(--chat-gold);
  border: 2px solid #fff;
  border-radius: 50%;
  transition: opacity .3s ease;
}

.fe-chat-toggle[aria-expanded="true"] .fe-chat-toggle__dot {
  opacity: 0;
}

/* ---------- Chat window ---------- */
.fe-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: var(--chat-z);
  width: var(--chat-width);
  height: var(--chat-height);
  max-height: calc(100vh - 120px);
  border-radius: var(--chat-radius);
  background: var(--chat-offwhite);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(.95);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.4,0,.2,1),
              opacity .3s cubic-bezier(.4,0,.2,1);
}

.fe-chat-window[aria-hidden="false"] {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Header ---------- */
.fe-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--chat-forest), var(--chat-moss));
  color: #fff;
  flex-shrink: 0;
}

.fe-chat-header__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.fe-chat-header__avatar svg {
  width: 20px;
  height: 20px;
}

.fe-chat-header__info {
  flex: 1;
  min-width: 0;
}

.fe-chat-header__title {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: .95rem;
  line-height: 1.2;
}

.fe-chat-header__subtitle {
  font-size: .75rem;
  opacity: .8;
  line-height: 1.3;
}

.fe-chat-header__close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  flex-shrink: 0;
}

.fe-chat-header__close:hover {
  background: rgba(255,255,255,.25);
}

.fe-chat-header__close:focus-visible {
  outline: 2px solid var(--chat-gold);
  outline-offset: 2px;
}

.fe-chat-header__close svg {
  width: 16px;
  height: 16px;
}

/* ---------- Messages area ---------- */
.fe-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.fe-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.fe-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.fe-chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-grey-mid);
  border-radius: 3px;
}

/* ---------- Message bubbles ---------- */
.fe-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: .875rem;
  line-height: 1.5;
  word-break: break-word;
  animation: feChatFadeIn .3s ease;
}

@keyframes feChatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fe-chat-msg--bot {
  align-self: flex-start;
  background: var(--chat-grey-light);
  color: var(--chat-forest);
  border-bottom-left-radius: 4px;
}

.fe-chat-msg--user {
  align-self: flex-end;
  background: var(--chat-moss);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.fe-chat-msg a {
  color: var(--chat-fern);
  text-decoration: underline;
}

.fe-chat-msg--user a {
  color: #d4f0e0;
}

/* ---------- Quick-reply buttons ---------- */
.fe-chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  animation: feChatFadeIn .3s ease;
}

.fe-chat-quick-btn {
  padding: 6px 14px;
  border: 1.5px solid var(--chat-fern);
  border-radius: 20px;
  background: transparent;
  color: var(--chat-fern);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s;
  white-space: nowrap;
}

.fe-chat-quick-btn:hover {
  background: var(--chat-fern);
  color: #fff;
}

.fe-chat-quick-btn:focus-visible {
  outline: 2px solid var(--chat-gold);
  outline-offset: 2px;
}

/* ---------- Typing indicator ---------- */
.fe-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  padding: 10px 18px;
  background: var(--chat-grey-light);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  animation: feChatFadeIn .3s ease;
}

.fe-chat-typing__dot {
  width: 7px;
  height: 7px;
  background: var(--chat-grey-mid);
  border-radius: 50%;
  animation: feChatBounce 1.2s ease-in-out infinite;
}

.fe-chat-typing__dot:nth-child(2) { animation-delay: .15s; }
.fe-chat-typing__dot:nth-child(3) { animation-delay: .3s; }

@keyframes feChatBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* ---------- Input area ---------- */
.fe-chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--chat-grey-mid);
  background: #fff;
  flex-shrink: 0;
}

.fe-chat-input__field {
  flex: 1;
  border: 1.5px solid var(--chat-grey-mid);
  border-radius: 22px;
  padding: 8px 16px;
  font-size: .875rem;
  font-family: inherit;
  background: var(--chat-offwhite);
  color: var(--chat-forest);
  outline: none;
  transition: border-color .2s;
  resize: none;
  min-height: 0;
  max-height: 80px;
  line-height: 1.4;
}

.fe-chat-input__field::placeholder {
  color: #999;
}

.fe-chat-input__field:focus {
  border-color: var(--chat-fern);
}

.fe-chat-input__send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--chat-moss);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .15s;
  flex-shrink: 0;
}

.fe-chat-input__send:hover {
  background: var(--chat-fern);
  transform: scale(1.06);
}

.fe-chat-input__send:focus-visible {
  outline: 2px solid var(--chat-gold);
  outline-offset: 2px;
}

.fe-chat-input__send:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.fe-chat-input__send svg {
  width: 18px;
  height: 18px;
}

/* ---------- Image upload button ---------- */
.fe-chat-input__upload {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--chat-grey-mid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s, background .2s;
  flex-shrink: 0;
}

.fe-chat-input__upload:hover {
  color: var(--chat-fern);
  background: rgba(64, 145, 108, .08);
}

.fe-chat-input__upload:focus-visible {
  outline: 2px solid var(--chat-gold);
  outline-offset: 2px;
}

.fe-chat-input__upload svg {
  width: 20px;
  height: 20px;
}

.fe-chat-input__file {
  display: none;
}

/* ---------- Image preview bar ---------- */
.fe-chat-img-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--chat-grey-mid);
  background: var(--chat-grey-light);
  flex-shrink: 0;
}

.fe-chat-img-preview img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--chat-grey-mid);
}

.fe-chat-img-preview__info {
  flex: 1;
  min-width: 0;
  font-size: .75rem;
  color: var(--chat-forest);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fe-chat-img-preview__remove {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.1);
  color: var(--chat-forest);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.fe-chat-img-preview__remove:hover {
  background: rgba(0,0,0,.2);
}

/* ---------- Image in message bubble ---------- */
.fe-chat-msg__image {
  max-width: 100%;
  border-radius: 10px;
  margin-bottom: 6px;
  display: block;
}

.fe-chat-msg--user .fe-chat-msg__image {
  max-width: 180px;
}

.fe-chat-msg--bot .fe-chat-msg__image {
  max-width: 200px;
}

/* ---------- Powered-by ---------- */
.fe-chat-powered {
  text-align: center;
  font-size: .65rem;
  color: #999;
  padding: 4px 0 8px;
  background: #fff;
  flex-shrink: 0;
}

/* ---------- Mobile responsive ---------- */
@media (max-width: 480px) {
  .fe-chat-window {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }

  .fe-chat-toggle {
    bottom: 16px;
    right: 16px;
  }
}

/* ---------- Cookie-banner offset ---------- */
.cookie-banner:not(.cookie-banner--hidden) ~ .fe-chat-toggle {
  bottom: 84px;
}

.cookie-banner:not(.cookie-banner--hidden) ~ .fe-chat-window {
  bottom: 156px;
}

@media (max-width: 480px) {
  .cookie-banner:not(.cookie-banner--hidden) ~ .fe-chat-window {
    bottom: 0;
    height: calc(100% - 60px);
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .fe-chat-window,
  .fe-chat-toggle,
  .fe-chat-toggle svg,
  .fe-chat-msg,
  .fe-chat-quick-replies,
  .fe-chat-typing {
    transition: none !important;
    animation: none !important;
  }
}
