/* ==========================================================================
   Tàu Hũ Tươi Phúc An — order.css
   Modal đặt hàng: chọn món (menu dọc) → giao hàng (phí ship) → xem lại +
   thanh toán → biên lai. File tự chứa (kể cả responsive riêng).
   ========================================================================== */

.order-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.order-modal[hidden] {
  display: none;
}

.order-modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-overlay);
  animation: fadeIn 220ms ease both;
}

.order-modal__dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  background-color: var(--color-bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: orderSlideUp 320ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes orderSlideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .order-modal__backdrop,
  .order-modal__dialog {
    animation: none;
  }
}

/* ---------- Header ---------- */
.order-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: 18px var(--container-padding) 12px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.order-modal__title {
  font-size: 1.2rem;
  margin: 0;
}

.order-modal__close {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--color-text);
  flex-shrink: 0;
}

.order-modal__close:hover,
.order-modal__close:focus-visible {
  border-color: var(--color-gold);
  color: var(--color-gold-strong);
}

/* ---------- Step indicator ---------- */
.order-steps {
  display: flex;
  gap: 6px;
  padding: 12px var(--container-padding) 0;
  flex-shrink: 0;
}

.order-steps__item {
  flex: 1;
  height: 4px;
  border-radius: var(--radius-full);
  background-color: var(--color-border);
  transition: background-color var(--transition-base);
}

.order-steps__item.is-active,
.order-steps__item.is-done {
  background-color: var(--color-gold);
}

.order-steps__labels {
  display: flex;
  justify-content: space-between;
  padding: 6px var(--container-padding) 0;
  font-size: 0.72rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.order-steps__labels span[data-current] {
  color: var(--color-gold-strong);
  font-weight: 700;
}

[data-theme='dark'] .order-steps__labels span[data-current] {
  color: var(--color-gold);
}

/* ---------- Body ---------- */
.order-modal__body {
  padding: var(--space-md) var(--container-padding);
  overflow-y: auto;
  flex-grow: 1;
}

.order-step[hidden] {
  display: none;
}

.order-step__title {
  font-size: 1.05rem;
  margin-bottom: var(--space-sm);
}

/* ---------- Bước 1: menu dọc chọn món ---------- */
.order-menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.order-item:hover {
  border-color: var(--color-gold);
  box-shadow: var(--shadow-sm);
}

.order-item.has-qty {
  border-color: var(--color-gold);
  background-color: var(--color-bg-soft);
}

.order-item__media {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 50%;
  padding: 2.5px;
  background: var(--metallic-gold);
  background-size: 220% 220%;
  background-position: 0% 0%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-base), box-shadow var(--transition-base), background-position 900ms var(--ease-premium);
}

.order-item:hover .order-item__media {
  transform: scale(1.08);
  box-shadow: var(--shadow-md);
  background-position: 100% 100%;
}

.order-item__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  background: #fff;
}

.order-item__info {
  flex: 1 1 auto;
  min-width: 0;
}

.order-item__name {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--color-heading);
}

.order-item__price {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.order-item__subtotal {
  min-height: 1.1em;
  font-size: 0.78rem;
  color: var(--color-gold-strong);
  font-weight: 600;
}

[data-theme='dark'] .order-item__subtotal {
  color: var(--color-gold);
}

.order-item__qty {
  flex-shrink: 0;
}

.qty-control {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.qty-control button {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--color-text);
  transition: background-color var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
  /* Chặn double-tap zoom riêng ở nút đổi số lượng, vẫn giữ cuộn và pinch zoom. */
  touch-action: manipulation;
}

/* Các nút mở/điều hướng giỏ hàng cũng là thao tác chạm lặp lại trên mobile. */
[data-order-open],
[data-order-next],
[data-order-back],
[data-order-reset] {
  touch-action: manipulation;
}

.qty-control button:hover,
.qty-control button:focus-visible {
  background-color: var(--color-bg-soft);
  color: var(--color-gold-strong);
}

.qty-control input {
  width: 34px;
  height: 40px;
  text-align: center;
  border: none;
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  background-color: transparent;
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  -moz-appearance: textfield;
  /* Gõ/chạm liên tục vào ô số lượng cũng không nên kích hoạt double-tap zoom. */
  touch-action: manipulation;
}

.qty-control input::-webkit-outer-spin-button,
.qty-control input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---------- Bước 2: option card (giao hàng) ---------- */
.order-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: var(--space-md);
}

.option-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.option-card:hover {
  border-color: var(--color-gold);
}

.option-card input {
  margin-top: 3px;
  accent-color: var(--color-gold);
  flex-shrink: 0;
}

.option-card:has(input:checked) {
  border-color: var(--color-gold);
  background-color: var(--color-bg-soft);
}

.option-card__title {
  font-weight: 600;
  color: var(--color-heading);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.option-card__fee {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-gold-strong);
}

[data-theme='dark'] .option-card__fee {
  color: var(--color-gold);
}

