/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    background: white;
    padding: 30px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.header-logo {
    width: 200px;
    height: auto;
    margin-bottom: 20px;
}

header h1 {
    color: #333;
    font-size: 2rem;
    margin-bottom: 10px;
}

header p {
    color: #666;
    font-size: 1rem;
}

/* Control Panel */
.control-panel {
    background: white;
    padding: 30px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.control-panel h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    color: #555;
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.button-group {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

button {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    background: #dc2626;
    color: white;
}

button:hover {
    background: #b91c1c;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.print-btn {
    background: #48bb78;
}

.print-btn:hover {
    background: #38a169;
}

button[onclick="clearForm()"] {
    background: #718096;
}

button[onclick="clearForm()"]:hover {
    background: #4a5568;
}

/* Preview Section */
.preview-section {
    background: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.preview-section h2 {
    color: #333;
    margin-bottom: 10px;
}

.print-hint {
    color: #666;
    font-size: 0.9rem;
    font-style: italic;
}

/* Print Area - Screen View */
.print-area {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
}

/* A4 Page Layout - Landscape */
.a4-page {
    width: 29.7cm;
    min-height: 21cm;
    margin: 0 auto;
    background: white;
    padding: 1cm 0.75cm;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);

    /* Grid for labels: 3 columns × 2 rows */
    display: grid;
    grid-template-columns: repeat(3, 9.4cm);
    grid-template-rows: repeat(2, 9.5cm);
    gap: 0.5cm 0.4cm;
    justify-content: center;
}

/* Individual Label Styles */
.label {
    width: 9.4cm;
    height: 9.5cm;
    border: 2px solid #333;
    padding: 0.25cm;
    background: white;
    display: flex;
    flex-direction: column;
    position: relative;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    border-radius: 5px;
    overflow: hidden;
    transition: opacity 0.3s ease;
}

/* Label Top Section */
.label-top {
    text-align: center;
    margin-bottom: 0.2cm;
}

.product-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.product-name {
    font-size: 1.1rem;
    font-weight: bold;
    color: #dc2626;
    margin-top: 0.1cm;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Logo Section */
.logo-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0.2cm 0;
}

.logo {
    width: 2.5cm;
    height: auto;
    opacity: 0.9;
}

.est-date {
    font-size: 0.6rem;
    color: #000;
    margin-top: 0.1cm;
    font-weight: normal;
}

/* QR Code styles moved to qrcode-section */

/* Date Section */
.date-section {
    text-align: center;
    margin: 0.2cm 0;
    padding: 0.1cm 0;
}

.empacado-label {
    font-size: 0.6rem;
    font-weight: normal;
    color: #000;
}

.pack-date {
    font-size: 0.8rem;
    font-weight: bold;
    color: #000;
    margin-left: 0.2cm;
}

/* Label Content */
.label-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.65rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin: 0.1cm 0;
    padding: 0.05cm 0;
}

.label-field {
    font-weight: normal;
    color: #000;
    font-size: 0.6rem;
}

.label-value {
    font-weight: bold;
    color: #000;
    font-size: 0.7rem;
}

/* Refrigeration Info */
.refrigeration-info {
    margin-top: auto;
    padding: 0.15cm;
    font-size: 0.55rem;
    line-height: 1.3;
}

.caducidad-ref,
.caducidad-cong {
    font-weight: normal;
    color: #000;
}

.ref-date,
.cong-date {
    font-weight: bold;
    color: #000;
    margin-bottom: 0.05cm;
}

/* Print Styles */
@media print {
    body {
        margin: 0;
        padding: 0;
        background: white;
        height: 21cm;
        overflow: hidden;
        /* Force single page */
        page-break-after: avoid !important;
        page-break-before: avoid !important;
    }

    .container {
        max-width: none;
        margin: 0;
        padding: 0;
        /* Force single page */
        page-break-after: avoid !important;
        page-break-before: avoid !important;
        page-break-inside: avoid !important;
    }

    /* Hide everything except the print area */
    header,
    .control-panel,
    .preview-section,
    .print-hint {
        display: none !important;
    }

    .print-area {
        padding: 0;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        background: white;
        height: 21cm;
        overflow: hidden;
        /* Force single page */
        page-break-after: avoid !important;
        page-break-before: avoid !important;
        page-break-inside: avoid !important;
    }

    /* A4 Page for printing - Landscape */
    .a4-page {
        width: 29.7cm !important;
        height: 21cm !important;
        margin: 0 !important;
        padding: 1cm 0.75cm !important;
        box-shadow: none;
        /* Force single page */
        page-break-after: avoid !important;
        page-break-before: avoid !important;
        page-break-inside: avoid !important;
        /* Reset any transforms applied for mobile view */
        transform: none !important;
        transform-origin: unset !important;
        margin-bottom: 0 !important;
        /* Ensure proper grid layout for labels */
        display: grid !important;
        grid-template-columns: repeat(3, 9.4cm) !important;
        grid-template-rows: repeat(2, 9.5cm) !important;
        gap: 0.5cm 0.4cm !important;
        justify-content: center !important;
    }

    /* Label adjustments for print */
    .label {
        width: 9.4cm;
        height: 9.5cm;
        border: 2px solid #333;
        /* Force labels to stay on same page */
        page-break-inside: avoid !important;
        page-break-after: avoid !important;
        page-break-before: avoid !important;
        border-radius: 5px;
        opacity: 1 !important;
    }

    /* Print-specific label content adjustments */
    /* No longer needed - base styles now match print requirements */

    @page {
        size: A4 landscape;
        margin: 0;
    }

    /* Force maximum one page */
    @page :first {
        margin: 0;
    }

    @page :left {
        display: none;
    }

    @page :right {
        display: none;
    }

    .logo {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .button-group {
        flex-direction: column;
    }

    .print-area {
        overflow-x: scroll;
    }

    .a4-page {
        transform: scale(0.5);
        transform-origin: top left;
        margin-bottom: -50%;
    }
}

/* New Label Styles */
.label-header {
    display: flex;
    align-items: center;
    gap: 0.5cm;
    padding-bottom: 0.2cm;
}

.label-header-logo {
    text-align: center;
    padding: 0.05cm 0;
}

.logo-header {
    height: 1.6cm;
    width: auto;
}

.header-left {
    flex-shrink: 0;
}

.logo-compact {
    height: 1.8cm;
    width: auto;
}

.header-right {
    flex: 1;
    text-align: left;
}

.header-right .product-label {
    font-size: 0.55rem;
    color: #666;
    font-weight: 600;
    letter-spacing: 1px;
    display: block;
}

.header-right .product-name {
    font-size: 1rem;
    color: #dc2626;
    font-weight: bold;
    margin: 0;
    text-transform: uppercase;
    line-height: 1.2;
}

.product-section {
    text-align: center;
    padding: 0.15cm 0;
    margin-bottom: 0.1cm;
}

.product-section .product-label {
    font-size: 0.5rem;
    color: #666;
    font-weight: 600;
    letter-spacing: 1px;
    display: block;
    text-transform: uppercase;
}

.product-section .product-name {
    font-size: 0.95rem;
    color: #dc2626;
    font-weight: bold;
    margin: 0.05cm 0 0 0;
    text-transform: uppercase;
    line-height: 1.1;
}

.label-divider {
    height: 3px !important;
    min-height: 3px !important;
    background: #dc2626 !important; /* Solid fallback color */
    background: linear-gradient(to right, #dc2626, #991b1b) !important;
    margin: 0.15cm 0 0.1cm 0 !important;
    width: 100% !important;
    display: block !important;
    box-sizing: border-box !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.label-body {
    display: flex;
    gap: 0.3cm;
    margin: 0.2cm 0;
    flex: 1;
}

.body-left,
.body-right {
    flex: 1;
}

.label-body-single {
    margin: 0.2cm 0;
    flex: 1;
}

.label-body-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.3cm;
    margin: 0.15cm 0 0.25cm 0;
    padding: 0.15cm 0;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 0.15cm;
    flex: 1;
    justify-content: center;
}

.info-item > div {
    text-align: center;
}

.info-item .info-label {
    display: block;
    font-size: 0.45rem;
    color: #666;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}

.info-item .info-value {
    display: block;
    font-size: 0.75rem;
    color: #000;
    font-weight: bold;
}

.info-item .info-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.info-group {
    display: flex;
    align-items: flex-start;
    gap: 0.2cm;
    margin-bottom: 0.15cm;
}

.info-icon {
    font-size: 0.8rem;
    width: 0.6cm;
    flex-shrink: 0;
}

.info-group > div {
    flex: 1;
}

.info-label {
    display: block;
    font-size: 0.5rem;
    color: #666;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    display: block;
    font-size: 0.7rem;
    color: #000;
    font-weight: bold;
    margin-top: 1px;
}

.expiration-section {
    display: flex;
    gap: 0.2cm;
    margin: 0.2cm 0;
}

.exp-box {
    flex: 1;
    padding: 0.15cm;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.15cm;
}

.exp-box.refrigeracion {
    border: 1px solid #ddd;
}

.exp-box.congelacion {
    border: 1px solid #ddd;
}

.exp-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.exp-box > div {
    flex: 1;
    text-align: center;
}

.exp-label {
    display: block;
    font-size: 0.45rem;
    color: #333;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: center;
}

.exp-date {
    display: block;
    font-size: 0.75rem;
    font-weight: bold;
    color: #000;
    margin-top: 1px;
    text-align: center;
}

.qrcode-section {
    margin-top: 0.2cm;
    text-align: center;
    padding: 0.1cm;
    display: flex;
    justify-content: center;
    align-items: center;
}

.qrcode {
    width: 2cm !important;
    height: 2cm !important;
}

.qrcode img,
.qrcode canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    max-width: 2cm;
    max-height: 2cm;
}

/* QR Code implementation - no special fonts needed */

/* Label Selection Styles */
.selection-section {
    margin-top: 20px;
    padding: 15px;
    background: #f8f8f8;
    border-radius: 5px;
    border: 1px solid #e0e0e0;
}

.selection-section h3 {
    color: #333;
    font-size: 1rem;
    margin-bottom: 15px;
    font-weight: 600;
}

.label-checkboxes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.checkbox-label:hover {
    background: #f0f0f0;
    border-color: #dc2626;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.checkbox-label input[type="checkbox"]:checked {
    accent-color: #dc2626;
}

.checkbox-label span {
    font-size: 0.9rem;
    color: #555;
    user-select: none;
}

.selection-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.selection-buttons button {
    padding: 8px 16px;
    font-size: 0.85rem;
    background: #666;
    color: white;
}

.selection-buttons button:hover {
    background: #555;
}

.selection-info {
    text-align: center;
    padding: 8px;
    background: white;
    border-radius: 4px;
    border: 1px solid #ddd;
}

#selectionCount {
    color: #dc2626;
    font-weight: 600;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .label-checkboxes {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Override mobile styles specifically for print to ensure proper A4 format */
@media print and (max-width: 768px) {
    .print-area {
        overflow: visible !important;
        padding: 0 !important;
    }

    .a4-page {
        /* Reset all mobile transforms for printing */
        transform: none !important;
        margin-bottom: 0 !important;
    }

    /* Ensure all labels are at full opacity when printing from mobile */
    .label {
        opacity: 1 !important;
    }
}