:root {
  --brand: #0057b8;
  --brand-dark: #003d82;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #6b7684;
  --line: #e6eaf0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08), 0 1px 2px rgba(20, 30, 50, 0.04);
  --tabbar-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--brand);
  color: #fff;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Toggle Giá NPP */
.npp-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  flex: 0 0 auto;
  user-select: none;
}
.npp-text { font-size: 12.5px; font-weight: 600; color: #fff; opacity: .95; }
.npp-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.npp-track {
  width: 38px; height: 22px;
  background: rgba(255, 255, 255, .35);
  border-radius: 999px;
  position: relative;
  transition: background .18s;
}
.npp-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff; border-radius: 50%;
  transition: transform .18s;
}
.npp-toggle input:checked + .npp-track { background: #16a34a; }
.npp-toggle input:checked + .npp-track .npp-thumb { transform: translateX(16px); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .2px; }

main { max-width: 640px; margin: 0 auto; }

/* ===== Toolbar / tìm kiếm ===== */
.toolbar {
  position: sticky;
  top: 58px;
  z-index: 10;
  background: var(--bg);
  padding: 12px 14px 6px;
}
.search-wrap {
  position: relative;
  display: flex; align-items: center;
}
.search-ico {
  position: absolute; left: 12px; width: 18px; height: 18px; color: var(--muted);
}
#search, #order-search {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
  outline: none;
}
#search:focus, #order-search:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0,87,184,.12); }

