/* ═══════════════════════════════════════════════════════════════════
   Shop VN — CSS thuần, không framework, không cần Node để build.
   Mobile-first: mọi thứ viết cho màn hình hẹp trước, màn rộng thêm sau.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --ink:      #17202a;
  --muted:    #697586;
  --line:     #e5e8ed;
  --paper:    #ffffff;
  --surface:  #f2f4f7;
  --brand:    #0b5fd0;   /* xanh đậm — tin cậy, dùng cho hành động/thanh toán */
  --brand-dk: #084aa3;
  --price:    #e1252b;   /* đỏ — ngôn ngữ giá của thương mại điện tử VN */
  --ok:       #0e8a4f;
  --warn:     #b26a00;
  --warn-bg:  #fff7e6;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;

  --nav-h: 58px;

  /* Font hệ thống: hiển thị dấu tiếng Việt chuẩn trên mọi máy, tải tức thì,
     không phụ thuộc Google Fonts (vốn nhiều font thiếu dấu tiếng Việt). */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--surface);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

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

a { color: inherit; text-decoration: none; }

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.015em; }
h1 { font-size: 20px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }

p { margin: 0 0 10px; }

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

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ── Bố cục ───────────────────────────────────────────────────── */
.wrap { max-width: 640px; margin: 0 auto; padding: 0 14px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Thanh trên ───────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-in { display: flex; align-items: center; gap: 10px; height: 54px; }
.logo { font-weight: 800; font-size: 18px; color: var(--brand); letter-spacing: -0.02em; }
.back { font-size: 22px; line-height: 1; padding: 6px; margin-left: -6px; }

.searchbox {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 999px; padding: 0 14px; height: 40px;
}
.searchbox input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 16px;   /* ⚠ 16px: nhỏ hơn thì iOS Safari tự phóng to trang */
  font-family: inherit; color: var(--ink); min-width: 0;
}

/* ── Thanh điều hướng dưới (vùng ngón cái) ────────────────────── */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--paper); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav-in { display: grid; grid-template-columns: repeat(4, 1fr); height: var(--nav-h); }
.navitem {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: 11px; position: relative;
}
.navitem.on { color: var(--brand); font-weight: 600; }
.navitem svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: 4px; left: 54%;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--price); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}

/* ── Thẻ, khối ────────────────────────────────────────────────── */
.card {
  background: var(--paper); border-radius: var(--r);
  border: 1px solid var(--line); overflow: hidden;
}
.card-pad { padding: 14px; }
.section { margin-top: 18px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.section-head a { color: var(--brand); font-size: 13px; font-weight: 600; }

/* ── Lưới sản phẩm ────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.pcard { background: var(--paper); border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); }
.pcard-img { position: relative; aspect-ratio: 1 / 1; background: var(--surface); }
.pcard-img img { width: 100%; height: 100%; object-fit: cover; }
.pcard-body { padding: 8px 10px 10px; }
.pcard-name { font-size: 13px; line-height: 1.35; height: 2.7em; margin-bottom: 4px; }

/* Giá là thứ nổi nhất trên mỗi thẻ — đúng ngôn ngữ mua sắm ở VN */
.price { color: var(--price); font-weight: 700; font-size: 15px; }
.price-lg { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.price-old { color: var(--muted); font-size: 12px; text-decoration: line-through; margin-left: 5px; }

.tag-sale {
  position: absolute; top: 6px; right: 6px;
  background: var(--price); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
}
.tag-out {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.78); font-size: 13px; font-weight: 600; color: var(--muted);
}

/* ── Danh mục ─────────────────────────────────────────────────── */
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 4px; text-align: center;
}
.cat-ico { font-size: 24px; line-height: 1; }
.cat-name { font-size: 11px; margin-top: 5px; color: var(--muted); }

/* ── Nút ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px;      /* >= 44px: ngón tay bấm được */
  border: 0; border-radius: var(--r);
  font-family: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer; background: var(--surface); color: var(--ink);
  transition: background .12s;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dk); }
