:root {
  --brand: #e2571c;
  --brand-dark: #b8430f;
  --brand-soft: #fff1e8;
  --bg: #f6f4f1;
  --card: #ffffff;
  --text: #1f1a17;
  --muted: #7a716b;
  --line: #e9e4df;
  --ok: #1f9d55;
  --ok-soft: #e6f6ec;
  --warn: #d68a00;
  --warn-soft: #fff6e0;
  --danger: #d33b2c;
  --danger-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
img { display: block; max-width: 100%; }
a { color: var(--brand); }
[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); cursor: pointer; font-weight: 600;
  transition: background .15s, transform .05s;
  white-space: nowrap;
  text-decoration: none;
  color: inherit;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { min-height: 80px; resize: vertical; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--bg); color: var(--muted); }

/* công tắc mở/đóng */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; }
.switch .track {
  width: 48px; height: 28px; border-radius: 999px; background: #cfc8c2; position: relative; transition: background .2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(20px); }

.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 14, 10, .45); padding: 16px;
}
.modal-box {
  background: var(--card); border-radius: 18px; width: 100%; max-width: 480px;
  max-height: calc(100vh - 32px); overflow: auto; padding: 22px;
  /* iPhone: 100vh tính cả phần bị thanh công cụ Safari che, dvh mới là chiều cao nhìn thấy thật */
  max-height: calc(100dvh - 32px); overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.modal-box h3 { margin-bottom: 16px; font-size: 19px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.btn-lg { min-height: 50px; font-size: 16px; }
body.has-bottom-nav .toast { bottom: calc(86px + env(safe-area-inset-bottom)); }

/* điện thoại: hộp thoại nổi từ đáy màn hình, nút bấm giãn đều cho dễ chạm */
@media (max-width: 560px) {
  .modal { align-items: flex-end; padding: 8px; }
  .modal { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .modal-box { padding: 18px 16px 22px; border-radius: 18px; max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px - env(safe-area-inset-bottom)); }
  .modal-actions .btn { flex: 1 1 auto; }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: #1f1a17; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-weight: 600; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center;
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

.muted { color: var(--muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* icon SVG trong nút */
.ic { width: 20px; height: 20px; flex: none; }
.btn-order { gap: 8px; border-radius: 14px; box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 35%, transparent); }
.btn-order .ic-arrow { width: 18px; height: 18px; transition: transform .15s; }
.btn-order:hover .ic-arrow { transform: translateX(3px); }

/* thanh danh mục: căn giữa khi đủ chỗ, vẫn cuộn ngang được khi nhiều mục */
.cats > :first-child { margin-left: auto; }
.cats > :last-child { margin-right: auto; }

/* nút X đóng popup ở góc trên bên phải */
.modal-box { position: relative; }
.modal-box > h3:first-of-type, .modal-box > .pre-title { padding-right: 44px; }
.modal-x { position: absolute; top: 12px; right: 12px; z-index: 2; display: grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border: 0; border-radius: 50%; background: var(--bg); color: var(--muted); cursor: pointer; transition: background .15s, color .15s, transform .1s; }
.modal-x svg { width: 20px; height: 20px; }
.modal-x:hover { background: var(--line); color: var(--text); }
.modal-x:active { transform: scale(.94); }

/* popup thông báo / xác nhận */
.ui-dialog { z-index: 90; }
.ui-dialog .modal-box { max-width: 420px; }
.ui-dialog-msg { margin: 0 0 14px; white-space: pre-line; line-height: 1.5; }
.ui-dialog-copy { margin: 0 0 14px; padding: 12px; border-radius: 10px; background: var(--bg); white-space: pre-wrap; font-family: inherit; font-size: 14px; }
.ui-dialog-input { margin-bottom: 14px; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