.chips {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding: 10px 0 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ===== Danh sách sản phẩm ===== */
.product-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 8px 14px 24px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card-media { display: block; line-height: 0; }
.card-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #f0f2f6;
}
.card-body { padding: 10px 11px 11px; display: flex; flex-direction: column; flex: 1; }
.card-cat { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.card-name {
  margin: 3px 0 6px;
  font-size: 13.5px;
  line-height: 1.3;
  font-weight: 600;
}
.card-pvbv { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.card-foot {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 6px;
  margin-top: auto;
}
.card-prices { min-width: 0; }
.card-price { display: block; font-size: 14px; font-weight: 800; color: var(--brand-dark); }
.card-npp { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.btn-add {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border: none; border-radius: 9px;
  background: var(--brand); color: #fff;
  font-size: 20px; line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
}
.btn-add.added { background: #2e7d32; }

/* ===== Trang Đơn hàng ===== */
/* Đơn mẫu */
.order-add { padding: 12px 14px 10px; }

/* Kết quả tìm kiếm: chạm để thêm */
.order-results {
  margin-top: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(20, 30, 50, .08);
  overflow: hidden;
}
.result-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none; border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
  font: inherit; color: inherit;
  cursor: pointer;
}
.result-row:last-child { border-bottom: none; }
.result-row:active { background: #f3f6fb; }
.result-img { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 8px; object-fit: cover; background: #f0f2f6; }
.result-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.result-name { font-size: 13px; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-price { font-size: 12px; color: var(--muted); }
.result-count {
  flex: 0 0 auto;
  font-size: 11.5px; font-weight: 700;
  color: #16a34a; background: rgba(22, 163, 74, .12);
  padding: 2px 7px; border-radius: 999px;
}
.result-add {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
  font-size: 18px; line-height: 1;
}
.result-empty { margin: 0; padding: 12px; font-size: 13px; color: var(--muted); text-align: center; }

/* Đơn mẫu: dòng phụ dưới ô tìm */
.templates {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 8px;
}
.tpl-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.tpl-btn {
  border: 1px solid var(--brand);
  background: rgba(0, 87, 184, .06);
  color: var(--brand);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.tpl-btn:active { background: rgba(0, 87, 184, .14); }

.order-items { padding: 0 14px; display: flex; flex-direction: column; gap: 7px; }
.order-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  grid-template-areas:
    "img info info"
    "img qty  line";
  gap: 2px 9px;
  align-items: center;
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
}
.order-img { grid-area: img; width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.order-info { grid-area: info; min-width: 0; }
.order-name { margin: 0; font-size: 12.5px; font-weight: 600; line-height: 1.25; }
.order-unit { font-size: 11.5px; color: var(--muted); }

.qty { grid-area: qty; display: flex; align-items: center; gap: 5px; }
.qty-btn {
  width: 24px; height: 24px;
  border: 1px solid var(--line); background: #fff;
  border-radius: 7px; font-size: 15px; line-height: 1;
  cursor: pointer; color: var(--brand);
}
.qty-input {
  width: 34px; height: 24px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
  -moz-appearance: textfield;
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.order-line { grid-area: line; text-align: right; }
.line-total { display: block; font-size: 13.5px; font-weight: 800; color: var(--brand-dark); }
.line-total.is-gift { color: #16a34a; }
.gift-tag {
  display: inline-block;
  font-size: 10.5px; font-weight: 700;
  color: #16a34a; background: rgba(22, 163, 74, .12);
  padding: 1px 7px; border-radius: 999px;
  vertical-align: middle;
}
.line-remove {
  border: none; background: none; color: #c0392b;
  font-size: 11.5px; cursor: pointer; padding: 1px 0;
}

/* ===== Tổng kết ===== */
.order-summary {
  margin: 12px 14px 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 16px;
}
.btn-block {
  width: 100%;
  margin-top: 12px;
  border: none;
  background: var(--brand);
  color: #fff;
  padding: 12px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn-block svg { width: 18px; height: 18px; }

/* Hàng nút cuối trang đơn hàng */
.order-actions {
  display: flex; gap: 8px;
  margin: 12px 14px 18px;
}
.order-actions .btn-ghost,
.order-actions .btn-block { margin-top: 0; }
.order-actions .btn-ghost { flex: 1; }
.order-actions .btn-block { flex: 2; }
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.summary-row.sub { font-size: 13px; color: var(--muted); padding: 4px 0; }
.summary-row.total {
  border-top: 1px dashed var(--line);
  margin-top: 4px; padding-top: 12px;
  font-size: 18px; font-weight: 800;
}
.summary-row.total span:last-child { color: var(--brand-dark); }
.btn-ghost {
  width: 100%;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: #c0392b;
  padding: 11px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.empty { text-align: center; color: var(--muted); padding: 28px 20px; font-size: 14px; }

/* ===== Tabbar dưới ===== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff;
  border-top: 1px solid var(--line);
  display: flex;
}
.tab {
  flex: 1;
  border: none; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11.5px; font-weight: 600;
  cursor: pointer;
  position: relative;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--brand); }
.badge {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(6px);
  min-width: 18px; height: 18px;
  padding: 0 5px;
  background: #e53935; color: #fff;
  border-radius: 999px;
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

/* ===== Thanh toán ===== */
.payment {
  margin: 14px 14px 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}
.payment-title { margin: 0 0 12px; font-size: 15px; font-weight: 800; color: var(--brand-dark); }
.payment-qr {
  width: 200px; max-width: 70%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.payment-info { margin: 12px auto 0; max-width: 320px; }
.pay-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}
.pay-row:last-child { border-bottom: none; }
.pay-row span { color: var(--muted); }
.pay-row b { font-weight: 700; margin-left: auto; }
.bank-acc { letter-spacing: .5px; }
.pay-missing { margin: 4px 0 10px; color: var(--muted); font-size: 14px; }
.link-btn,
.copy-btn {
  flex: 0 0 auto;
  border: 1px solid var(--brand);
  background: rgba(0, 87, 184, .06);
  color: var(--brand);
  font-size: 12px; font-weight: 700;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.payment-note { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.payment-note:empty { display: none; }

/* ===== Tài khoản ===== */
.account { padding: 12px 14px 24px; }
.acc-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.acc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.acc-name { font-size: 16px; font-weight: 800; }
.acc-sub { font-size: 12.5px; color: var(--muted); }
.acc-title { margin: 0 0 4px; font-size: 15px; font-weight: 800; color: var(--brand-dark); }
.acc-hint { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.acc-form { display: flex; flex-direction: column; gap: 10px; }
.acc-form .btn-block { margin-top: 2px; }
.acc-field { display: flex; flex-direction: column; gap: 4px; }
.acc-field span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.acc-field input,
.acc-field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  color: var(--text);
  outline: none;
}
.acc-field input:focus,
.acc-field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0,87,184,.12); }
.acc-msg { margin: 0; font-size: 13px; color: #c0392b; }
.acc-msg.ok { color: #16a34a; }
.acc-msg:empty { display: none; }
.btn-block:disabled { opacity: .6; }
.btn-sm {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 12.5px; font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-sm.danger { color: #c0392b; }

.user-list { margin-top: 14px; border-top: 1px solid var(--line); }
.user-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: none; }
.user-main { font-size: 14px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.tag { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; vertical-align: middle; }
.tag-admin { color: var(--brand); background: rgba(0, 87, 184, .1); }
.tag-lock { color: #c0392b; background: rgba(192, 57, 43, .1); }

/* ===== Liên kết ===== */
.links-list { padding: 14px 14px 24px; }
.link-group { margin-bottom: 18px; }
.link-group-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
}
.link-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  margin-bottom: 9px;
  text-decoration: none;
  color: inherit;
}
.link-card:active { background: #f7f9fc; }
.link-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.link-title { font-size: 14.5px; font-weight: 600; line-height: 1.3; }
.link-note { font-size: 12.5px; color: var(--muted); }
.link-url { font-size: 12px; color: var(--brand); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-arrow { flex: 0 0 auto; width: 18px; height: 18px; color: var(--muted); }

/* ===== Màn hình rộng ===== */
@media (min-width: 560px) {
  .product-list { grid-template-columns: repeat(3, 1fr); }
}
