/* iLoveView support chatbot — premium widget */
#ilv-support-chat-root {
  --ilv-red: #e51711;
  --ilv-red-deep: #c11313;
  --ilv-ink: #16181d;
  --ilv-muted: #6b7280;
  --ilv-line: rgba(22, 24, 29, 0.08);
  --ilv-soft: #f6f5f3;
  --ilv-panel: #ffffff;
  --ilv-shadow: 0 18px 50px rgba(22, 24, 29, 0.16);

  position: fixed !important;
  right: 22px !important;
  bottom: 22px !important;
  left: auto !important;
  top: auto !important;
  z-index: 2147483000 !important;
  font-family: Poppins, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ilv-ink);
  -webkit-font-smoothing: antialiased;
  pointer-events: auto !important;
  transform: none !important;
}

#ilv-support-chat-root.ilv-chat-hidden {
  display: none !important;
}

#ilv-support-chat-root *,
#ilv-support-chat-root *::before,
#ilv-support-chat-root *::after {
  box-sizing: border-box;
}

#ilv-support-chat-root button {
  font-family: inherit;
}

/* Launcher */
.ilv-chat-launcher {
  position: relative;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  background: var(--ilv-red);
  color: #fff;
  box-shadow: 0 12px 28px rgba(229, 23, 17, 0.32);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: visible;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.ilv-chat-launcher:hover {
  background: var(--ilv-red-deep);
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(229, 23, 17, 0.38);
}

.ilv-chat-launcher:focus-visible {
  outline: 2px solid var(--ilv-ink);
  outline-offset: 3px;
}

.ilv-chat-launcher svg {
  width: 24px;
  height: 24px;
  display: block;
  flex-shrink: 0;
  overflow: visible;
}

.ilv-chat-launcher .ilv-chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  min-width: 0;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ilv-red);
  display: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.ilv-chat-launcher.has-hint .ilv-chat-badge {
  display: block;
}

.ilv-chat-hint {
  position: absolute;
  right: 72px;
  bottom: 10px;
  max-width: 210px;
  background: var(--ilv-ink);
  color: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  box-shadow: var(--ilv-shadow);
  display: none;
}

.ilv-chat-hint.visible {
  display: block;
  animation: ilvChatIn 0.22s ease;
}

.ilv-chat-hint::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: 18px;
  width: 10px;
  height: 10px;
  background: var(--ilv-ink);
  transform: rotate(45deg);
}

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

/* Panel */
.ilv-chat-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: min(390px, calc(100vw - 28px));
  height: min(580px, calc(100vh - 120px));
  min-height: 0;
  background: var(--ilv-panel);
  border-radius: 22px;
  border: 1px solid var(--ilv-line);
  box-shadow: var(--ilv-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.ilv-chat-panel.open {
  display: flex;
  animation: ilvChatIn 0.22s ease;
}

.ilv-chat-header {
  position: relative;
  background: #fff;
  color: var(--ilv-ink);
  padding: 16px 16px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--ilv-line);
}

.ilv-chat-header::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--ilv-red), #ff6b6b 55%, var(--ilv-red));
}

.ilv-chat-header-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ilv-chat-header-mark img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  display: block;
  background: transparent;
  /* logo asset has a white square; blend it into the white header */
  mix-blend-mode: multiply;
}

.ilv-chat-header-mark svg {
  width: 18px;
  height: 18px;
  display: block;
  color: #ff8b8b;
}

.ilv-chat-header-copy {
  min-width: 0;
  flex: 1;
}

.ilv-chat-header h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.ilv-chat-header p {
  display: none;
}

.ilv-chat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  font-size: 10.5px;
  font-weight: 600;
  color: #15803d;
}

.ilv-chat-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

.ilv-chat-close {
  margin-left: auto;
  border: none;
  background: var(--ilv-soft);
  color: var(--ilv-ink);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.ilv-chat-close:hover {
  background: #eceae7;
}

.ilv-chat-close svg {
  width: 14px;
  height: 14px;
  display: block;
}

.ilv-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background:
    radial-gradient(ellipse 80% 50% at 100% 0%, rgba(229, 23, 17, 0.04), transparent 55%),
    var(--ilv-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
}

.ilv-chat-bubble {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  letter-spacing: -0.01em;
}

.ilv-chat-bubble.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--ilv-line);
  color: var(--ilv-ink);
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 2px rgba(22, 24, 29, 0.03);
}

.ilv-chat-bubble.user {
  align-self: flex-end;
  background: var(--ilv-ink);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.ilv-chat-bubble.system {
  align-self: center;
  background: #fff8f0;
  border: 1px solid #f3d9bc;
  color: #8a4b12;
  font-size: 12px;
  max-width: 94%;
  text-align: left;
}

.ilv-chat-typing {
  align-self: flex-start;
  display: none;
  gap: 5px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--ilv-line);
  border-radius: 14px;
  margin: 0 14px 4px;
}

.ilv-chat-typing.on {
  display: inline-flex;
}

.ilv-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c5c5c8;
  animation: ilvDot 1s infinite ease-in-out;
}

.ilv-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ilv-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ilvDot {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.ilv-chat-escalate {
  display: none;
  padding: 12px 14px;
  border-top: 1px solid var(--ilv-line);
  background: #fff;
  gap: 8px;
  flex-direction: column;
}

.ilv-chat-escalate.open {
  display: flex;
}

.ilv-chat-escalate label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ilv-muted);
}

