/* GIAO DIỆN TERRA — phong cách iOS: nền xám nhạt, thẻ trắng bo tròn, chữ to rõ, ít màu. */
:root {
  --bg: #f2f2f7; --card: #fff; --text: #1c1c1e; --sub: #6e6e73; --line: #e5e5ea;
  --brand: #1f6f54; --brand-soft: #e3f1eb; --blue: #0a6cff; --red: #d92d20; --orange: #b25e09; --green: #18794e;
  --radius: 16px; --tab-h: 62px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }

.screen { max-width: 860px; margin: 0 auto; padding: 14px 16px calc(var(--tab-h) + 40px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.back { display: inline-flex; align-items: center; gap: 2px; background: none; border: 0; color: var(--brand); padding: 6px 8px 6px 0; font-size: 17px; }
.back svg { width: 22px; height: 22px; }
.topbar .spacer { flex: 1; }
h1 { font-size: 30px; line-height: 1.15; margin: 6px 0 2px; letter-spacing: -.02em; }
.subtitle { color: var(--sub); margin: 0 0 14px; font-size: 15px; }

.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; background: #e9e9ee; color: var(--text); min-height: 44px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.danger { background: #fdecea; color: var(--red); }
.btn.small { min-height: 36px; padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--sub); margin: 22px 16px 7px; }
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.card.pad { padding: 14px 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); min-height: 52px; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.row:last-child { border-bottom: 0; }
a.row { color: var(--text); }
button.row:active, a.row:active { background: #f0f0f3; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .sub { color: var(--sub); font-size: 14px; overflow-wrap: anywhere; }
.row .right { text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.row .right .sub { font-size: 13px; }
.row .chev { color: #c4c4c9; width: 18px; height: 18px; flex-shrink: 0; }
.empty { padding: 22px 16px; color: var(--sub); text-align: center; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #ececf0; color: #48484d; white-space: nowrap; }
.badge.green { background: #e1f3ea; color: var(--green); }
.badge.orange { background: #fdf0dc; color: var(--orange); }
.badge.red { background: #fdecea; color: var(--red); }
.badge.blue { background: #e4eeff; color: #0b57d0; }
.count { min-width: 26px; height: 26px; border-radius: 13px; background: var(--red); color: #fff; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; padding: 0 7px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 28px; line-height: 1.1; }
.stat span { color: var(--sub); font-size: 14px; }

.apps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px 8px; padding: 6px 0; }
.app { display: flex; flex-direction: column; align-items: center; gap: 7px; background: none; border: 0; padding: 0; font-size: 13px; text-align: center; color: var(--text); }
.app i { width: 60px; height: 60px; border-radius: 15px; display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.app i svg { width: 30px; height: 30px; }
.app:active i { filter: brightness(.9); }

svg.ic { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(249,249,251,.92); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); display: flex; justify-content: center; z-index: 5; }
.tabbar a { flex: 1; max-width: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #8e8e93; font-size: 11.5px; font-weight: 500; }
.tabbar a svg { width: 25px; height: 25px; }
.tabbar a.on { color: var(--brand); }

.seg { display: flex; background: #e3e3e8; border-radius: 10px; padding: 2px; margin: 10px 0; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 7px 6px; font-size: 14px; font-weight: 500; }
.seg button.on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.14); font-weight: 600; }
.search { width: 100%; border: 0; background: #e3e3e8; border-radius: 10px; padding: 10px 12px; margin: 4px 0 6px; }

/* Bước tiến độ của lệnh sản xuất */
.steps { display: flex; gap: 4px; margin: 4px 0 2px; }
.steps span { flex: 1; height: 6px; border-radius: 3px; background: #e0e0e5; }
.steps span.done { background: var(--brand); }
.steps span.now { background: #7fc2a8; }
.next { background: var(--brand-soft); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.next p { margin: 0 0 10px; }
.next.wait { background: #fff7e6; }
.next.stop { background: #fdecea; }

.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--sub); }
.kv { flex-wrap: wrap; }
.kv span:first-child { flex: 1 1 40%; }
.kv span:last-child { text-align: right; font-weight: 500; overflow-wrap: break-word; max-width: 100%; margin-left: auto; }
.row .right > div:first-child { white-space: nowrap; }
.note-block { padding: 10px 16px; color: var(--text); font-size: 14.5px; overflow-wrap: anywhere; }
.note-block span { display: block; color: var(--sub); font-size: 13px; margin-bottom: 2px; }
.warn-text { color: var(--red) !important; font-weight: 600; }
.env { background: #fff3cd; color: #6b4e00; text-align: center; font-size: 12.5px; padding: 3px 8px; font-weight: 600; }
.total { font-size: 18px; font-weight: 700; }
.note { color: var(--sub); font-size: 14px; margin: 8px 16px; }
.warn { background: #fff7e6; color: #7a4a00; border-radius: 12px; padding: 10px 14px; margin: 10px 0; font-size: 14.5px; }

/* Bảng trượt từ dưới lên (biểu mẫu) */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .2s; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: -8px; background: var(--bg); padding: 10px 0; z-index: 1; }
.sheet-head h2 { font-size: 19px; margin: 0; }
.sheet-head button { border: 0; background: none; color: var(--brand); font-size: 16px; padding: 6px 0; }
.sheet .intro { color: var(--sub); font-size: 14.5px; margin: 0 0 10px; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.field { background: var(--card); border-radius: 12px; padding: 9px 14px; margin-bottom: 9px; }
.field label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 2px; }
.field input, .field select, .field textarea { width: 100%; border: 0; background: transparent; padding: 4px 0; outline: none; font-size: 17px; }
.field textarea { resize: vertical; min-height: 56px; }
.field .hint { font-size: 13px; color: var(--sub); margin-top: 3px; }
.field:focus-within { box-shadow: 0 0 0 2px var(--brand); }
.checks label { display: flex; align-items: center; gap: 10px; font-size: 16px; color: var(--text); padding: 6px 0; }
.checks input { width: 20px; height: 20px; accent-color: var(--brand); }
.line { display: flex; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line); }
.line select { flex: 2; min-width: 0; } .line input { flex: 1; min-width: 0; text-align: right; }
.line button { border: 0; background: none; color: var(--red); font-size: 20px; padding: 0 4px; }
.err { background: #fdecea; color: var(--red); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; font-weight: 500; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 22px); transform: translateX(-50%); background: #1c1c1e; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: 90vw; text-align: center; }
#toast.show { opacity: .95; }

.login { max-width: 400px; margin: 0 auto; padding: 9vh 20px 30px; }
.login .logo { width: 76px; height: 76px; border-radius: 18px; display: block; margin: 0 auto 14px; }
.login .logo.custom { width: auto; max-width: 180px; object-fit: contain; border-radius: 10px; }   /* logo doanh nghiệp tự tải lên */
.login h1 { text-align: center; font-size: 26px; }
.login .subtitle { text-align: center; }
.demo-note { font-size: 13.5px; color: var(--sub); margin-top: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips button { border: 0; background: #e3e3e8; border-radius: 999px; padding: 6px 12px; font-size: 13.5px; }

.tree { border-left: 2px solid var(--line); margin-left: 22px; padding-left: 0; }
@media (min-width: 700px) { .apps { grid-template-columns: repeat(6, 1fr); } .stats { grid-template-columns: repeat(4, 1fr); } }

/* ===== Bản 2.0: pha → bồn → đóng gói ===== */
/* Công tắc phân đoạn dùng được cả cho liên kết (thanh Lệnh pha · Đóng gói · Bồn chứa). Vùng chạm tối thiểu 44px. */
.seg a, .seg button { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 8px; padding: 6px; font-size: 14px; font-weight: 500; color: var(--text); text-align: center; }
.seg a.on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.14); font-weight: 600; }
.seg { min-height: 44px; }
.seg.small { margin: 8px 0; }
.seg.small button { font-size: 13px; padding: 4px; min-height: 36px; }
.row.urgent .count { background: var(--orange); }
/* Thẻ "Chuẩn bị chạy thật": bước chưa làm = số thứ tự xám, bước xong = dấu ✓ xanh. */
.count.ok { background: var(--green); }
.card.setup .count:not(.ok) { background: #8e8e93; }
.row { min-height: 52px; }
.btn.small { min-height: 40px; }
.tabbar a { min-height: 44px; }

/* Thẻ dòng nhập (đơn hàng, đóng gói) */
.field.custom { background: transparent; padding: 0; }
.field.custom > label { padding: 0 4px; }
.lines-box { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.line-card { background: var(--card); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.line-card select, .line-card input[type=number], .line-card input[type=text] { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: #fafafc; font-size: 16px; min-height: 44px; }
.line-top { display: flex; gap: 8px; align-items: center; }
.line-top .x { border: 0; background: #fdecea; color: var(--red); width: 44px; height: 44px; border-radius: 10px; font-size: 22px; flex-shrink: 0; }
.line-inputs { display: flex; gap: 8px; align-items: center; }
.line-inputs > span { color: var(--sub); flex-shrink: 0; }
.line-card .check { display: flex; gap: 10px; align-items: center; font-size: 15px; min-height: 44px; }
.line-card .check input { width: 22px; height: 22px; accent-color: var(--brand); }
.mini-title { font-size: 12.5px; color: var(--sub); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.comp { display: flex; gap: 6px; align-items: center; }
.comp > span { font-size: 14px; color: var(--sub); flex-shrink: 0; }
.comp select { flex: 2; }
.comp select.src { flex: 1.2; }
.comp input { flex: 1; }
.comp-box { display: flex; flex-direction: column; gap: 6px; }
.preview { background: var(--brand-soft); color: #0f4d39; border-radius: 10px; padding: 8px 10px; font-size: 14.5px; font-weight: 600; }
.preview.bad { background: #fdecea; color: var(--red); }
.hint { font-size: 13px; color: var(--sub); }
/* Vùng chạm tối thiểu 44 px cho mọi nút (theo hướng dẫn iOS). */
.back { min-height: 44px; }
.btn.small { min-height: 44px; }
.seg a, .seg button, .seg.small button { min-height: 44px; }
.search { min-height: 44px; }
.chips button { min-height: 44px; }
.sheet-head button { min-height: 44px; min-width: 44px; }
.field input, .field select { min-height: 44px; }
/* Ô tick một dòng (check-one): vùng chạm 44 px nằm ở cả dòng nhãn, ô vuông giữ 22 px. */
.field .check-one input { width: 22px; min-height: 0; height: 22px; padding: 0; }
/* Dòng "Phần mềm hiểu là: …" dưới ô số (components/number.js); đỏ khi gõ chưa phải số. */
.num-hint { margin-top: 3px; color: var(--sub); }
.num-hint.bad { color: var(--red); font-weight: 600; }
.field.custom:focus-within { box-shadow: none; }
/* Dòng thùng / vỏ: trên điện thoại hẹp, ô chọn vật tư chiếm cả dòng, số lượng + nguồn xuống dòng dưới. */
.comp { flex-wrap: wrap; }
.comp select:not(.src) { flex: 1 1 100%; }
.comp input, .comp select.src { flex: 1 1 40%; }
.comp > span { flex: 0 0 auto; }

/* ===== Bản 2.1: gọn cho doanh nghiệp nhỏ ===== */
/* Ô chọn có tìm kiếm (danh sách dài) */
.pick { display: flex; flex-direction: column; gap: 6px; }
.pick-search { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fafafc; font-size: 16px; min-height: 44px; }
.field .pick-search { border: 1px solid var(--line); padding: 8px 10px; }
.line { flex-wrap: wrap; }
.line .pick { flex: 1 1 100%; }
.line-card .pick select { width: 100%; }
.comp .pick { flex: 1 1 100%; }
/* Công thức: in mờ tên người đang xem để ngại chụp ảnh màn hình */
.watermark { position: fixed; inset: 0; pointer-events: none; z-index: 5; opacity: .07; overflow: hidden;
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 60px 40px; padding: 40px 10px; transform: rotate(-18deg) scale(1.3); }
.watermark span { font-size: 18px; font-weight: 700; color: #000; white-space: nowrap; }
.secret-note { background: #fff4e5; color: #8a4b00; border-radius: 12px; padding: 10px 14px; font-size: 14px; margin: 8px 0; }

/* Ô chọn có tìm kiếm trong thẻ dòng (đợt 5) */
.line-top .pick { flex: 1 1 auto; min-width: 0; }
.line .pick-search { text-align: left; }
/* Bản 3.0: ô tick đơn, tiêu đề nhóm trong biểu mẫu */
.check-one { display: flex; gap: 10px; align-items: center; min-height: 44px; font-size: 15px; }
.check-one input { width: 22px; height: 22px; accent-color: var(--brand); flex-shrink: 0; }
.form-heading { margin: 14px 0 4px; font-weight: 600; color: var(--sub); text-transform: uppercase; font-size: 12px; letter-spacing: .02em; }
