@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;700&display=swap');

body {
    margin: 0;
    padding: 0;
    background-color: #f0f0f0;
    font-family: 'Sarabun', sans-serif;
}

.dashboard-container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
    background: white;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.hidden {
    display: none !important;
}

/* ... existing styles ... */

.control-bar {
    background: #333;
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.filter-form label {
    margin-right: 10px;
}

.filter-form select {
    padding: 5px;
    border-radius: 4px;
}

.btn-print {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.btn-print:hover {
    background: #45a049;
}

.a4-page {
    width: 210mm;
    min-height: 297mm;
    background: white;
    margin: 20px auto;
    padding: 10mm;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

.order-card {
    width: 48%; /* Leave gap */
    height: 130mm; /* Fixed height for 2x2 layout */
    display: inline-block;
    vertical-align: top;
    box-sizing: border-box;
    border: 1px solid #000;
    padding: 15px;
    margin-bottom: 5mm; 
    margin-right: 1%;
    position: relative;
    page-break-inside: avoid;
}

.header {
    border-bottom: 2px solid #333;
    padding-bottom: 5px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.date {
    font-size: 12px;
}

/* Info Grid */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2 columns for better density */
    gap: 4px;
    margin-bottom: 10px;
}

.info-item {
    font-size: 14px;
}

.label {
    font-weight: bold;
    margin-right: 5px;
}

.prescription-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 14px;
}

.prescription-table th, .prescription-table td {
    border: 1px solid #999;
    padding: 6px;
    text-align: center;
}

.prescription-table th {
    background-color: #eee;
    font-weight: bold;
}

.note-row {
    margin-top: 10px;
    background: #f9f9f9;
    padding: 5px;
    border-radius: 4px;
    font-size: 14px;
}

.note {
    color: #cc0000;
    font-weight: bold;
}

.alien-flag {
    color: red;
    font-weight: bold;
    margin-left: 5px;
}

.info-item.full-width {
    grid-column: 1 / -1;
}

.header-right {
    text-align: right;
}

.hn {
    font-weight: bold;
    font-size: 14px;
}

@media print {
    @page {
        margin: 0; /* Removing margins usually hides browser headers/footers */
        size: auto;
    }

    .no-print {
        display: none !important;
    }

    body {
        margin: 0;
        background: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .a4-page {
        width: 210mm;
        height: 297mm;
        margin: 0;
        box-shadow: none;
        padding: 5mm; /* 5mm padding around the page */
        position: relative; /* For absolute positioning of cut lines */
        page-break-after: always; /* Force new page after each block */
        box-sizing: border-box;
        overflow: hidden; /* Prevent spillover */
    }
    .order-card {
        width: calc(50% - 1mm); /* 2 columns with small gap */
        height: calc(50% - 1mm); /* 2 rows */
        float: left;
        margin-right: 2mm; 
        margin-bottom: 2mm;
        border: 1px solid #000;
        break-inside: avoid;
        box-sizing: border-box;
        padding: 10px;
    }
    /* Remove margins for the last item in row/column to fit perfectly */
    .order-card:nth-child(even) {
        margin-right: 0;
    }
    
    /* Cut Lines */
    .cut-line-horizontal {
        position: absolute;
        top: 50%;
        left: 0;
        width: 100%;
        border-top: 1px dashed #999;
        z-index: 10;
        pointer-events: none;
    }
    .cut-line-vertical {
        position: absolute;
        top: 0;
        left: 50%;
        height: 100%;
        border-left: 1px dashed #999;
        z-index: 10;
        pointer-events: none;
    }
}
