:root {
  --ink: #0e2a33;
  --muted: #6a7d83;
  --cream: #f3fcff;
  --paper: #ffffff;
  --line: #e6f4f7;
  --gold: #31e1ff;
  --gold-deep: #1cb6cf;
  --teal: #1cb6cf;
  --teal-soft: #0e8fa6;
  --rose: #c2410c;
  --ok: #16a34a;
  --theme: #31e1ff;
  --accent: #f6cf2f;
  --shadow: 0 16px 40px rgba(28, 182, 207, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Sarabun", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
  line-height: 1.55;
}
h1, h2, h3, .display {
  font-family: "Be Vietnam Pro", "Sarabun", sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.35em;
}
a { color: inherit; }
img { max-width: 100%; }

.admin {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  font-family: "Sarabun", "Segoe UI", sans-serif;
  font-size: 15px;
}
.admin h1, .admin h2, .admin h3, .admin .display, .admin .stat b, .admin .card-no strong {
  font-family: "Sarabun", "Segoe UI", sans-serif;
  letter-spacing: 0;
}
.admin h1 { font-size: 1.2rem; font-weight: 700; }
.admin h2 { font-size: 1rem; font-weight: 700; }
.admin .btn, .admin a.btn, .admin button.btn {
  font: 600 0.82rem "Sarabun", sans-serif;
  padding: 6px 12px;
  gap: 6px;
}
.admin .btn.small { padding: 5px 10px; font-size: 0.78rem; }
.sidebar {
  background: linear-gradient(180deg, #0e2a33 0%, #12343f 100%);
  color: #f3fcff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.site-logo { display: inline-block; line-height: 0; text-decoration: none; }
.site-logo img { display: block; width: auto; height: 52px; object-fit: contain; }
.brand .site-logo img { height: 56px; }
.login-logo img, .home-logo img { height: 88px; margin: 0 auto 12px; }
.poster-logo img { height: 56px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--gold); color: var(--teal);
  display: grid; place-items: center;
  font-family: "Cormorant Garamond", serif;
  font-weight: 700; font-size: 1.15rem;
}
.brand strong { display: block; font-size: 1.05rem; }
.brand small { color: #d8c89a; }
.sidebar nav { display: flex; flex-direction: column; gap: 6px; }
.sidebar nav a {
  text-decoration: none;
  padding: 7px 10px;
  border-radius: 8px;
  color: #efe6d4;
  font-size: 0.88rem;
}
.sidebar nav a.active,
.sidebar nav a:hover { background: rgba(49, 225, 255, 0.18); color: #fff; }
.sidebar-foot { margin-top: auto; font-size: 0.9rem; color: #d8c89a; }
.sidebar-foot span { display: block; color: #fff; }
.sidebar-foot small { display: block; margin-top: 2px; color: #d8c89a; }
.sidebar-foot a { display: block; margin-top: 6px; color: #fff; }

.admin-main { padding: 22px 24px 40px; }
.page-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 16px;
}
.page-head p { margin: 0; color: var(--muted); }
.settings-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -8px 0 22px;
}
.settings-nav-item {
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
.settings-nav-item:hover,
.settings-nav-item.active {
  background: #e8f6fb;
  border-color: #b7e4ee;
  color: var(--teal-soft);
}
.settings-hub {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.settings-tile {
  display: block;
  text-decoration: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.settings-tile:hover { border-color: #b7e4ee; }
.settings-tile strong { display: block; font-size: 1.15rem; margin-bottom: 4px; }
.settings-tile span { display: block; color: var(--muted); font-size: 0.92rem; }
.settings-tile b { display: block; margin-top: 12px; color: var(--teal-soft); font-size: 0.95rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 1.2rem; font-family: "Sarabun", "Segoe UI", sans-serif; font-weight: 700; }
.stat span { color: var(--muted); font-size: 0.8rem; }

.card, .table-wrap, .form-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card, .form-card { padding: 22px 24px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); }
th { font-size: 0.82rem; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }

.btn, a.btn, a.btn:link, a.btn:visited, button.btn {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; text-decoration: none;
  background: linear-gradient(135deg, #31e1ff 0%, #1cb6cf 100%);
  color: #0e2a33;
  -webkit-text-fill-color: #0e2a33;
  border-radius: 999px; padding: 10px 18px;
  font: 600 0.95rem "Sarabun", sans-serif;
}
.btn:hover, a.btn:hover {
  filter: none;
  background: #0e8fa6;
  color: #ffffff;
  -webkit-text-fill-color: #ffffff;
}
.btn.gold, a.btn.gold, a.btn.gold:visited {
  background: #f6cf2f;
  color: #0e2a33;
  -webkit-text-fill-color: #0e2a33;
}
.btn.gold:hover, a.btn.gold:hover { background: #e6bf20; color: #0e2a33; -webkit-text-fill-color: #0e2a33; }
.btn.ghost, a.btn.ghost, a.btn.ghost:visited {
  background: #ffffff;
  color: #0e2a33;
  -webkit-text-fill-color: #0e2a33;
  border: 1px solid #9ad7e4;
}
.btn.ghost:hover, a.btn.ghost:hover {
  background: #e6f9ff;
  color: #0e2a33;
  -webkit-text-fill-color: #0e2a33;
}
.btn.danger, a.btn.danger, a.btn.danger:visited, button.btn.danger {
  background: var(--rose);
  color: #ffffff;
  -webkit-text-fill-color: #ffffff;
}
.btn.danger:hover, a.btn.danger:hover { background: #9a3412; color: #ffffff; -webkit-text-fill-color: #ffffff; }
.btn.small { padding: 7px 12px; font-size: 0.85rem; }
.btn:disabled, button.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  color: #0e2a33;
  -webkit-text-fill-color: #0e2a33;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.flash {
  padding: 12px 16px; border-radius: 12px; margin-bottom: 18px;
  border: 1px solid var(--line); background: #fff;
}
.flash-ok { background: #e8f5ee; border-color: #b7ddc6; }
.flash-err { background: #fdecea; border-color: #f0c2bc; }
.flash-warn { background: #fff3d6; border-color: #e6c36a; }

.form-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr;
  gap: 22px;
}
label { display: block; font-weight: 600; margin: 0 0 4px; font-size: 0.85rem; }
input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="url"], textarea, select {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font: 0.9rem "Sarabun", sans-serif;
}
.color-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 220px;
}
.color-picker input[type="color"],
.vle-mini input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 42px;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  flex: 0 0 42px;
}
.color-picker input[type="color"]::-webkit-color-swatch-wrapper,
.vle-mini input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
.color-picker input[type="color"]::-webkit-color-swatch,
.vle-mini input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 7px;
}
.color-picker input[type="color"]::-moz-color-swatch,
.vle-mini input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 7px;
}
.color-picker .color-hex {
  flex: 1 1 auto;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.vle-mini input[type="color"] {
  width: 40px;
  height: 36px;
  margin-top: 4px;
}
textarea { min-height: 110px; resize: vertical; }
.field { margin-bottom: 16px; }
.entrance-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.entrance-row input { flex: 1 1 auto; }
.entrance-row .btn { flex: 0 0 auto; white-space: nowrap; }
.type-crud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.type-crud-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1 1 auto;
}
.type-crud-row input[name="name"] { min-width: 160px; flex: 1 1 180px; margin: 0; }
.type-crud-row input[name="type_code"] { width: 96px; margin: 0; text-transform: uppercase; }
.type-crud-del { margin: 0; }
.hint { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.benefit-row {
  display: grid; grid-template-columns: 1fr 1.4fr auto;
  gap: 8px; margin-bottom: 8px;
}
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700;
  background: #e8f5ee; color: var(--ok);
}
.badge.off { background: #f3eee4; color: var(--muted); }
.badge.warn { background: #fff3d6; color: #8a5a00; }
.badge.st-printed { background: #e8f6fb; color: #0e8fa6; }
.badge.st-issued { background: #fff3d6; color: #8a5a00; }
.badge.st-active { background: #e8f5ee; color: var(--ok); }
.badge.st-used { background: #f3eee4; color: var(--muted); }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(1200px 700px at 10% 0%, #dbf4ff 0%, #ffffff 55%, #fff9e9 100%);
}
.login-card {
  width: min(420px, calc(100% - 32px));
  background: var(--paper);
  border-radius: 22px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 2.1rem; }
.login-card p { color: var(--muted); margin-top: 0; }

.public {
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(196,163,90,.18), transparent 36%),
    linear-gradient(180deg, var(--theme), #071f1d 80%);
  color: #fffdf8;
  padding: 32px 16px 48px;
}
.voucher-shell { width: min(640px, 100%); margin: 0 auto; }
.voucher-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.28);
}
.voucher-cover {
  min-height: 160px;
  background:
    linear-gradient(180deg, rgba(11,61,58,.15), rgba(11,61,58,.55)),
    var(--theme);
  display: grid; place-items: end start;
  padding: 22px;
  color: #fff;
}
.voucher-cover.has-img {
  background-size: cover;
  background-position: center;
}
.voucher-cover small {
  letter-spacing: 0.18em; text-transform: uppercase; font-size: 0.75rem;
}
.voucher-body { padding: 28px 26px 32px; }
.voucher-body h1 { font-size: 2.2rem; }
.lead { color: var(--muted); font-size: 1.05rem; }
.benefit-list { list-style: none; padding: 0; margin: 22px 0; }
.benefit-list li {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.benefit-list strong { display: block; }
.terms {
  background: #f6f1e8; border-radius: 16px; padding: 14px 16px;
  color: var(--muted); font-size: 0.92rem;
}
.serial {
  margin-top: 18px; color: var(--muted); font-size: 0.9rem;
  letter-spacing: 0.06em;
}
.card-no {
  background: #f6f1e8;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 0 0 20px;
  text-align: center;
}
.card-no span {
  display: block;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--gold-deep);
  margin-bottom: 4px;
}
.card-no strong {
  font-family: "Sarabun", "Segoe UI", sans-serif;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  word-break: break-all;
}
.card-no.mini { padding: 8px; margin: 8px 0 0; background: transparent; border: 0; }
.card-no.mini strong { font-size: 1rem; }
.card-no.preview-no { display: inline-block; min-width: 240px; margin: 8px 0 16px; }
.gen-box { margin-bottom: 28px; }
.gen-box h2 { font-size: 1rem; }
.campaign-page .page-head {
  align-items: center;
  margin-bottom: 14px;
}
.campaign-page .page-head h1 {
  font-size: 1.25rem;
  letter-spacing: 0;
  margin: 0 0 2px;
}
.campaign-page .page-head p { font-size: 0.9rem; }
.campaign-page .stats {
  gap: 10px;
  margin-bottom: 14px;
}
.campaign-page .stat { padding: 10px 14px; }
.campaign-page .stat b {
  font-family: "Be Vietnam Pro", "Sarabun", sans-serif;
  font-size: 1.2rem;
}
.campaign-page .stat span { font-size: 0.82rem; }
.campaign-page .gen-box {
  margin-bottom: 16px;
  padding: 18px 20px 16px;
}
.campaign-page .gen-box h2,
.campaign-page .vle-card h2 {
  font-size: 1.05rem;
  margin: 0 0 4px;
}
.campaign-page .card-no.preview-no { margin: 0; }
.campaign-page .card-no.preview-no strong { font-size: 1rem; }
.campaign-page .vle-card .page-head { margin-bottom: 10px; }
.gen-fields {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}
.gen-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 4px;
}
.gen-head .hint { margin: 0; }
.gen-sample {
  flex: 0 0 auto;
  min-width: 200px;
  background: #f6f1e8;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  text-align: right;
}
.gen-sample span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.gen-sample strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  word-break: break-all;
}
.gen-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.gen-section h3 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.gen-grid {
  display: grid;
  gap: 12px 14px;
  align-items: end;
}
.gen-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gen-grid-2 { grid-template-columns: 1.5fr 1fr; }
.gen-box .field { margin-bottom: 0; }
.gen-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.gen-link-preview {
  margin: 0;
  flex: 1 1 220px;
  word-break: break-all;
}
.gen-foot .btn {
  height: 38px;
  padding: 0 18px;
  white-space: nowrap;
}
@media (max-width: 900px) {
  .gen-head { flex-direction: column; align-items: stretch; }
  .gen-sample { text-align: left; }
  .gen-grid-4 { grid-template-columns: 1fr 1fr; }
  .gen-grid-2 { grid-template-columns: 1fr; }
}
.qr-page-head {
  display: block;
  margin-bottom: 16px;
}
.qr-page-sub {
  margin: 2px 0 4px !important;
  font-weight: 700;
  color: var(--ink) !important;
}
.qr-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
}
.qr-search {
  flex: 1 1 200px;
  min-width: 180px;
  max-width: 280px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid #9ad7e4;
  border-radius: 999px;
  background: #fff;
  font: 500 0.95rem "Sarabun", sans-serif;
  color: var(--ink);
  box-sizing: border-box;
}
.qr-toolbar form { margin: 0; display: flex; align-items: center; }
.qr-toolbar .btn,
.qr-toolbar a.btn,
.qr-toolbar button.btn {
  height: 42px;
  min-height: 42px;
  padding: 0 16px;
  box-sizing: border-box;
  line-height: 1;
}
.qr-add-form {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 4px 0 14px;
  background: #fff;
  border: 1px solid #9ad7e4;
  border-radius: 999px;
  box-sizing: border-box;
}
.qr-add-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.qr-add-form input[type="number"] {
  width: 64px;
  height: 34px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: #f3fcff;
  font: 600 1rem "Sarabun", sans-serif;
  color: var(--ink);
}
.qr-add-form .btn {
  height: 34px;
  min-height: 34px;
  padding: 0 14px;
}
.qr-add-form select {
  height: 34px;
  max-width: 160px;
  border: 0;
  background: #f3fcff;
  border-radius: 8px;
  font: 600 0.88rem "Sarabun", sans-serif;
  color: var(--ink);
}
.qr-type-form {
  margin-top: 8px;
}
.qr-type-form select {
  width: 100%;
  font-size: 0.78rem;
}
.import-block h2 { font-size: 1.15rem; }
.code-list {
  margin: 8px 0 0;
  word-break: break-word;
  font-family: "Be Vietnam Pro", "Sarabun", sans-serif;
  font-size: 0.92rem;
}
.qr-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.qr-item {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
}
.qr-item-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}
.qr-code-wrap {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.qr-code {
  display: block;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  word-break: break-all;
  line-height: 1.2;
  text-decoration: none;
}
a.qr-code:hover { color: var(--gold-deep); }
.qr-scans {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--muted);
}
.qr-trash-form { margin: 0; flex-shrink: 0; }
.qr-trash {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #fdecea;
  color: var(--rose);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.qr-trash:hover { background: var(--rose); color: #fff; }
.qr-box { display: grid; place-items: center; min-height: 120px; }
.qr-box img, .qr-box canvas { max-width: 100%; height: auto; }
body.public.public-home-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
}
.public-home { text-align: center; }
.public-home .home-logo img {
  height: 120px;
  margin: 0 auto 18px;
}
.public-home h1 {
  font-size: clamp(1.25rem, 3.2vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #fffdf8;
  margin: 0;
}
.public-home-page .public-foot { display: none; }
.public-foot {
  text-align: center; margin-top: 28px;
  color: rgba(255,253,248,.62); font-size: 0.85rem;
}
.state { text-align: center; padding: 48px 20px; }
.state h1 { font-size: 2rem; }

.notfound-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 28px;
  padding: 40px 28px 36px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,.28);
}
.notfound-icon {
  width: 88px; height: 88px; margin: 0 auto 16px;
  border-radius: 22px;
  display: grid; place-items: center;
  background: #f6e8e4;
  color: var(--rose);
}
.notfound-kicker {
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--gold-deep);
  margin: 0 0 8px;
}
.notfound-card h1 {
  font-size: clamp(2rem, 6vw, 2.8rem);
  margin-bottom: 8px;
}
.notfound-lead { color: var(--muted); margin: 0 0 16px; font-size: 1.05rem; }
.notfound-code {
  display: inline-block;
  background: #f6f1e8;
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  margin: 0 0 18px;
  color: var(--muted);
}
.notfound-code strong { color: var(--ink); letter-spacing: 0.08em; }
.notfound-hints {
  text-align: left;
  margin: 8px auto 0;
  padding: 0 0 0 1.2em;
  max-width: 360px;
  color: var(--muted);
  font-size: 0.95rem;
}
.notfound-hints li { margin: 6px 0; }
.gen-inline label { margin-bottom: 8px; }

.print-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 18px;
}
.print-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.print-cell {
  border: 1px dashed #c9b896;
  border-radius: 10px;
  padding: 10px 8px 8px;
  text-align: center;
  background: #fff;
  break-inside: avoid;
  page-break-inside: avoid;
}
.print-cell .name { font-size: 0.72rem; color: var(--muted); }
.print-cell .serial { margin: 4px 0 0; font-size: 0.78rem; letter-spacing: 0.04em; }
.print-cell canvas, .print-cell img { width: 118px; height: 118px; }

@media (max-width: 960px) {
  .admin { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin-top: 0; margin-left: auto; }
  .admin-main { padding: 22px 16px 48px; }
  .stats, .form-grid, .gen-fields, .settings-hub { grid-template-columns: 1fr 1fr; }
  .print-grid { grid-template-columns: repeat(2, 1fr); }
}

@media print {
  .sidebar, .print-toolbar, .flash, .admin-main > .page-head { display: none !important; }
  .admin { display: block; background: #fff; }
  .admin-main { padding: 0; }
  .print-grid { gap: 6px; }
  .print-cell { box-shadow: none; }
}

.vle-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}
.vle-stage-wrap {
  background: #e8f4f7;
  border-radius: 18px;
  padding: 14px;
  overflow: auto;
}
.vle-stage-outer {
  margin: 0 auto;
  width: fit-content;
}
.vle-stage {
  position: relative;
  width: 800px;
  height: 1000px;
  transform-origin: top left;
  container-type: inline-size;
  background: #ddd 0 0 / 100% 100% no-repeat #e7e5e4;
  box-shadow: var(--shadow);
  touch-action: none;
}
.vle-item {
  position: absolute;
  cursor: grab;
  user-select: none;
  outline: 2px dashed rgba(28, 182, 207, 0.7);
  background: rgba(49, 225, 255, 0.12);
  border-radius: 6px;
  padding: 2px 4px;
  max-width: 92%;
  z-index: 2;
}
.vle-item.is-selected { outline-color: #16a34a; z-index: 5; }
.vle-item-badge {
  position: absolute; top: -18px; left: 0;
  font-size: 10px; font-weight: 800; color: #fff;
  background: #1cb6cf; padding: 1px 6px; border-radius: 4px;
}
.vle-item-text { white-space: pre-wrap; line-height: 1.25; }
.vle-item.is-stroke .vle-item-text,
.ov-item.is-stroke {
  -webkit-text-stroke: 0.04em #111;
  paint-order: stroke fill;
  text-shadow: 0 1px 0 #111;
}
.vle-resize {
  position: absolute; right: -7px; bottom: -7px;
  width: 14px; height: 14px;
  background: #16a34a; border: 2px solid #fff; border-radius: 3px;
  cursor: nwse-resize;
}
.vle-block {
  background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; margin-bottom: 10px;
}
.vle-block.active { border-color: #31e1ff; box-shadow: 0 0 0 3px rgba(49,225,255,.22); }
.vle-block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.vle-mini { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 8px; }
.vle-mini label { font-size: 0.78rem; }

.poster-page,
.scan-page { background: #071820; padding: 0; margin: 0; min-height: 100dvh; }
body.public.poster-page,
body.public.scan-page {
  background: #071820;
  padding: 0;
  margin: 0;
  min-height: 100dvh;
  overflow: auto;
  -webkit-text-size-adjust: 100%;
}
.poster-page .public-foot,
.scan-page .public-foot,
.poster-page .poster-top { display: none !important; }

.scan-app {
  min-height: 100dvh;
  min-height: 100svh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  padding:
    calc(12px + env(safe-area-inset-top, 0px))
    16px
    calc(18px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(120% 70% at 50% -8%, rgba(49, 225, 255, 0.3), transparent 52%),
    radial-gradient(90% 45% at 100% 110%, rgba(246, 207, 47, 0.14), transparent 48%),
    linear-gradient(180deg, #0c3340 0%, #071820 58%, #041014 100%);
}
.scan-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}
.scan-top img {
  display: block;
  height: 38px;
  width: auto;
}
.scan-top span {
  font-family: "Be Vietnam Pro", "Sarabun", sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(243, 252, 255, 0.72);
}
.scan-banner {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 14px;
  text-align: center;
  font-weight: 700;
  background: rgba(194, 65, 12, 0.92);
  color: #fff;
}
.scan-banner.is-used {
  background: rgba(246, 207, 47, 0.95);
  color: #0e2a33;
}
.scan-stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.scan-meta {
  margin-top: 16px;
  text-align: center;
}
.scan-code {
  display: inline-block;
  font-family: "Be Vietnam Pro", "Sarabun", sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.1em;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(49, 225, 255, 0.4);
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}
.scan-status {
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: rgba(243, 252, 255, 0.78);
}
.scan-status.is-ok { color: #8ff0b4; }
.scan-status.is-off { color: #ffb4a2; }
.scan-status.is-used { color: #f6cf2f; }
.scan-dl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  min-height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: #f6cf2f;
  color: #0e2a33;
  -webkit-text-fill-color: #0e2a33;
  font: 700 1rem "Be Vietnam Pro", "Sarabun", sans-serif;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(246, 207, 47, 0.28);
}
.scan-dl:hover { background: #e6bf20; }
.scan-dl:disabled { opacity: 0.6; cursor: wait; }
.scan-hint {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: rgba(243, 252, 255, 0.5);
}

.poster-app {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100dvh;
  margin: 0 auto;
}
.poster-app > .flash {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 5;
}
.poster {
  position: relative;
  flex: 0 0 auto;
  width: min(100%, calc(100dvh * var(--art-w, 3) / var(--art-h, 4)));
  aspect-ratio: var(--art-w, 3) / var(--art-h, 4);
  line-height: 0;
  overflow: hidden;
  border-radius: 18px;
  background: #10232a;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.14),
    0 22px 56px rgba(0, 0, 0, 0.42),
    0 0 36px rgba(49, 225, 255, 0.12);
  animation: scanIn 0.45s ease;
}
.poster.is-empty { min-height: 280px; }
.poster-bg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: fill;
  vertical-align: top;
}
.poster-layers {
  position: absolute;
  inset: 0;
  container-type: inline-size;
}
@keyframes scanIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.ov-item {
  position: absolute;
  max-width: 90%;
  line-height: 1.25;
  white-space: pre-wrap;
  pointer-events: none;
}

@media (max-width: 960px) {
  .vle-workspace { grid-template-columns: 1fr; }
}

.use-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.use-row input { flex: 1 1 220px; }
.use-row .btn { flex: 0 0 auto; }
.use-camera {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0e2a33;
}
.use-camera video {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}
.use-camera .hint,
.use-camera .btn { margin-top: 10px; }
.use-camera .hint { color: #d8eef2; }
.use-result-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.use-result-head h2 { margin: 0; letter-spacing: 0.04em; }
.use-msg {
  font-weight: 700;
  margin: 0 0 14px;
}
.use-msg.is-ok { color: var(--ok); }
.use-msg.is-used { color: var(--rose); }
.use-msg.is-wait { color: #8a5a00; }
