/* =========================
   Thiết lập màu sắc và kích thước
   ========================= */
.feedback-widget {
  --wine: #7b110a;
  --wine-dark: #570b07;
  --gold: #fbd652;
  --cream: #fffaf0;
  --text: #2c211f;
  --muted: #746663;
  --success: #167547;
  --error: #b42318;
  --shadow: 0 18px 55px rgba(70, 14, 9, 0.25);
  position: fixed;
  z-index: 9999;
  right: auto;
  left: 24px;
  bottom: 24px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
}

.feedback-widget *,
.feedback-widget *::before,
.feedback-widget *::after {
  box-sizing: border-box;
}

/* =========================
   Nút bong bóng chat
   ========================= */
.feedback-fab {
  position: relative;
  display: grid;
  width: 62px;
  height: 62px;
  margin-right: auto;
  padding: 0;
  place-items: center;
  color: var(--gold);
  background: linear-gradient(145deg, #8f1a12, var(--wine));
  border: 2px solid rgba(251, 214, 82, 0.85);
  border-radius: 50%;
  box-shadow: 0 10px 28px rgba(123, 17, 10, 0.38);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.feedback-fab:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 14px 34px rgba(123, 17, 10, 0.45);
}

.feedback-fab:focus-visible,
.feedback-close:focus-visible,
.feedback-submit:focus-visible,
.zalo-button:focus-visible,
.feedback-file-input:focus-visible + .feedback-file-button,
.feedback-widget input:focus-visible,
.feedback-widget textarea:focus-visible {
  outline: 3px solid rgba(251, 214, 82, 0.55);
  outline-offset: 3px;
}

.feedback-fab svg {
  position: absolute;
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  transition: opacity 180ms ease, transform 220ms ease;
}

.feedback-fab .icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.65);
}

.feedback-widget.is-open .feedback-fab .icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.65);
}

.feedback-widget.is-open .feedback-fab .icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.feedback-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: #39b978;
  border: 2px solid #fff;
  border-radius: 50%;
  animation: feedback-pulse 2.2s infinite;
}

.feedback-widget.is-open .feedback-badge {
  display: none;
}

/* =========================
   Khung chat
   ========================= */
.feedback-panel {
  position: absolute;
  right: auto;
  left: 0;
  bottom: 78px;
  width: min(380px, calc(100vw - 32px));
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(123, 17, 10, 0.12);
  border-radius: 20px;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.96);
  transform-origin: left bottom;
  pointer-events: none;
  transition:
    opacity 220ms ease,
    transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
    visibility 220ms ease;
}

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

.feedback-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 104px;
  padding: 22px 22px 20px;
  color: #fff;
  background:
    radial-gradient(circle at 90% 15%, rgba(251, 214, 82, 0.3), transparent 28%),
    linear-gradient(135deg, #8e1b13, var(--wine-dark));
}

.feedback-header::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.feedback-eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.feedback-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 25px;
  font-weight: 700;
}

.feedback-close {
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  cursor: pointer;
  transition: background 180ms ease, transform 180ms ease;
}

.feedback-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(8deg);
}

.feedback-close svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.feedback-body {
  max-height: min(560px, calc(100vh - 150px));
  padding: 22px;
  overflow-y: auto;
  background:
    linear-gradient(rgba(255, 250, 240, 0.72), rgba(255, 255, 255, 0.96)),
    #fff;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.form-group label span {
  color: var(--muted);
  font-weight: 400;
}

.form-group label strong {
  color: var(--wine);
}

.feedback-widget input,
.feedback-widget textarea {
  display: block;
  width: 100%;
  padding: 12px 13px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  background: #fff;
  border: 1px solid #d9cecb;
  border-radius: 11px;
  resize: vertical;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.feedback-widget input::placeholder,
.feedback-widget textarea::placeholder {
  color: #9b908d;
}

.feedback-widget input:focus,
.feedback-widget textarea:focus {
  border-color: var(--wine);
  box-shadow: 0 0 0 3px rgba(123, 17, 10, 0.09);
  outline: none;
}

.feedback-widget textarea {
  min-height: 108px;
}

.feedback-attachments {
  margin: -3px 0 17px;
}

/* Ẩn input gốc nhưng vẫn cho phép truy cập bằng bàn phím/trình đọc màn hình. */
.feedback-widget .feedback-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

.feedback-file-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--wine);
  background: #fff;
  border: 1px solid rgba(123, 17, 10, 0.35);
  border-radius: 9px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.feedback-file-button:hover {
  background: var(--cream);
  border-color: var(--wine);
  transform: translateY(-1px);
}

