/* SPC Chatbot Widget */
.chat-launcher {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 200;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #8fbf3a, #1b6b38);
  color: #fff;
  box-shadow: 0 10px 28px rgba(27, 107, 56, 0.4);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-launcher:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 32px rgba(27, 107, 56, 0.45);
}
.chat-launcher svg { width: 26px; height: 26px; fill: currentColor; }
.chat-launcher .badge-dot {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fbbf24;
  border: 2px solid #fff;
  display: none;
}
.chat-launcher.has-alert .badge-dot { display: block; }

.chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  z-index: 200;
  width: min(380px, calc(100vw - 1.5rem));
  height: min(620px, calc(100vh - 6rem));
  max-height: calc(100vh - 5.5rem);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(15, 46, 28, 0.25);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #d9e5dc;
}
.chat-panel.open { display: flex; }

.chat-head {
  flex: 0 0 auto;
  background: linear-gradient(90deg, #8fbf3a, #1b6b38);
  color: #fff;
  padding: 0.95rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.chat-head h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}
.chat-head .status {
  font-size: 0.75rem;
  opacity: 0.9;
  margin-top: 0.15rem;
}
.chat-head button {
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  background: #f4f8f3;
}

.chat-body {
  flex: 0 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 140px;
}

.chat-msg {
  max-width: 85%;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.bot,
.chat-msg.staff {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #d9e5dc;
  color: #122018;
  border-bottom-left-radius: 4px;
}
.chat-msg.staff {
  border-left: 3px solid #1b6b38;
}
.chat-msg.visitor {
  align-self: flex-end;
  background: #1b6b38;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg .who {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chat-msg.visitor .who { color: rgba(255,255,255,0.8); }

.chat-faqs {
  flex: 0 0 auto;
  padding: 0.65rem 0.85rem 0.35rem;
  border-top: 1px solid #e5efe8;
  background: #fff;
}
.chat-panel.human-open .chat-faqs {
  display: none;
}
.chat-faqs-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #5f7266;
  margin-bottom: 0.45rem;
}
.chat-faq-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 90px;
  overflow-y: auto;
}
.chat-faq-btn {
  border: 1px solid #cfe0d4;
  background: #f4f8f3;
  color: #1b6b38;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.chat-faq-btn:hover {
  background: #e7f3e3;
  border-color: #8fbf3a;
}

.chat-actions {
  flex: 0 0 auto;
  padding: 0.5rem 0.85rem;
  background: #fff;
  display: flex;
  gap: 0.5rem;
}
.chat-human-btn {
  flex: 1;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.chat-human-btn:hover { background: #ffedd5; }
.chat-human-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.chat-form {
  flex: 0 0 auto;
  display: flex;
  gap: 0.45rem;
  padding: 0.65rem 0.85rem 0.85rem;
  background: #fff;
  border-top: 1px solid #e5efe8;
}
.chat-form input[type="text"] {
  flex: 1;
  border: 1px solid #d9e5dc;
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  min-width: 0;
}
.chat-form input:focus {
  outline: none;
  border-color: #8fbf3a;
  box-shadow: 0 0 0 3px rgba(143, 191, 58, 0.18);
}
.chat-form button {
  border: none;
  background: #1b6b38;
  color: #fff;
  border-radius: 8px;
  padding: 0 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.chat-form button:hover { background: #0f4a26; }

.chat-human-form {
  display: none;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.75rem 0.85rem 1rem;
  background: #fffaf5;
  border-top: 1px solid #fed7aa;
}
.chat-human-form.open { display: flex; }
.chat-human-form input,
.chat-human-form textarea,
.chat-human-form select {
  border: 1px solid #e0b48a;
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  font-family: inherit;
  font-size: 0.88rem;
  background: #fffdf9;
  color: #333;
  width: 100%;
  resize: vertical;
  box-sizing: border-box;
}
.chat-human-form select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #1b6b38 50%),
    linear-gradient(135deg, #1b6b38 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}
.chat-human-form textarea {
  min-height: 64px;
  max-height: 120px;
}
.chat-human-form input:focus,
.chat-human-form textarea:focus,
.chat-human-form select:focus {
  outline: none;
  border-color: #1b6b38;
  box-shadow: 0 0 0 3px rgba(27, 107, 56, 0.12);
}
.chat-human-error {
  color: #b91c1c;
  font-size: 0.8rem;
  font-weight: 500;
}
.chat-human-form button {
  border: none;
  background: #1b6b38;
  color: #fff;
  border-radius: 10px;
  padding: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.chat-rating {
  flex: 0 0 auto;
  padding: 1rem 0.9rem 1.1rem;
  background: linear-gradient(180deg, #f7fbf4, #eef7e8);
  border-top: 1px solid #cfe5c0;
  text-align: center;
}
.chat-rating[hidden] { display: none !important; }
.chat-rating-title {
  font-weight: 700;
  font-size: 0.98rem;
  color: #14532d;
  margin-bottom: 0.35rem;
}
.chat-rating-hint {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: #4b5563;
  line-height: 1.4;
}
.chat-stars {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}
.chat-star {
  border: none;
  background: transparent;
  color: #d1d5db;
  font-size: 1.85rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
  transition: color 0.15s, transform 0.15s;
}
.chat-star:hover,
.chat-star.is-hover,
.chat-star.is-active {
  color: #f59e0b;
  transform: scale(1.12);
}
.chat-rate-submit,
.chat-rate-new {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
}
.chat-rate-submit {
  background: #1b6b38;
  color: #fff;
}
.chat-rate-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.chat-rate-submit:not(:disabled):hover { background: #0f4a26; }
.chat-rate-thanks {
  margin: 0.6rem 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #14532d;
}
.chat-rate-thanks[hidden],
.chat-rate-new[hidden] { display: none !important; }
.chat-rate-new {
  background: #fff;
  color: #1b6b38;
  border: 1px solid #8fbf3a;
}
.chat-rate-new:hover { background: #f3faf0; }
.chat-panel.rating-open .chat-faqs,
.chat-panel.rating-open .chat-actions,
.chat-panel.rating-open .chat-human-form,
.chat-panel.rating-open .chat-form {
  display: none !important;
}

@media (max-width: 560px) {
  .chat-launcher { right: 1rem; bottom: 1rem; }
  .chat-panel {
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    bottom: 4.75rem;
    height: min(70vh, calc(100vh - 5.5rem));
    max-height: calc(100vh - 5.5rem);
  }
  .back-top { right: 5.5rem; }
}
