:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1d4ed8;
  --primary-soft: #e0e8ff;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --purple: #7c3aed;
  --purple-soft: #ede9fe;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.splash { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* layout */
#view { max-width: 1400px; margin: 0 auto; padding: 0 12px calc(var(--nav-h) + var(--safe-b) + 24px); }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 12px 0 8px;
  display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { font-size: 22px; padding: 4px 10px 4px 0; }

nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: #fff; border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding-bottom: var(--safe-b); height: calc(var(--nav-h) + var(--safe-b)); }
nav.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11.5px; color: var(--muted); }
nav.bottom a .ic { font-size: 21px; line-height: 1; }
nav.bottom a.on { color: var(--primary); font-weight: 600; }
nav.bottom a.plus .ic { background: var(--primary); color: #fff; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; font-size: 26px; box-shadow: 0 4px 12px rgba(29, 78, 216, .35); }

/* elements */
.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05);
  border: 1px solid var(--line); display: block; }
.section { margin: 12px 0; }
.section h2 { font-size: 15px; margin: 18px 2px 8px; display: flex; align-items: center; gap: 8px; }
.section h2 .count { background: var(--line); border-radius: 99px; padding: 0 8px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.right { text-align: right; }
.hidden { display: none !important; }

.btn { border: 0; border-radius: 10px; padding: 10px 14px; background: var(--primary-soft); color: var(--primary);
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px;
  background: var(--line); color: #374151; white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }

/* forms */
label.f { display: block; margin: 10px 0; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=tel], input[type=datetime-local], input[type=month], input:not([type]),
select, textarea {
  width: 100%; border: 1px solid #d1d5db; border-radius: 10px; padding: 10px 12px; background: #fff; font-size: 16px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; }
.grid2 input, .grid2 select { min-width: 0; }
input[type=datetime-local] { min-height: 44px; font-size: 15px; padding: 8px 8px; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.check input { width: 20px; height: 20px; }
.quick { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

/* chips */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 12px; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; }
.chip b { font-weight: 700; margin-left: 2px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.warn b { color: var(--red); }
.chip.on.warn b { color: #fff; }

/* board */
.board { display: block; }
.col { margin-bottom: 6px; }
.col .items { display: grid; gap: 8px; }
.item-card { position: relative; border-left: 4px solid var(--primary); }
.item-card.late { border-left-color: var(--red); }
.item-card.hold { border-left-color: var(--amber); }
.item-card .l1 { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.item-card .l1 .cust { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-card .title { font-weight: 600; margin: 3px 0; }
.item-card .l3 { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.late-text { color: var(--red); font-weight: 600; }
.today-text { color: var(--amber); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

@media (min-width: 900px) {
  .board.kanban { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 12px; }
  .board.kanban .col { flex: 0 0 290px; background: #e9edf5; border-radius: var(--radius); padding: 2px 8px 8px; }
  .board.kanban .col h2 { margin: 10px 4px; }
  #view.narrow { max-width: 760px; }
}

/* order page */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.money3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.money3 b { display: block; font-size: 16px; }
.money3 span { font-size: 12px; color: var(--muted); }
.steps { display: flex; gap: 4px; overflow-x: auto; padding: 8px 0; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.step { flex: none; font-size: 12px; padding: 4px 9px; border-radius: 99px; background: #f3f4f6; color: var(--muted); }
.step.done { background: var(--green-soft); color: var(--green); }
.step.cur { background: var(--primary); color: #fff; font-weight: 600; }
.item-block { margin-bottom: 10px; }
.item-block.focus { outline: 3px solid var(--primary-soft); }
.item-head { display: flex; gap: 8px; align-items: flex-start; }
.item-head .title { font-weight: 700; font-size: 16px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.actions .btn.primary { flex: 1 1 100%; }
.admin-box { margin-top: 10px; padding: 10px; background: #fffbeb; border: 1px dashed #f59e0b; border-radius: 10px; }
.admin-box .t { font-size: 12px; font-weight: 700; color: var(--amber); margin-bottom: 4px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .ic { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 14px; background: #f3f4f6; }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline img { display: block; max-width: 160px; max-height: 160px; border-radius: 8px; margin-top: 6px; object-fit: cover; }

/* sheet (modal) */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + var(--safe-b)); animation: up .18s ease-out; }
.sheet h3 { margin: 0 0 6px; font-size: 18px; }
@media (min-width: 600px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }

.photo-pick { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.photo-pick img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }

/* tables / admin */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat b { display: block; font-size: 19px; margin-top: 2px; }
.stat.red b { color: var(--red); }
.stat.green b { color: var(--green); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; }
.list-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }

/* login */
.login { max-width: 380px; margin: 0 auto; padding: 12vh 20px 20px; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 10px; }
.login h1 { text-align: center; margin: 0 0 4px; }
.err { color: var(--red); font-size: 14px; min-height: 20px; margin: 6px 0; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }

/* ---- v2: dây chuyền ---- */
.lnk { color: var(--primary); }
.seg { display: flex; background: #e5e9f2; border-radius: 12px; padding: 3px; margin-bottom: 8px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; font-size: 14px; }
.seg button b { display: inline-block; margin-left: 5px; background: rgba(0,0,0,.08); border-radius: 99px; padding: 0 7px; font-size: 12px; }
.seg button.on { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.item-card { cursor: pointer; overflow: hidden; }
.item-card .thumb { float: right; width: 64px; height: 64px; object-fit: cover; border-radius: 8px; margin: 0 0 6px 8px; }
.item-card .title { font-size: 16px; }
.qty { color: var(--primary); font-weight: 700; }
.spec { font-size: 13.5px; background: #f8fafc; border-radius: 8px; padding: 6px 8px; margin: 4px 0; white-space: pre-wrap; }
.spec.big { font-size: 15px; margin-top: 8px; }
.stage-line { margin: 3px 0; }
.chips-mini { font-size: 11.5px; color: var(--muted); margin: 2px 0 4px; }
.chips-mini span { padding: 0 3px; }
.gh { font-size: 13.5px; background: var(--green-soft); color: #14532d; border-radius: 8px; padding: 6px 8px; margin: 4px 0; }
.item-card .claim { width: 100%; margin-top: 8px; padding: 10px; font-size: 15px; }
nav.bottom a .ic { position: relative; }
.dot { position: absolute; top: -4px; right: -10px; background: var(--red); color: #fff; font-style: normal; font-size: 10.5px; font-weight: 700;
  min-width: 17px; height: 17px; line-height: 17px; border-radius: 99px; padding: 0 4px; text-align: center; }
.steps-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 4px 0 6px; }
.stp { font-size: 13px; padding: 5px 9px; border-radius: 99px; background: #eef2f7; }
.stp.opt { background: #fff; border: 1px dashed #94a3b8; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.stp.opt:has(input:checked) { background: var(--primary-soft); border-style: solid; border-color: var(--primary); color: var(--primary); }
.stp input { width: 16px; height: 16px; margin: 0; }
.arr { color: #94a3b8; font-size: 12px; }
.f .lbl { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
div.f { margin: 10px 0; }
.now-box { background: var(--primary-soft); border-radius: 10px; padding: 8px 10px; font-size: 14px; margin-top: 4px; }
.now-box.ok { background: var(--green-soft); }
.preview { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; margin: 8px 0; object-fit: contain; background: #f1f5f9; }
.hint { background: #eff6ff; border-color: #bfdbfe; margin-bottom: 10px; font-size: 14px; }
.list-row.unread { font-weight: 600; }
.list-row.unread::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex: none; }
.person { margin-bottom: 8px; }
.person .list-row { padding: 6px 0; gap: 8px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.checks .check { margin: 4px 0; font-size: 14px; }
.step-row { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 6px; background: #fafafa; }
.step-row label { display: inline-flex; gap: 4px; align-items: center; margin-right: 8px; }
.stat.amber b { color: var(--amber); }
