/* =============================================================
   XX8 | ABCVIP — Trung Tâm Khuyến Mãi
   Layout PC (Figma 14:1847) + Mobile (Figma 15:2122)
   ============================================================= */

/* ---------- Tokens ---------- */
:root {
  --brand-from: #f8586c;
  --brand-to:   #c63741;
  --title-from: #ff3c01;
  --title-to:   #ff1201;

  --ink:        #303233;
  --ink-strong: #000;
  --ink-mute:   #6b6f73;
  --line:       rgba(0, 0, 0, .23);
  --line-soft:  rgba(0, 0, 0, .1);
  --line-focus: #c63741;
  --danger:     #d32f2f;
  --success:    #2fa96a;

  --radius-card:  16px;
  --radius-field: 8.685px;
  --radius-promo: 13.027px;

  --control-h: 58.622px;
  --border-w:  1.086px;

  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
             "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Montserrat", var(--font-ui);

  --shadow-card: 0 0 16.6px rgba(0, 0, 0, .12), 0 4px 4px rgba(0, 0, 0, .25);
  --grad-brand: linear-gradient(180deg, var(--brand-from) 0%, var(--brand-to) 100%);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  color: var(--ink);
  background: #fff url("../assets/bg.png") center top / cover no-repeat fixed;
}

body.is-locked { overflow: hidden; }

img { display: block; max-width: 100%; }

button { font: inherit; color: inherit; }

.is-hidden { display: none !important; }

/* ---------- Shell ---------- */
.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding-bottom: 40px;
}

.wrap {
  width: 100%;
  max-width: 1400px;
  padding: 0 20px;
}

/* ---------- Logo ---------- */
.brand {
  width: 559.09px;
  max-width: calc(100% - 40px);
  margin: 119px 0 73px;
}

/* Recreates the Figma crop: the source PNG has large transparent padding. */
.brand__crop {
  position: relative;
  overflow: hidden;
  aspect-ratio: 559.09 / 89;
}

.brand__crop img {
  position: absolute;
  left: -8.7%;
  top: -47.14%;
  width: 116.34%;
  height: 192.51%;
  max-width: none;
}

/* ---------- Card ---------- */
.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px;
  background: #fff;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.card__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 28.225px;
  line-height: normal;
  letter-spacing: -0.5645px;
  text-align: center;
  background-image: linear-gradient(180deg, var(--title-from) 0%, var(--title-to) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Form ---------- */
.form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26.054px;
  width: 100%;
}

.form__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4.342px;
  position: relative;
}

.field--grow    { flex: 1 1 0; min-width: 210px; }
.field--bank    { flex: 0 0 auto; }
/* Ô captcha cần chỗ cho ảnh 162px + ô nhập, nếu không đủ thì xuống dòng */
.field--captcha { min-width: 296px; }

.field__label {
  font-size: 16px;
  font-weight: 510;
  line-height: 16.284px;
  background-image: var(--grad-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  width: fit-content;
}

.field__error {
  display: none;
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  color: var(--danger);
}

.field.is-invalid .field__error { display: block; }

/* ---------- Controls ---------- */
.control {
  position: relative;
  display: flex;
  align-items: center;
  height: var(--control-h);
  background: #fff;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-field);
}

.control__input {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  padding: 0 15.198px;
  margin: 0;
  border: 0;
  outline: 0;
  background: none;
  border-radius: inherit;
  font-family: var(--font-ui);
  font-size: 15.198px;
  color: var(--ink);
}

.control__input::placeholder { color: var(--ink); opacity: 1; }

.control:focus-within {
  border-color: var(--line-focus);
  box-shadow: 0 0 0 1px var(--line-focus);
}

.field.is-invalid .control,
.field.is-invalid .digits__box {
  border-color: var(--danger);
}

/* Ô "Thông tin khuyến mãi" — bấm để mở modal */
.control--select { padding-right: 49.53px; }

.control__input--select {
  display: flex;
  align-items: center;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.control__value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  color: var(--ink-strong);
}

.control__value.is-placeholder {
  font-weight: 400;
  color: var(--ink);
}

.control__addon {
  position: absolute;
  top: 50%;
  right: 9.53px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-field);
  background: var(--grad-brand);
  cursor: pointer;
  transition: filter .15s ease;
}

.control__addon:hover { filter: brightness(1.08); }

/* ---------- 4 số đuôi ngân hàng ---------- */
.digits {
  display: flex;
  gap: 4px;
}

.digits__box {
  width: var(--control-h);
  height: var(--control-h);
  padding: 0;
  margin: 0;
  background: #fff;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-field);
  outline: 0;
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  color: var(--ink-strong);
}

.digits__box:focus {
  border-color: var(--line-focus);
  box-shadow: 0 0 0 1px var(--line-focus);
}

/* ---------- Captcha ---------- */
.captcha {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.captcha__image {
  position: relative;
  flex: 0 0 auto;
  width: 162px;
  height: var(--control-h);
  padding: 0;
  border: 0;
  border-radius: var(--radius-field);
  overflow: hidden;
  background: #f4f5f6;
  cursor: pointer;
}

.captcha__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity .2s ease;
}

.captcha__spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2.5px solid rgba(0, 0, 0, .15);
  border-top-color: var(--brand-to);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.captcha__image.is-loading img { opacity: .25; }