.btn-buy { background: var(--price); color: #fff; }
.btn-line { background: var(--paper); border: 1.5px solid var(--brand); color: var(--brand); }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 36px; font-size: 13px; padding: 0 12px; border-radius: var(--r-sm); }

/* Thanh mua hàng dính đáy — không phải cuộn lên mới bấm được */
.buybar {
  position: fixed; left: 0; right: 0; bottom: var(--nav-h); z-index: 39;
  background: var(--paper); border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 10px;
}
.buybar .btn { flex: 1; }

/* ── Biểu mẫu ─────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.input, .textarea, .select {
  width: 100%; padding: 12px 14px;
  font-family: inherit; font-size: 16px;   /* ⚠ 16px chống iOS tự phóng to */
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r);
  outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--brand); }
.textarea { min-height: 84px; resize: vertical; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.err { font-size: 13px; color: var(--price); margin-top: 5px; }

.pick { display: flex; gap: 10px; }
.pick label {
  flex: 1; border: 1.5px solid var(--line); border-radius: var(--r);
  padding: 12px; cursor: pointer; background: var(--paper);
}
.pick input { position: absolute; opacity: 0; }
.pick input:checked + span { color: var(--brand); font-weight: 700; }
.pick label:has(input:checked) { border-color: var(--brand); background: #f3f8ff; }

/* ── Thông báo ────────────────────────────────────────────────── */
.alert { border-radius: var(--r); padding: 12px 14px; font-size: 14px; margin-top: 12px; }
.alert-ok { background: #eaf7f0; color: var(--ok); }
.alert-err { background: #fdeceb; color: var(--price); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }

/* ── Số lượng ─────────────────────────────────────────────────── */
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.qty button {
  width: 36px; height: 36px; border: 0; background: var(--paper);
  font-size: 18px; color: var(--ink); cursor: pointer;
}
.qty span { min-width: 38px; text-align: center; font-size: 14px; font-weight: 600; }

/* ── Dòng trong giỏ ───────────────────────────────────────────── */
.line { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line img { width: 68px; height: 68px; border-radius: var(--r-sm); object-fit: cover; background: var(--surface); }

.sum { padding: 14px; }
.sum-row { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; }
.sum-total { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 10px; font-weight: 700; }

/* ── Trạng thái đơn ───────────────────────────────────────────── */
.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.chip-pending   { background: var(--warn-bg); color: var(--warn); }
.chip-paid      { background: #eaf7f0; color: var(--ok); }
.chip-shipping  { background: #e9f1ff; color: var(--brand); }
.chip-completed { background: #eaf7f0; color: var(--ok); }
.chip-cancelled { background: var(--surface); color: var(--muted); }
.chip-refunded  { background: var(--surface); color: var(--muted); }

/* ── Trang thanh toán QR ──────────────────────────────────────── */
.qr-box {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 16px; display: inline-block;
}
.qr-box img { width: 250px; height: 250px; }
.bank-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.bank-row:last-child { border-bottom: 0; }
.copy {
  background: none; border: 0; padding: 0; font-family: inherit; font-size: 14px;
  font-weight: 700; color: var(--ink); cursor: pointer; text-align: right;
}
.copy.ref { color: var(--brand); letter-spacing: .5px; }
.waiting { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

/* ── Trống ────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-ico { font-size: 40px; margin-bottom: 10px; }

/* ── Quản trị ─────────────────────────────────────────────────── */
.admin-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; }
.admin-tabs a {
  white-space: nowrap; padding: 7px 13px; border-radius: 999px;
  background: var(--paper); border: 1px solid var(--line); font-size: 13px; font-weight: 600;
}
.admin-tabs a.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 13px; }
.stat-n { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.stat-l { font-size: 12px; color: var(--muted); }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }

.pager { display: flex; justify-content: space-between; gap: 10px; margin: 16px 0; }
