/* ── IIE AI Chat Widget ─ Modern Redesign ────────────────────────────────── */

:root {
  --iie-c-green:      #1b6b3a;
  --iie-c-green-d:    #14532d;
  --iie-c-green-l:    #22843d;
  --iie-c-gold:       #c9972b;
  --iie-c-gold-l:     #f0c060;
  --iie-c-bg:         #f5f7fa;
  --iie-c-radius:     20px;
  --iie-c-shadow:     0 24px 64px rgba(0,0,0,.22), 0 4px 16px rgba(0,0,0,.10);
  --iie-c-shadow-btn: 0 8px 24px rgba(27,107,58,.45);
  --iie-c-glass:      rgba(255,255,255,0.72);
}

/* ── Floating toggle button ─────────────────────────────────────────────── */
#iie-chat-toggle {
  position: fixed;
  bottom: 84px;        /* above the back-to-top button (bottom-5 = 20px + ~56px height + 8px gap) */
  right: 20px;
  top: auto;
  z-index: 9999;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #fff;
  color: var(--iie-c-green);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.18), 0 1px 6px rgba(0,0,0,.1);
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
  outline: none;
  overflow: hidden;
  padding: 8px;
}
#iie-chat-toggle:hover,
#iie-chat-toggle:focus-visible {
  transform: scale(1.1) translateY(-2px);
  box-shadow: 0 8px 28px rgba(0,0,0,.2), 0 2px 8px rgba(0,0,0,.1);
}
#iie-chat-toggle:active { transform: scale(0.96); }

/* logo image shown in the button */
#iie-chat-toggle .iie-btn-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 0;
  display: block;
  transition: opacity .2s;
}
#iie-chat-toggle.is-open .iie-btn-logo { opacity: 0; position: absolute; pointer-events: none; }

/* close X icon */
#iie-chat-toggle .iie-chat-close-icon {
  display: none;
  width: 22px;
  height: 22px;
  color: var(--iie-c-green);
  stroke: var(--iie-c-green);
}
#iie-chat-toggle.is-open .iie-chat-close-icon { display: block; }

/* unread badge */
#iie-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: linear-gradient(135deg, #ff4e4e, #c0392b);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #fff;
  opacity: 0;
  transform: scale(0);
  transition: opacity .2s, transform .3s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
  z-index: 10000;
}
#iie-chat-badge.show {
  opacity: 1;
  transform: scale(1);
}

/* ── Chat window ─────────────────────────────────────────────────────────── */
#iie-chat-window {
  position: fixed;
  bottom: 158px;
  right: 20px;
  top: auto;
  z-index: 9998;
  width: 390px;
  max-width: calc(100vw - 32px);  /* never touch left/right edges */
  height: 520px;
  max-height: calc(100vh - 170px); /* never touch top/bottom edges */
  background: #ffffff;
  border-radius: var(--iie-c-radius);
  box-shadow: var(--iie-c-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(.88) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .25s ease;
  transform-origin: bottom right;
  border: 1px solid rgba(255,255,255,0.6);
}
#iie-chat-window.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* header */
#iie-chat-header {
  background: linear-gradient(135deg, var(--iie-c-green) 0%, var(--iie-c-green-d) 100%);
  color: #fff;
  padding: 0 16px;
  height: 72px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
/* decorative geometric shimmer */
#iie-chat-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 80% 50%, rgba(201,151,43,.18) 0%, transparent 65%),
    radial-gradient(ellipse at -10% 50%, rgba(255,255,255,.07) 0%, transparent 60%);
  pointer-events: none;
}
#iie-chat-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201,151,43,.5), transparent);
}
#iie-chat-header .avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.2), 0 0 0 2px rgba(201,151,43,.4);
  z-index: 1;
  padding: 5px;
}
#iie-chat-header .avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#iie-chat-header .info { flex: 1; min-width: 0; z-index: 1; }
#iie-chat-header .name {
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.3;
  letter-spacing: .01em;
}
#iie-chat-header .sub {
  font-size: 11px;
  opacity: .75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}
#iie-chat-header .online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(74,222,128,.3);
  animation: iiePulse 2s infinite;
}
@keyframes iiePulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(74,222,128,.3); }
  50%      { box-shadow: 0 0 0 4px rgba(74,222,128,.15); }
}
#iie-chat-clear {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  cursor: pointer;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  transition: background .15s, border-color .15s;
  z-index: 1;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
