/* =========================================================
   Certificate System — Canva-inspired UI
   ========================================================= */
:root {
  --brand: #8b3dff;
  --brand-600: #7731d8;
  --brand-50: #f3ecff;
  --brand-100: #e7d9ff;
  --teal: #00c4cc;
  --grad: linear-gradient(135deg, #00c4cc 0%, #5a32fa 55%, #7d2ae8 100%);
  --grad-soft: linear-gradient(135deg, #e6fbfc 0%, #efe8ff 100%);
  --ink: #0e1318;
  --ink-2: #3d4350;
  --muted: #6b7280;
  --line: #e4e6eb;
  --line-2: #eef0f3;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --green: #12a150;
  --green-50: #e7f8ee;
  --red: #e5484d;
  --red-50: #fdecec;
  --amber: #c27c00;
  --amber-50: #fff6e0;
  --blue: #2f6bff;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(14, 19, 24, .06), 0 1px 1px rgba(14, 19, 24, .04);
  --shadow: 0 2px 8px rgba(14, 19, 24, .06), 0 8px 24px rgba(14, 19, 24, .06);
  --shadow-lg: 0 12px 40px rgba(64, 27, 140, .18);
  --font: "Noto Sans Thai", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg, canvas { max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.ic { flex-shrink: 0; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; }
.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.container.narrow { max-width: 820px; }

/* ---------- layout utils ---------- */
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; } .mt-4 { margin-top: 32px; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }

/* ---------- buttons ---------- */
.btn {
  --b: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border: 1px solid transparent; border-radius: 8px;
  font: inherit; font-weight: 600; font-size: 14px; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, box-shadow .15s, transform .05s, color .15s, border-color .15s;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); color: #fff; box-shadow: 0 4px 14px rgba(139, 61, 255, .35); }
.btn-gradient { background: var(--grad); color: #fff; }
.btn-gradient:hover { color: #fff; box-shadow: 0 6px 18px rgba(90, 50, 250, .35); filter: brightness(1.05); }
.btn-secondary { background: #eef0f3; color: var(--ink); }
.btn-secondary:hover { background: #e3e6ea; color: var(--ink); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-outline:hover { border-color: #c9cdd4; color: var(--ink); background: #fafbfc; }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: #eef0f3; color: var(--ink); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #cf3a3f; color: #fff; }
.btn-danger-soft { background: var(--red-50); color: var(--red); }
.btn-danger-soft:hover { background: #fadada; color: #c22d32; }
.btn-white { background: #fff; color: var(--brand); }
.btn-white:hover { color: var(--brand-600); box-shadow: var(--shadow); }
.btn-sm { min-height: 32px; padding: 5px 12px; font-size: 13px; border-radius: 7px; }
.btn-lg { min-height: 50px; padding: 12px 24px; font-size: 16px; border-radius: 10px; }
.btn-block { display: flex; width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: #eef0f3; color: var(--ink); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.danger:hover { background: var(--red-50); color: var(--red); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .label { font-weight: 600; font-size: 14px; color: var(--ink-2); }
.field small, .hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.req { color: var(--red); }
.input, .select, textarea.input {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1.5px solid var(--line); border-radius: 8px; background: #fff;
  font: inherit; font-size: 15px; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.55; }
.input:hover, .select:hover { border-color: #cfd3da; }
.input:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139, 61, 255, .16); }
.input.invalid, .select.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, .12); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.input-sm { min-height: 34px; padding: 5px 10px; font-size: 14px; }
.input-group { display: flex; align-items: stretch; }
.input-group > .input { border-radius: 8px 0 0 8px; }
.input-group > .btn { border-radius: 0 8px 8px 0; }
input[type=color].input { padding: 4px; width: 56px; height: 42px; cursor: pointer; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 500; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { position: relative; width: 42px; height: 24px; border-radius: 999px; background: #d4d7dd; transition: background .2s; flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(139, 61, 255, .25); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; font-size: 17px; }
.card-body { padding: 24px; }
@media (max-width: 640px) { .card-pad, .card-body { padding: 18px; } .card-head { padding: 14px 18px; } }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: #eef0f3; color: var(--ink-2); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.badge-green { background: var(--green-50); color: var(--green); }
.badge-red { background: var(--red-50); color: var(--red); }
.badge-amber { background: var(--amber-50); color: var(--amber); }
.badge-gray { background: #eef0f3; color: #5b616e; }
.badge-brand { background: var(--brand-50); color: var(--brand-600); }
.badge-teal { background: #e0f9fa; color: #008a91; }

/* alerts */
.alert { padding: 12px 16px; border-radius: 10px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: var(--green-50); color: #0b6b36; border-color: #c4ecd4; }
.alert-error { background: var(--red-50); color: #a52a2e; border-color: #f6caca; }
.alert-warning { background: var(--amber-50); color: #8a5800; border-color: #f6e0a8; }
.alert-info { background: var(--brand-50); color: #5a23b5; border-color: var(--brand-100); }

/* tables */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: none; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
.table th.text-right { text-align: right; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fbfaff; }
.table .actions { display: flex; gap: 4px; justify-content: flex-end; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .ic { color: #c3c7cf; margin-bottom: 8px; }

/* pagination */
.pager { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 16px; }
.pager a, .pager span { min-width: 36px; height: 36px; padding: 0 10px; display: inline-grid; place-items: center; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.pager a:hover { background: #eef0f3; }
.pager .current { background: var(--brand); color: #fff; }

/* toasts */
.toast-stack { position: fixed; top: 16px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 10px; background: var(--ink); color: #fff; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; animation: toastIn .25s ease; pointer-events: auto; max-width: 420px; }
.toast-success .ic { color: #4ade80; }
.toast-error { background: #b42318; }
.toast-warning { background: #8a5800; }
.toast.out { animation: toastOut .3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* modal */
.modal { position: fixed; inset: 0; z-index: 900; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(14, 19, 24, .45); backdrop-filter: blur(2px); }
.modal.open { display: flex; animation: fadeIn .15s ease; }
.modal-box { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: popIn .2s ease; }
.modal-box.lg { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line-2); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line-2); background: #fafbfc; border-radius: 0 0 var(--radius-lg) var(--radius-lg); flex-wrap: wrap; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.97) translateY(6px); } }

/* brand */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.brand:hover { color: var(--ink); }
.brand-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--grad); color: #fff; box-shadow: 0 4px 12px rgba(90, 50, 250, .3); flex-shrink: 0; }
.brand-mark.lg { width: 56px; height: 56px; border-radius: 16px; font-size: 26px; }
.brand-text { font-size: 16px; }

/* =========================================================
   PUBLIC
   ========================================================= */
body.public { background: #fff; display: flex; flex-direction: column; min-height: 100vh; }
.pub-main { flex: 1; }
.pub-nav { position: sticky; top: 0; z-index: 50; background: rgba(255, 255, 255, .92); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line-2); }
.pub-nav-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 12px; }
.pub-links { display: flex; gap: 4px; }
.pub-links a { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; color: var(--ink-2); font-weight: 600; font-size: 14px; }
.pub-links a:hover { background: #f2f3f5; color: var(--ink); }
.pub-links a.active { background: var(--brand-50); color: var(--brand-600); }
@media (max-width: 560px) { .brand-text { font-size: 14px; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .pub-links a span { display: none; } .pub-links a:first-child { display: none; } }
.pub-footer { padding: 28px 0; color: var(--muted); font-size: 13px; text-align: center; border-top: 1px solid var(--line-2); background: #fafbfc; }

/* hero */
.hero { position: relative; margin: 20px 16px 0; border-radius: 24px; background: var(--grad); color: #fff; overflow: hidden; padding: 56px 24px 64px; text-align: center; }
.hero::before, .hero::after { content: ""; position: absolute; border-radius: 50%; filter: blur(2px); opacity: .25; }
.hero::before { width: 360px; height: 360px; background: #fff; top: -180px; left: -80px; opacity: .12; }
.hero::after { width: 280px; height: 280px; background: #00e0e8; bottom: -140px; right: -40px; }
.hero > * { position: relative; z-index: 1; }
.hero h1 { font-size: clamp(26px, 4.4vw, 44px); font-weight: 800; margin-bottom: 10px; }
.hero p { font-size: clamp(15px, 1.8vw, 18px); opacity: .92; max-width: 640px; margin: 0 auto 28px; }
.hero-search { max-width: 640px; margin: 0 auto; position: relative; }
.hero-search .ic { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.hero-search input { width: 100%; height: 56px; padding: 0 20px 0 52px; border: 0; border-radius: 14px; font: inherit; font-size: 16px; box-shadow: 0 10px 30px rgba(20, 0, 60, .25); color: var(--ink); }
.hero-search input:focus { outline: 3px solid rgba(255, 255, 255, .5); }
.chips { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.chip { padding: 7px 16px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .45); background: rgba(255, 255, 255, .12); color: #fff; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s; }
.chip:hover { background: rgba(255, 255, 255, .22); }
.chip.active { background: #fff; color: var(--brand-600); border-color: #fff; }

.section { padding: 40px 0; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.section-title h2 { font-size: 22px; margin: 0; }

/* form cards */
.fcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.fcard { display: flex; flex-direction: column; border-radius: 16px; background: #fff; border: 1px solid var(--line-2); overflow: hidden; color: var(--ink); transition: transform .2s, box-shadow .2s; }
.fcard:hover { transform: translateY(-4px); box-shadow: var(--shadow); color: var(--ink); }
.fcard-cover { position: relative; aspect-ratio: 16 / 9; display: grid; place-items: center; color: #fff; }
.fcard-cover .big-ic { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: rgba(255, 255, 255, .2); backdrop-filter: blur(4px); }
.fcard-cover .badge { position: absolute; top: 12px; left: 12px; background: rgba(255, 255, 255, .95); }
.fcard-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.fcard-body h3 { font-size: 16.5px; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fcard-body p { font-size: 13.5px; color: var(--muted); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fcard-link { display: flex; flex-direction: column; flex: 1; color: inherit; }
.fcard-link:hover { color: inherit; }
.fcard-actions { display: flex; align-items: center; gap: 6px; padding: 0 14px 14px 18px; }
.qr-box { display: grid; place-items: center; min-height: 240px; background: var(--grad-soft); border-radius: 14px; padding: 16px; }
.qr-box canvas { width: 100%; max-width: 280px; height: auto; border-radius: 10px; box-shadow: var(--shadow); background: #fff; }
.share-row { display: flex; flex-wrap: wrap; gap: 8px; }
.share-row .btn { flex: 1 1 auto; }
.btn-line { background: #06c755; color: #fff; }
.btn-line:hover { background: #05b04b; color: #fff; }
.btn-fb { background: #1877f2; color: #fff; }
.btn-fb:hover { background: #0f66d9; color: #fff; }
.fcard-meta { margin-top: auto; padding-top: 10px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.fcard-meta span { display: inline-flex; align-items: center; gap: 4px; }

/* public form page */
.form-hero { border-radius: 20px; padding: 32px 28px; color: #fff; margin: 24px 0 20px; position: relative; overflow: hidden; }
.form-hero h1 { font-size: clamp(22px, 3.4vw, 32px); margin-bottom: 8px; }
.form-hero p { opacity: .92; margin: 0; white-space: pre-line; }
.form-hero .row { margin-top: 16px; }
.form-hero .badge { background: rgba(255, 255, 255, .2); color: #fff; }
.q-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 22px 24px; margin-bottom: 14px; transition: border-color .2s, box-shadow .2s; scroll-margin-top: 90px; }
.q-card.has-error { border-color: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, .1); }
.q-card .q-title { font-size: 16.5px; font-weight: 600; margin-bottom: 4px; white-space: pre-line; }
.q-card .q-num { color: var(--brand); font-weight: 700; margin-right: 6px; }
.q-card .q-desc { color: var(--muted); font-size: 14px; margin-bottom: 8px; white-space: pre-line; }
.q-card .q-points { float: right; margin-left: 8px; }
.q-card .q-error { display: none; color: var(--red); font-size: 13.5px; margin-top: 10px; font-weight: 500; }
.q-card.has-error .q-error { display: block; }
.q-section { padding: 18px 4px 8px; }
.q-section h2 { font-size: 20px; margin: 0 0 4px; }
.q-section p { color: var(--muted); margin: 0; white-space: pre-line; }
.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.choice { position: relative; display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer; transition: border-color .15s, background .15s; }
.choice:hover { border-color: #c9b5ff; background: #fcfaff; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .mark { width: 20px; height: 20px; margin-top: 2px; border: 2px solid #b9bec7; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; transition: all .15s; }
.choice.is-check .mark { border-radius: 6px; }
.choice input:checked ~ .mark { border-color: var(--brand); background: var(--brand); box-shadow: inset 0 0 0 3px #fff; }
.choice.is-check input:checked ~ .mark { box-shadow: none; background: var(--brand) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 14px no-repeat; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-50); }
.choice input:focus-visible ~ .mark { box-shadow: 0 0 0 3px rgba(139, 61, 255, .3); }
.choice .other-input { margin-top: 8px; }
.rating { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.rating label { position: relative; }
.rating input { position: absolute; opacity: 0; pointer-events: none; }
.rating span.rb { display: grid; place-items: center; min-width: 46px; height: 46px; padding: 0 10px; border: 1.5px solid var(--line); border-radius: 10px; font-weight: 700; cursor: pointer; transition: all .15s; }
.rating span.rb:hover { border-color: #c9b5ff; background: #fcfaff; }
.rating input:checked + span.rb { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(139, 61, 255, .3); }
.rating input:focus-visible + span.rb { box-shadow: 0 0 0 3px rgba(139, 61, 255, .3); }
.rating-labels { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 6px; max-width: 560px; }
.rating.stars span.rb { border: 0; min-width: 40px; color: #d4d7dd; padding: 0; }
.rating.stars span.rb svg { width: 34px; height: 34px; }
.rating.stars label.lit span.rb { color: #ffb400; background: none; box-shadow: none; }
.rating.stars input:checked + span.rb { background: none; box-shadow: none; color: #ffb400; }
.sticky-progress { position: sticky; top: 64px; z-index: 40; background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line-2); padding: 10px 0; }
.progress { height: 8px; border-radius: 999px; background: #eceef2; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--grad); border-radius: 999px; transition: width .3s; }
.timer { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 4px 12px; border-radius: 999px; background: var(--brand-50); color: var(--brand-600); font-size: 14px; }
.timer.warn { background: var(--red-50); color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 24px 0 48px; flex-wrap: wrap; }
.name-grid { display: grid; grid-template-columns: 150px minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 640px) { .name-grid { grid-template-columns: 1fr; } }
.hp-field { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }

/* state page (closed etc.) */
.state-box { max-width: 560px; margin: 60px auto; text-align: center; padding: 40px 28px; }
.state-icon { width: 80px; height: 80px; margin: 0 auto 18px; border-radius: 24px; display: grid; place-items: center; background: var(--grad-soft); color: var(--brand); }

/* result page */
.result-head { text-align: center; padding: 32px 0 8px; }
.score-ring { --p: 0; --c: var(--brand); width: 168px; height: 168px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--p) * 1%), #eceef2 0); position: relative; }
.score-ring::before { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: #fff; }
.score-ring > div { position: relative; text-align: center; line-height: 1.1; }
.score-ring strong { font-size: 38px; font-weight: 800; display: block; }
.score-ring small { color: var(--muted); font-size: 13px; }
.result-title { font-size: clamp(22px, 3.6vw, 30px); font-weight: 800; }
.celebrate { font-size: 44px; }
.cert-viewer { background: var(--grad-soft); border-radius: 20px; padding: 24px; margin: 24px 0; }
.cert-canvas-wrap { position: relative; background: #fff; border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; min-height: 200px; display: grid; place-items: center; }
.cert-canvas-wrap canvas { display: block; width: 100%; height: auto; }
.cert-loading { padding: 60px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--brand-100); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.cert-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.cert-meta { display: flex; gap: 8px 18px; justify-content: center; flex-wrap: wrap; margin-top: 14px; font-size: 14px; color: var(--ink-2); }
.review-item { border-left: 4px solid var(--line); padding: 10px 14px; margin-bottom: 10px; background: #fafbfc; border-radius: 0 10px 10px 0; }
.review-item.ok { border-color: var(--green); }
.review-item.bad { border-color: var(--red); }
.verify-card { max-width: 640px; margin: 32px auto; }
.verify-ok { display: flex; gap: 16px; align-items: flex-start; padding: 18px; border-radius: 14px; background: var(--green-50); border: 1px solid #c4ecd4; }
.verify-ok .ic { color: var(--green); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } }
.tabs { display: inline-flex; padding: 4px; border-radius: 10px; background: #eef0f3; gap: 4px; flex-wrap: wrap; }
.tabs button, .tabs a { padding: 8px 16px; border: 0; border-radius: 8px; background: transparent; font: inherit; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.tabs .active { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }

/* =========================================================
   AUTH (login / install)
   ========================================================= */
body.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--grad); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 22px; padding: 36px 32px; box-shadow: 0 20px 60px rgba(30, 0, 80, .35); }
.auth-card.wide { max-width: 720px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .brand-mark { margin: 0 auto 14px; }
.auth-brand h1 { font-size: 22px; margin-bottom: 4px; }
.section-label { font-size: 14px; color: var(--brand-600); margin: 8px 0 0; text-transform: none; }
.auth-card textarea { width: 100%; }
@media (max-width: 520px) { .auth-card { padding: 28px 20px; } }

/* =========================================================
   ADMIN
   ========================================================= */
body.admin { background: var(--bg); }
.adm-shell { display: flex; min-height: 100vh; }
.adm-side { position: fixed; inset: 0 auto 0 0; width: 260px; background: #fff; border-right: 1px solid var(--line-2); display: flex; flex-direction: column; z-index: 80; transition: transform .25s ease; }
.adm-brand { padding: 18px 18px 14px; }
.adm-brand .brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.adm-brand strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-brand small { color: var(--muted); font-weight: 500; font-size: 12px; }
.adm-menu { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; overflow-y: auto; }
.adm-menu a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 600; font-size: 14px; transition: background .15s, color .15s; }
.adm-menu a:hover { background: #f2f3f5; color: var(--ink); }
.adm-menu a.active { background: var(--brand-50); color: var(--brand-600); }
.adm-menu a.active .ic { color: var(--brand); }
.adm-side-foot { padding: 12px; border-top: 1px solid var(--line-2); }
.adm-side-foot a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 600; font-size: 13.5px; background: var(--grad-soft); }
.adm-main { flex: 1; margin-left: 260px; min-width: 0; display: flex; flex-direction: column; }
.adm-top { position: sticky; top: 0; z-index: 60; display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 28px; background: rgba(246, 247, 249, .9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line-2); }
.adm-title { font-size: 19px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-top-right { display: flex; align-items: center; gap: 8px; }
.adm-top-right form { margin: 0; }
.adm-user { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--grad); color: #fff; font-weight: 700; }
.adm-burger { display: none; }
.adm-content { padding: 28px; flex: 1; width: 100%; max-width: 1320px; }
.adm-backdrop { display: none; }
@media (max-width: 980px) {
  .adm-side { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.side-open .adm-side { transform: none; }
  body.side-open .adm-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 70; }
  .adm-main { margin-left: 0; }
  .adm-burger { display: inline-grid; }
  .adm-top { padding: 0 16px; }
  .adm-content { padding: 20px 16px; }
  .adm-user-name { display: none; }
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.breadcrumb { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 6px; flex-wrap: wrap; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--brand); }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: #fff; border: 1px solid var(--line-2); border-radius: 16px; padding: 18px 20px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow-sm); }
.stat-ic { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
.stat-ic.c1 { background: var(--brand-50); color: var(--brand); }
.stat-ic.c2 { background: #e0f9fa; color: #00a3aa; }
.stat-ic.c3 { background: var(--green-50); color: var(--green); }
.stat-ic.c4 { background: #fff1e6; color: #e8590c; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12.5px; color: var(--muted); }

/* admin form cards grid */
.acards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.acard { background: #fff; border: 1px solid var(--line-2); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow-sm); transition: box-shadow .2s; }
.acard:hover { box-shadow: var(--shadow); }
.acard-cover { height: 96px; position: relative; padding: 14px 16px; color: #fff; display: flex; align-items: flex-start; justify-content: space-between; }
.acard-cover .badge { background: rgba(255, 255, 255, .95); }
.acard-body { padding: 14px 16px; flex: 1; }
.acard-body h3 { font-size: 16px; margin: 0 0 4px; }
.acard-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.acard-meta span { display: inline-flex; gap: 4px; align-items: center; }
.acard-foot { display: flex; gap: 4px; padding: 10px 12px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }
.acard-foot .btn { flex: 1 1 auto; }

/* cover picker */
.cover-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.cover-picker label { position: relative; cursor: pointer; }
.cover-picker input { position: absolute; opacity: 0; }
.cover-picker span { display: block; width: 56px; height: 40px; border-radius: 10px; border: 3px solid transparent; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); transition: transform .15s; }
.cover-picker input:checked + span { border-color: #fff; box-shadow: 0 0 0 2px var(--brand); transform: scale(1.05); }
.type-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.type-picker label { position: relative; cursor: pointer; }
.type-picker input { position: absolute; opacity: 0; }
.type-picker .tp { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border: 2px solid var(--line); border-radius: 12px; transition: all .15s; }
.type-picker .tp strong { display: block; }
.type-picker .tp small { color: var(--muted); }
.type-picker input:checked + .tp { border-color: var(--brand); background: var(--brand-50); }
@media (max-width: 640px) { .type-picker { grid-template-columns: 1fr; } }

/* settings layout */
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.form-layout .side-sticky { position: sticky; top: 84px; }
@media (max-width: 1080px) { .form-layout { grid-template-columns: 1fr; } .form-layout .side-sticky { position: static; } }
.toggle-list > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.toggle-list > div:last-child { border-bottom: 0; }
.toggle-list p { margin: 0; font-size: 12.5px; color: var(--muted); }

/* ---------- question builder ---------- */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 20px; align-items: start; }
@media (max-width: 1080px) { .builder { grid-template-columns: 1fr; } }
.qb-list { display: flex; flex-direction: column; gap: 14px; }
.qb-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-sm); position: relative; transition: box-shadow .2s, border-color .2s; }
.qb-card:focus-within { border-color: #cdb6ff; box-shadow: 0 0 0 3px rgba(139, 61, 255, .1), var(--shadow); }
.qb-card::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: transparent; }
.qb-card:focus-within::before { background: var(--brand); }
.qb-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px 0 10px; }
.qb-handle { cursor: grab; color: #b0b5bd; padding: 6px; border-radius: 6px; display: grid; place-items: center; }
.qb-handle:hover { background: #f2f3f5; color: var(--ink-2); }
.qb-num { font-weight: 800; color: var(--brand); min-width: 28px; }
.qb-type { max-width: 260px; }
.qb-body { padding: 12px 18px 6px 18px; }
textarea.input.qb-title { font-size: 16px; font-weight: 600; min-height: 46px; resize: none; overflow: hidden; }
.qb-opts { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.qb-opt { display: flex; align-items: center; gap: 8px; }
.qb-opt .mk { width: 18px; height: 18px; border: 2px solid #b9bec7; border-radius: 50%; flex-shrink: 0; }
.qb-opt.multi .mk { border-radius: 5px; }
.qb-opt .input { min-height: 38px; }
.qb-correct { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.qb-correct:hover { border-color: #9ad8b2; color: var(--green); }
.qb-correct.on { background: var(--green-50); border-color: var(--green); color: var(--green); }
.qb-foot { display: flex; align-items: center; gap: 10px 16px; padding: 10px 16px 12px; border-top: 1px solid var(--line-2); margin-top: 12px; flex-wrap: wrap; }
.qb-foot .sep { width: 1px; height: 24px; background: var(--line); }
.qb-points { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.qb-points input { width: 72px; }
.qb-palette { position: sticky; top: 84px; }
.qb-palette button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 12px; border: 0; border-radius: 10px; background: transparent; font: inherit; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; text-align: left; }
.qb-palette button:hover { background: var(--brand-50); color: var(--brand-600); }
.qb-palette .pi { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: #f2f3f5; font-size: 13px; font-weight: 800; color: var(--brand); flex-shrink: 0; }
.qb-key { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--green-50); border: 1px dashed #9ad8b2; }
.qb-key .label { color: #0b6b36; font-size: 13px; }
.save-bar { position: sticky; bottom: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; margin-top: 20px; background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 -4px 20px rgba(0, 0, 0, .06); flex-wrap: wrap; }
.dirty-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); margin-right: 6px; }
.sortable-ghost { opacity: .4; }
.sortable-chosen { box-shadow: var(--shadow-lg) !important; }

/* ---------- template designer ---------- */
.designer { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
@media (max-width: 1080px) { .designer { grid-template-columns: 1fr; } }
.stage { background: #e9ebef url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Crect width='8' height='8' fill='%23e2e4e9'/%3E%3Crect x='8' y='8' width='8' height='8' fill='%23e2e4e9'/%3E%3C/svg%3E"); border-radius: 16px; padding: 24px; display: grid; place-items: center; }
.designer > * { min-width: 0; }
.stage { overflow: hidden; }
.stage-inner { max-width: 100%; position: relative; box-shadow: 0 8px 30px rgba(0, 0, 0, .15); background: #fff; line-height: 0; touch-action: none; }
.stage-inner canvas { display: block; width: 100%; height: auto; }
.stage-inner canvas.overlay { position: absolute; inset: 0; cursor: default; }
.field-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.field-tabs button { padding: 7px 12px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.field-tabs button.active { border-color: var(--brand); background: var(--brand-50); color: var(--brand-600); }
.field-tabs button .dot { width: 8px; height: 8px; border-radius: 50%; background: #c3c7cf; }
.field-tabs button.on .dot { background: var(--green); }
.align-group { display: inline-flex; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; }
.align-group button { padding: 7px 12px; border: 0; background: #fff; font: inherit; font-size: 13px; cursor: pointer; }
.align-group button + button { border-left: 1px solid var(--line); }
.align-group button.active { background: var(--brand); color: #fff; }
.tpl-thumb { aspect-ratio: 1.414 / 1; background: #f2f3f5; display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--line-2); }
.tpl-thumb canvas { width: 100%; height: 100%; object-fit: contain; }

/* drop zone */
.dropzone { border: 2px dashed #cdb6ff; border-radius: 14px; background: #fcfaff; padding: 28px 16px; text-align: center; cursor: pointer; transition: background .15s, border-color .15s; display: block; }
.dropzone:hover, .dropzone.drag { background: var(--brand-50); border-color: var(--brand); }
.dropzone .ic { color: var(--brand); }
.dropzone input { display: none; }

/* report */
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 900px) { .report-grid { grid-template-columns: 1fr; } }
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 360px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 160px 52px; gap: 12px; align-items: center; padding: 6px 0; font-size: 14px; }
.bar-row .bar { height: 10px; border-radius: 999px; background: #eceef2; overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar-row .bar i.ok { background: var(--green); }
@media (max-width: 560px) { .bar-row { grid-template-columns: minmax(0, 1fr) 80px 44px; } }
.text-answers { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.text-answers div { padding: 8px 12px; background: #f6f7f9; border-radius: 8px; font-size: 14px; white-space: pre-line; }
.q-stat { padding: 18px 0; border-bottom: 1px solid var(--line-2); break-inside: avoid; page-break-inside: avoid; }
.q-stat:last-child { border-bottom: 0; }
.q-stat h4 { font-size: 15px; margin-bottom: 8px; }
.pdf-export .no-pdf { display: none !important; }
.pdf-export .card { box-shadow: none; }

/* print */
@media print {
  .adm-side, .adm-top, .no-print, .toast-stack, .pub-nav, .pub-footer { display: none !important; }
  .adm-main { margin: 0 !important; }
  .adm-content { padding: 0 !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; break-inside: avoid; }
}