.option-card__fee--free {
  color: var(--color-primary);
}

[data-theme='dark'] .option-card__fee--free {
  color: #8fc7a4;
}

.option-card__desc {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  display: block;
  margin-top: 2px;
}

.order-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: var(--space-md);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* .field tự set display:flex nên đè mất display:none mặc định của [hidden] —
   phải khai báo lại tường minh (cùng lý do đã sửa cho .btn/.order-modal__footer). */
.field[hidden] {
  display: none;
}

.field__required {
  color: var(--color-gold-strong);
}

[data-theme='dark'] .field__required {
  color: var(--color-gold);
}

.field input,
.field select {
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface);
  color: var(--color-text);
}

.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a08f74' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
}

.field input:focus-visible,
.field select:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 1px;
}

.field.has-error input,
.field.has-error select {
  border-color: #c1503f;
}

.field__error {
  font-size: 0.78rem;
  color: #c1503f;
  display: none;
}

.field__hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-weight: 400;
}

.field.has-error .field__error {
  display: block;
}

.order-note {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  background-color: var(--color-bg-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* Cảnh báo hiển thị khi TẮT bán hàng — tổng tiền ở bước Chọn món chỉ mang tính tham khảo */
.order-mode-notice {
  margin-top: var(--space-sm);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-gold-strong);
  background-color: rgba(var(--color-gold-rgb), 0.12);
  border: 1px solid rgba(var(--color-gold-rgb), 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

[data-theme='dark'] .order-mode-notice {
  color: var(--color-gold);
}

.btn--sm {
  padding: 8px 16px;
  font-size: 0.84rem;
}

/* ---------- Bước 3: xem lại đơn + thanh toán ---------- */
.order-review {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  background-color: var(--color-bg-soft);
}

.order-review__title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-heading);
  margin-bottom: 6px;
}

.order-review__line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.86rem;
  padding: 4px 0;
  color: var(--color-text);
}

.order-review__line--muted {
  color: var(--color-text-muted);
}

.order-review__line--discount {
  color: #3a8a5e;
  font-weight: 600;
}

[data-theme='dark'] .order-review__line--discount {
  color: #6fcf9a;
}

.order-review__divider {
  border: none;
  border-top: 1px dashed var(--color-border);
  margin: 6px 0;
}

.order-review__total {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-heading);
  padding-top: 4px;
}

.order-review__total strong {
  color: var(--color-gold-strong);
}

[data-theme='dark'] .order-review__total strong {
  color: var(--color-gold);
}

.order-review__meta {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 6px;
}

/* ---------- QR box ---------- */
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: var(--space-md);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  text-align: center;
  margin-bottom: var(--space-md);
}

.qr-box[hidden] {
  display: none;
}

.qr-box img {
  width: 190px;
  height: auto;
  border-radius: var(--radius-sm);
}

.qr-box p {
  font-size: 0.85rem;
  margin: 0;
}

/* ---------- Bước 4: biên lai ---------- */
.receipt {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

.receipt__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: var(--space-sm);
  border-bottom: 1px dashed var(--color-border);
  margin-bottom: var(--space-sm);
}

.receipt__header img {
  height: 44px;
  width: auto;
}

.receipt__meta {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.receipt__meta strong {
  color: var(--color-heading);
}

.receipt__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-bottom: var(--space-sm);
}

.receipt__table th,
.receipt__table td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid var(--color-border);
}

.receipt__table th:last-child,
.receipt__table td:last-child {
  text-align: right;
}

.receipt__block {
  font-size: 0.88rem;
  margin-bottom: 6px;
}

.receipt__block strong {
  color: var(--color-heading);
}

.receipt__total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--font-heading);
  font-size: 1.2rem;
  color: var(--color-heading);
  padding-top: var(--space-sm);
  margin-top: var(--space-sm);
  border-top: 1px solid var(--color-border);
}

.receipt__total strong {
  color: var(--color-gold-strong);
}

[data-theme='dark'] .receipt__total strong {
  color: var(--color-gold);
}

.receipt__care-note {
  margin-top: var(--space-sm);
  font-size: 0.82rem;
  color: var(--color-text-muted);
  background-color: var(--color-bg-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 1.5;
}

.receipt__thanks {
  margin-top: var(--space-md);
  text-align: center;
  font-size: 0.92rem;
  color: var(--color-text);
}

.receipt__slogan-quote {
  margin-top: 4px;
  text-align: center;
  font-family: var(--font-heading);
  font-style: italic;
  font-weight: 700;
  color: var(--color-gold-strong);
}

[data-theme='dark'] .receipt__slogan-quote {
  color: var(--color-gold);
}

.receipt__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: var(--space-md);
}

.receipt__actions .btn {
  flex: 1 1 auto;
}

/* ---------- Footer / navigation ---------- */
.order-modal__footer[hidden] {
  display: none;
}