#iie-chat-clear:hover {
  background: rgba(255,255,255,.22);
  border-color: rgba(255,255,255,.35);
}

/* messages area */
#iie-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #f0f4f8 0%, #f8fafb 100%);
  scroll-behavior: smooth;
}
#iie-chat-messages::-webkit-scrollbar { width: 3px; }
#iie-chat-messages::-webkit-scrollbar-track { background: transparent; }
#iie-chat-messages::-webkit-scrollbar-thumb { background: #c7d4c9; border-radius: 4px; }

/* individual message bubbles */
.iie-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  animation: iieSlideIn .2s cubic-bezier(.34,1.2,.64,1);
}
@keyframes iieSlideIn {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.iie-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--iie-c-green-l), var(--iie-c-green-d));
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 3px 10px rgba(27,107,58,.25);
}
.iie-msg-bot {
  align-self: flex-start;
  background: #ffffff;
  color: #1a202c;
  border-bottom-left-radius: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
}
.iie-msg-error {
  align-self: flex-start;
  background: #fff5f5;
  color: #c53030;
  border: 1px solid #fecaca;
  border-bottom-left-radius: 5px;
  font-size: 12.5px;
}

/* greeting / disclaimer */
.iie-msg-notice {
  align-self: center;
  background: linear-gradient(135deg, rgba(27,107,58,.07), rgba(201,151,43,.07));
  color: #2d6a4f;
  text-align: center;
  font-size: 11.5px;
  border-radius: 12px;
  padding: 8px 14px;
  max-width: 92%;
  border: 1px solid rgba(27,107,58,.15);
  font-style: italic;
}

/* typing indicator */
#iie-chat-typing {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: #ffffff;
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  align-self: flex-start;
}
#iie-chat-typing.show { display: flex; }
#iie-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--iie-c-green);
  animation: iieTypingBounce 1.3s infinite;
}
#iie-chat-typing span:nth-child(2) { animation-delay: .18s; }
#iie-chat-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes iieTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* footer / input area */
#iie-chat-footer {
  border-top: 1px solid rgba(0,0,0,.06);
  padding: 10px 12px 10px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #fff;
  flex-shrink: 0;
}
#iie-chat-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 24px;
  padding: 9px 16px;
  font-size: 13.5px;
  outline: none;
  resize: none;
  line-height: 1.5;
  max-height: 100px;
  overflow-y: auto;
  font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
  background: #f8fafc;
  color: #1e293b;
  scrollbar-width: none;       /* Firefox, Chrome 121+ */
  -ms-overflow-style: none;    /* IE/Edge */
}
#iie-chat-input::-webkit-scrollbar { width: 0; height: 0; display: none; } /* Chrome/Safari/older Chrome/Samsung Internet */
#iie-chat-input:focus {
  border-color: var(--iie-c-green);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(27,107,58,.1);
}
#iie-chat-input::placeholder { color: #94a3b8; }
#iie-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--iie-c-green-l), var(--iie-c-green-d));
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
  box-shadow: 0 4px 12px rgba(27,107,58,.35);
}
#iie-chat-send:hover  { box-shadow: 0 6px 18px rgba(27,107,58,.45); transform: translateY(-1px); }
#iie-chat-send:active { transform: scale(.92); }
#iie-chat-send:disabled {
  background: #cbd5e1;
  box-shadow: none;
  cursor: not-allowed;
}
#iie-chat-send svg { width: 16px; height: 16px; margin-left: 1px; }

/* powered-by line */
#iie-chat-powered {
  text-align: center;
  font-size: 10px;
  color: #94a3b8;
  padding: 4px 0 8px;
  background: #fff;
  flex-shrink: 0;
  letter-spacing: .02em;
}

/* ── Mobile — keep as floating window, never full page ─────────────────── */
@media (max-width: 480px) {
  #iie-chat-toggle {
    bottom: 84px;
    right: 14px;
    top: auto;
  }
  #iie-chat-window {
    right: 16px;
    left: 16px;
    bottom: 158px;
    top: auto;
    width: auto;
    max-width: none;
    height: 65vh;
    max-height: calc(100vh - 165px);
    transform: scale(.88) translateY(16px);
    transform-origin: bottom right;
  }
  #iie-chat-window.is-open {
    transform: scale(1) translateY(0);
  }
}
