/* ===================================================================
   WISDOM HILL ACADEMY — CAMERA PHOTO BOOTH & BATCH ID CARD STUDIO
   Standalone module (zero edits to style.css / app.js / api.php)
   =================================================================== */

/* Side Menu Button Icon Accent */
.wha-id-studio-icon-bg {
    background: linear-gradient(135deg, #0ea5e9, #2563eb) !important;
    color: #ffffff !important;
}

/* Studio Modal Overlay & Shell */
.wha-studio-overlay {
    position: fixed;
    inset: 0;
    z-index: 10500;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    box-sizing: border-box;
}

.wha-studio-overlay.hidden {
    display: none !important;
}

.wha-studio-dialog {
    width: 100%;
    max-width: 1100px;
    max-height: 92vh;
    background: #ffffff;
    color: #0f172a;
    border-radius: 18px;
    border: 1px solid #cbd5e1;
    box-shadow: 0 24px 60px rgba(2, 6, 23, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Plus Jakarta Sans', 'Segoe UI', Arial, sans-serif;
}

html[data-theme="dark"] .wha-studio-dialog {
    background: #0f172a;
    color: #f8fafc;
    border-color: #1e293b;
}

.wha-studio-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #0b2545 0%, #1e3a8a 100%);
    color: #ffffff;
    flex-shrink: 0;
}

.wha-studio-title-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.wha-studio-badge-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.wha-studio-title {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
    line-height: 1.25;
}

.wha-studio-sub {
    margin: 2px 0 0 0;
    font-size: 12px;
    color: #cbd5e1;
}

.wha-studio-close {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.wha-studio-close:hover {
    background: rgba(255, 255, 255, 0.24);
}

/* Studio Mode Tabs */
.wha-studio-tabs {
    display: flex;
    gap: 8px;
    padding: 10px 20px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

html[data-theme="dark"] .wha-studio-tabs {
    background: #111827;
    border-bottom-color: #1f2937;
}

.wha-studio-tab {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.16s ease;
}

html[data-theme="dark"] .wha-studio-tab {
    background: #1e293b;
    border-color: #334155;
    color: #cbd5e1;
}

.wha-studio-tab.active {
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    border-color: #1d4ed8;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.wha-studio-tab:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Body Grid */
.wha-studio-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.wha-studio-panel.hidden {
    display: none !important;
}

.wha-booth-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 16px;
    align-items: start;
}

.wha-booth-grid.id-split {
    grid-template-columns: 280px 1fr;
}

.wha-studio-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px;
    box-sizing: border-box;
}

html[data-theme="dark"] .wha-studio-card {
    background: #1e293b;
    border-color: #334155;
}

.wha-filter-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.wha-input,
.wha-select {
    width: 100%;
    padding: 9px 11px;
    border-radius: 9px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    font-size: 13px;
    font-family: inherit;
    box-sizing: border-box;
}

html[data-theme="dark"] .wha-input,
html[data-theme="dark"] .wha-select {
    background: #0f172a;
    border-color: #334155;
    color: #f8fafc;
}

.wha-check-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.wha-roster-list {
    max-height: 410px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 2px;
}

.wha-roster-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    cursor: pointer;
    text-align: left;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.15s, background 0.15s;
}

html[data-theme="dark"] .wha-roster-item {
    background: #0f172a;
    border-color: #334155;
    color: #f8fafc;
}

.wha-roster-item.active {
    border-color: #2563eb;
    background: #eff6ff;
}

html[data-theme="dark"] .wha-roster-item.active {
    background: rgba(37, 99, 235, 0.22);
    border-color: #60a5fa;
}

.wha-roster-thumb {
    width: 36px;
    height: 42px;
    border-radius: 7px;
    object-fit: cover;
    border: 1px solid #cbd5e1;
    flex-shrink: 0;
    background: #e2e8f0;
}

.wha-roster-meta {
    flex: 1;
    min-width: 0;
}

.wha-roster-name {
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wha-roster-sub {
    font-size: 11px;
    color: #64748b;
}

html[data-theme="dark"] .wha-roster-sub {
    color: #94a3b8;
}

.wha-photo-pill {
    font-size: 10px;
    font-weight: 800;
    padding: 3px 7px;
    border-radius: 999px;
    flex-shrink: 0;
}

.wha-photo-pill.real {
    background: #dcfce7;
    color: #166534;
}

.wha-photo-pill.missing {
    background: #fef3c7;
    color: #92400e;
}

/* Camera & Crop Stage */
.wha-stage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e2e8f0;
    flex-wrap: wrap;
}

html[data-theme="dark"] .wha-stage-header {
    border-bottom-color: #334155;
}

.wha-stage-learner {
    font-size: 15px;
    font-weight: 800;
}

.wha-stage-learner-id {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
}

html[data-theme="dark"] .wha-stage-learner-id {
    color: #94a3b8;
}

.wha-capture-split {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 14px;
    align-items: start;
}

.wha-viewfinder-box {
    position: relative;
    width: 100%;
    aspect-ratio: 356 / 420;
    max-height: 360px;
    border-radius: 14px;
    overflow: hidden;
    background: #020617;
    border: 2px dashed #475569;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wha-viewfinder-box video,
.wha-viewfinder-box canvas.wha-live-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.wha-viewfinder-guide {
    position: absolute;
    inset: 10% 18% 12% 18%;
    border: 2px dashed rgba(255, 255, 255, 0.72);
    border-radius: 50% 50% 42% 42%;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.28);
}

.wha-viewfinder-placeholder {
    text-align: center;
    color: #94a3b8;
    padding: 18px;
    font-size: 12.5px;
    line-height: 1.5;
}

.wha-passport-out-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.wha-passport-canvas {
    width: 178px;
    height: 210px;
    border-radius: 10px;
    border: 2px solid #0f2b59;
    background: #ffffff;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.14);
}

.wha-slider-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11.5px;
    font-weight: 600;
}

