/* ===================================================================
   CARD STYLES - KARTU PELAJAR HORIZONTAL (87 x 56 mm)
   Standard ID-1 / CR80 ratio (1.553). Exact 87mm x 56mm print sizing.
   =================================================================== */

:root {
    --card-w: 87mm;
    --card-h: 56mm;
    --card-radius: 3.5mm;
    --card-border: #cbd5e1;
}

/* Card Preview Wrapper on Screen */
.card-preview-viewport {
    perspective: 1200px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem 1rem;
    background: radial-gradient(circle at 50% 50%, #1e293b 0%, #0f172a 100%);
    border-radius: 1rem;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.4);
}

.card-preview-viewport::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 80% 20%, rgba(99, 102, 241, 0.15), transparent 50%),
                radial-gradient(circle at 20% 80%, rgba(14, 165, 233, 0.1), transparent 50%);
    pointer-events: none;
}

/* 3D Flip Container */
.id-card-flip-wrap {
    width: 480px;
    height: 309px; /* Exact 87:56 ratio (480 / 87 * 56 = 308.96px) */
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    user-select: none;
}

.id-card-flip-wrap.flipped {
    transform: rotateY(180deg);
}

/* Base Card Element */
.id-card {
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
    border-radius: 14px;
    box-shadow: 0 20px 35px -10px rgba(0, 0, 0, 0.5), 0 0 1px 1px rgba(255, 255, 255, 0.2);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    color: #0f172a;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background: #ffffff;
}

/* Back face */
.id-card-back {
    transform: rotateY(180deg);
}

/* ===================================================================
   CARD THEMES (PALET WARNA RESMI & MENARIK)
   =================================================================== */

