:root {
    --bg: #f6f7fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --soft: #e8f5f3;
    --danger: #b91c1c;
    --warning: #92400e;
    --success: #047857;
    --ink: #111827;
    --paper: #fbfbf7;
    --accent: #d71920;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}
img { max-width: 100%; display: block; }
.page { width: min(1380px, calc(100% - 28px)); margin: 28px auto; }
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 16px 45px rgba(15, 23, 42, .07);
    padding: 24px;
}
.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
}
.eyebrow {
    margin: 0 0 8px;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    font-size: 12px;
}
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(28px, 4vw, 42px); }
h2 { font-size: 22px; margin-bottom: 16px; }
.muted, .hint { color: var(--muted); }
.hint { margin: -6px 0 14px; font-size: 14px; }
.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(110px, 1fr));
    gap: 12px;
    min-width: 360px;
}
.stats div { background: var(--soft); border-radius: 16px; padding: 14px; }
.stats strong { display: block; font-size: 30px; color: var(--primary-dark); }
.stats span { color: var(--muted); font-size: 13px; }
.grid-two {
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 18px;
    margin-bottom: 18px;
}
label { display: block; font-weight: 700; margin: 14px 0 7px; }
input, select, button, .secondary { font: inherit; }
input[type="search"], input[type="file"], select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    padding: 12px 14px;
    outline: none;
}
input[type="search"]:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(15, 118, 110, .12);
}
button.primary, .secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    text-decoration: none;
    cursor: pointer;
    font-weight: 700;
    padding: 12px 16px;
    border: 1px solid transparent;
}
button.primary { width: 100%; background: var(--primary); color: white; }
button.primary:hover { background: var(--primary-dark); }
.secondary { color: var(--primary-dark); border-color: #99d4ce; background: var(--soft); }
.small-btn { width: 100%; padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.disabled-btn { cursor: not-allowed; opacity: .55; color: var(--muted); border-color: var(--line); background: #f9fafb; }
.photo-preview {
    min-height: 260px;
    border: 1px dashed #b8c3d4;
    background: #fbfdff;
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}
.photo-preview img {
    width: 100%;
    height: auto;
    object-fit: contain;
    background: #f8fafc;
}
.photo-placeholder, .empty { color: var(--muted); text-align: center; padding: 26px; }
.detail-table { width: 100%; border-collapse: collapse; overflow: hidden; border-radius: 16px; }
.detail-table th, .detail-table td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.detail-table th { width: 210px; color: var(--muted); background: #f9fafb; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; }
.alert { border-radius: 16px; padding: 14px 16px; margin-bottom: 18px; font-weight: 700; }
.alert.success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.alert.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.section-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.table-search { margin-bottom: 16px; }
.autocomplete { position: relative; }
.search-results { margin-top: 10px; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #fff; }
.search-help, .selected-person { padding: 14px 16px; color: var(--muted); }
.selected-person strong, .result-item strong { display: block; color: var(--text); }
.selected-person span, .result-item span { display: block; font-size: 13px; margin-top: 3px; }
.result-item { width: 100%; text-align: left; padding: 14px 16px; border: 0; border-top: 1px solid var(--line); background: #fff; }
.result-item:hover { background: #f8fafc; }
.badge, .photo-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    border-radius: 999px;
    padding: 8px 12px;
}
.badge.ok, .photo-status.ok { background: #ecfdf5; color: var(--success); }
.badge.wait, .photo-status.wait { background: #fff7ed; color: var(--warning); }
.gallery-card { margin-bottom: 20px; }
.card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
}
.passport-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--paper);
    border: 1px solid #111827;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 12px 28px rgba(17, 24, 39, .08);
}
.passport-top { height: 14px; background: var(--accent); }
.passport-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 126px;
    gap: 14px;
    padding: 12px;
    flex: 1;
}
.passport-main { min-width: 0; }
.passport-row {
    display: grid;
    grid-template-columns: 120px 12px minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    padding: 6px 0;
    border-bottom: 2px solid #111827;
}
.passport-row.small-row { padding-top: 1px; border-bottom: 0; }
.passport-row .label { font-weight: 800; color: #111827; font-size: 12px; }
.passport-row .colon { font-weight: 800; color: #111827; }
.passport-row .value, .passport-row .sub-value {
    min-width: 0;
    font-weight: 900;
    color: #111827;
    line-height: 1.18;
    word-break: break-word;
}
.passport-row .sub-value { font-size: 13px; font-weight: 800; }
.passport-row .value { font-size: 15px; }
.passport-row .value.big { font-size: 17px; }
.passport-row .value.strong { font-size: 18px; letter-spacing: .02em; }
.passport-row .value-title { text-transform: none; }
.name-row { border-bottom: 0; padding-bottom: 0; }
.passport-photo-area { display: flex; flex-direction: column; gap: 8px; }
.passport-photo-frame {
    border: 3px solid #111827;
    background: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 4px;
    padding: 0;
    width: 100%;
    max-width: 170px;
}
.passport-photo-frame img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
}
.passport-photo-empty {
    width: 100%;
    min-height: 170px;
    color: var(--muted);
    text-align: center;
    font-size: 14px;
    line-height: 1.25;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 10px;
}
.hidden { display: none !important; }
@media (max-width: 1220px) {
    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 940px) {
    .hero { flex-direction: column; align-items: stretch; }
    .stats { min-width: 0; }
    .grid-two { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .page { width: min(100%, calc(100% - 16px)); margin: 16px auto; }
    .card { padding: 18px; border-radius: 18px; }
    .stats { grid-template-columns: 1fr; }
    .section-head { flex-direction: column; }
    .toolbar { width: 100%; justify-content: flex-start; }
    .card-grid { grid-template-columns: 1fr; }
    .passport-content { grid-template-columns: 1fr; }
    .passport-photo-area { order: -1; }
    .passport-photo-frame { max-width: 240px; margin: 0 auto; }
    .passport-photo-empty { min-height: 210px; }
    .passport-row { grid-template-columns: 110px 12px minmax(0, 1fr); }
}
@page { size: A4 landscape; margin: 8mm; }
@media print {
    body { background: #fff; }
    .page { width: 100%; margin: 0; }
    .hero, .grid-two, .alert, .table-search, .toolbar, .eyebrow, .muted { display: none !important; }
    .card { box-shadow: none; border: 0; padding: 0; background: transparent; }
    .gallery-card { margin: 0; padding: 0; }
    .section-head { margin: 0 0 8px; }
    .section-head h2 { font-size: 18px; margin: 0; }
    .card-grid { grid-template-columns: repeat(2, 1fr); gap: 6mm; }
    .passport-card { break-inside: avoid; page-break-inside: avoid; box-shadow: none; border-radius: 6px; }
    .passport-top { height: 8px; }
    .passport-content { grid-template-columns: minmax(0, 1fr) 32mm; gap: 8px; padding: 7px; }
    .passport-row { grid-template-columns: 29mm 4mm minmax(0, 1fr); gap: 4px; padding: 3px 0; border-bottom-width: 1px; }
    .passport-row .label, .passport-row .colon, .passport-row .sub-value { font-size: 8.5pt; }
    .passport-row .value { font-size: 10pt; }
    .passport-row .value.big { font-size: 11pt; }
    .passport-row .value.strong { font-size: 12pt; }
    .passport-photo-frame { max-width: 32mm; border-width: 2px; }
    .passport-photo-empty { min-height: 42mm; }
    .photo-status, .small-btn { display: none !important; }
}


/* Update v10: kartu data terpilih + area foto bisa diklik */
.selected-card-wrap {
    margin-top: 12px;
}

.selected-passport-card {
    width: 100%;
    max-width: 820px;
}

.selected-passport-card .passport-content {
    grid-template-columns: minmax(0, 1fr) 170px;
}

button.passport-photo-frame {
    width: 100%;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

button.passport-photo-frame:hover,
.photo-preview:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(15, 118, 110, .12);
}

.photo-preview {
    cursor: pointer;
}

.photo-click-hint {
    color: var(--muted);
    font-size: 12px;
    text-align: center;
    line-height: 1.25;
}

.card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 720px) {
    .selected-passport-card .passport-content {
        grid-template-columns: 1fr;
    }

    .selected-passport-card .passport-photo-area {
        order: -1;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }
}

@media print {
    .photo-click-hint {
        display: none !important;
    }

    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}


/* Update v13: adaptive photo frame + lightbox */
.passport-photo-frame.has-photo {
    cursor: zoom-in;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, .88);
}

.lightbox.show {
    display: flex;
}

.lightbox img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(96vw, 1400px);
    max-height: 92vh;
    object-fit: contain;
    border-radius: 10px;
    background: white;
}

.lightbox-close {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: white;
    color: #111827;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 720px) {
    .lightbox {
        padding: 12px;
    }

    .lightbox img {
        max-width: 96vw;
        max-height: 88vh;
    }
}


/* Update v15: frame foto benar-benar fixed 3x4, foto contain tanpa crop */
.passport-photo-area {
    align-items: center !important;
}

.passport-photo-frame,
button.passport-photo-frame,
.selected-passport-card .passport-photo-frame,
.selected-passport-card button.passport-photo-frame {
    width: 180px !important;
    height: 240px !important;
    min-width: 180px !important;
    max-width: 180px !important;
    min-height: 240px !important;
    max-height: 240px !important;
    aspect-ratio: auto !important;
    padding: 6px !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
    background: #ffffff !important;
}

.passport-photo-frame img,
button.passport-photo-frame img,
.selected-passport-card .passport-photo-frame img,
.selected-passport-card button.passport-photo-frame img {
    display: block !important;
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
    object-position: center center !important;
}

.passport-photo-empty {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
}

@media (max-width: 720px) {
    .passport-photo-frame,
    button.passport-photo-frame,
    .selected-passport-card .passport-photo-frame,
    .selected-passport-card button.passport-photo-frame {
        width: 180px !important;
        height: 240px !important;
        min-width: 180px !important;
        max-width: 180px !important;
        min-height: 240px !important;
        max-height: 240px !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

@media print {
    .passport-photo-frame,
    button.passport-photo-frame {
        width: 32mm !important;
        height: 42.67mm !important;
        min-width: 32mm !important;
        max-width: 32mm !important;
        min-height: 42.67mm !important;
        max-height: 42.67mm !important;
    }
}


/* Update v16: rapikan kartu semua jamaah 2 kolom */
.card-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 20px !important;
    align-items: stretch !important;
}

.passport-card {
    height: 100% !important;
    min-height: 410px !important;
}

.passport-content {
    grid-template-columns: minmax(0, 1fr) 205px !important;
    gap: 22px !important;
    padding: 18px 16px 16px !important;
    align-items: start !important;
}

.passport-main {
    min-width: 0 !important;
}

.passport-photo-area {
    width: 205px !important;
    justify-self: end !important;
    align-items: center !important;
    flex-shrink: 0 !important;
}

.passport-photo-frame,
button.passport-photo-frame {
    width: 180px !important;
    height: 240px !important;
    min-width: 180px !important;
    max-width: 180px !important;
    min-height: 240px !important;
    max-height: 240px !important;
    padding: 6px !important;
}

.passport-row {
    grid-template-columns: 136px 12px minmax(0, 1fr) !important;
    gap: 8px !important;
}

.passport-row .value.big {
    font-size: 18px !important;
}

.passport-row .value.strong {
    font-size: 19px !important;
}

.passport-row .label {
    font-size: 13px !important;
}

@media (max-width: 1100px) {
    .card-grid {
        grid-template-columns: 1fr !important;
    }

    .passport-content {
        grid-template-columns: minmax(0, 1fr) 205px !important;
    }
}

@media (max-width: 720px) {
    .card-grid {
        grid-template-columns: 1fr !important;
    }

    .passport-card {
        min-height: 0 !important;
    }

    .passport-content {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }

    .passport-photo-area {
        width: 100% !important;
        justify-self: center !important;
        order: -1 !important;
    }

    .passport-row {
        grid-template-columns: 116px 12px minmax(0, 1fr) !important;
    }

    .passport-row .value.big {
        font-size: 16px !important;
    }
}

@media print {
    .card-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 5mm !important;
    }

    .passport-content {
        grid-template-columns: minmax(0, 1fr) 36mm !important;
        gap: 4mm !important;
        padding: 5mm !important;
    }

    .passport-photo-area {
        width: 36mm !important;
    }

    .passport-photo-frame,
    button.passport-photo-frame {
        width: 32mm !important;
        height: 42.67mm !important;
        min-width: 32mm !important;
        max-width: 32mm !important;
        min-height: 42.67mm !important;
        max-height: 42.67mm !important;
    }

    .passport-row {
        grid-template-columns: 30mm 4mm minmax(0, 1fr) !important;
    }
}