.feedback-file-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.feedback-file-list {
  display: grid;
  gap: 5px;
  margin: 9px 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  list-style: none;
}

.feedback-file-list:empty {
  display: none;
}

.feedback-file-list li {
  position: relative;
  padding-left: 14px;
  overflow-wrap: anywhere;
}

.feedback-file-list li::before {
  position: absolute;
  top: 0.55em;
  left: 2px;
  width: 4px;
  height: 4px;
  content: "";
  background: var(--wine);
  border-radius: 50%;
}

.feedback-submit,
.zalo-button {
  display: flex;
  width: 100%;
  min-height: 47px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 11px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  border-radius: 11px;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.feedback-submit {
  color: var(--gold);
  background: var(--wine);
  border: 1px solid var(--wine);
  box-shadow: 0 7px 18px rgba(123, 17, 10, 0.2);
}

.feedback-submit:hover:not(:disabled) {
  background: var(--wine-dark);
  box-shadow: 0 9px 22px rgba(123, 17, 10, 0.28);
  transform: translateY(-1px);
}

.feedback-submit:disabled {
  cursor: wait;
  opacity: 0.68;
}

.feedback-submit svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.feedback-status {
  display: none;
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  border-radius: 9px;
}

.feedback-status.is-success,
.feedback-status.is-error {
  display: block;
}

.feedback-status.is-success {
  color: var(--success);
  background: #ecfdf3;
  border: 1px solid #a6f4c5;
}

.feedback-status.is-error {
  color: var(--error);
  background: #fff1f0;
  border: 1px solid #fecdca;
}

.feedback-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 12px;
}

.feedback-divider::before,
.feedback-divider::after {
  height: 1px;
  flex: 1;
  content: "";
  background: #e5dcda;
}

.zalo-button {
  color: var(--wine);
  background: #fff;
  border: 1px solid rgba(123, 17, 10, 0.35);
}

.zalo-button:hover {
  background: var(--cream);
  border-color: var(--wine);
  transform: translateY(-1px);
}

.zalo-logo {
  display: block;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  object-fit: contain;
}

@keyframes feedback-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(57, 185, 120, 0.45);
  }
  50% {
    box-shadow: 0 0 0 7px rgba(57, 185, 120, 0);
  }
}

/* =========================
   Tối ưu cho màn hình nhỏ
   ========================= */
@media (max-width: 767px) {
  .feedback-widget {
    right: auto;
    left: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  /* Icon mobile tối giản: bỏ vòng tròn lớn và nền đỏ. */
  .feedback-fab {
    width: 40px;
    height: 40px;
    color: var(--wine);
    background: rgba(255, 250, 240, 0.1);
    border: 1px solid rgba(123, 17, 10, 0.28);
    border-radius: 9px;
    box-shadow: 0 3px 10px rgba(44, 33, 31, 0.14);
  }

  .feedback-fab:hover {
    background: rgba(255, 250, 240, 0.1);
    box-shadow: 0 3px 10px rgba(44, 33, 31, 0.14);
    transform: none;
  }

  .feedback-fab svg {
    width: 24px;
    height: 24px;
    stroke-width: 1.8;
  }

  /* Chấm trạng thái nằm hoàn toàn bên trong góc trên bên phải. */
  .feedback-badge {
    top: 5px;
    right: 5px;
    width: 8px;
    height: 8px;
    border: 1px solid #fff;
    animation: feedback-mobile-pulse 2.2s infinite;
  }

  .feedback-panel {
    position: fixed;
    right: 12px;
    bottom: calc(66px + env(safe-area-inset-bottom));
    left: 12px;
    width: auto;
    transform-origin: center bottom;
  }

  .feedback-header {
    min-height: 92px;
    padding: 18px;
  }

  .feedback-body {
    max-height: calc(100dvh - 190px);
    padding: 18px;
  }
}

/* Hiệu ứng lan tỏa nhỏ hơn để luôn nằm gọn trong icon mobile. */
@keyframes feedback-mobile-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(57, 185, 120, 0.48);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(57, 185, 120, 0);
  }
}

/* Tôn trọng tùy chọn giảm chuyển động của người dùng. */
@media (prefers-reduced-motion: reduce) {
  .feedback-widget *,
  .feedback-widget *::before,
  .feedback-widget *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
