/* =========================
   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, "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
}

.feedback-widget.is-right {
  right: 24px;
  left: auto;
}

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

/* =========================
   Nút bong bóng chat — thiết kế chữ nhật nhỏ gọn cho mọi thiết bị
   ========================= */
.feedback-fab {
  position: relative;
  display: grid;
  width: 40px;
  height: 40px;
  margin-right: auto;
  padding: 0;
  place-items: center;
  color: var(--wine);
  background-color: rgba(253, 250, 246, 0.2);
  border: 1px solid #d1c7b5;
  border-radius: 4px;
  box-shadow: 0 3px 10px rgba(44, 33, 31, 0.14);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.feedback-fab:hover {
  background-color: rgba(253, 250, 246, 0.2);
  box-shadow: 0 3px 10px rgba(44, 33, 31, 0.14);
  transform: none;
}

.feedback-fab:focus-visible,
.feedback-close:focus-visible,
.feedback-submit:focus-visible,
.zalo-button:focus-visible,
.feedback-capture-button:focus-visible,
.feedback-screenshot-remove:focus-visible,
.feedback-screenshot-preview:focus-visible,
.feedback-preview-close:focus-visible,
.feedback-file-input:focus-visible + .feedback-attachment-actions .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: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  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);
}

/* Chấm trạng thái online — nằm trong góc trên phải của icon */
.feedback-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: #39b978;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  animation: feedback-pulse 2.2s infinite;
}

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

.feedback-honeypot {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =========================
   Khung chat
   ========================= */
.feedback-panel {
  position: absolute;
  right: auto;
  left: 0;
  bottom: 54px;
  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-right .feedback-panel {
  right: 0;
  left: auto;
  transform-origin: right bottom;
}

.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: 60px;
  padding: 11px 16px;
  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-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.feedback-close {
  display: grid;
  width: 32px;
  height: 32px;
  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: 17px;
  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-attachment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feedback-file-button,
.feedback-capture-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-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.feedback-capture-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

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

.feedback-file-button svg,
.feedback-capture-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;
  overflow-wrap: anywhere;
}

.feedback-upload-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 7px 7px 12px;
  background: rgba(255, 250, 240, 0.75);
  border: 1px solid rgba(123, 17, 10, 0.16);
  border-radius: 9px;
}

.feedback-upload-item::before {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  content: "";
  background: var(--wine);
  border-radius: 50%;
}

.feedback-screenshot-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px;
  background: rgba(255, 250, 240, 0.75);
  border: 1px solid rgba(123, 17, 10, 0.16);
  border-radius: 9px;
}

.feedback-screenshot-preview {
  width: 52px;
  height: 38px;
  flex: 0 0 52px;
  padding: 0;
  overflow: hidden;
  background: #eee;
  border: 1px solid #ded4d1;
  border-radius: 5px;
  cursor: zoom-in;
}

.feedback-screenshot-thumbnail {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 180ms ease;
}

.feedback-screenshot-preview:hover .feedback-screenshot-thumbnail {
  transform: scale(1.08);
}

.feedback-screenshot-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feedback-screenshot-remove {
  display: grid;
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  padding: 0;
  place-items: center;
  color: var(--wine);
  background: #fff;
  border: 1px solid rgba(123, 17, 10, 0.25);
  border-radius: 50%;
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.feedback-screenshot-remove:hover {
  color: #fff;
  background: var(--wine);
}

/* Hộp phóng lớn ảnh chụp màn hình trước khi gửi. */
.feedback-preview {
  position: fixed;
  z-index: 10001;
  inset: 0;
  display: grid;
  padding: 24px;
  place-items: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.feedback-preview.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.feedback-preview-backdrop {
  position: absolute;
  inset: 0;
  padding: 0;
  background: rgba(20, 12, 11, 0.82);
  border: 0;
  cursor: zoom-out;
}

.feedback-preview-content {
  position: relative;
  z-index: 1;
  max-width: min(1100px, 94vw);
  max-height: 90vh;
}

.feedback-preview-content img {
  display: block;
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.38);
}

.feedback-preview-close {
  position: absolute;
  top: -14px;
  right: -14px;
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  color: #fff;
  background: var(--wine);
  border: 2px solid #fff;
  border-radius: 50%;
  font: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.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.48);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(57, 185, 120, 0);
  }
}

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

  .feedback-widget.is-right {
    left: auto;
    right: 14px;
  }

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

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


/* 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;
  }
}
