:root {
  --bg: #e7eef6;
  --bg-2: #d5e2f0;
  --surface: #f5f9fc;
  --ink: #122033;
  --muted: #5b6d82;
  --line: #b7c7d8;
  --accent: #0f4c81;
  --accent-2: #d97706;
  --ok: #0f7a4d;
  --wait: #b7791f;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(15, 76, 129, 0.1);
  --radius: 18px;
  --font: "Be Vietnam Pro", "Segoe UI", sans-serif;
  --display: "Sora", "Be Vietnam Pro", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 8% -8%, #f6d9a8 0%, transparent 40%),
    radial-gradient(circle at 100% 0%, #9ec4ea 0%, transparent 38%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px 16px 96px;
  position: relative;
}

.hidden { display: none !important; }

.login-wrap {
  min-height: calc(100dvh - 32px);
  display: grid;
  align-content: center;
  gap: 20px;
}
.brand { text-align: center; }
.brand-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: linear-gradient(145deg, #0b3a63, #0f4c81 55%, #d97706);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.04em;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.7rem, 6vw, 2.1rem);
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.brand p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card {
  background: color-mix(in srgb, var(--surface) 92%, white);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--ink);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 13px 16px;
  font-weight: 700;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-warn { background: var(--accent-2); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { width: auto; padding: 8px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.hint {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.topbar h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.user-chip {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: right;
}
.user-chip strong { display: block; color: var(--ink); font-size: 0.9rem; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  background: #fff;
  border-radius: 16px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
}
.stat .label { color: var(--muted); font-size: 0.78rem; }
.stat .value {
  margin-top: 4px;
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.ton-title-row {
  gap: 10px;
  align-items: center;
}
.ton-branch-select {
  max-width: 180px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
}

.list { display: grid; gap: 10px; }
.item {
  background: #fff;
  border: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
  border-radius: 16px;
  padding: 14px;
}
.item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 6px;
}
.item-head strong { font-size: 0.98rem; }
.meta { color: var(--muted); font-size: 0.8rem; line-height: 1.45; }
.vot-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  margin-top: 4px;
}
.vot-meta div {
  background: #f3f7fb;
  border-radius: 10px;
  padding: 8px 10px;
}
.vot-meta div.full { grid-column: 1 / -1; }
.vot-meta span {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}
.vot-meta b {
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
  word-break: break-word;
}

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chi-tiet { margin-top: 8px; font-size: 0.9rem; }

.btn-xem-anh {
  width: auto !important;
  margin-top: 8px;
}

.anh-viewer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(10, 20, 30, 0.88);
  padding: 20px;
  align-items: center;
  justify-content: center;
}
.anh-viewer.show {
  display: flex;
}
.anh-viewer img {
  max-width: min(920px, 100%);
  max-height: calc(100dvh - 80px);
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
}
.anh-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.item-compact {
  padding: 12px !important;
}
.item-compact .item-head {
  margin-bottom: 6px;
}
.item-compact .meta-line {
  margin-top: 2px;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}
.journey-compact {
  margin: 6px 0 8px !important;
  padding: 8px !important;
}
.journey-compact .journey-steps {
  margin-bottom: 6px;
}
.journey-compact .step {
  font-size: 0.62rem !important;
  padding: 3px 2px !important;
}
.compact-code {
  text-align: center;
}
.compact-code code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  display: inline-block;
}
.compact-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 0.78rem;
  color: var(--muted);
}
.compact-meta .note {
  color: var(--ink);
  font-weight: 600;
  flex: 1 1 100%;
}
.item-compact .row-actions {
  margin-top: 8px;
}
.thumb-lg {
  width: 100%;
  max-height: 180px;
  border-radius: 12px;
  object-fit: cover;
  margin-top: 10px;
  border: 1px solid var(--line);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-wait { background: #fff4d6; color: var(--wait); }
.badge-ok { background: #e4f6ec; color: var(--ok); }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 12px;
  width: min(448px, calc(100% - 24px));
  background: rgba(245, 249, 252, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 8px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  z-index: 20;
}
.tab {
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 10px 2px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.tab.active {
  background: var(--accent);
  color: #fff;
}

.row-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.product-row {
  display: grid;
  grid-template-columns: 56px 1fr 88px;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.product-row:last-child { border-bottom: 0; }
.product-row .name { font-weight: 600; font-size: 0.92rem; }
.product-row .ton { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.product-row input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%) translateY(-120%);
  width: min(420px, calc(100% - 32px));
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  z-index: 50;
  transition: transform 0.25s ease;
  font-size: 0.9rem;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-size: 0.92rem;
}

/* Mã vạch + hành trình */
.barcode {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px 6px;
  display: inline-block;
  max-width: 100%;
}
.barcode-bars {
  display: flex;
  align-items: flex-end;
  height: 42px;
  gap: 0;
  overflow: hidden;
}
.barcode-bars i {
  display: block;
  width: 2px;
  height: 100%;
  flex: 0 0 2px;
}
.barcode-bars i.on { background: #111; }
.barcode-bars i.off { background: transparent; width: 1.5px; flex-basis: 1.5px; }
.barcode-bars i.on {
  animation: barPulse 1.6s ease-in-out infinite;
}
@keyframes barPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}
.barcode-text {
  margin-top: 4px;
  text-align: center;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--ink);
  font-weight: 700;
}

.journey {
  margin: 10px 0 12px;
  padding: 10px;
  border-radius: 14px;
  background: linear-gradient(90deg, #eef5fb, #f7fafc 50%, #eef8f1);
  border: 1px dashed color-mix(in srgb, var(--line) 80%, transparent);
}
.journey-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}
.journey-in .journey-steps { grid-template-columns: 1fr 1fr; }
.journey-steps .step {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 2px;
  border-radius: 8px;
  background: rgba(255,255,255,0.55);
}
.journey-steps .step.active { color: var(--accent); background: #dceaf7; }
.journey-steps .step.done { color: var(--ok); background: #dff3e8; }

.journey-track,
.journey-marker {
  display: none !important;
}

#pwa-install-banner {
  display: none;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 84px;
  width: min(448px, calc(100% - 24px));
  background: #0b3a63;
  color: #fff;
  border-radius: 16px;
  padding: 12px 14px;
  z-index: 30;
  box-shadow: var(--shadow);
}
#pwa-install-banner.show { display: block; }
#pwa-install-banner p { margin: 0 0 10px; font-size: 0.86rem; line-height: 1.4; }
#pwa-install-banner .row-actions { margin: 0; }
#pwa-install-banner .btn { width: auto; }

@media (min-width: 720px) {
  .app { padding-top: 28px; }
}
