:root {
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card.narrow { max-width: 560px; margin: 0 auto; width: 100%; }
.big-icon { font-size: 2.4rem; margin-bottom: 6px; }

.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--brand); color: #fff; border: 1px solid transparent; padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { filter: brightness(.95); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; color: var(--brand); border-color: var(--line); }
.btn.ghost:hover { background: #f3f4f6; }
.btn.danger { background: var(--bad); }
.btn.ghost.danger { background: transparent; color: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.lg { padding: 12px 22px; font-size: 1.05rem; }
.btn.light { background: #fff; color: var(--brand); }
.btn.ghost.light { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 1rem; color: var(--muted); }
.icon-btn:hover { background: #f3f4f6; color: var(--ink); }

label { display: block; font-weight: 600; font-size: .9rem; margin: 0 0 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=date], input[type=time], input[type=datetime-local], input[type=url], input[type=color], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input[type=color] { padding: 2px; height: 38px; width: 60px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin: 6px 0; cursor: pointer; }
.check input { margin-top: 4px; }

.chip { display: inline-block; padding: 2px 10px; border-radius: 99px; background: color-mix(in srgb, var(--brand) 12%, white); color: var(--brand); font-size: .78rem; font-weight: 700; }
.chip.t-attendance { background: #dcfce7; color: #15803d; }
.chip.t-quiz { background: #fef3c7; color: #b45309; }
.chip.t-pretest { background: #e0e7ff; color: #4338ca; }
.chip.t-posttest { background: #fce7f3; color: #be185d; }
.chip.t-questionnaire { background: #cffafe; color: #0e7490; }
.chip.gray { background: #f3f4f6; color: var(--muted); }
.chip.red { background: #fee2e2; color: var(--bad); }
.chip.green { background: #dcfce7; color: var(--ok); }

table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.table th, table.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.table th { background: #f9fafb; font-weight: 600; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
table.kv { width: 100%; border-collapse: collapse; margin: 14px 0; }
table.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: 7px 10px 7px 0; width: 40%; vertical-align: top; }
table.kv td { padding: 7px 0; font-weight: 600; word-break: break-word; }

/* ---------- Brand ---------- */
.logo { display: inline-flex; align-items: center; gap: 9px; font-weight: 800; font-size: 1.3rem; letter-spacing: -.02em; color: var(--ink); line-height: 1; }
.logo img { width: 34px; height: 34px; display: block; }
.logo .wm b { background: linear-gradient(90deg, #4f46e5, #06b6d4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-link { text-decoration: none; display: inline-flex; }
.brand-link.light .logo { color: #fff; }
.brand-link.light .logo .wm b { background: linear-gradient(90deg, #c7d2fe, #67e8f9); -webkit-background-clip: text; background-clip: text; }
.brand-link.sm .logo { font-size: .95rem; gap: 6px; }
.brand-link.sm .logo img { width: 20px; height: 20px; }
.topbar .logo { color: #fff; font-size: 1.1rem; }
.topbar .logo img { width: 28px; height: 28px; }
.topbar .logo .wm b { background: linear-gradient(90deg, #c7d2fe, #67e8f9); -webkit-background-clip: text; background-clip: text; }
.powered { margin-top: 24px; display: flex; gap: 6px; align-items: center; justify-content: center; }
.center-page.col { flex-direction: column; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: #0f172a; color: #cbd5e1; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { padding: 4px 8px 18px; }
.side a.brand:hover { background: none; }
.side a { display: flex; gap: 10px; align-items: center; color: inherit; text-decoration: none; padding: 9px 12px; border-radius: 8px; margin-bottom: 2px; }
.side a:hover { background: #1e293b; color: #fff; }
.side a.active { background: var(--brand); color: #fff; }
.side .sep { border-top: 1px solid #1e293b; margin: 12px 0; }
.side .user { font-size: .85rem; padding: 10px 12px; color: #94a3b8; }
.main { padding: 24px 28px 60px; min-width: 0; }
.topbar { display: none; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 10px; background: #0f172a; color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 40; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 1.4rem; }
  .main { padding: 16px; }
}

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 1.7rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: .85rem; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

.form-list .item { display: flex; gap: 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.form-list .item:last-child { border-bottom: 0; }
.form-list .item .t { font-weight: 700; font-size: 1.02rem; color: var(--ink); text-decoration: none; }
.form-list .item .meta { font-size: .83rem; color: var(--muted); }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

.type-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.type-pick button { text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; font: inherit; }
.type-pick button.active { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 6%, white); }
.type-pick b { display: block; margin: 4px 0; }

/* Builder */
.builder { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .builder { grid-template-columns: 1fr; } }
.q-card { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.q-card.open { border-left-color: var(--brand); box-shadow: 0 4px 14px rgba(37,99,235,.08); }
.q-card .q-head { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.q-card .q-head .lbl { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-card .q-body { margin-top: 12px; }
.opt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.opt-row input[type=text] { flex: 1; }
.opt-row .correct { font-size: .8rem; white-space: nowrap; display: flex; gap: 4px; align-items: center; font-weight: 500; }
.add-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.add-bar button { font-size: .82rem; }
.sticky-side { position: sticky; top: 16px; }
.savebar { position: sticky; bottom: 0; background: rgba(244,246,251,.95); backdrop-filter: blur(4px); padding: 12px 0; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--line); margin-top: 16px; z-index: 5; }
.link-box { display: flex; gap: 0; }
.link-box .prefix { padding: 9px 10px; background: #f3f4f6; border: 1px solid #d1d5db; border-right: 0; border-radius: 8px 0 0 8px; color: var(--muted); white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.link-box input { border-radius: 0 8px 8px 0 !important; }
.copy-line { display: flex; gap: 8px; }
.copy-line input { flex: 1; font-family: ui-monospace, monospace; font-size: .85rem; }
.qr-img { width: 160px; height: 160px; border: 1px solid var(--line); border-radius: 8px; }

/* Certificate designer */
.designer { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .designer { grid-template-columns: 1fr; } }
.preview-frame { width: 100%; aspect-ratio: 297 / 225; border: 1px solid var(--line); border-radius: 10px; background: #e9ecf1; }
.preview-frame.two { aspect-ratio: 297 / 440; }
.preview-frame.portrait { aspect-ratio: 210 / 312; }
.preview-frame.portrait.two { aspect-ratio: 210 / 615; }
.design-file { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.design-file img { width: 120px; max-height: 120px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; background: #f3f4f6; }
.designer h4 { margin: 14px 0 6px; font-size: .9rem; }
.designer input[type=color] { width: 64px; height: 34px; padding: 2px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tpl { border: 2px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; background: #fff; padding: 0; font: inherit; text-align: left; }
.tpl.active { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.tpl .thumb { position: relative; width: 100%; aspect-ratio: 297/210; overflow: hidden; pointer-events: none; background: #eee; }
.tpl .thumb iframe { position: absolute; left: 0; top: 0; width: 1150px; height: 840px; border: 0; transform-origin: 0 0; }
.tpl .nm { font-size: .8rem; font-weight: 600; padding: 6px 8px; }
.partner-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.partner-row img { width: 44px; height: 32px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.partner-row input { flex: 1; }
.pos-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pos-pick label { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 2px solid var(--line); border-radius: 10px; padding: 8px 4px; font-size: .78rem; font-weight: 500; text-align: center; cursor: pointer; }
.pos-pick label:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 6%, white); }
.pos-pick input { display: none; }
.mat-row { display: grid; grid-template-columns: 1fr 70px 30px; gap: 6px; margin-bottom: 6px; }

/* Analytics */
.q-analytics { break-inside: avoid; }
.q-analytics .chart-box { position: relative; height: 260px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 10px 0; }
.kpi { background: #f9fafb; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.kpi .v { font-size: 1.1rem; font-weight: 800; line-height: 1.3; }
.kpi .l { font-size: .78rem; color: var(--muted); }
.answers { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.answers div { padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: .9rem; white-space: pre-wrap; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.thumbs a { display: block; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; text-decoration: none; color: var(--ink); font-size: .75rem; }
.thumbs img { width: 100%; height: 90px; object-fit: cover; display: block; background: #f3f4f6; }
.thumbs span { display: block; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-inline { height: 8px; background: #e5e7eb; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar-inline > div { height: 100%; background: var(--brand); }
.report-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }

/* Toast & modal */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); white-space: pre-line; }
.toast.err { background: var(--bad); }
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal.wide { max-width: 900px; }

/* Auth */
.center-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { max-width: 420px; }
.auth-brand { text-align: center; margin-bottom: 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.auth-brand .logo { font-size: 1.6rem; }
.auth-brand .logo img { width: 44px; height: 44px; }

/* Public fill */
.fill-body { background: color-mix(in srgb, var(--brand) 8%, #f4f6fb); }
.fill-wrap { max-width: 720px; margin: 0 auto; padding: 24px 14px 50px; }
.fill-head { border-top: 8px solid var(--brand); }
.fill-head h1 { margin-top: 8px; }
.fill-head .desc { margin-top: 10px; }
.req-note { color: var(--bad); font-size: .82rem; margin-top: 10px; }
.fill-form .card { margin-top: 14px; }
.fill-form .q-label { font-weight: 600; font-size: 1rem; margin-bottom: 6px; }
.fill-form .q-label .req { color: var(--bad); }
.fill-form .q-help { color: var(--muted); font-size: .86rem; margin-bottom: 8px; }
.fill-form .q-err { color: var(--bad); font-size: .85rem; margin-top: 6px; }
.fill-form .card.has-err { border-color: var(--bad); }
.fill-form .section { background: var(--brand); color: #fff; border: 0; }
.fill-form .section .q-help { color: rgba(255,255,255,.85); }
.scale { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-end; }
.scale label { display: flex; flex-direction: column; align-items: center; font-weight: 400; gap: 4px; min-width: 38px; cursor: pointer; }
.scale .end { font-size: .8rem; color: var(--muted); max-width: 120px; }
.likert { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.likert label { border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px; text-align: center; font-size: .8rem; font-weight: 500; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.likert label:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, white); }
@media (max-width: 520px) { .likert { grid-template-columns: 1fr; } .likert label { flex-direction: row; text-align: left; } }
.stars { display: flex; flex-direction: row-reverse; justify-content: flex-end; gap: 4px; }
.stars input { display: none; }
.stars label { font-size: 2rem; color: #d1d5db; cursor: pointer; margin: 0; }
.stars input:checked ~ label, .stars label:hover, .stars label:hover ~ label { color: #f59e0b; }
.drop { border: 2px dashed #cbd5e1; border-radius: 10px; padding: 18px; text-align: center; cursor: pointer; color: var(--muted); }
.drop.drag { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 6%, white); }
.drop img { max-width: 100%; max-height: 220px; border-radius: 8px; margin-top: 8px; }
.sig-pad { border: 1px solid #d1d5db; border-radius: 8px; background: #fff; touch-action: none; width: 100%; height: 180px; display: block; }
.submit-row { margin-top: 18px; display: flex; justify-content: space-between; align-items: center; }
.result-card { text-align: center; border-top: 8px solid var(--ok); }
.score-big { font-size: 3rem; font-weight: 800; color: var(--brand); }
.review-item { text-align: left; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 8px 0; }
.review-item.ok { border-left: 4px solid var(--ok); }
.review-item.no { border-left: 4px solid var(--bad); }
.cert-lookup summary { cursor: pointer; font-weight: 600; }
.cert-lookup .row { margin-top: 10px; }
.cert-lookup input { flex: 1; }

/* Verify */
.verify-card.good { border-top: 8px solid var(--ok); }
.verify-card.bad { border-top: 8px solid var(--bad); }

/* Landing */
.land-hero { background: linear-gradient(135deg, #312e81, #4f46e5 55%, #0891b2); color: #fff; padding: 0 16px 70px; }
.land-nav { max-width: 1100px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; padding: 18px 0; }
.land-logo img { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 12px 30px rgba(0,0,0,.25); margin-bottom: 18px; }
.land-inner h1 { font-size: 2.6rem; letter-spacing: -.02em; }
.land-foot { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.land-inner { max-width: 760px; margin: 50px auto 0; text-align: center; }
.land-inner h1 { font-size: 2.3rem; }
.land-inner p { font-size: 1.1rem; opacity: .9; margin-bottom: 26px; }
.land-feats { max-width: 1100px; margin: -40px auto 0; padding: 0 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.land-feats .card + .card { margin-top: 0; }
.land-foot { text-align: center; padding: 40px; }
.land-support { max-width: 1100px; margin: 40px auto 0; padding: 0 16px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-transform: none; }
.land-support > .small { text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }
.support-link { display: flex; align-items: center; gap: 16px; text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 24px; box-shadow: var(--shadow); }
.support-link:hover { border-color: var(--brand); }
.support-link img { width: 72px; height: 72px; object-fit: contain; }
.support-link span { line-height: 1.35; }
.support-link b { font-size: 1.15rem; color: #1e4fa8; }

@media print {
  .side, .topbar, .no-print, .savebar, .tabs { display: none !important; }
  .shell { display: block; } .main { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* Timer & quota bar on public forms */
.form-status { position: sticky; top: 8px; z-index: 5; display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; align-items: center; padding: 10px 14px; margin-bottom: 14px;
  background: #fff; border: 1px solid var(--line, #e2e8f0); border-left: 5px solid var(--brand); border-radius: 10px; box-shadow: 0 2px 10px rgba(15, 23, 42, .06); font-size: .95rem; }
.form-status .countdown { font-variant-numeric: tabular-nums; }
.form-status .urgent { color: #dc2626; }
.form-status.closed { border-left-color: #dc2626; color: #b91c1c; font-weight: 600; }
.countdown { font-variant-numeric: tabular-nums; }
#closedCard .countdown { margin-top: 6px; font-size: 1.1rem; }
.lookup-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--line, #e2e8f0); }
.lookup-item:first-child { border-top: 0; }
/* Timer & quota card in the form editor */
.timer-live { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 12px; border-radius: 10px; background: #f8fafc; border: 1px solid var(--line, #e2e8f0); margin: 10px 0; }
.timer-live .big { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.quota-bar { height: 8px; border-radius: 99px; background: #e2e8f0; overflow: hidden; margin-top: 6px; }
.quota-bar span { display: block; height: 100%; background: var(--brand, #2563eb); }
.alert-warn { padding: 10px 12px; border-radius: 10px; background: #fef3c7; color: #92400e; font-size: .9rem; margin: 8px 0; }