.ilv-chat-escalate input,
.ilv-chat-escalate textarea {
  width: 100%;
  border: 1px solid var(--ilv-line);
  border-radius: 12px;
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  background: var(--ilv-soft);
  color: var(--ilv-ink);
}

.ilv-chat-escalate input:focus,
.ilv-chat-escalate textarea:focus,
.ilv-chat-composer textarea:focus {
  outline: none;
  border-color: rgba(229, 23, 17, 0.45);
  box-shadow: 0 0 0 3px rgba(229, 23, 17, 0.1);
  background: #fff;
}

.ilv-chat-escalate textarea {
  min-height: 58px;
  resize: vertical;
}

.ilv-chat-escalate-actions {
  display: flex;
  gap: 8px;
}

.ilv-chat-escalate-actions button {
  flex: 1;
  border: none;
  border-radius: 11px;
  padding: 10px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.ilv-chat-escalate-actions .primary {
  background: var(--ilv-red);
  color: #fff;
}

.ilv-chat-escalate-actions .ghost {
  background: var(--ilv-soft);
  color: var(--ilv-ink);
}

.ilv-chat-composer {
  border-top: 1px solid var(--ilv-line);
  padding: 10px 12px 8px;
  display: flex;
  gap: 8px;
  background: #fff;
  align-items: flex-end;
  flex-shrink: 0;
}

.ilv-chat-composer textarea {
  flex: 1;
  width: 100%;
  border: 1px solid var(--ilv-line);
  border-radius: 14px;
  padding: 11px 12px;
  margin: 0;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  font-family: inherit;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  height: 44px;
  line-height: 1.375;
  background: var(--ilv-soft);
  color: var(--ilv-ink);
  overflow-y: hidden;
  overflow-x: hidden;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  vertical-align: bottom;
  field-sizing: content;
}

.ilv-chat-composer textarea.ilv-chat-input-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.ilv-chat-composer button {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 14px;
  background: var(--ilv-red);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  overflow: visible;
  align-self: flex-end;
  transition: background 0.15s ease;
}

.ilv-chat-composer button:hover {
  background: var(--ilv-red-deep);
}

.ilv-chat-composer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ilv-chat-composer button svg {
  width: 18px;
  height: 18px;
  display: block;
  flex-shrink: 0;
  overflow: visible;
}

.ilv-chat-footer-links {
  padding: 0 14px 12px;
  background: #fff;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.ilv-chat-footer-links a {
  font-size: 11px;
  font-weight: 500;
  color: var(--ilv-muted);
  text-decoration: none;
}

.ilv-chat-footer-links a:hover {
  color: var(--ilv-red);
}

/* Mobile: full-bleed sheet pinned to visual viewport (keyboard-safe) */
@media (max-width: 640px) {
  #ilv-support-chat-root {
    --ilv-vv-top: 0px;
    --ilv-vv-left: 0px;
    --ilv-vv-width: 100vw;
    --ilv-vv-height: 100dvh;
    right: 14px !important;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    left: auto !important;
    width: auto !important;
  }

  #ilv-support-chat-root.ilv-chat-is-open {
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    pointer-events: none !important;
  }

  #ilv-support-chat-root.ilv-chat-is-open .ilv-chat-panel,
  #ilv-support-chat-root.ilv-chat-is-open .ilv-chat-launcher {
    pointer-events: auto !important;
  }

  #ilv-support-chat-root.ilv-chat-is-open .ilv-chat-launcher {
    display: none !important;
  }

  .ilv-chat-hint {
    display: none !important;
  }

  #ilv-support-chat-root.ilv-chat-is-open .ilv-chat-panel.open {
    position: fixed !important;
    top: var(--ilv-vv-top, 0px) !important;
    left: var(--ilv-vv-left, 0px) !important;
    right: auto !important;
    bottom: auto !important;
    width: var(--ilv-vv-width, 100vw) !important;
    height: var(--ilv-vv-height, 100dvh) !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 18px 18px 0 0;
    border: none;
    border-top: 1px solid var(--ilv-line);
    box-shadow: 0 -10px 40px rgba(22, 24, 29, 0.18);
  }

  .ilv-chat-header {
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }

  .ilv-chat-header-mark {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: transparent;
  }

  .ilv-chat-header-mark img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    mix-blend-mode: multiply;
  }

  .ilv-chat-messages {
    padding: 12px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    min-height: 0; /* allow flex child to shrink above keyboard */
  }

  .ilv-chat-bubble {
    max-width: 92%;
    font-size: 14px;
  }

  .ilv-chat-composer {
    padding: 10px 12px;
    gap: 10px;
  }

  .ilv-chat-composer textarea {
    font-size: 16px;
    min-height: 44px;
    max-height: 110px;
    line-height: 1.375;
    padding: 11px 12px;
  }

  .ilv-chat-footer-links {
    padding: 0 14px calc(12px + env(safe-area-inset-bottom, 0px));
    gap: 18px;
    justify-content: flex-start;
  }

  .ilv-chat-footer-links a {
    font-size: 12px;
    padding: 6px 0;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
  }

  /* Free vertical space for the composer when the soft keyboard is up */
  #ilv-support-chat-root.ilv-chat-kb-open .ilv-chat-footer-links {
    display: none;
  }

  #ilv-support-chat-root.ilv-chat-kb-open .ilv-chat-composer {
    padding-bottom: 10px;
  }

  .ilv-chat-launcher {
    width: 56px;
    height: 56px;
    box-shadow: 0 10px 28px rgba(229, 23, 17, 0.36);
  }
}

@media (min-width: 641px) {
  .ilv-chat-composer textarea {
    font-size: 13px;
  }
}
