﻿:root {
    --page-bg: #eef3f7;
    --panel-bg: #ffffff;
    --ink: #1d2b3a;
    --accent: #006d77;
    --card-shadow: 0 14px 30px rgba(22, 44, 66, 0.18);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at top left, #f8fcff, var(--page-bg));
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(300px, 360px) 1fr;
    gap: 24px;
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.panel {
    background: var(--panel-bg);
    border-radius: 14px;
    box-shadow: var(--card-shadow);
    padding: 20px;
}

h1 {
    margin: 0 0 8px;
    font-size: 1.4rem;
}

.subtitle {
    margin: 0 0 18px;
    color: #4c6277;
}

.form-grid {
    display: grid;
    gap: 12px;
}

label {
    display: grid;
    gap: 6px;
    font-size: 0.92rem;
    font-weight: 600;
}

input,
textarea,
button {
    font: inherit;
}

input,
textarea {
    width: 100%;
    border: 1px solid #bfd0de;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fbfdff;
}

textarea {
    resize: vertical;
}

.actions {
    margin-top: 16px;
    display: grid;
    gap: 8px;
}

button {
    border: 0;
    border-radius: 10px;
    padding: 11px 14px;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, #007f8b, #005f68);
    font-weight: 700;
}

.print-hint {
    color: #4d6274;
    line-height: 1.45;
}

.preview-zone {
    display: grid;
    align-content: start;
    justify-content: center;
    gap: 18mm;
    padding: 14px;
}

.pvc-card {
    width: 86mm;
    height: 54mm;
    border-radius: 4mm;
    overflow: hidden;
    position: relative;
    box-shadow: var(--card-shadow);
    background: #fff;
}

.card-template-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    opacity: 0.95;
}

.overlay {
    position: absolute;
    inset: 0;
}

.front-overlay {
    padding: 4mm;
}

.lab-title,
.back-title {
    font-size: 2.85mm;
    font-weight: 800;
    letter-spacing: 0.2px;
    color: #00394e;
}

.patient-name {
    margin-top: 1.8mm;
    font-size: 3.8mm;
    font-weight: 800;
    max-width: 52mm;
}

.meta-line {
    margin-top: 1.1mm;
    font-size: 2.5mm;
    max-width: 55mm;
}

.meta-line span {
    font-weight: 600;
}

.blood-big {
    position: absolute;
    right: 6mm;
    top: 20mm;
    font-size: 11mm;
    font-weight: 900;
    color: #9b0014;
    line-height: 1;
}

.lab-logo {
    position: absolute;
    top: 3mm;
    right: 4mm;
    width: 14mm;
    height: 14mm;
    border-radius: 2mm;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.85);
    padding: 0.8mm;
}

.patient-photo {
    position: absolute;
    left: 58mm;
    top: 20mm;
    width: 20mm;
    height: 24mm;
    object-fit: cover;
    border-radius: 2mm;
    border: 0.4mm solid rgba(255, 255, 255, 0.9);
}

.qr-box {
    position: absolute;
    width: 16mm;
    height: 16mm;
    padding: 0.6mm;
    background: rgba(255, 255, 255, 0.93);
    border-radius: 1.2mm;
}

.front-overlay .qr-box {
    right: 4mm;
    bottom: 4mm;
}

.back-overlay {
    padding: 4mm;
}

.back-contact,
.back-address,
.back-specialties {
    margin-top: 1.8mm;
    font-size: 2.45mm;
    line-height: 1.35;
    max-width: 58mm;
}

.back-overlay .qr-box {
    right: 4mm;
    bottom: 4mm;
}

@media (max-width: 1024px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .preview-zone {
        justify-content: start;
        overflow-x: auto;
    }
}

@media print {
    /* CR80 final size: 86mm x 54mm. Keep orientation implicit to avoid driver rotation issues. */
    @page {
        size: 86mm 54mm;
        margin: 0;
    }

    html,
    body {
        width: 86mm;
        min-width: 86mm;
        max-width: 86mm;
        margin: 0;
        padding: 0;
        background: #fff !important;
        overflow: hidden !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Print only card area: hide everything first, then reveal print root. */
    body * {
        visibility: hidden !important;
    }

    .print-root,
    .print-root * {
        visibility: visible !important;
    }

    .print-root {
        position: absolute;
        left: 0;
        top: 0;
        padding: 0;
        margin: 0;
        display: block !important;
        width: 86mm !important;
    }

    .pvc-card {
        width: 86mm !important;
        height: 54mm !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        overflow: hidden !important;
        page-break-inside: avoid;
        break-inside: avoid;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }

    /* Force recto and verso on two distinct pages. */
    .front-card {
        page-break-after: always;
        break-after: page;
    }

    .back-card {
        page-break-after: auto;
        break-after: auto;
    }
}
