:root {
  --green-900: #0f3d28;
  --green-700: #1a5c3a;
  --green-500: #2d8a56;
  --green-100: #e8f5ee;
  --soil: #5c4030;
  --cream: #f7f4ef;
  --ink: #1c241f;
  --muted: #5a6b62;
  --line: #d5ddd8;
  --danger: #b42318;
  --warn: #b54708;
  --white: #ffffff;
  --shadow: 0 10px 30px rgba(15, 61, 40, 0.12);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Be Vietnam Pro", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--cream);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(45, 138, 86, 0.22), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(92, 64, 48, 0.12), transparent 50%),
    linear-gradient(180deg, #eef6f1 0%, var(--cream) 40%, #efe8dc 100%);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(145deg, var(--green-500), var(--green-900));
  color: white; display: grid; place-items: center;
  font-weight: 700; font-size: 1.1rem;
  box-shadow: var(--shadow);
}
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.02em; }
.brand-sub { font-size: 0.72rem; color: var(--muted); }

.icon-btn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(8px);
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; cursor: pointer; color: var(--green-700);
}

.tabs {
  display: flex; gap: 6px; padding: 8px 16px 12px;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, rgba(238,246,241,0.95), rgba(238,246,241,0.75));
  backdrop-filter: blur(10px);
}
.tab {
  flex: 1; border: none; border-radius: 999px; padding: 10px 8px;
  background: transparent; color: var(--muted); font-weight: 600;
  font-family: inherit; font-size: 0.88rem; cursor: pointer;
}
.tab.active {
  background: var(--green-700); color: white;
  box-shadow: 0 6px 16px rgba(26, 92, 58, 0.28);
}

