:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --line: #e5e7eb;
    --text: #111827;
    --muted: #6b7280;
    --brand: #1d4ed8;
    --brand2: #2563eb;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --radius: 18px;
    --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
.container { width: min(1280px, calc(100% - 32px)); margin: 0 auto; }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 32px; background: linear-gradient(135deg, #dbeafe, #f8fafc 48%, #e0e7ff); }
.auth-card { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 26px; padding: 32px; box-shadow: var(--shadow); }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 275px 1fr; }
.sidebar { background: #0f172a; color: #fff; padding: 22px; position: sticky; top: 0; height: 100vh; }
.sidebar h1 { font-size: 20px; margin: 0 0 22px; line-height: 1.2; }
.nav-link { display: block; padding: 12px 14px; border-radius: 12px; color: #dbeafe; margin-bottom: 6px; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,0.12); color: #fff; text-decoration: none; }
.main { padding: 26px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-title { margin: 0; font-size: 28px; letter-spacing: -0.03em; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card-title { margin: 0 0 14px; font-size: 18px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-number { font-size: 34px; font-weight: 800; letter-spacing: -0.04em; }
.stat-label { color: var(--muted); margin-top: 4px; }
.form-row { display: grid; gap: 8px; margin-bottom: 14px; }
label { font-weight: 700; font-size: 14px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="file"], select, textarea {
    width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 11px 12px; font-size: 15px; background: #fff; color: var(--text);
}
textarea { min-height: 100px; resize: vertical; }
.help { color: var(--muted); font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 10px 14px; background: #e5e7eb; color: #111827; font-weight: 700; cursor: pointer; line-height: 1.1; }
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--line); color: var(--text); }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8fafc; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: #475569; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 800; background: #e0f2fe; color: #075985; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-muted { background: #f3f4f6; color: #4b5563; }
.alert { padding: 12px 14px; border-radius: 14px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: #ecfdf5; border-color: #bbf7d0; color: #166534; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.public-wrap { min-height: 100vh; padding: 28px 0; background: linear-gradient(135deg, #eff6ff, #f8fafc); }
.public-card { max-width: 920px; margin: 0 auto; background: #fff; border-radius: 26px; border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.public-head { padding: 28px; background: #0f172a; color: #fff; display: flex; gap: 16px; align-items: center; }
.public-head img { width: 64px; height: 64px; object-fit: contain; background: #fff; border-radius: 16px; padding: 8px; }
.public-body { padding: 28px; }
.template-preview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.preview-card { position: relative; background: #fff; border: 1px solid #cbd5e1; border-radius: 16px; overflow: hidden; box-shadow: 0 14px 25px rgba(15,23,42,0.08); aspect-ratio: var(--card-w) / var(--card-h); }
.preview-card img.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mapping-item { position: absolute; border: 2px dashed rgba(37, 99, 235, 0.85); background: rgba(255,255,255,0.65); color: #111827; border-radius: 8px; display: flex; align-items: center; justify-content: center; text-align: center; font-weight: 700; cursor: move; overflow: hidden; padding: 3px; touch-action: none; }
.mapping-item.image::before { content: ''; width: 70%; height: 70%; background: rgba(37, 99, 235, 0.18); border-radius: 50%; position: absolute; }
.mapping-item .label { position: relative; font-size: 11px; line-height: 1.1; pointer-events: none; }
.mapping-item .resize { position: absolute; width: 12px; height: 12px; right: -1px; bottom: -1px; background: #1d4ed8; border-radius: 3px; cursor: nwse-resize; }
.template-edit-preview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 10px 0 14px; }
.template-edit-preview > div { border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: #f8fafc; }
.template-edit-preview img { width: 100%; aspect-ratio: 85.6 / 54; object-fit: cover; border-radius: 10px; border: 1px solid #dbeafe; background: #fff; }
.mapping-panel { max-height: 680px; overflow: auto; }
.mapping-row { display: grid; grid-template-columns: minmax(190px,1fr) 78px 78px 78px 78px 72px 58px 82px 92px 62px 58px 96px; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); min-width: 1220px; }
.mapping-row-head { font-weight: 800; color: #475569; position: sticky; top: -20px; background: #fff; z-index: 2; }
.mapping-row:last-child { border-bottom: 0; }
.mapping-row input, .mapping-row select { padding: 8px; border-radius: 9px; font-size: 13px; }
.mapping-row input[type="color"] { min-height: 38px; padding: 3px; }
.viewer-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.search-box { max-width: 320px; }
@media (max-width: 920px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: relative; height: auto; }
    .grid-2, .grid-3, .template-preview, .template-edit-preview { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; flex-direction: column; }
}

.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stats-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.entry-section { border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 16px; background: #f8fafc; }
.entry-section h3 { margin: 0 0 14px; font-size: 16px; }
.entry-image-preview { width: 96px; height: 96px; object-fit: contain; border: 1px solid var(--line); border-radius: 12px; background: #fff; margin-top: 8px; padding: 4px; }
.entry-image-preview.is-empty { display: none; }
@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 920px) {
    .grid-4, .stats-grid { grid-template-columns: 1fr; }
}


.mapping-add-card { border-left: 5px solid var(--brand); }
.mapping-add-form { display: grid; gap: 12px; }
.btn-small { padding: 8px 10px; border-radius: 9px; font-size: 12px; }
.mapping-row form { margin: 0; }
.mapping-item.image { background: rgba(219, 234, 254, 0.78); }
.mapping-item.text { background: rgba(255, 255, 255, 0.72); }

.public-id-output { width: 100%; overflow: auto; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: #f8fafc; }
.public-id-output .id-pair { display: flex; gap: 16px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.id-card { position: relative; width: var(--card-w); height: var(--card-h); overflow: hidden; border: 0.2mm dashed #9ca3af; background: #fff; flex: 0 0 auto; }
.id-card .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.id-field { position: absolute; overflow: hidden; display: flex; align-items: center; justify-content: center; white-space: pre-line; overflow-wrap: anywhere; line-height: 1.08; padding: 0.6mm; }
.id-field.align-left { justify-content: flex-start; text-align: left; }
.id-field.align-center { justify-content: center; text-align: center; }
.id-field.align-right { justify-content: flex-end; text-align: right; }
.id-field img { width: 100%; height: 100%; object-fit: cover; }
.id-field.logo img { object-fit: contain; }
.id-field.barcode { background: #ffffff; padding: 0.4mm; }
.id-field.barcode img { object-fit: fill; }

/* V4.8 mobile-ready public forms and advanced school filtering */
.filter-card { border-left: 5px solid var(--brand); }
.filter-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.filter-grid .form-row { margin-bottom: 0; }
.filter-actions { margin-top: 14px; }
.entries-workspace { align-items: start; }
.responsive-table td .actions { min-width: 190px; }
.btn-large { min-height: 48px; padding: 13px 18px; font-size: 16px; border-radius: 14px; }
.public-mobile-ready { padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)); }
.public-mobile-ready .public-card { width: min(920px, 100%); }
.public-data-form .entry-section { background: #ffffff; border-color: #dbeafe; }
.public-data-form input,
.public-data-form textarea,
.public-data-form select { font-size: 16px; min-height: 46px; }
.public-submit-bar { position: sticky; bottom: 0; z-index: 20; display: flex; justify-content: flex-end; gap: 10px; margin: 20px -28px -28px; padding: 14px 28px calc(14px + env(safe-area-inset-bottom)); background: rgba(255,255,255,0.96); border-top: 1px solid var(--line); backdrop-filter: blur(10px); }
.public-submit-bar .btn { width: min(360px, 100%); }
.public-success-actions { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; }
.public-success-actions .btn { flex: 0 1 auto; }
.public-id-output { -webkit-overflow-scrolling: touch; }
.public-id-output .id-pair { min-width: min-content; }

@media (max-width: 760px) {
    .main { padding: 16px; }
    .public-wrap { padding: 0; }
    .public-card { border-radius: 0; border-left: 0; border-right: 0; box-shadow: none; }
    .public-head { padding: 20px 16px; align-items: flex-start; }
    .public-head img { width: 52px; height: 52px; border-radius: 12px; }
    .public-head h1 { font-size: 22px; line-height: 1.15; }
    .public-body { padding: 18px 16px; }
    .entry-section { padding: 14px; border-radius: 14px; }
    .public-submit-bar { margin: 18px -16px -18px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
    .public-submit-bar .btn, .public-success-actions .btn, .actions .btn { width: 100%; }
    .actions { width: 100%; }
    .filter-title-row { flex-direction: column; }
    .viewer-toolbar { align-items: stretch; }
    .search-box { max-width: none; width: 100%; }
    .responsive-table table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table th,
    .responsive-table td,
    .responsive-table tr { display: block; width: 100%; }
    .responsive-table thead { display: none; }
    .responsive-table tr { border-bottom: 1px solid var(--line); padding: 12px; }
    .responsive-table td { border-bottom: 0; padding: 8px 0; display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: start; }
    .responsive-table td::before { content: attr(data-label); font-weight: 800; color: #475569; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
    .responsive-table td .actions { min-width: 0; }
    .public-id-output { padding: 10px; border-radius: 14px; }
    .public-id-output .id-pair { justify-content: flex-start; flex-wrap: nowrap; gap: 10px; }
}

@media (max-width: 520px) {
    .sidebar { padding: 16px; }
    .sidebar h1 { font-size: 18px; }
    .page-title { font-size: 23px; }
    .card { padding: 16px; border-radius: 16px; }
    th, td { padding: 10px; }
    .public-id-output .id-card { transform: scale(0.82); transform-origin: top left; margin-right: -18mm; margin-bottom: -30mm; }
}

/* V4.10 live camera capture for image upload options */
.image-capture-field { align-content: start; }
.image-capture-actions,
.camera-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.camera-panel {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}
.camera-video {
    width: 100%;
    max-height: 320px;
    object-fit: cover;
    border-radius: 14px;
    background: #0f172a;
    margin-bottom: 10px;
}

@media (max-width: 760px) {
    .image-capture-actions .btn,
    .camera-actions .btn {
        width: 100%;
    }
    .camera-video {
        max-height: 260px;
    }
}

/* V4.13 mobile-clickable image upload area */
.native-image-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
    opacity: 0;
}
.image-upload-tap-zone {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 118px;
    padding: 14px;
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    background: #ffffff;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.16);
    user-select: none;
    transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}
.image-upload-tap-zone:hover,
.image-upload-tap-zone:focus-within {
    border-color: var(--brand2);
    background: #f8fbff;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.10);
}
.image-upload-tap-zone:active {
    transform: scale(0.992);
}
.image-upload-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: #dbeafe;
    color: var(--brand);
    font-size: 30px;
    line-height: 1;
    font-weight: 800;
}
.image-upload-text {
    display: grid;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
}
.image-upload-text strong {
    color: var(--text);
    font-size: 14px;
}
.image-upload-text small {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}
.image-upload-tap-zone .entry-image-preview {
    width: 96px;
    height: 96px;
    flex: 0 0 auto;
    margin-top: 0;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    padding: 4px;
}
.image-upload-tap-zone .entry-image-preview.is-empty {
    display: none;
}
.image-upload-action {
    min-height: 38px;
}

@media (max-width: 760px) {
    .image-upload-tap-zone {
        min-height: 148px;
        padding: 16px;
        flex-direction: column;
        justify-content: center;
        text-align: center;
    }
    .image-upload-icon {
        width: 54px;
        height: 54px;
        font-size: 34px;
    }
    .image-upload-text strong {
        font-size: 15px;
    }
    .image-upload-text small {
        font-size: 13px;
    }
    .image-upload-tap-zone .entry-image-preview {
        width: min(180px, 70vw);
        height: 140px;
    }
    .image-upload-action {
        width: 100%;
    }
}