/* 1. Theme: Royal Navy (Default) */
.id-card.theme-navy {
    --theme-primary: #1e3a8a;
    --theme-secondary: #0284c7;
    --theme-accent: #f59e0b;
    --theme-dark: #0f172a;
    --theme-bg-grad: linear-gradient(135deg, #f8fafc 0%, #edf2f7 60%, #e0e7ff 100%);
    --header-bg: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #0369a1 100%);
    --header-text: #ffffff;
    --header-accent: #fbbf24;
}

/* 2. Theme: Emerald Green (Adiwiyata / Berprestasi) */
.id-card.theme-emerald {
    --theme-primary: #065f46;
    --theme-secondary: #059669;
    --theme-accent: #f59e0b;
    --theme-dark: #064e3b;
    --theme-bg-grad: linear-gradient(135deg, #f0fdf4 0%, #e6f4ea 60%, #d1fae5 100%);
    --header-bg: linear-gradient(135deg, #064e3b 0%, #065f46 50%, #0d9488 100%);
    --header-text: #ffffff;
    --header-accent: #fde047;
}

/* 3. Theme: Ruby Crimson (Kombinasi Merah Putih Nasional) */
.id-card.theme-crimson {
    --theme-primary: #991b1b;
    --theme-secondary: #dc2626;
    --theme-accent: #f59e0b;
    --theme-dark: #7f1d1d;
    --theme-bg-grad: linear-gradient(135deg, #fff5f5 0%, #fed7d7 60%, #ffe4e6 100%);
    --header-bg: linear-gradient(135deg, #7f1d1d 0%, #991b1b 50%, #c026d3 100%);
    --header-text: #ffffff;
    --header-accent: #fef08a;
}

/* 4. Theme: Cyan Futuristic (Modern Smart Card) */
.id-card.theme-cyan {
    --theme-primary: #0e7490;
    --theme-secondary: #0284c7;
    --theme-accent: #fbbf24;
    --theme-dark: #155e75;
    --theme-bg-grad: linear-gradient(135deg, #ecfeff 0%, #e0f2fe 60%, #dbeafe 100%);
    --header-bg: linear-gradient(135deg, #164e63 0%, #0e7490 50%, #0284c7 100%);
    --header-text: #ffffff;
    --header-accent: #38bdf8;
}

/* 5. Theme: Royal Purple / Gold */
.id-card.theme-purple {
    --theme-primary: #581c87;
    --theme-secondary: #7e22ce;
    --theme-accent: #f59e0b;
    --theme-dark: #3b0764;
    --theme-bg-grad: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 60%, #e9d5ff 100%);
    --header-bg: linear-gradient(135deg, #3b0764 0%, #6b21a8 50%, #9333ea 100%);
    --header-text: #ffffff;
    --header-accent: #facc15;
}

/* ===================================================================
   CARD STRUCTURE & LAYOUT (FRONT SIDE)
   =================================================================== */

.id-card-front {
    background: var(--theme-bg-grad);
    position: relative;
}

/* Guilloche Security Vector Pattern Background */
.id-card-watermark-pattern {
    position: absolute;
    inset: 0;
    opacity: 0.06;
    pointer-events: none;
    background-image: 
        radial-gradient(circle at 100% 100%, var(--theme-primary) 15%, transparent 16%),
        radial-gradient(circle at 0% 0%, var(--theme-primary) 15%, transparent 16%),
        linear-gradient(45deg, transparent 48%, var(--theme-primary) 50%, transparent 52%);
    background-size: 20px 20px, 20px 20px, 10px 10px;
}

/* Large School Logo Watermark in Center */
.id-card-center-watermark {
    position: absolute;
    top: 55%;
    left: 55%;
    transform: translate(-50%, -50%);
    width: 170px;
    height: 170px;
    opacity: 0.07;
    pointer-events: none;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    filter: grayscale(100%);
}

/* Decorative Card Curves */
.card-wave-bg {
    position: absolute;
    bottom: -15px;
    right: -20px;
    width: 220px;
    height: 130px;
    background: linear-gradient(135deg, transparent 20%, var(--theme-secondary) 100%);
    opacity: 0.08;
    border-radius: 50%;
    pointer-events: none;
}

/* ===================================================================
   HEADER SECTION (KOP SEKOLAH)
   =================================================================== */

/* ===================================================================
   HEADER SECTION (KOP SEKOLAH)
   =================================================================== */

.card-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 6px 10px 5px 10px;
    height: 72px; /* Fixed screen height */
    display: flex;
    align-items: center;
    gap: 9px;
    position: relative;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    border-bottom: 2px solid var(--header-accent);
    box-sizing: border-box;
    flex-shrink: 0;
}

.card-header::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: -4px;
    left: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--header-accent) 0%, transparent 100%);
}

.card-logo-wrap {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    background: #ffffff;
    border-radius: 50%;
    padding: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.card-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.card-school-meta {
    flex: 1;
    min-width: 0;
    line-height: 1.15;
    text-align: center;
}

.card-gov-title {
    font-size: 7.2px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.95);
    line-height: 1.15;
}

.card-gov-subtitle {
    font-size: 6.8px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--header-accent);
    line-height: 1.15;
}

.card-school-name {
    font-size: 11.5px;
    font-weight: 800;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: #ffffff;
    margin: 1px 0;
    text-shadow: 0 1px 2px rgba(0,0,0,0.35);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-school-address {
    font-size: 6.8px;
    font-weight: 500;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===================================================================
   CARD BODY (FOTO & BIODATA SISWA - SPATIAL BALANCE & PRECISION)
   =================================================================== */

.card-body {
    flex: 1;
    display: flex;
    padding: 7px 12px 7px 12px;
    gap: 12px;
    position: relative;
    z-index: 2;
    box-sizing: border-box;
    overflow: hidden;
}

/* Photo Column */
.card-photo-col {
    width: 86px;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    height: 100%;
}

.card-photo-box {
    width: 82px;
    height: 108px;
    border-radius: 6px;
    overflow: hidden;
    background: #e2e8f0;
    border: 2px solid #ffffff;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--theme-secondary);
    position: relative;
    flex-shrink: 0;
}

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

.card-photo-tag {
    margin-top: 4px;
    background: var(--theme-primary);
    color: #ffffff;
    font-size: 6.5px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 2px 0;
    border-radius: 4px;
    width: 82px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    flex-shrink: 0;
}

/* Info Biodata Column */
.card-info-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    position: relative;
    box-sizing: border-box;
}

.card-table-info {
    width: 100%;
    border-collapse: collapse;
    font-size: 8.5px;
    line-height: 1.25;
    table-layout: fixed;
}

.card-table-info tr {
    vertical-align: top;
    height: 14.5px;
}

.card-table-info td {
    padding: 1px 0;
}

.card-td-label {
    width: 60px;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

.card-td-sep {
    width: 8px;
    color: #64748b;
    text-align: center;
}

.card-td-val {
    font-weight: 600;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-val-nama {
    font-size: 9.6px;
    font-weight: 800;
    color: var(--theme-dark);
    letter-spacing: 0.1px;
}

.card-val-nisn {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 9.2px;
    font-weight: 700;
    color: var(--theme-primary);
    letter-spacing: 0.5px;
}

.card-val-ttl {
    font-size: 8.2px;
    color: #1e293b;
}

.card-val-kelas {
    display: inline-block;
    background: #e2e8f0;
    color: var(--theme-dark);
    font-weight: 700;
    padding: 0.5px 5px;
    border-radius: 3px;
    border: 1px solid #cbd5e1;
    font-size: 7.8px;
}

.card-val-jk {
    font-size: 8px;
    color: #475569;
}

.card-val-alamat {
    font-size: 7.8px;
    color: #334155;
}

/* ===================================================================
   CARD BOTTOM ROW (QR CODE & TANDA TANGAN - FIXED ALIGNMENT)
   =================================================================== */

.card-bottom-row {
    margin-top: auto;
    height: 52px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding-top: 3px;
    border-top: 1px dashed rgba(148, 163, 184, 0.45);
    box-sizing: border-box;
    flex-shrink: 0;
}

.card-qr-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    width: 44px;
}

.card-qr-box {
    width: 40px;
    height: 40px;
    background: #ffffff;
    padding: 1.5px;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-qr-box svg {
    width: 100%;
    height: 100%;
    display: block;
}

.card-qr-label {
    font-size: 5.5px;
    font-weight: 700;
    color: #64748b;
    letter-spacing: 0.5px;
    margin-top: 1px;
    text-align: center;
    line-height: 1;
}

/* Signature & Official Seal Box */
.card-signature-box {
    text-align: center;
    position: relative;
    padding-left: 6px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 48px;
    box-sizing: border-box;
}

.card-sig-city {
    font-size: 6.2px;
    color: #475569;
    font-weight: 500;
    line-height: 1.1;
}

.card-sig-role {
    font-size: 6.5px;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.1;
}

.card-sig-stamp-wrap {
    height: 20px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-digital-stamp {
    position: absolute;
    left: 44%;
    transform: translateX(-50%) rotate(-8deg);
    width: 28px;
    height: 28px;
    border: 1.5px dashed #2563eb;
    border-radius: 50%;
    color: #2563eb;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 3.5px;
    font-weight: 800;
    line-height: 1;
    opacity: 0.8;
    pointer-events: none;
    background: rgba(37, 99, 235, 0.04);
}

.card-digital-sig {
    font-family: 'Caveat', cursive, sans-serif;
    font-size: 17px;
    color: #1e3a8a;
    font-weight: 700;
    position: relative;
    z-index: 2;
    transform: rotate(-3deg);
    line-height: 1;
}

.card-headmaster-name {
    font-size: 7.2px;
    font-weight: 800;
    color: #0f172a;
    text-decoration: underline;
    line-height: 1;
    white-space: nowrap;
}

.card-headmaster-nip {
    font-size: 5.8px;
    color: #64748b;
    font-family: 'JetBrains Mono', Consolas, monospace;
    line-height: 1;
    white-space: nowrap;
}


/* ===================================================================
   CARD BACK SIDE (KETENTUAN & TATA TERTIB)
   =================================================================== */

.id-card-back {
    background: var(--theme-bg-grad);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
}

.card-back-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 6px 12px;
    text-align: center;
    border-bottom: 2px solid var(--header-accent);
}

.card-back-title {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.card-back-body {
    flex: 1;
    padding: 10px 14px 6px 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.card-rules-list {
    margin: 0;
    padding-left: 14px;
    font-size: 7.5px;
    color: #334155;
    line-height: 1.45;
}

.card-rules-list li {
    margin-bottom: 3.5px;
}

.card-back-notice {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 5px 8px;
    margin-top: 4px;
    text-align: center;
}

.card-back-notice-text {
    font-size: 6.8px;
    color: #475569;
    font-style: italic;
    line-height: 1.25;
}

.card-back-footer {
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    padding: 4px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 6.5px;
    color: #64748b;
}

.card-back-motto {
    font-weight: 700;
    color: var(--theme-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===================================================================
   ACCURATE PHYSICAL PRINT MEASUREMENTS (87 x 56 mm)
   =================================================================== */

@media print {
    /* Hide everything on page except print-container */
    body * {
        visibility: hidden;
    }

    #print-stage, #print-stage * {
        visibility: visible;
    }

    #print-stage {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        background: transparent !important;
    }

    /* Print Single Card Exact 87x56mm */
    .print-mode-single .id-card {
        width: 87mm !important;
        height: 56mm !important;
        min-width: 87mm !important;
        min-height: 56mm !important;
        max-width: 87mm !important;
        max-height: 56mm !important;
        margin: 0 !important;
        border-radius: 3.5mm !important;
        page-break-after: always;
        break-after: page;
        box-shadow: none !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Print Batch A4 Grid (Hemat Kertas & Garis Potong) */
    .print-mode-a4 {
        width: 210mm;
        margin: 0 auto;
        padding: 8mm 6mm;
        box-sizing: border-box;
    }

    .print-a4-page {
        display: grid;
        grid-template-columns: repeat(2, 87mm);
        grid-auto-rows: 56mm;
        gap: 6mm 10mm;
        justify-content: center;
        page-break-after: always;
        break-after: page;
        box-sizing: border-box;
        margin-bottom: 0;
    }

    .print-a4-page:last-child {
        page-break-after: avoid;
        break-after: avoid;
    }

    .print-card-wrapper {
        width: 87mm;
        height: 56mm;
        position: relative;
        box-sizing: border-box;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Fine cut marks (garis potong halus) */
    .print-card-wrapper::before {
        content: '';
        position: absolute;
        inset: -2px;
        border: 0.5px dashed #94a3b8;
        pointer-events: none;
        border-radius: 4mm;
    }

    .print-card-wrapper .id-card {
        width: 87mm !important;
        height: 56mm !important;
        min-width: 87mm !important;
        min-height: 56mm !important;
        max-width: 87mm !important;
        max-height: 56mm !important;
        border-radius: 3mm !important;
        box-shadow: none !important;
        border: 0.5px solid #cbd5e1 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}