main { padding: 0 16px calc(24px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
.panel { display: none; animation: fade .25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat {
  background: rgba(255,255,255,0.75); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-n { display: block; font-size: 1.6rem; font-weight: 700; color: var(--green-700); font-variant-numeric: tabular-nums; }
.stat-l { font-size: 0.8rem; color: var(--muted); }

.scanner-card, .form-card {
  background: rgba(255,255,255,0.82);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.reader {
  width: 100%;
  min-height: 280px;
  height: min(52vh, 420px);
  border-radius: 14px;
  overflow: hidden;
  background: #0f1a14;
  position: relative;
}
.reader video { object-fit: cover !important; }
#reader video, #reader canvas { border-radius: 14px; }
#reader__dashboard_section, #reader__header_message { display: none !important; }
#reader__scan_region { min-height: 220px; }
.scanner-overlay-hint {
  text-align: center; font-size: 0.82rem; color: var(--muted);
  margin: 10px 0 8px;
}
.scanner-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file-btn { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  background: #e8ece9;
  color: var(--ink);
}
.btn.primary { background: var(--green-700); color: white; }
.btn.primary:active { background: var(--green-900); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: var(--danger); color: white; }
.btn.danger.ghost { background: transparent; color: var(--danger); border-color: #f3c4c0; }
.btn.block { width: 100%; }
.btn.lg { padding: 14px; font-size: 1rem; margin-top: 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-text {
  border: none; background: none; color: var(--green-700);
  font-weight: 600; font-family: inherit; cursor: pointer; font-size: 0.85rem;
}

.manual-row { margin-bottom: 14px; }
.manual-row label, .field label {
  display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 6px; color: var(--soil);
}
.input-row { display: flex; gap: 8px; }
input[type="text"], input[type="search"], input[type="date"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 1rem;
  background: white;
  color: var(--ink);
}
textarea.mono { font-family: var(--mono); font-size: 0.78rem; line-height: 1.45; }
.req { color: var(--danger); }

.form-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 10px; margin-bottom: 14px;
  padding-bottom: 12px; border-bottom: 1px dashed var(--line);
}
.label-sm { font-size: 0.75rem; color: var(--muted); }
.code-display {
  font-family: var(--mono); font-weight: 600; font-size: 1.05rem;
  color: var(--green-900); word-break: break-all;
}
.field { margin-bottom: 14px; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink);
}
.chip.active {
  background: var(--green-100);
  border-color: var(--green-500);
  color: var(--green-900);
  font-weight: 600;
}

.product-picker {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: white;
}
.product-picker input { border: none; border-bottom: 1px solid var(--line); border-radius: 0; }
.product-list { max-height: 180px; overflow: auto; }
.product-item {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 10px 12px; border-bottom: 1px solid #eef2ef;
  cursor: pointer; text-align: left; width: 100%;
  background: white; border-left: none; border-right: none; border-top: none;
  font-family: inherit;
}
.product-item:last-child { border-bottom: none; }
.product-item:active { background: var(--green-100); }
.product-item .name { font-size: 0.85rem; font-weight: 500; }
.product-item .sku { font-size: 0.72rem; color: var(--muted); font-family: var(--mono); }
.product-item .add {
  flex-shrink: 0; width: 32px; height: 32px; border-radius: 8px;
  background: var(--green-100); color: var(--green-700);
  display: grid; place-items: center; font-weight: 700;
}

.selected-products { margin-top: 10px; display: grid; gap: 8px; }
.sel-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px; align-items: center;
  background: var(--green-100);
  border-radius: 12px;
  padding: 10px 12px;
}
.sel-row .name { font-size: 0.85rem; font-weight: 500; }
.qty-ctrl {
  display: inline-flex; align-items: center; gap: 0;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: white;
}
.qty-ctrl button {
  width: 36px; height: 36px; border: none; background: #f0f4f1;
  font-size: 1.15rem; font-weight: 700; cursor: pointer; color: var(--green-700);
  font-family: inherit;
}
.qty-ctrl button:active { background: var(--green-100); }
.qty-ctrl .qty {
  width: 48px; text-align: center; padding: 8px 4px;
  border: none; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  border-radius: 0; font-family: var(--mono); font-weight: 600; font-size: 0.95rem;
}
.sel-row .rm {
  border: none; background: transparent; color: var(--danger);
  font-size: 1.2rem; cursor: pointer; width: 32px;
}

.dup-alert {
  background: #fff7ed;
  border: 1px solid #fdba74;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}
.dup-title { font-weight: 700; color: var(--warn); margin-bottom: 6px; }
.dup-body { font-size: 0.85rem; color: #7c2d12; line-height: 1.45; }

.photo-preview {
  position: relative; margin-bottom: 12px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line);
}
.photo-preview img { width: 100%; display: block; max-height: 220px; object-fit: cover; }
.photo-badge {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(15, 61, 40, 0.85); color: white;
  font-size: 0.72rem; padding: 4px 8px; border-radius: 6px;
}

.filters { display: grid; gap: 8px; margin-bottom: 14px; }
.filter-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.order-list { display: grid; gap: 10px; }
.order-card {
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left; width: 100%;
  font-family: inherit; cursor: pointer;
  box-shadow: 0 4px 14px rgba(15,61,40,0.06);
}
.order-card:active { transform: scale(0.99); }
.order-card .code { font-family: var(--mono); font-weight: 600; color: var(--green-900); word-break: break-all; }
.order-card .meta { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.order-card .type-tag {
  display: inline-block; margin-top: 8px;
  background: var(--green-100); color: var(--green-900);
  font-size: 0.75rem; font-weight: 600;
  padding: 4px 8px; border-radius: 6px;
}
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

.section-title { margin: 0 0 6px; font-size: 1.05rem; }
.muted { color: var(--muted); font-size: 0.85rem; margin: 0 0 12px; }
.hint { font-size: 0.8rem; color: var(--muted); line-height: 1.4; }
code { font-family: var(--mono); font-size: 0.85em; background: #eef2ef; padding: 1px 5px; border-radius: 4px; }

.type-row {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 8px; align-items: center; margin-bottom: 8px;
}
.type-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--green-700); }
.add-type-row { display: flex; gap: 8px; margin: 12px 0; }
.url-list { padding-left: 18px; margin: 0 0 10px; }
.url-list li { margin-bottom: 6px; word-break: break-all; }
.url-list a { color: var(--green-700); font-weight: 600; }

.dialog {
  border: none; border-radius: 18px; padding: 0;
  width: min(96vw, 520px); max-height: 90dvh;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.dialog::backdrop { background: rgba(15, 30, 22, 0.45); backdrop-filter: blur(3px); }
.dialog-inner { padding: 16px; overflow: auto; max-height: 90dvh; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; font-size: 1.1rem; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.confirm-scan-dialog { width: min(96vw, 420px); }
.confirm-scan-hint { margin: 0 0 12px; color: var(--muted); font-size: 0.88rem; }
.confirm-scan-code {
  font-family: var(--mono); font-weight: 700; font-size: 1.25rem;
  color: var(--green-900); word-break: break-all;
  background: var(--green-100); border: 1px solid #b7dcc6;
  border-radius: 12px; padding: 16px; text-align: center;
  letter-spacing: 0.02em;
}
.confirm-scan-preview {
  margin-top: 12px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); max-height: 160px;
}
.confirm-scan-preview img { width: 100%; display: block; object-fit: cover; max-height: 160px; }
.confirm-scan-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail-grid { display: grid; gap: 8px; font-size: 0.9rem; }
.detail-grid .k { color: var(--muted); font-size: 0.75rem; }
.detail-grid .v { font-weight: 500; word-break: break-word; }
.detail-photo { width: 100%; border-radius: 10px; margin-top: 10px; border: 1px solid var(--line); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--green-900); color: white;
  padding: 12px 18px; border-radius: 999px;
  font-size: 0.88rem; font-weight: 500;
  z-index: 100; max-width: 90vw; text-align: center;
  box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); }

/* Phiếu xuất kho – print */
.print-root { display: none; }
@media print {
  body > *:not(.print-root) { display: none !important; }
  .print-root, .print-root * { visibility: visible; }
  .print-root {
    display: block !important;
    position: absolute; left: 0; top: 0; width: 100%;
    background: white; color: black; padding: 12mm;
    font-family: "Times New Roman", Times, serif;
  }
}

.pxk {
  width: 100%;
  max-width: 190mm;
  margin: 0 auto;
  font-size: 12pt;
  line-height: 1.35;
}
.pxk-header {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
  border-bottom: 2px solid #000;
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.pxk-company { font-weight: 700; text-transform: uppercase; }
.pxk-company-sub { font-size: 10pt; }
.pxk-meta { text-align: right; font-size: 10pt; }
.pxk-title {
  text-align: center;
  font-size: 18pt;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 10px 0 4px;
  text-transform: uppercase;
}
.pxk-sub { text-align: center; font-size: 11pt; margin-bottom: 14px; }
.pxk-info { margin-bottom: 12px; }
.pxk-info p { margin: 4px 0; }
.pxk table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 14px;
}
.pxk th, .pxk td {
  border: 1px solid #000;
  padding: 6px 8px;
  font-size: 11pt;
}
.pxk th { background: #f0f0f0; text-align: center; }
.pxk .num { text-align: center; }
.pxk .right { text-align: right; }
.pxk-signs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 28px;
  text-align: center;
  font-size: 11pt;
}
.pxk-signs .role { font-weight: 700; }
.pxk-signs .space { height: 64px; }

@media (max-width: 420px) {
  .brand-name { font-size: 0.95rem; }
  .tab { font-size: 0.8rem; padding: 10px 4px; }
}
