:root {
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --card: #ffffff;
  --border: #e3e6ea;
  --text: #111417;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --accent: #2f6bff;
  --accent-2: #5b8cff;
  --green: #22c55e;
  --green-bg: #e7f8ee;
  --amber: #f59e0b;
  --amber-bg: #fef3e2;
  --red: #ef4444;
  --red-bg: #fdecec;
  --gray-bg: #f0f1f3;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --nav-h: 58px;
}

html[data-scheme="dark"] {
  --bg: #17212b;
  --bg-soft: #10161d;
  --card: #212d3a;
  --border: #2e3a48;
  --text: #f5f7fa;
  --text-2: #9aa5b1;
  --text-3: #6c7a89;
  --accent: #5288ff;
  --accent-2: #7aa5ff;
  --green: #3ecf6a;
  --green-bg: #1d3a2b;
  --amber: #f5b13c;
  --amber-bg: #3a2f1b;
  --red: #f26a6a;
  --red-bg: #3a1f22;
  --gray-bg: #1c2733;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body { display: flex; flex-direction: column; }

.hidden { display: none !important; }

#app {
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.container { max-width: 640px; margin: 0 auto; padding: 12px 14px 20px; }

/* ---------- Nav bar ---------- */
.nav-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  z-index: 40;
}
.nav-item {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  position: relative;
  cursor: pointer;
}
.nav-item.active { color: var(--accent); }
.nav-ico { font-size: 20px; line-height: 1; }
.nav-badge {
  position: absolute;
  top: 4px; right: calc(50% - 18px);
  background: var(--red);
  color: #fff;
  font-size: 10px;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* ---------- Typography / generic ---------- */
h1.title { font-size: 20px; font-weight: 700; margin-bottom: 12px; }
h2.sub { font-size: 16px; font-weight: 650; margin: 16px 0 10px; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.center { text-align: center; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.section-title {
  background: var(--bg-soft);
  border-color: transparent;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-2);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.05s;
  background: var(--bg-soft);
  color: var(--text);
  width: 100%;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 8px; width: auto; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-2);
}
.input, .select, textarea.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--text);
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none;
  border-color: var(--accent);
}
textarea.input { min-height: 84px; resize: vertical; }

/* ---------- Product grid ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.product-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.product-card .img-wrap {
  aspect-ratio: 1 / 1;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.product-card .img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.product-card .ph { font-size: 40px; color: var(--text-3); }
.product-card .info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.product-card .pname { font-size: 14px; font-weight: 600; line-height: 1.25; }
.product-card .price { font-weight: 700; color: var(--accent); font-size: 15px; }
.product-card .compare { text-decoration: line-through; color: var(--text-3); font-size: 12px; font-weight: 400; margin-left: 6px; }
.product-card .stock-line { font-size: 12px; color: var(--text-3); }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.tag-featured { background: var(--amber-bg); color: var(--amber); }

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-pending, .badge-pending_payment { background: var(--amber-bg); color: var(--amber); }
.badge-under_review { background: #e8efff; color: var(--accent); }
html[data-scheme="dark"] .badge-under_review { background: #1e2c44; }
.badge-confirmed, .badge-processing, .badge-shipped { background: #e8efff; color: var(--accent); }
html[data-scheme="dark"] .badge-confirmed, html[data-scheme="dark"] .badge-processing, html[data-scheme="dark"] .badge-shipped { background: #1e2c44; }
.badge-delivered, .badge-completed { background: var(--green-bg); color: var(--green); }
.badge-cancelled, .badge-rejected { background: var(--red-bg); color: var(--red); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before {
  content: "";
  position: absolute;
  left: 8px; top: 4px; bottom: -4px;
  width: 2px;
  background: var(--border);
}
.timeline li:last-child::before { display: none; }
.timeline li::after {
  content: "";
  position: absolute;
  left: 4px; top: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.timeline li.done::after { background: var(--green); }
.timeline li.current::after { background: var(--accent); box-shadow: 0 0 0 4px rgba(47,107,255,0.18); }
.timeline .tl-title { font-size: 14px; font-weight: 600; }
.timeline .tl-time { font-size: 12px; color: var(--text-3); }
.timeline .tl-note { font-size: 13px; color: var(--text-2); margin-top: 2px; }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed;
  top: 12px; left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: rgba(20, 24, 30, 0.95);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 20px;
  max-width: 90%;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  animation: slideDown 0.2s ease;
}
.toast.error { background: rgba(190, 40, 40, 0.95); }
.toast.success { background: rgba(30, 130, 60, 0.95); }
@keyframes slideDown { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: 16px;
  max-width: 420px;
  width: 100%;
  padding: 18px;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.modal h3 { margin-bottom: 12px; font-size: 17px; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.row-label { color: var(--text-2); font-size: 14px; }
.row-value { font-weight: 600; font-size: 14px; }
.total-line { font-size: 16px; font-weight: 700; }

.qty {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.qty button {
  width: 34px; height: 34px;
  border: none;
  background: var(--bg-soft);
  font-size: 18px;
  color: var(--text);
  cursor: pointer;
}
.qty span { min-width: 36px; text-align: center; font-weight: 600; font-size: 15px; }

.avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-soft) 25%, var(--border) 50%, var(--bg-soft) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 8px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-3);
}
.empty .ico { font-size: 44px; display: block; margin-bottom: 10px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; }
.chip {
  flex-shrink: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.search {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}
.search:focus { outline: none; border-color: var(--accent); }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  padding: 8px;
  color: var(--text-3);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table .row-link { color: var(--accent); cursor: pointer; font-weight: 600; }

.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 12px; }
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.kpi .k-label { font-size: 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; }
.kpi .k-value { font-size: 22px; font-weight: 800; margin-top: 4px; }

.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.bar-chart .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-chart .bar { width: 100%; max-width: 26px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-chart .bar-lbl { font-size: 9px; color: var(--text-3); transform: rotate(-45deg); }

.banner {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
}
.banner h2 { font-size: 20px; margin-bottom: 4px; }
.banner p { opacity: 0.9; font-size: 14px; }

.file-drop {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
  color: var(--text-2);
  cursor: pointer;
  font-size: 14px;
}
.file-drop input { display: none; }
.thumb-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumb {
  width: 72px; height: 72px;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .x {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  font-size: 12px;
  cursor: pointer;
}

.pay-option {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: center;
}
.pay-option.selected { border-color: var(--accent); background: rgba(47,107,255,0.06); }
.pay-option .ico { font-size: 26px; }
.pay-option .name { font-weight: 700; }
.pay-option .desc { font-size: 13px; color: var(--text-2); }
.radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; }
.pay-option.selected .radio { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 45%, transparent 50%); }

.qr-img {
  max-width: 220px;
  margin: 10px auto;
  display: block;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  background: #fff;
}

.pill-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill { border: 1px solid var(--border); background: none; color: var(--text-2); border-radius: 20px; padding: 6px 14px; font-size: 13px; cursor: pointer; font-weight: 600; }
.pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.step-note {
  background: var(--amber-bg);
  color: var(--amber);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 10px 0;
}
.step-note.info { background: #e8efff; color: var(--accent); }
html[data-scheme="dark"] .step-note.info { background: #1e2c44; }

footer.page-footer { text-align: center; font-size: 12px; color: var(--text-3); padding: 20px 0 8px; }
