:root {
  --wood: #7a4a21; --wood-dark: #5a3414; --cream: #fbf6ec; --paper: #ffffff; --line: #e6dac4;
  --text: #2b2118; --muted: #7b6b58; --ok: #2f7d4f; --warn: #b66a00; --bad: #b3261e; --warn-bg: #fff1d6; --bad-bg: #fde6e4; --ok-bg: #e3f3e8;
  --radius: 14px; --nav-h: 62px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--cream); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
body.public { padding-bottom: 24px; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--wood); color: #fff; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
.brand { font-weight: 700; font-size: 18px; }
.userchip { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.16); color: #fff; border: 0; border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-size: 14px; }
.offline { background: var(--bad); color: #fff; text-align: center; padding: 6px 10px; font-size: 14px; }

#finbar { padding: 0; }
.finbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; font-size: 14px; background: var(--warn-bg); color: #6b4300; border-bottom: 1px solid #f0d9a8; }
.finbar.open { background: var(--ok-bg); color: #1d5a37; border-color: #bfe3cb; }

main { max-width: 760px; margin: 0 auto; padding: 12px 14px 24px; }
.loading, .empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty .big { font-size: 40px; }

/* Nút */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--wood); border-color: var(--wood); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost-danger { color: var(--bad); border-color: #efc2be; background: #fff; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; padding: 6px; cursor: pointer; font-weight: 600; }

/* Thanh công cụ danh sách */
.toolbar { display: grid; gap: 8px; margin-bottom: 10px; }
.searchrow { display: flex; gap: 8px; }
.search { flex: 1; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; background: var(--paper); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--wood); border-color: var(--wood); color: #fff; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #eadfc9; border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; min-height: 40px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--paper); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.count-line { color: var(--muted); font-size: 14px; margin: 4px 2px 8px; }

/* Thẻ đơn hàng */
.list { display: grid; gap: 10px; }
.card { display: flex; gap: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; cursor: pointer; }
.card:active { background: #fffaf0; }
.card.trashed { opacity: .72; background: #f4efe6; }
.thumb { position: relative; flex: none; width: 92px; height: 92px; border-radius: 10px; background: #efe3cc; overflow: hidden; display: grid; place-items: center; font-size: 30px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .n { position: absolute; right: 4px; bottom: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; border-radius: 8px; padding: 0 6px; }
.info { min-width: 0; flex: 1; display: grid; gap: 2px; align-content: start; }
.info h3 { font-size: 17px; line-height: 1.25; overflow-wrap: anywhere; }
.code { font-size: 12px; color: var(--muted); }
.meta { font-size: 14px; color: #4a3d2e; overflow-wrap: anywhere; }
.note-prev { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.moneyline { font-size: 13px; color: var(--wood-dark); font-weight: 600; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 3px 0; }
.badge { display: inline-block; font-size: 13px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: #efe6d3; color: #5d4a30; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.dark { background: #5b5347; color: #fff; }

.fab { position: fixed; right: 16px; bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); z-index: 15; min-height: 54px; padding: 0 22px; border-radius: 999px; border: 0; background: var(--wood-dark); color: #fff; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.3); cursor: pointer; }

/* Thanh điều hướng dưới */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--paper); border-top: 1px solid var(--line); display: flex; }
.nav button { flex: 1; border: 0; background: none; display: grid; place-items: center; align-content: center; gap: 0; font-size: 12px; color: var(--muted); cursor: pointer; }
.nav button .ico { font-size: 22px; line-height: 1.1; }
.nav button.on { color: var(--wood); font-weight: 700; }

/* Hộp thoại / tấm trượt */
.layer { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(30,20,10,.5); }
.sheet { width: 100%; max-width: 640px; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain; background: var(--cream); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
.sheet.center { border-radius: 20px; margin: auto 14px; width: auto; max-width: 440px; }
.layer.center { align-items: center; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet h2 { font-size: 20px; margin-bottom: 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.x { border: 0; background: #eadfc9; width: 40px; height: 40px; border-radius: 50%; font-size: 20px; cursor: pointer; flex: none; }

.gallery { display: grid; gap: 8px; margin-bottom: 12px; }
.gallery .main { width: 100%; max-height: 52dvh; object-fit: contain; background: #2a2118; border-radius: 12px; cursor: zoom-in; display: block; }
.gallery .thumbs { display: flex; gap: 8px; overflow-x: auto; }
.gallery .thumbs img { flex: none; width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 2px solid transparent; cursor: pointer; }
.gallery .thumbs img.on { border-color: var(--wood); }
.noimg { height: 120px; display: grid; place-items: center; background: #efe3cc; border-radius: 12px; color: var(--muted); margin-bottom: 12px; }
.lightbox { background: rgba(0,0,0,.92); align-items: center; }
.lightbox img { max-width: 100%; max-height: 100dvh; object-fit: contain; }

.kv { display: grid; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.kv div { display: grid; grid-template-columns: 110px 1fr; gap: 8px; font-size: 15px; }
.kv dt, .kv .k { color: var(--muted); }
.kv .v { overflow-wrap: anywhere; white-space: pre-wrap; }

/* Biểu mẫu */
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field label { font-weight: 600; font-size: 14px; }
.field input, .field select, .field textarea { width: 100%; min-height: 48px; border: 1px solid #d5c6a8; border-radius: 12px; padding: 10px 12px; background: var(--paper); font-size: 16px; }
.field textarea { min-height: 96px; resize: vertical; }
.field .hint { font-size: 13px; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two > * { min-width: 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--wood); }
.lockfield { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--warn-bg); color: #6b4300; border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.ph { position: relative; width: 78px; height: 78px; border-radius: 10px; overflow: hidden; background: #e9dcc3; }
.ph img { width: 100%; height: 100%; object-fit: cover; }
.ph button { position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.7); color: #fff; cursor: pointer; line-height: 1; }
.ph.gone img { opacity: .25; }
.addphoto { display: grid; place-items: center; width: 78px; height: 78px; border-radius: 10px; border: 2px dashed #c9b48a; color: var(--wood); font-size: 26px; cursor: pointer; background: transparent; }
.formerr { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }

/* Thống kê */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .lbl { font-size: 13px; color: var(--muted); }
.stat .val { font-size: 22px; font-weight: 800; color: var(--wood-dark); overflow-wrap: anywhere; }
.stat.wide { grid-column: 1 / -1; }
.stat.lock { background: var(--warn-bg); border-color: #f0d9a8; }
.tbl-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid #f0e8d6; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--paper); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.section { font-size: 17px; margin: 16px 2px 8px; }
.note-box { background: #efe6d3; border-radius: 10px; padding: 9px 12px; font-size: 14px; color: #5d4a30; margin-bottom: 12px; }

/* Quản lý */
.rowitem { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.rowitem .t { font-weight: 600; overflow-wrap: anywhere; }
.rowitem .s { font-size: 13px; color: var(--muted); }
.rowitem.off { opacity: .6; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }

.remind-group { margin-bottom: 12px; }
.remind-group h3 { font-size: 16px; margin-bottom: 6px; }
.remind-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 6px; cursor: pointer; }
.remind-item.bad { border-color: #efc2be; background: #fff7f6; }
.remind-item .t { font-weight: 600; overflow-wrap: anywhere; }
.remind-item .s { font-size: 13px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); max-width: 90vw; background: #2b2118; color: #fff; padding: 11px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 80; font-size: 15px; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.skel { height: 112px; border-radius: var(--radius); background: linear-gradient(90deg, #efe6d3, #f8f1e2, #efe6d3); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

@media (min-width: 700px) {
  .layer { align-items: center; }
  .sheet { border-radius: 20px; }
}

.panel h3 { margin-bottom: 6px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; padding: 6px 0; border-bottom: 1px solid #f0e8d6; cursor: pointer; }
.switch:last-child { border-bottom: 0; }
.sw-text { display: grid; gap: 1px; }
.sw-text small { color: var(--muted); font-size: 12.5px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sw-ui { flex: none; position: relative; width: 52px; height: 30px; border-radius: 999px; background: #cdbd9f; transition: background .15s; }
.sw-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .sw-ui { background: var(--ok); }
.switch input:checked + .sw-ui::after { transform: translateX(22px); }
.switch input:focus-visible + .sw-ui { outline: 3px solid #e0b25f; }
.switch input:disabled + .sw-ui { opacity: .5; }
