/* Hatch Tracker Pro — customer chat widget */

.htp-chat * {
  box-sizing: border-box;
}

/* ---------- Launcher ---------- */

.htp-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 998;
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--jade) 0%, var(--jade-dark) 100%);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 10px 32px rgba(12, 123, 98, 0.38);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s ease;
  animation: htp-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) 0.6s backwards;
}

.htp-launcher:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 16px 40px rgba(12, 123, 98, 0.45);
}

.htp-launcher:focus-visible {
  outline: 3px solid rgba(12, 123, 98, 0.35);
  outline-offset: 3px;
}

.htp-launcher svg {
  grid-area: 1 / 1;
  width: 28px;
  height: 28px;
  transition: opacity 0.2s ease, transform 0.25s ease;
}

.htp-launcher .htp-ic-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.htp-chat.is-open .htp-launcher .htp-ic-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.htp-chat.is-open .htp-launcher .htp-ic-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

@keyframes htp-pop {
  from {
    transform: scale(0);
    opacity: 0;
  }
}

.htp-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 999px;
  border: 2px solid var(--paper);
  background: var(--gold);
  color: #2c220e;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.htp-badge.is-hidden {
  display: none;
}

.htp-badge.is-bumped {
  animation: htp-bounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes htp-bounce {
  30% {
    transform: scale(1.35);
  }
}

/* ---------- Panel ---------- */

.htp-panel {
  position: fixed;
  right: 20px;
  bottom: 94px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  width: 380px;
  height: min(600px, calc(100vh - 120px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow), 0 6px 22px rgba(23, 32, 29, 0.14);
  opacity: 0;
  transform: translateY(18px) scale(0.97);
  transform-origin: bottom right;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.26s ease, transform 0.26s cubic-bezier(0.21, 1.02, 0.55, 1),
    visibility 0.26s;
}

.htp-chat.is-open .htp-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
}

/* ---------- Header ---------- */

.htp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px;
  background: linear-gradient(135deg, var(--jade) 0%, var(--jade-dark) 100%);
  color: #ffffff;
}

.htp-avatar {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 12px rgba(7, 90, 72, 0.35);
}

.htp-avatar img {
  width: 26px;
  height: 26px;
  display: block;
}

.htp-header-info {
  min-width: 0;
  flex: 1;
}

.htp-header-title {
  display: block;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
}

.htp-header-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  font-weight: 700;
}

.htp-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffd166;
  box-shadow: 0 0 0 0 rgba(255, 209, 102, 0.55);
  animation: htp-pulse 2.4s ease-out infinite;
}

@keyframes htp-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 209, 102, 0.55);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(255, 209, 102, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 209, 102, 0);
  }
}

.htp-header-close {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: background 0.15s ease;
}

.htp-header-close:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.htp-header-close svg {
  width: 18px;
  height: 18px;
}

/* ---------- Banner ---------- */

.htp-banner {
  padding: 8px 16px;
  background: #fdf3d7;
  color: #7a5c10;
  font-size: 12.5px;
  font-weight: 800;
  text-align: center;
}

.htp-banner.is-error {
  background: #fde8df;
  color: #9f3525;
}

.htp-banner.is-neutral {
  background: var(--mint);
  color: var(--jade-dark);
}

.htp-banner.is-hidden {
  display: none;
}

/* ---------- Body / messages ---------- */

.htp-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

.htp-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(23, 32, 29, 0.18) transparent;
}

.htp-messages::-webkit-scrollbar {
  width: 6px;
}

.htp-messages::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background: rgba(23, 32, 29, 0.18);
}

.htp-day {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 10px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 800;
}

.htp-day::before,
.htp-day::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.htp-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 12px;
  animation: htp-msg-in 0.24s ease backwards;
}

.htp-row.is-grouped {
  margin-top: 3px;
}

@keyframes htp-msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.htp-row.from-customer {
  flex-direction: row-reverse;
}

.htp-msg-avatar {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--mint);
  color: var(--jade-dark);
  font-size: 12px;
  font-weight: 950;
}

.htp-row.is-grouped .htp-msg-avatar {
  visibility: hidden;
}

.htp-bubble-wrap {
  max-width: 78%;
  display: flex;
  flex-direction: column;
}

.htp-row.from-customer .htp-bubble-wrap {
  align-items: flex-end;
}

.htp-bubble {
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.htp-row.from-agent .htp-bubble {
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}

.htp-row.from-customer .htp-bubble {
  border-bottom-right-radius: 4px;
  background: linear-gradient(135deg, var(--jade) 0%, var(--jade-dark) 100%);
  color: #ffffff;
}

.htp-time {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
}

.htp-row.is-grouped .htp-time {
  display: none;
}

/* typing indicator */

.htp-typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 13px 14px;
}

.htp-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(23, 32, 29, 0.35);
  animation: htp-blink 1.2s infinite;
}

.htp-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.htp-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes htp-blink {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* jump-to-latest pill */

.htp-jump {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 2;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #ffffff;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
  transform: translateX(-50%);
  box-shadow: 0 6px 18px rgba(23, 32, 29, 0.3);
}

.htp-jump.is-hidden {
  display: none;
}

/* ---------- Pre-chat ---------- */

.htp-prechat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
}

.htp-prechat.is-hidden,
.htp-messages.is-hidden {
  display: none;
}

.htp-greeting {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
}

.htp-greeting .htp-bubble {
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}

.htp-prechat label {
  display: grid;
  gap: 5px;
  margin-bottom: 12px;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 900;
}

.htp-prechat input {
  width: 100%;
  border: 1px solid #cdd8d2;
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
}

.htp-prechat input:focus {
  outline: 3px solid rgba(12, 123, 98, 0.18);
  border-color: var(--jade);
}

.htp-start {
  width: 100%;
  min-height: 46px;
  margin-top: 4px;
  border: 0;
  border-radius: 8px;
  background: var(--gold);
  color: #2c220e;
  font: inherit;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
}

.htp-start:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.htp-start:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.htp-field-error {
  color: var(--coral);
  font-size: 11.5px;
  font-weight: 800;
}

.htp-field-error.is-hidden {
  display: none;
}

/* ---------- Composer ---------- */

.htp-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.htp-composer.is-hidden {
  display: none;
}

.htp-input {
  flex: 1;
  max-height: 110px;
  border: 0;
  padding: 9px 2px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  resize: none;
}

.htp-input:focus {
  outline: none;
}

.htp-send {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--jade) 0%, var(--jade-dark) 100%);
  color: #ffffff;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.htp-send:hover {
  transform: scale(1.08);
}

.htp-send:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.htp-send svg {
  width: 18px;
  height: 18px;
  margin-left: 2px;
}

.htp-newchat {
  margin: 10px auto 16px;
  display: block;
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--jade-dark);
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.htp-newchat:hover {
  background: var(--mint);
}

.htp-newchat.is-hidden {
  display: none;
}

/* ---------- Mobile ---------- */

@media (max-width: 480px) {
  .htp-panel {
    right: 12px;
    left: 12px;
    bottom: 88px;
    width: auto;
    height: min(560px, calc(100dvh - 104px));
  }

  .htp-launcher {
    right: 16px;
    bottom: 16px;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .htp-launcher,
  .htp-panel,
  .htp-row,
  .htp-badge,
  .htp-dot,
  .htp-launcher svg {
    animation: none !important;
    transition: none !important;
  }
}
