:root {
  --bg: #f3f4f6; --card: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --brand: #1f6feb; --brand-soft: #e8f0fe;
  --ok: #15803d; --ok-bg: #dcfce7; --warn: #b45309; --warn-bg: #fef3c7; --bad: #dc2626; --bad-bg: #fee2e2;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
body.has-nav { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

header.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--brand); color: #fff; padding: 12px 16px;
}
header.top h1 { flex: 1; margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .who { font-size: 13px; opacity: .85; }
header .back { color: #fff; text-decoration: none; font-size: 30px; line-height: 1; padding: 0 6px 0 0; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }
h2 {
  display: flex; align-items: center; gap: 8px; margin: 20px 0 8px;
  font-size: 14px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
}
.panel h2 { margin-top: 4px; }
.count { background: var(--line); color: var(--text); border-radius: 99px; padding: 0 8px; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 18px; font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 16px; background: var(--card); border-radius: 12px; }
.warn-text { color: var(--warn); font-weight: 600; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Thẻ đơn */
.card {
  background: var(--card); border-radius: 12px; margin-bottom: 10px; overflow: hidden;
  border-left: 5px solid var(--ok); box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.card.soon { border-left-color: var(--warn); }
.card.late { border-left-color: var(--bad); }
.card.done { border-left-color: var(--muted); }
.card-main { display: block; padding: 12px 14px; color: inherit; text-decoration: none; }
.card .cust { font-weight: 600; margin-top: 2px; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.soon { background: var(--warn-bg); color: var(--warn); }
.badge.late { background: var(--bad-bg); color: var(--bad); }
.badge.done { background: var(--line); color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 12px; }
.actions form { flex: 1 1 140px; margin: 0; }
.actions.solo { padding: 0; margin-bottom: 12px; }

/* Form */
button {
  width: 100%; min-height: 46px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--brand); color: #fff; font-family: inherit; font-size: 16px; font-weight: 600; line-height: 1.2; padding: 10px 14px;
}
button.secondary { background: var(--brand-soft); color: var(--brand); }
button.danger { background: var(--bad); }
button:disabled { opacity: .55; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font-family: inherit; font-size: 16px; color: inherit;
  background: #fff; border: 1px solid #d1d5db; border-radius: 10px;
}
textarea { resize: vertical; }
label { display: block; margin: 12px 0 4px; font-size: 14px; font-weight: 600; }
form > button { margin-top: 16px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 16px 0 0; }
.check input { width: 22px; min-height: 22px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel { background: var(--card); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.panel summary { font-weight: 600; cursor: pointer; padding: 2px 0; }
.panel[open] summary { margin-bottom: 4px; }
.login { margin-top: 24px; }
.searchbar, .noteform { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar button, .noteform button { width: auto; margin: 0; }
.flash { padding: 10px 12px; border-radius: 10px; margin-bottom: 10px; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: #14532d; }
.flash.err { background: var(--bad-bg); color: #7f1d1d; }

/* Chi tiết đơn */
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0 0; }
dt { color: var(--muted); }
dd { margin: 0; }
.note { white-space: pre-wrap; background: var(--warn-bg); border-radius: 8px; padding: 10px; margin: 12px 0 0; }
.steps { display: flex; list-style: none; padding: 0; margin: 4px 0 16px; }
.steps li { flex: 1; text-align: center; font-size: 12px; color: var(--muted); position: relative; }
.steps li span {
  display: block; width: 18px; height: 18px; margin: 0 auto 4px; border-radius: 50%;
  background: #fff; border: 3px solid var(--line); position: relative; z-index: 1;
}
.steps li::before { content: ""; position: absolute; top: 8px; left: -50%; width: 100%; height: 3px; background: var(--line); }
.steps li:first-child::before { display: none; }
.steps li.past span { background: var(--ok); border-color: var(--ok); }
.steps li.past::before, .steps li.now::before { background: var(--ok); }
.steps li.now { color: var(--brand); font-weight: 700; }
.steps li.now span { border-color: var(--brand); background: var(--brand-soft); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 14px; border-left: 3px solid var(--line); }
.timeline li.return { border-left-color: var(--bad); }
.timeline li.complete { border-left-color: var(--ok); }
.timeline li.note { border-left-color: var(--warn); }

/* Bảng tổng */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stats div { background: var(--card); border-radius: 12px; padding: 10px; text-align: center; font-size: 13px; color: var(--muted); }
.stats b { display: block; font-size: 22px; color: var(--text); }
.stats .bad b { color: var(--bad); }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 8px; padding: 2px 16px 6px; scrollbar-width: none; }
.tab {
  flex: none; padding: 8px 12px; border-radius: 99px; font-size: 14px; text-decoration: none;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
}
.tab.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.late-dot { font-style: normal; font-size: 11px; font-weight: 700; color: #fff; background: var(--bad); border-radius: 99px; padding: 1px 6px; }

.user.inactive summary b { text-decoration: line-through; color: var(--muted); }

/* Thanh điều hướng dưới */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex;
  background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom a { flex: 1; text-align: center; padding: 8px 2px 10px; font-size: 11px; color: var(--muted); text-decoration: none; }
nav.bottom a .i { display: block; font-size: 20px; line-height: 1.3; }
nav.bottom a.on { color: var(--brand); font-weight: 700; }

/* Dòng sản phẩm trong form */
.items { display: grid; gap: 10px; margin-bottom: 10px; }
fieldset.item { position: relative; margin: 0; padding: 4px 12px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fafafa; }
fieldset.item .x {
  position: absolute; top: 6px; right: 6px; width: 32px; min-height: 32px; padding: 0;
  background: transparent; color: var(--muted); font-size: 18px;
}
.items > .item:only-child .x { display: none; }

/* Dòng sản phẩm khi xem đơn */
.item-view { padding: 10px 0; border-top: 1px solid var(--line); }
.item-view:first-of-type { border-top: 0; padding-top: 0; }
.item-view .qty { color: var(--brand); white-space: nowrap; }
.item-view .req { white-space: pre-wrap; margin-top: 4px; }
.item-view .spec { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.item-view .spec span { background: var(--brand-soft); color: #1e3a8a; border-radius: 6px; padding: 2px 8px; font-size: 14px; font-weight: 600; }
.total { border-top: 2px solid var(--line); padding-top: 10px; margin-top: 4px; font-size: 17px; }
.linkbtn {
  display: block; text-align: center; padding: 12px; margin-bottom: 12px; border-radius: 10px;
  background: var(--card); color: var(--brand); font-weight: 600; text-decoration: none; border: 1px solid var(--line);
}

/* Lưới số đo (VC, V, VV, …) */
.mgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.mgrid div { display: flex; align-items: center; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; overflow: hidden; }
.mgrid span { flex: none; width: 28px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--bg); align-self: stretch; display: flex; align-items: center; justify-content: center; }
.mgrid input { border: 0; border-radius: 0; min-height: 40px; padding: 6px 1px; text-align: center; font-weight: 700; min-width: 0; }
.mgrid input:focus { outline: 2px solid var(--brand); outline-offset: -2px; }
.mview { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.mview span { border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-weight: 700; font-size: 14px; }
.mview i { font-style: normal; font-weight: 400; color: var(--muted); margin-right: 4px; font-size: 12px; }

/* Hôm nay & thi đua */
.stats.flat div { background: var(--bg); }
.leaders { list-style: none; padding: 0; margin: 0 0 12px; }
.leaders li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.leaders li:first-child { border-top: 0; }
.rank { list-style: none; padding: 0; margin: 0; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.rank li:first-child { border-top: 0; }
.rank .pos { width: 28px; text-align: center; font-size: 18px; font-weight: 700; color: var(--muted); }
.rank .nm { flex: 1; min-width: 0; }
.rank .nm i { display: block; height: 6px; margin-top: 4px; border-radius: 3px; background: var(--brand); min-width: 2px; }
.rank .val { text-align: right; white-space: nowrap; }
.rank .val b { font-size: 18px; }
.rank .val small { display: block; color: var(--muted); font-size: 12px; }

/* Ô nhập mã nhanh 5 số */
.quick { display: flex; gap: 8px; margin-bottom: 12px; }
.quick input { font-size: 20px; font-weight: 700; letter-spacing: 3px; text-align: center; }
.quick input::placeholder { font-size: 15px; font-weight: 400; letter-spacing: 0; }
.quick button { width: auto; margin: 0; flex: none; }
.q5 { letter-spacing: 2px; }
.item-view.picked { background: var(--warn-bg); margin: 0 -14px; padding: 10px 14px; border-radius: 8px; }

/* Tiến độ theo từng sản phẩm */
.progress { position: relative; margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--bg); overflow: hidden; }
.progress i { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--ok); }
.progress.done { background: var(--ok-bg); color: #14532d; font-weight: 600; }
.ok-text { color: var(--ok); }
.steps.mini { margin: 8px 0 6px; }
.steps.mini li { font-size: 10px; }
.steps.mini li span { width: 12px; height: 12px; border-width: 2px; }
.steps.mini li::before { top: 5px; height: 2px; }
.item-view .actions.solo { margin: 8px 0 0; }
.item-view.is-done > .row b:first-child { color: var(--ok); }
details.return { margin-top: 8px; }
details.return summary { cursor: pointer; color: var(--bad); font-weight: 600; font-size: 14px; }
details.return textarea { margin-top: 6px; }
details.return button { margin-top: 8px; }

.hint { display: block; min-height: 18px; margin-top: 3px; font-size: 13px; font-weight: 600; color: var(--ok); }