.order-modal__footer {
  flex-shrink: 0;
  flex-wrap: wrap;
  border-top: 1px solid var(--color-border);
  padding: 12px var(--container-padding);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  background-color: var(--color-bg);
}

.order-modal__total {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.order-modal__total strong {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  color: var(--color-heading);
  margin-left: 6px;
  white-space: nowrap;
}

.order-modal__actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.order-modal__actions .btn {
  padding: 11px 16px;
  font-size: 0.88rem;
  white-space: nowrap;
}

/* Màn hình hẹp: tổng tiền chiếm 1 dòng riêng, 2 nút xuống dòng dưới và giãn đều */
@media (max-width: 420px) {
  .order-modal__footer {
    flex-direction: column;
    align-items: stretch;
  }

  .order-modal__total {
    text-align: center;
  }

  .order-modal__actions {
    width: 100%;
  }

  .order-modal__actions .btn {
    flex: 1;
  }
}

.order-modal__actions .btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- Toast xác nhận nhỏ ---------- */
.order-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background-color: var(--color-primary);
  color: #f3ecdd;
  padding: 12px 20px;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  box-shadow: var(--shadow-md);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}

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

/* ---------- Account panel (đăng nhập nhẹ, lưu cục bộ) ---------- */
.account-panel[hidden] {
  display: none;
}

/* Tông mint riêng cho bảng Tài khoản — điểm nhấn "tươi mát" tách biệt khỏi
   tông vàng-kem ấm của web chính (xem biến --color-mint* trong variables.css).
   Đồng thời sửa lỗi bảng bị che/tràn khúc cuối: panel giờ có max-height + chỉ
   phần THÂN (.account-panel__body) cuộn riêng, còn tiêu đề/nút Đóng luôn cố
   định phía trên, không bị cuộn mất khỏi tầm nhìn. */
.account-panel {
  position: fixed;
  top: calc(var(--header-height-mobile) + 10px);
  right: 14px;
  left: 14px;
  z-index: 210;
  max-width: 340px;
  margin-left: auto;
  max-height: calc(100vh - var(--header-height-mobile) - 30px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(165deg, var(--color-mint-soft) 0%, var(--color-surface) 55%);
  border: 1px solid rgba(var(--color-mint-rgb), 0.3);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 48px rgba(var(--color-mint-rgb), 0.22);
  padding: var(--space-md);
  animation: orderSlideUp 220ms ease both;
}

@media (min-width: 1024px) {
  .account-panel {
    top: calc(var(--header-height) + 10px);
    max-height: calc(100vh - var(--header-height) - 30px);
  }
}

.account-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
  flex: 0 0 auto;
}

.account-panel__header h3 {
  font-size: 1.05rem;
  margin: 0;
  color: var(--color-mint-strong);
}

.account-panel__body {
  overflow-y: auto;
  min-height: 0;
}

.account-panel__desc {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

.account-panel__hello {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  margin-bottom: 2px;
  color: var(--color-mint-strong);
}

.account-panel__note {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: var(--space-sm);
}

.account-panel__subheading {
  font-size: 0.85rem;
  margin: var(--space-md) 0 6px;
  color: var(--color-heading);
}

.account-panel .field {
  margin-bottom: 10px;
}

/* Nút "Lưu thông tin" trong bảng đổi sang tông mint cho đồng bộ với màu bảng,
   thay vì vàng gold mặc định (dễ lẫn với các nút khác ngoài trang). */
.account-panel .btn--primary {
  background-color: var(--color-mint);
  color: var(--color-on-mint);
  box-shadow: none;
}

.account-panel .btn--primary:hover,
.account-panel .btn--primary:focus-visible {
  background-color: var(--color-mint-strong);
}

.account-panel .field input:focus-visible {
  outline-color: var(--color-mint);
}

.account-history {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: var(--space-sm);
}

/* Mỗi đơn trong lịch sử: 1 hàng duy nhất — ngày, số món, tổng tiền, nút
   "Đặt lại" nhỏ nằm bên phải (đã bỏ cột mã đơn, khách không cần xem mã). */
.account-history__item {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(var(--color-mint-rgb), 0.25);
  border-radius: var(--radius-sm);
  background-color: rgba(var(--color-mint-rgb), 0.05);
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.account-history__item span:nth-child(3) {
  color: var(--color-mint-strong);
  font-weight: 600;
  text-align: right;
}

[data-theme='dark'] .account-history__item span:nth-child(3) {
  color: var(--color-mint);
}

.account-history__item [data-reorder-history] {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.78rem;
}

.account-history__empty {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  text-align: center;
  padding: 10px 0;
}

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
  .order-modal {
    align-items: center;
    padding: var(--space-lg);
  }

  .order-modal__dialog {
    border-radius: var(--radius-lg);
    max-height: 88vh;
  }

  .order-options {
    flex-direction: row;
  }

  .option-card {
    flex: 1;
  }

  .order-fields {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .field {
    flex: 1 1 220px;
  }
}
