/**
 * Stili 3D per la Tessera Sanitaria Italiana (Carta Nazionale dei Servizi)
 * Conforme alle proporzioni ISO/IEC 7810 ID-1 (85.60 × 53.98 mm).
 * Animazione Flip 3D a 60fps con supporto Dark/Light mode e Stampa in scala 1:1.
 */

:root {
    --card-width: 440px;
    --card-height: 278px;
    --card-radius: 14px;
    --card-bg-gradient: linear-gradient(135deg, #00897b 0%, #26a69a 50%, #00695c 100%);
    --card-back-bg: linear-gradient(135deg, #e0f2f1 0%, #b2dfdb 100%);
    --chip-gold: linear-gradient(135deg, #ffd54f 0%, #ffb300 50%, #ffe082 100%);
}

@media (max-width: 480px) {
    :root {
        --card-width: 330px;
        --card-height: 208px;
        --card-radius: 10px;
    }
}

@media (max-width: 360px) {
    :root {
        --card-width: 300px;
        --card-height: 190px;
        --card-radius: 10px;
    }
}

/* Contenitore 3D Perspective */
.tessera-scene {
    width: var(--card-width);
    max-width: 100%; /* Previene overflow orizzontale su mobile */
    /* Se la larghezza è ridotta da max-width, l'altezza si adatta proporzionalmente */
    height: var(--card-height);
    aspect-ratio: 440 / 278; /* Rapporto ISO/IEC 7810 ID-1: mantiene le proporzioni */
    margin: 24px auto;
    perspective: 1200px;
    cursor: pointer;
    user-select: none;
    contain: layout; /* Impedisce al contenuto 3D di espandersi oltre il bordo */
}

.tessera-card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
    border-radius: var(--card-radius);
    box-shadow: 0 16px 36px rgba(0, 105, 92, 0.28), 0 4px 12px rgba(0, 0, 0, 0.12);
}

.tessera-card.flipped {
    transform: rotateY(180deg);
}

/* Facce della carta */
.tessera-face {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--card-radius);
    overflow: hidden;
    padding: 16px 20px;
    box-sizing: border-box;
}

/* =========================================
   FRONTE DELLA TESSERA
   ========================================= */
.tessera-front {
    background: var(--card-bg-gradient);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

/* Texture di sicurezza della tessera */
.tessera-front::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.15) 0%, transparent 60%),
                repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.03) 0px, rgba(255, 255, 255, 0.03) 2px, transparent 2px, transparent 6px);
    pointer-events: none;
}

/* Header della tessera */
.tessera-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: relative;
    z-index: 1;
}

.tessera-titles {
    flex: 1;
}

.tessera-title-main {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: #ffffff;
    margin: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.tessera-title-sub {
    font-size: 9.5px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    margin-top: 1px;
    letter-spacing: 0.3px;
}

.tessera-flag-badge {
    display: flex;
    align-items: center;
    gap: 6px;
}

.eu-flag {
    width: 24px;
    height: 16px;
    background: #003399;
    border-radius: 2px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0.5px solid rgba(255, 255, 255, 0.6);
}

.eu-flag::after {
    content: '★';
    color: #ffcc00;
    font-size: 11px;
}

.ita-stripes {
    display: flex;
    width: 18px;
    height: 16px;
    border-radius: 2px;
    overflow: hidden;
    border: 0.5px solid rgba(255, 255, 255, 0.4);
}
.ita-stripes span { flex: 1; height: 100%; }
.ita-stripes .green { background: #009246; }
.ita-stripes .white { background: #ffffff; }
.ita-stripes .red   { background: #ce2b37; }

/* Microchip Smart Card */
.tessera-chip-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 4px;
    position: relative;
    z-index: 1;
}

.chip-metal {
    width: 42px;
    height: 32px;
    background: var(--chip-gold);
    border-radius: 6px;
    border: 1px solid #c68a00;
    position: relative;
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.5), 0 2px 4px rgba(0, 0, 0, 0.15);
}

.chip-metal::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #c68a00;
}
.chip-metal::after {
    content: '';
    position: absolute;
    left: 45%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: #c68a00;
}

/* Codice Fiscale principale sul fronte */
.tessera-cf-display {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: 2px;
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    background: rgba(0, 0, 0, 0.14);
    padding: 4px 8px;
    border-radius: 6px;
    display: inline-block;
}

@media (max-width: 480px) {
    .tessera-cf-display {
        font-size: 14.5px;
        letter-spacing: 1px;
        padding: 2px 6px;
    }
}

/* Griglia dati anagrafici fronte */
.tessera-data-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 4px 12px;
    font-size: 10.5px;
    position: relative;
    z-index: 1;
    margin-top: 6px;
}

@media (max-width: 480px) {
    .tessera-data-grid {
        font-size: 8.5px;
        gap: 2px 8px;
    }
}

.tessera-field-label {
    font-size: 8px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.75);
    margin-bottom: 1px;
    font-weight: 600;
    letter-spacing: 0.4px;
}

.tessera-field-value {
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-transform: uppercase;
}

/* =========================================
   RETRO DELLA TESSERA
   ========================================= */
.tessera-back {
    background: var(--card-back-bg);
    color: #1e293b;
    transform: rotateY(180deg);
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid #cbd5e1;
}

/* Banda Magnetica */
.magnetic-stripe {
    width: 100%;
    height: 44px;
    background: linear-gradient(180deg, #18181b 0%, #27272a 50%, #09090b 100%);
    margin-top: 14px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

@media (max-width: 480px) {
    .magnetic-stripe {
        height: 32px;
        margin-top: 8px;
    }
}

/* Sezione Barcode */
.barcode-section {
    padding: 8px 16px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.barcode-svg-wrapper {
    background: #ffffff;
    padding: 6px 10px;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: center;
    width: 90%;
    box-sizing: border-box;
}

.barcode-svg-wrapper svg {
    max-width: 100%;
    height: auto;
    display: block;
}

.card-back-disclaimer {
    font-size: 8px;
    color: #64748b;
    text-align: center;
    margin: 2px 16px 8px;
    line-height: 1.2;
}

/* =========================================
   CONTROLLI E PULSANTI TESSERA
   ========================================= */
.tessera-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.tessera-hint {
    text-align: center;
    font-size: 13px;
    color: var(--text-muted, #64748b);
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* =========================================
   STAMPA FISICA (SCALA 1:1 CARTA DI CREDITO)
   ========================================= */
@media print {
    body * {
        visibility: hidden;
    }
    .tessera-print-container,
    .tessera-print-container * {
        visibility: visible;
    }
    .tessera-print-container {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 30px;
        padding: 40px;
        box-sizing: border-box;
    }
    .tessera-card {
        width: 85.6mm !important;
        height: 53.98mm !important;
        box-shadow: none !important;
        border: 1px dashed #94a3b8 !important;
        page-break-inside: avoid;
    }
    .tessera-card.flipped {
        transform: none !important;
    }
}
