/* Web nhận mẫu — mobile first, neutral colours, big touch targets. */
:root {
  --bg: #f6f7f9; --card: #ffffff; --ink: #1d2430; --muted: #5f6b7a; --line: #d9dee5;
  --accent: #1f5fae; --accent-ink: #ffffff; --accent-soft: #e6eef9;
  --green: #1f7a3f; --green-soft: #e3f3e8; --yellow: #8a5a00; --yellow-soft: #fdf1d6; --flag: #fff4cf;
  --red: #b42318; --red-soft: #fde7e5; --grey-soft: #eceff3;
  --radius: 12px; --tap: 48px;
  font-size: 17px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.dev-banner { background: #5b2a86; color: #fff; text-align: center; font-weight: 700; padding: .35rem; font-size: .85rem; letter-spacing: .02em; }

/* top bar and navigation (bottom bar on phones) */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top .inner { max-width: 72rem; margin: 0 auto; display: flex; align-items: center; gap: .75rem; padding: .5rem 1rem; }
.brand { font-weight: 700; margin-right: auto; }
.who { color: var(--muted); font-size: .9rem; }
.who form { display: inline; }
.linkish { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0 0 0 .4rem; }
nav.tabs { display: flex; gap: .25rem; }
nav.tabs a { text-decoration: none; color: var(--ink); padding: .55rem .8rem; border-radius: 10px; min-height: var(--tap); display: flex; align-items: center; gap: .35rem; }
nav.tabs a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: .75rem; padding: 0 .45rem; min-width: 1.4rem; text-align: center; }
@media (max-width: 899px) {
  nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); justify-content: space-around; padding: .25rem .25rem calc(.25rem + env(safe-area-inset-bottom)); z-index: 10; }
  nav.tabs a { flex-direction: column; font-size: .78rem; padding: .3rem .4rem; gap: 0; }
  main { padding-bottom: 5.5rem !important; }
}
main { max-width: 72rem; margin: 0 auto; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stack > * + * { margin-top: .75rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: var(--tap); padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--red); border-color: #f0c3bf; }
.btn.big { width: 100%; min-height: 64px; font-size: 1.15rem; border-radius: var(--radius); }
.btn.block { width: 100%; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }

/* forms */
label.field { display: block; }
label.field > span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .15rem; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=number], textarea, select {
  width: 100%; min-height: var(--tap); padding: .55rem .7rem; font: inherit; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 4.5rem; }