.captcha__image.is-loading .captcha__spinner {
  opacity: 1;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.captcha__control { flex: 1 1 0; min-width: 0; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8.685px 23.883px;
  border: 0;
  border-radius: var(--radius-field);
  background: var(--grad-brand);
  color: #fff;
  font-weight: 700;
  font-size: 17.37px;
  cursor: pointer;
  transition: filter .15s ease, transform .12s ease;
}

.btn:hover  { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }

.btn--submit {
  width: 196.493px;
  min-width: 86.847px;
  height: 52.109px;
}

.btn[disabled],
.btn.is-loading {
  pointer-events: none;
  opacity: .7;
}

/* ---------- Banner khuyến mãi ----------
   Lưới 2 cột như Figma. Ô banner cao theo đúng tỉ lệ gốc của ảnh nên
   ảnh luôn hiển thị TRỌN VẸN, không cắt phần trên/dưới. */
.promos {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-top: 29px;
}

.promo {
  display: block;
  overflow: hidden;
  border-radius: var(--radius-promo);
  transition: transform .2s ease, box-shadow .2s ease;
}

.promo:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 22px rgba(0, 0, 0, .22);
}

.promo__img {
  width: 100%;
  height: auto;
}

/* =============================================================
   Modal
   ============================================================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 16, 18, .55);
  backdrop-filter: blur(2px);
  animation: fade-in .18s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal__box {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 620px;
  max-height: min(80vh, 720px);
  background: #fff;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  animation: pop-in .2s ease;
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 52px;
  border-bottom: 1px solid var(--line-soft);
}

.modal__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.4px;
  text-align: center;
  background-image: linear-gradient(180deg, var(--title-from) 0%, var(--title-to) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #f1f2f4;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease;
}

.modal__close:hover { background: #e4e6e9; }

.modal__search {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.modal__search input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-field);
  outline: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--ink);
}

.modal__search input:focus {
  border-color: var(--line-focus);
  box-shadow: 0 0 0 1px var(--line-focus);
}

/* ---------- Danh sách khuyến mãi ---------- */
.promo-list {
  flex: 1 1 auto;
  margin: 0;
  padding: 8px;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.promo-list__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s ease;
}

.promo-list__item:hover,
.promo-list__item.is-active { background: rgba(248, 88, 108, .1); }

.promo-list__item[aria-selected="true"] { background: rgba(248, 88, 108, .16); }

.promo-list__code {
  flex: 0 0 auto;
  min-width: 92px;
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--grad-brand);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
  letter-spacing: .2px;
}

.promo-list__name {
  flex: 1 1 auto;
  font-size: 14.5px;
  line-height: 1.35;
  color: var(--ink);
}

.promo-list__empty {
  margin: 0;
  padding: 28px 16px;
  text-align: center;
  font-size: 14.5px;
  color: var(--ink-mute);
}

.promo-list__empty[hidden] { display: none; }

/* =============================================================
   Dialog kết quả
   ============================================================= */
.dialog {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 28px 24px 24px;
  background: #fff;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  text-align: center;
  animation: pop-in .2s ease;
}

.dialog__icon {
  width: 68px;
  height: 68px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 3px solid var(--success);
  color: var(--success);
  font-size: 36px;
  line-height: 62px;
  font-weight: 700;
}

.dialog__icon::before { content: "\2713"; }

.dialog--error .dialog__icon {
  border-color: var(--danger);
  color: var(--danger);
}

.dialog--error .dialog__icon::before { content: "\2715"; }

.dialog__title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.3px;
  color: var(--ink-strong);
}

.dialog__text {
  margin: 0 0 22px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-line;
  word-break: break-word;
}

.dialog__ok {
  width: 100%;
  height: 48px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 10px;
  background: #23262b;
  color: #fff;
  font-size: 14.5px;
  line-height: 1.4;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
}

.toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

.toast--ok    { background: linear-gradient(180deg, #2fa96a, #1e8351); }
.toast--error { background: linear-gradient(180deg, #e2545f, #b8323d); }

/* =============================================================
   Tablet — thu gọn hàng 4 cột thành 2 cột
   ============================================================= */
@media (max-width: 1180px) {
  .field--grow,
  .field--bank { flex: 1 1 calc(50% - 10px); min-width: 260px; }

  .field--captcha { min-width: 296px; }

  .digits { width: 100%; }
  .digits__box { flex: 1 1 0; width: auto; min-width: 0; }
}

/* =============================================================
   Mobile — Figma 15:2122 (440px)
   ============================================================= */
@media (max-width: 768px) {
  .page { padding-bottom: 24px; }

  .wrap { padding: 0 12px; }

  .brand {
    width: 374px;
    max-width: calc(100% - 24px);
    margin: 30px 0 24px;
  }

  .brand__crop { aspect-ratio: 374 / 59; }

  .card {
    gap: 24px;
    padding: 12px;
  }

  /* Các trường xếp dọc, khoảng cách 13.027px như thiết kế mobile */
  .form__row {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 13.027px;
  }

  .field--grow,
  .field--bank,
  .field--captcha {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }

  .btn--submit { width: 100%; }

  .captcha__image { width: 162px; }

  /* Mobile: banner xếp dọc 1 cột, vẫn hiện trọn ảnh */
  .promos {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    margin-top: 24px;
  }

  .promo:hover { transform: none; box-shadow: none; }

  .modal { padding: 12px; align-items: flex-end; }
  .modal--dialog { align-items: center; }

  .modal__box {
    max-width: 100%;
    max-height: 86vh;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
  }

  .modal__title { font-size: 19px; }
  .promo-list__code { min-width: 84px; font-size: 11.5px; }
  .promo-list__name { font-size: 13.5px; }

  .toast { bottom: 20px; }
}

/* Màn hình rất hẹp: ảnh captcha co lại để ô nhập còn chỗ */
@media (max-width: 390px) {
  .captcha__image { width: 138px; }
  .card__title { font-size: 24px; }
}

/* ---------- A11y ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

:focus-visible { outline: 2px solid var(--brand-to); outline-offset: 2px; }
