:root {
  --blue: #1a4db8;
  --blue-deep: #0e2f7a;
  --blue-soft: #e8effc;
  --royal: #2563eb;
  --silver: #c5ced9;
  --silver-lt: #f4f6f9;
  --ink: #1a2332;
  --muted: #5b6b7c;
  --ok: #0d9f6e;
  --bad: #d64545;
  --warn: #c9891a;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(14, 47, 122, 0.12);
  --font: "Segoe UI", "Noto Sans Thai", "Noto Sans SC", "Noto Sans Myanmar",
    "Pyidaungsu", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, #f7f9fc 0%, #e8effc 55%, #f0f4fa 100%);
  min-height: 100%;
}
body { -webkit-font-smoothing: antialiased; }

.app-shell { max-width: 980px; margin: 0 auto; padding: 12px 14px 80px; }

.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: linear-gradient(120deg, var(--blue-deep), var(--blue) 55%, #3b82f6);
  color: #fff; border-radius: 18px; padding: 12px 16px;
  box-shadow: var(--shadow); position: sticky; top: 8px; z-index: 40;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 180px; }
.topbar .logo { height: 42px; width: auto; background: #fff; border-radius: 8px; padding: 4px 6px; object-fit: contain; }
.topbar .mascot { height: 48px; width: auto; filter: drop-shadow(0 2px 4px rgba(0,0,0,.25)); }
.topbar .titles { line-height: 1.2; }
.topbar .titles h1 { margin: 0; font-size: 1rem; font-weight: 700; letter-spacing: .02em; }
.topbar .titles p { margin: 2px 0 0; font-size: .72rem; opacity: .9; }
.lang-switch { display: flex; gap: 4px; background: rgba(255,255,255,.15); padding: 4px; border-radius: 999px; }
.lang-switch button {
  border: 0; background: transparent; color: #fff; font-weight: 600;
  font-size: .78rem; padding: 6px 10px; border-radius: 999px; cursor: pointer;
}
.lang-switch button.active { background: #fff; color: var(--blue-deep); }
.offline-pill {
  font-size: .68rem; background: rgba(255,255,255,.18); padding: 4px 8px;
  border-radius: 999px; white-space: nowrap;
}

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid rgba(197,206,217,.55);
  padding: 16px; margin-top: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; color: var(--blue-deep); }
.muted { color: var(--muted); font-size: .85rem; }

.lot-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.lot-card {
  border: 1px solid var(--silver); border-radius: 14px; padding: 12px;
  background: linear-gradient(180deg, #fff, var(--silver-lt));
  display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.lot-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(26,77,184,.15); }
.lot-card .lot-meta { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.lot-card .lot-id { font-weight: 800; color: var(--blue-deep); font-size: 1.05rem; }
.lot-card .model-chip {
  background: var(--blue-soft); color: var(--blue); font-weight: 700;
  padding: 3px 8px; border-radius: 999px; font-size: .78rem;
}
.lot-card .qty { font-size: .85rem; color: var(--muted); }
.lot-card .qr-box {
  align-self: center; background: #fff; padding: 6px; border-radius: 10px;
  border: 1px dashed var(--silver); min-height: 112px; min-width: 112px;
  display: flex; align-items: center; justify-content: center;
}
.lot-card .qr-box img, .lot-card .qr-box canvas { display: block; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn {
  appearance: none; border: 0; border-radius: 10px; padding: 9px 12px;
  font-weight: 700; font-size: .82rem; cursor: pointer;
  background: var(--blue); color: #fff; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: #fff; color: var(--blue-deep); border: 1px solid var(--silver); }
.btn.ghost { background: transparent; color: var(--blue); border: 1px dashed var(--blue); }
.btn.danger { background: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar .spacer { flex: 1; }

.form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
}
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar .titles h1 { font-size: .92rem; }
  .topbar .mascot { height: 40px; }
}

.field label {
  display: block; font-size: .78rem; font-weight: 700; color: var(--muted);
  margin-bottom: 4px;
}
.field .req { color: var(--bad); margin-left: 2px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--silver); border-radius: 10px;
  padding: 10px 12px; font: inherit; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(37,99,235,.35); border-color: var(--royal);
}
.field textarea { min-height: 72px; resize: vertical; }
.field.full { grid-column: 1 / -1; }

.test-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.test-table th {
  text-align: left; background: var(--blue-deep); color: #fff;
  padding: 8px 10px; font-weight: 700;
}
.test-table td { padding: 8px 8px; border-bottom: 1px solid #e6ebf2; vertical-align: middle; }
.test-table tr:nth-child(even) td { background: #f8fafc; }
.test-table .crit { color: var(--muted); font-size: .78rem; }
.test-table select, .test-table input {
  width: 100%; border: 1px solid var(--silver); border-radius: 8px;
  padding: 7px 8px; font: inherit; background: #fff;
}
.test-item-name { font-weight: 700; }

.records-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.records-table th, .records-table td {
  padding: 8px; border-bottom: 1px solid #e6ebf2; text-align: left;
}
.records-table th { background: var(--silver-lt); color: var(--blue-deep); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 800;
}
.badge.pass { background: #d1fae5; color: #065f46; }
.badge.fail { background: #fee2e2; color: #991b1b; }
.badge.na { background: #e5e7eb; color: #374151; }

.empty-state {
  text-align: center; padding: 28px 12px; color: var(--muted);
}
.empty-state img { width: 120px; height: auto; margin-bottom: 8px; opacity: .95; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: .85rem; z-index: 100; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 40, .55);
  display: none; align-items: center; justify-content: center; z-index: 80; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: 16px; max-width: 420px; width: 100%;
  padding: 18px; box-shadow: var(--shadow); text-align: center;
}
.modal h3 { margin: 0 0 8px; color: var(--blue-deep); }
.modal .qr-large { margin: 12px auto; display: inline-block; padding: 10px; border: 1px solid var(--silver); border-radius: 12px; }
.footer-note {
  text-align: center; margin-top: 18px; color: var(--muted); font-size: .75rem;
}

/* Print */
@media print {
  body { background: #fff !important; }
  .topbar, .toolbar, .btn-row, .lang-switch, .offline-pill,
  .no-print, .toast, .modal-backdrop, .footer-note { display: none !important; }
  .app-shell { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .print-only { display: block !important; }
  .test-table th { background: #222 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4; margin: 12mm; }
}
.print-only { display: none; }
.print-header {
  display: flex; align-items: center; gap: 12px; border-bottom: 2px solid var(--blue);
  padding-bottom: 8px; margin-bottom: 12px;
}
.print-header img.logo { height: 48px; }
.print-header img.mascot { height: 56px; }

.view { display: none; }
.view.active { display: block; }

.status-pass select { border-color: var(--ok); }
.status-fail select { border-color: var(--bad); }

/* —— Blank-form home hero QR —— */
.hero-qr-card { text-align: center; }
.hero-qr-wrap {
  display: flex; flex-wrap: wrap; gap: 20px; align-items: center; justify-content: center;
  margin: 16px 0;
}
.qr-hero {
  background: #fff; padding: 14px; border-radius: 16px;
  border: 2px solid var(--silver); box-shadow: var(--shadow);
  min-width: 240px; min-height: 240px;
  display: flex; align-items: center; justify-content: center;
}
.hero-actions { display: flex; flex-direction: column; gap: 8px; min-width: 200px; max-width: 280px; }
.howto { text-align: left; background: var(--blue-soft); border-radius: 12px; padding: 12px 16px; margin-top: 8px; }
.howto h3 { margin: 0 0 6px; color: var(--blue-deep); font-size: .95rem; }
.howto ol { margin: 0; padding-left: 1.2rem; color: var(--ink); font-size: .88rem; line-height: 1.55; }
.suggest-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--silver); background: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: .78rem; font-weight: 700; color: var(--blue-deep); cursor: pointer;
}
.chip:hover { border-color: var(--royal); background: var(--blue-soft); }
.badge.special { background: #fef3c7; color: #92400e; }
.badge.synced { background: #d1fae5; color: #065f46; }
.badge.local { background: #e5e7eb; color: #374151; }
.badge.failed { background: #fee2e2; color: #991b1b; }