.wha-slider-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}

.wha-slider-row input[type="range"] {
    width: 115px;
}

.wha-btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.wha-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 14px;
    border-radius: 9px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s ease;
}

html[data-theme="dark"] .wha-btn {
    background: #0f172a;
    border-color: #334155;
    color: #f8fafc;
}

.wha-btn-primary {
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    border-color: #1d4ed8;
    color: #ffffff !important;
}

.wha-btn-success {
    background: linear-gradient(135deg, #059669, #10b981);
    border-color: #059669;
    color: #ffffff !important;
}

.wha-btn-amber {
    background: linear-gradient(135deg, #d97706, #f59e0b);
    border-color: #d97706;
    color: #ffffff !important;
}

.wha-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Batch ID Card Builder */
.wha-id-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.wha-id-preview-stage {
    background: #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    max-height: 410px;
    overflow: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
}

html[data-theme="dark"] .wha-id-preview-stage {
    background: #020617;
}

/* Official CR80 Student ID Card Design (85.6mm x 54mm) */
.wha-id-pair-wrap {
    display: inline-flex;
    gap: 0;
    border: 1px dashed #94a3b8;
    padding: 3px;
    background: #ffffff;
    page-break-inside: avoid;
    break-inside: avoid;
}

.wha-id-card {
    width: 85.6mm;
    height: 54mm;
    border: 1px solid #0f2b59;
    border-radius: 6px;
    overflow: hidden;
    background: #ffffff;
    color: #0f172a;
    position: relative;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    font-family: 'Plus Jakarta Sans', 'Segoe UI', Arial, sans-serif;
    page-break-inside: avoid;
    break-inside: avoid;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

.wha-id-card-wm {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.06;
    pointer-events: none;
    z-index: 0;
}

.wha-id-card-wm img {
    width: 34mm;
    height: 34mm;
    object-fit: contain;
}

.wha-id-card-head {
    background: linear-gradient(135deg, #0b2545 0%, #1e3a8a 100%) !important;
    color: #ffffff !important;
    padding: 2mm 3mm;
    border-bottom: 1.5px solid #d4af37;
    display: flex;
    align-items: center;
    gap: 2.5mm;
    position: relative;
    z-index: 1;
}

.wha-id-crest {
    width: 8.5mm;
    height: 8.5mm;
    border-radius: 50%;
    background: #ffffff;
    padding: 0.5mm;
    object-fit: contain;
    flex-shrink: 0;
}

.wha-id-school-titles {
    flex: 1;
    min-width: 0;
}

.wha-id-school-name {
    font-size: 8.5pt;
    font-weight: 900;
    letter-spacing: 0.3px;
    line-height: 1.1;
}

.wha-id-school-sub {
    font-size: 5.5pt;
    color: #fde68a;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
}

.wha-id-body {
    flex: 1;
    padding: 2.5mm 3mm;
    display: flex;
    gap: 3mm;
    align-items: center;
    position: relative;
    z-index: 1;
}

.wha-id-photo-frame {
    width: 21mm;
    height: 25mm;
    border: 1.5px solid #0f2b59;
    border-radius: 3px;
    overflow: hidden;
    background: #f8fafc;
    flex-shrink: 0;
}

.wha-id-photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.wha-id-fields {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1mm;
}

.wha-id-student-name {
    font-size: 8.5pt;
    font-weight: 900;
    color: #0b2545;
    line-height: 1.15;
    text-transform: uppercase;
}

.wha-id-code-pill {
    display: inline-block;
    align-self: flex-start;
    background: #eff6ff !important;
    border: 1px solid #93c5fd;
    color: #1e3a8a !important;
    font-family: 'JetBrains Mono', monospace;
    font-size: 7pt;
    font-weight: 800;
    padding: 0.4mm 1.8mm;
    border-radius: 3px;
}

.wha-id-kv-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6mm 2mm;
    font-size: 6.5pt;
    margin-top: 0.5mm;
}

.wha-id-kv strong {
    color: #475569;
    font-weight: 700;
}

.wha-id-foot {
    padding: 1.2mm 3mm;
    background: #f1f5f9 !important;
    border-top: 1px solid #cbd5e1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 5.8pt;
    font-weight: 700;
    color: #0f172a;
    position: relative;
    z-index: 1;
}

/* Back Card */
.wha-id-back-body {
    flex: 1;
    padding: 2.5mm 3.5mm;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 6.4pt;
    line-height: 1.3;
    position: relative;
    z-index: 1;
}

.wha-id-back-notice {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-left: 3px solid #d97706;
    padding: 1.4mm 2mm;
    border-radius: 3px;
}

.wha-id-barcode-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5mm;
}

.wha-id-barcode-wrap svg {
    width: 48mm;
    height: 7.5mm;
    display: block;
}

/* Printable ID Sheet Container */
@media screen {
    #whaIdPrintContainer {
        display: none !important;
    }
}

.wha-id-print-sheet {
    display: grid;
    grid-template-columns: repeat(2, auto);
    justify-content: center;
    gap: 5mm 7mm;
    padding: 4mm 0;
    page-break-after: always;
    break-after: page;
}

.wha-id-print-sheet:last-child {
    page-break-after: auto;
    break-after: auto;
}

.wha-id-print-sheet.fold-mode {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 4.5mm;
}

@media print {
    html.has-active-session body.wha-printing-id-cards > :not(#whaIdPrintContainer),
    html body.wha-printing-id-cards > :not(#whaIdPrintContainer),
    body.wha-printing-id-cards > :not(#whaIdPrintContainer),
    html.has-active-session body.wha-printing-id-cards > #printReportContainer,
    body.wha-printing-id-cards > #printReportContainer {
        display: none !important;
    }

    html.has-active-session body.wha-printing-id-cards > #whaIdPrintContainer,
    html body.wha-printing-id-cards > #whaIdPrintContainer,
    body.wha-printing-id-cards > #whaIdPrintContainer {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: static !important;
        width: 100% !important;
        height: auto !important;
        max-width: none !important;
        max-height: none !important;
        overflow: visible !important;
        background: #ffffff !important;
        color: #0f172a !important;
        margin: 0 !important;
        padding: 0 !important;
        z-index: 1 !important;
    }
}

/* Mobile Layout */
@media (max-width: 768px) {
    .wha-studio-overlay {
        padding: 6px;
    }
    .wha-studio-dialog {
        max-width: calc(100vw - 12px);
        max-height: 94vh;
    }
    .wha-studio-tabs {
        padding: 8px 10px;
    }
    .wha-studio-tab {
        font-size: 12px;
        padding: 8px 10px;
    }
    .wha-studio-body {
        padding: 10px;
    }
    .wha-booth-grid,
    .wha-booth-grid.id-split {
        grid-template-columns: 1fr;
    }
    .wha-capture-split {
        grid-template-columns: 1fr;
    }
    .wha-id-controls {
        grid-template-columns: 1fr;
    }
    .wha-roster-list {
        max-height: 200px;
    }
}

@media screen and (max-width: 768px) {
    .wha-id-preview-stage {
        padding: 10px;
        justify-content: center;
    }
    .wha-id-preview-stage .wha-id-pair-wrap {
        zoom: 0.49;
    }
    .wha-id-preview-stage > .wha-id-card {
        zoom: 0.92;
    }
}