.flagged input, .flagged textarea { background: var(--flag); border-color: #e7c66b; }
.flag-note { color: var(--yellow); font-size: .8rem; font-weight: 600; }
.req { color: var(--red); font-weight: 700; }
.ok-note { color: var(--green); font-size: .8rem; font-weight: 600; }
#phong-note { color: var(--green); font-weight: 600; margin: 0; }
.error { background: var(--red-soft); color: var(--red); border-radius: 10px; padding: .6rem .8rem; font-weight: 600; }
.notice { background: var(--green-soft); color: var(--green); border-radius: 10px; padding: .6rem .8rem; font-weight: 600; }
.warn { background: var(--yellow-soft); color: var(--yellow); border-radius: 10px; padding: .6rem .8rem; font-weight: 600; }

/* tags */
.tag { display: inline-block; font-size: .78rem; font-weight: 700; padding: .2rem .55rem; border-radius: 999px; white-space: nowrap; }
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-yellow { background: var(--yellow-soft); color: var(--yellow); }
.tag-red { background: var(--red-soft); color: var(--red); }
.tag-grey { background: var(--grey-soft); color: var(--muted); }

/* lists of parcels */
.list { display: flex; flex-direction: column; gap: .5rem; }
.item { display: flex; gap: .75rem; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .55rem .7rem; text-decoration: none; color: var(--ink); }
.item img, .item .ph { width: 48px; height: 64px; object-fit: cover; border-radius: 6px; background: var(--grey-soft); flex: none; }
.item .tx { flex: 1; min-width: 0; line-height: 1.3; }
.item .tx b, .item .tx div { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .tx .sub { font-size: .82rem; color: var(--muted); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: .4rem; }
.thumb { position: relative; aspect-ratio: 3 / 4; border-radius: 8px; background: var(--grey-soft); overflow: hidden; font-size: .7rem; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .st { position: absolute; right: 3px; top: 3px; background: rgba(255,255,255,.9); border-radius: 999px; padding: 0 .3rem; }
.thumb.clash { outline: 3px solid var(--yellow); outline-offset: -3px; }
.clash-list { margin: .35rem 0 0; padding-left: 1.2rem; font-weight: 400; }
.clash-list a { color: inherit; }

/* review */
.review { display: grid; gap: 1rem; }
@media (min-width: 900px) { .review { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; } .review .photo { position: sticky; top: 1rem; } }
.review .photo img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.fields { display: grid; gap: .55rem; }
@media (min-width: 600px) { .fields { grid-template-columns: 1fr 1fr; } .fields .wide { grid-column: 1 / -1; } }
.labs { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
@media (min-width: 600px) { .labs { grid-template-columns: repeat(7, 1fr); } }
.labs label { display: block; }
.labs input { position: absolute; opacity: 0; pointer-events: none; }
.labs span { display: flex; align-items: center; justify-content: center; min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; background: #fff; font-weight: 700; font-size: .85rem; text-align: center; cursor: pointer; padding: .2rem; }
.labs input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.labs input:focus-visible + span { outline: 3px solid var(--accent-soft); }
.labs .suggest span { border: 2px dashed var(--accent); }
.match { border: 2px solid var(--green); border-radius: var(--radius); padding: .55rem .8rem; background: var(--green-soft); }
.banner-red { border: 2px solid var(--red); background: var(--red-soft); color: var(--red); border-radius: var(--radius); padding: .7rem .9rem; font-weight: 600; }
.sticky-save { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding-top: .75rem; }
@media (max-width: 899px) { .sticky-save { bottom: 4.6rem; } }
table.grid { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); font-size: .9rem; vertical-align: top; }
.counts { display: flex; flex-wrap: wrap; gap: .4rem; }
.counts a { text-decoration: none; }
.login { max-width: 24rem; margin: 3rem auto; }
.htmx-request .when-idle { display: none; }
.when-busy { display: none; }
.htmx-request .when-busy { display: inline; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: .9rem; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.only-wide { display: none; }
@media (min-width: 900px) { .only-wide { display: block; } }
.review .photo img { max-height: 42vh; object-fit: contain; }
@media (min-width: 900px) { .review .photo img { max-height: 85vh; } }

/* capture: lab buttons and the in-page camera */
.lab-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(5.2rem, 1fr)); gap: .35rem; }
.chip { min-height: 44px; padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
  font: inherit; font-size: .85rem; font-weight: 600; line-height: 1.15; cursor: pointer; touch-action: manipulation; }
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }
.chip[data-lab=""].on { background: var(--accent); border-color: var(--accent); }
.cam { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.cam video { display: block; width: 100%; height: min(62vh, 36rem); object-fit: cover; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.go { animation: cam-flash .18s ease-out; }
@keyframes cam-flash { from { opacity: .75; } to { opacity: 0; } }
.cam-count { position: absolute; left: .6rem; top: .6rem; background: rgba(0,0,0,.6); color: #fff; font-weight: 700; border-radius: 999px; padding: .25rem .7rem; font-size: .95rem;
  max-width: calc(100% - 9.5rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-off { position: absolute; right: .6rem; top: .6rem; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 999px; padding: .4rem .8rem; font: inherit; font-size: .85rem; cursor: pointer; }
.shutter { position: absolute; left: 50%; bottom: 1rem; transform: translateX(-50%); width: 76px; height: 76px; border-radius: 50%;
  border: 5px solid rgba(255,255,255,.9); background: rgba(255,255,255,.35); cursor: pointer; touch-action: manipulation; }
.shutter:active { background: rgba(255,255,255,.8); }
.cam-alert { position: absolute; left: .6rem; right: .6rem; top: 3rem; border: 0; background: var(--yellow-soft); color: var(--yellow); font: inherit; font-weight: 700; font-size: .9rem; border-radius: 10px; padding: .45rem .6rem; text-align: left; cursor: pointer; }
/* camera on: the page shrinks to lab buttons on one swipeable row and a picture that fits the screen */
body.cam-mode .cam-hide { display: none !important; }
body.cam-mode .lab-chips { display: flex; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
body.cam-mode .lab-chips::-webkit-scrollbar { display: none; }
body.cam-mode .chip { flex: none; min-width: 4.8rem; }
body.cam-mode .cam video { height: max(18rem, calc(100dvh - 15.5rem)); }
@media (min-width: 900px) { body.cam-mode .cam video { height: max(18rem, calc(100dvh - 11rem)); } }

/* photo viewer (viewer.js): the photo over the page, details under it */
html.viewer-open, html.viewer-open body { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 100; background: rgba(10, 12, 16, .94); color: #fff; }
.viewer-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-select: none; will-change: transform; }
.viewer-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem calc(.6rem + env(safe-area-inset-top)); background: linear-gradient(rgba(0,0,0,.55), transparent); }
.viewer-pos { margin-right: auto; font-weight: 600; font-size: .95rem; }
.viewer-btn { width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff; font-size: 1.35rem; cursor: pointer; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px; border: 0; border-radius: 12px; background: rgba(255,255,255,.14); color: #fff; font-size: 2rem; cursor: pointer; }
.viewer-prev { left: .5rem; }
.viewer-next { right: .5rem; }
@media (hover: none) { .viewer-nav { display: none; } }
.viewer-info { position: absolute; left: 0; right: 0; bottom: 0; padding: 1.4rem 1rem calc(1rem + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.75) 35%); pointer-events: none; }
.viewer-info b { display: block; font-size: 1.05rem; }
.viewer-lines { font-size: .9rem; opacity: .9; }
.viewer-link { pointer-events: auto; display: inline-block; margin-top: .4rem; color: #9cc4ff; font-weight: 600; }

/* Today: one block per lab, a card per parcel */
.day-nav { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .6rem; }
.day-nav h1 { margin: 0 auto 0 0; }
.lab-group { margin-top: 1.1rem; }
.lab-head { display: flex; align-items: baseline; gap: .6rem; margin: 0 0 .5rem; padding-bottom: .35rem; border-bottom: 2px solid var(--line); scroll-margin-top: .5rem; }
.lab-head .name { font-size: 1.15rem; font-weight: 800; }
.lab-head .sum { color: var(--muted); font-size: .9rem; font-weight: 600; }
.lab-group.misdelivered .lab-head { border-color: #f0c3bf; color: var(--red); }
.lab-group.unknown .lab-head { border-color: #e7c66b; color: var(--yellow); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.pcard.off { opacity: .5; }
.pcard-photo { display: block; aspect-ratio: 1 / 1; background: var(--grey-soft); position: relative; overflow: hidden; }
.pcard-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard-photo .qty { position: absolute; right: .35rem; bottom: .35rem; background: rgba(0,0,0,.65); color: #fff; font-size: .75rem; font-weight: 700; border-radius: 999px; padding: .05rem .45rem; }
.pcard-body { padding: .45rem .55rem .55rem; text-decoration: none; color: var(--ink); line-height: 1.3; flex: 1; }
.pcard-body b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .9rem; }
.pcard-body .sub { display: block; font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard-body .tag { margin-top: .25rem; }
