:root {
  --bg: #fbf6f0;
  --card: #ffffff;
  --ink: #3b2a20;
  --muted: #8c786a;
  --line: #efe3d7;
  --primary: #c2603d;
  --primary-ink: #ffffff;
  --primary-soft: #f8e6dc;
  --ok: #2f8a57;
  --ok-soft: #e1f3e8;
  --warn: #b7791f;
  --warn-soft: #fbefd9;
  --danger: #c0392b;
  --danger-soft: #fbe3e0;
  --info: #2c6fb7;
  --info-soft: #e1edf9;
  --purple: #7a4bb5;
  --purple-soft: #eee5f8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(59, 42, 32, .06), 0 4px 14px rgba(59, 42, 32, .06);
  --tabbar-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(251, 246, 240, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand img { border-radius: 9px; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%;
  font-size: 20px; cursor: pointer;
}
.icon-btn:active { background: var(--line); }

/* ---------- Layout ---------- */
.view { padding: 14px 16px calc(var(--tabbar-h) + 90px + env(safe-area-inset-bottom)); }
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 20px 2px 8px;
  display: flex; justify-content: space-between; align-items: center;
}
.section-title:first-child { margin-top: 4px; }
.section-title a, .link { color: var(--primary); text-transform: none; letter-spacing: 0; font-weight: 600; text-decoration: none; cursor: pointer; background: none; border: 0; padding: 0; font-size: 13px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 10px;
}
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(.99); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.start { justify-content: flex-start; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.right { text-align: right; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.mt { margin-top: 8px; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 6px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat.accent { background: var(--primary); color: var(--primary-ink); }
.stat.accent .label { color: rgba(255, 255, 255, .85); }
.stat.tap { cursor: pointer; border: 2px solid transparent; }
.stat.tap:active { transform: scale(.98); }
.stat.on { border-color: var(--danger, #d33); }
.hello { margin: 0 2px 12px; }
.hello h1 { font-size: 20px; margin: 0; }

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  white-space: nowrap; background: var(--line); color: var(--ink);
}
.s-new { background: var(--info-soft); color: var(--info); }
.s-doing { background: var(--warn-soft); color: var(--warn); }
.s-done { background: var(--purple-soft); color: var(--purple); }
.s-delivered { background: var(--ok-soft); color: var(--ok); }
.s-cancelled { background: #eee; color: #888; }
.b-danger { background: var(--danger-soft); color: var(--danger); }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px;
  font-size: 14px; white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .count { opacity: .7; margin-left: 4px; }

.search {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 11px 14px; font-size: 16px; margin-bottom: 10px; outline: none;
}
.search:focus { border-color: var(--primary); }

/* ---------- Order card ---------- */
.order .items { font-size: 14px; margin: 6px 0; }
.order.late { border-left: 4px solid var(--danger); }
.group-head { font-weight: 700; margin: 16px 2px 8px; display: flex; justify-content: space-between; }
.group-head:first-of-type { margin-top: 4px; }

/* ---------- Stock ---------- */
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.bar.low > i { background: var(--danger); }
.bar.mid > i { background: var(--warn); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table td, .table th { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: left; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 11px 16px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink);
  min-height: 44px;
}
.btn:active { opacity: .8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; border-style: dashed; color: var(--primary); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

.fab {
  position: fixed; z-index: 11;
  right: max(16px, calc(50vw - 280px + 16px));
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--primary); color: #fff; font-size: 28px; box-shadow: 0 6px 18px rgba(194, 96, 61, .45);
  cursor: pointer;
}
.fab:active { transform: scale(.95); }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 12;
  width: 100%; max-width: 560px;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: 0; background: none; height: var(--tabbar-h); font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.tabbar button span { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabbar button.on { color: var(--primary); font-weight: 700; }
.tabbar button.on span { filter: none; opacity: 1; }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(30, 20, 15, .45); z-index: 20; animation: fade .2s; }
.sheet {
  position: fixed; z-index: 21; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0; animation: up .25s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 8px 18px; position: relative; }
.sheet-grip { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); width: 40px; height: 4px; border-radius: 2px; background: var(--line); }
.sheet-head h2 { font-size: 18px; margin: 0; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Forms ---------- */
.form label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.form input, .form select, .form textarea {
  display: block; width: 100%; margin-top: 4px; font-size: 16px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: 11px 12px; outline: none;
  min-height: 46px;
}
.form textarea { min-height: 70px; resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.line-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.line-item .grid-li { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 8px; align-items: end; }
.line-item label { margin-bottom: 0; }
.line-item select { margin-top: 0; margin-bottom: 8px; }
.line-item .rm { height: 46px; border: 0; background: var(--danger-soft); color: var(--danger); border-radius: 12px; font-size: 18px; cursor: pointer; }
.summary { background: var(--card); border-radius: 12px; padding: 12px; margin: 6px 0 14px; }
.summary .row { padding: 3px 0; }
.summary .total { font-size: 18px; font-weight: 700; border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg input { display: none; }
.seg label { margin: 0; text-align: center; padding: 9px; border-radius: 10px; cursor: pointer; color: var(--ink); font-size: 15px; }
.seg input:checked + label { background: var(--card); box-shadow: var(--shadow); color: var(--primary); }
.check { display: flex !important; align-items: center; gap: 10px; color: var(--ink) !important; font-size: 15px !important; }
.check input { width: 22px; min-height: 22px; height: 22px; margin: 0; accent-color: var(--primary); }

.status-steps { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0; }
.status-steps button { flex: 1; min-width: 70px; border: 1px solid var(--line); background: var(--card); padding: 8px 4px; border-radius: 10px; font-size: 13px; cursor: pointer; }
.status-steps button.on { border-color: currentColor; font-weight: 700; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); animation: fade .2s;
}
.toast.err { background: var(--danger); }

.menu-list .btn { width: 100%; justify-content: flex-start; margin-bottom: 8px; }

/* ---------- Đăng nhập ---------- */
body.auth .topbar, body.auth .tabbar, body.auth .fab { display: none !important; }
body.auth .view { padding-bottom: 40px; }
.login { max-width: 380px; margin: 0 auto; padding-top: calc(48px + env(safe-area-inset-top)); text-align: center; }
.login img { border-radius: 18px; box-shadow: var(--shadow); }
.login h1 { margin: 14px 0 4px; font-size: 24px; }
.login p { margin: 0 0 20px; }
.login .form { text-align: left; padding: 18px 16px; }
