@import url('https://fonts.googleapis.com/css2?family=Sarabun:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800&display=swap');

@font-face {
    font-family: "TH Sarabun New";
    src: local("TH Sarabun New"), local("TH Sarabun PSK"), local("Sarabun");
}

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

* {
    box-sizing: border-box;
}

body {
    background: #e8e8e8;
    color: #000;
    font-family: "TH Sarabun New", "Sarabun", Arial, sans-serif;
    font-size: 12.5px;
    line-height: 1.1;
    margin: 0;
}

.a4-sheet {
    margin: 10px auto;
    width: 210mm;
}

.paper-form {
    background: #fff;
    border: 1px solid #111;
    min-height: 297mm;
    padding: 6mm;
}

/* Header Section */
.paper-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
    padding-bottom: 0;
}

.header-left {
    flex: 0 0 75px;
}

.company-logo {
    width: 65px;
    height: 65px;
    object-fit: contain;
}

.header-center {
    flex: 1;
    text-align: center;
    padding: 0 10px;
}

.header-center .company-name {
    font-size: 20px;
    font-weight: bold;
    color: #000;
    margin-bottom: 4px;
}

.header-center .form-title {
    font-size: 14.5px;
    font-weight: bold;
    color: #000;
}

.header-right {
    flex: 0 0 190px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.cp-stamp {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 52px;
    font-weight: bold;
    color: #0044cc; /* Rich blue ink color */
    line-height: 0.9;
    letter-spacing: -2px;
}

.doc-meta-container {
    text-align: right;
}

.fixed-doc-meta {
    font-family: Arial, sans-serif;
    font-size: 10px;
    line-height: 1.3;
    text-align: right;
    margin-bottom: 2px;
}

.form-no {
    font-size: 12px;
    font-weight: bold;
    border-bottom: 0;
    padding-top: 0;
    text-align: right;
}

/* Top Fields Section */
.top-fields-section {
    margin-bottom: 12px;
    padding: 5px 0;
}

.line-row {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    min-height: 20px;
    font-size: 13.5px;
}

.line-row .field-label {
    white-space: nowrap;
    font-size: 13.5px;
}

.line-row .field-value {
    border-bottom: 1px dotted #000;
    display: inline-block;
    font-weight: bold;
    min-height: 17px;
    padding: 0 4px;
    line-height: 1.1;
    font-size: 14.5px;
}

/* Specific field widths for Row 1 */
.val-farm-reg {
    flex: 1 1 120px;
}
.val-farm-no {
    flex: 1 1 100px;
}
.val-day {
    flex: 0 0 35px;
    text-align: center;
}
.val-month {
    flex: 0 0 35px;
    text-align: center;
}
.val-year {
    flex: 0 0 35px;
    text-align: center;
}
.val-shift {
    flex: 0 0 30px;
    text-align: center;
}

/* Bottom Container (2 Rows + Checkboxes) */
.bottom-fields-container {
    display: flex;
    gap: 15px;
    margin-top: 6px;
}

.info-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-column .line-row {
    margin-bottom: 0;
}

.val-driver {
    flex: 1 1 150px;
}
.val-plate {
    flex: 1 1 100px;
}
.val-farm-name {
    flex: 1 1 150px;
}
.val-sex {
    flex: 1 1 100px;
}

.checkbox-column {
    flex: 0 0 240px;
    display: flex;
    align-items: center;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 10px;
    width: 100%;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.box {
    border: 1px solid #000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: Arial, sans-serif;
    font-size: 11px;
    font-weight: bold;
    height: 14px;
    width: 14px;
    flex-shrink: 0;
    background: transparent;
}

.checkbox-label {
    white-space: nowrap;
    font-size: 12.5px;
}

/* "อื่นๆ" row: overlay custom text on top of dotted line */
.other-dots-wrap {
    display: inline-block;
    position: relative;
    vertical-align: bottom;
}

.other-dots {
    display: inline-block;
    color: #aaa;
    letter-spacing: 0;
}

.other-text {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-weight: 600;
    font-size: 12.5px;
    color: #000;
    background: transparent;
    padding: 0 2px;
    line-height: 1.1;
}


.section-caption {
    border: 0;
    font-weight: 700;
    padding: 4px 0;
}

.part1-layout + .section-caption,
.part2-table + .section-caption {
    margin-top: 4mm;
}

.caption-split {
    position: relative;
    text-align: center;
}

.caption-split .caption-part {
    position: absolute;
    left: 0;
    font-weight: 700;
}

.part1-layout {
    display: grid;
    gap: 3px;
    grid-template-columns: 1fr 44mm;
    margin-bottom: 3px;
}

.paper-table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
}

.paper-table th,
.paper-table td {
    border: 1px solid #000;
    padding: 3px 5px;
    vertical-align: middle;
    line-height: 1.25;
}

.paper-table th {
    background: #f2f2f2;
    font-weight: 700;
    text-align: center;
}

.paper-table td {
    text-align: center;
}

.paper-table td:first-child {
    text-align: left;
}

.part1-table th:nth-child(1),
.part1-table td:nth-child(1) {
    width: 33%;
}

.part1-table th:nth-child(2),
.part1-table td:nth-child(2) {
    width: 25%;
}

.part1-table th:nth-child(3),
.part1-table td:nth-child(3) {
    width: 18%;
}

.part1-table th:nth-child(4),
.part1-table td:nth-child(4) {
    width: 24%;
}

.side-table {
    border: 1px solid #000 !important;
    border-collapse: collapse;
}

.side-table-cell {
    border: 0 !important;
    display: flex;
    align-items: flex-end;
    padding: 2.8px 5px !important;
    min-height: 22px;
}

.side-table-cell .side-label {
    font-weight: 700;
    white-space: nowrap;
}

.side-table-cell .side-value {
    border-bottom: 1px dotted #000;
    flex: 1;
    text-align: center;
    margin-left: 6px;
    margin-right: 6px;
    font-weight: bold;
    min-height: 15px;
    line-height: 1.1;
}

.side-table-cell .side-unit {
    font-weight: 700;
    white-space: nowrap;
}

.no-col {
    width: 10mm;
}

/* Part 2 Table Column Widths */
.part2-table th:nth-child(1),
.part2-table td:nth-child(1) {
    width: 42%;
}
.part2-table th:nth-child(2),
.part2-table td:nth-child(2) {
    width: 8%;
}
.part2-table th:nth-child(3),
.part2-table td:nth-child(3) {
    width: 14%;
}
.part2-table th:nth-child(4),
.part2-table td:nth-child(4) {
    width: 20%;
}
.part2-table th:nth-child(5),
.part2-table td:nth-child(5) {
    width: 16%;
}

/* Part 3 Table Column Widths */
.part3-table th:nth-child(1),
.part3-table td:nth-child(1) {
    width: 42%;
}
.part3-table th:nth-child(2),
.part3-table td:nth-child(2) {
    width: 8%;
}
.part3-table th:nth-child(3),
.part3-table td:nth-child(3) {
    width: 14%;
}
.part3-table th:nth-child(4),
.part3-table td:nth-child(4) {
    width: 16%;
}
.part3-table th:nth-child(5),
.part3-table td:nth-child(5) {
    width: 12%;
}
.part3-table th:nth-child(6),
.part3-table td:nth-child(6) {
    width: 8%;
}

.part3-table {
    margin-bottom: 9mm;
}

.penalty-val-cell {
    height: 25px;
    text-align: center;
}

.signature-grid {
    display: grid;
    gap: 12mm;
    grid-template-columns: repeat(3, 1fr);
    text-align: center;
}

.signature-block {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.signature-title {
    font-size: 13.5px;
    margin-bottom: 24px;
}

.signature-draw-line {
    width: 85%;
    border-bottom: 1px dotted #000;
    margin-bottom: 8px;
}

.signature-name-line {
    width: 85%;
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.signature-name-line .bracket {
    font-size: 13.5px;
}

.signature-name-line .name-text-wrapper {
    flex: 1;
    border-bottom: 1px dotted #000;
    position: relative;
    height: 15px;
    margin: 0 2px;
}

.signature-name-line .name-text {
    position: absolute;
    bottom: -3px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 0 6px;
    font-size: 13.5px;
    white-space: nowrap;
}

.signature-position {
    font-size: 13.5px;
}

.preview-toolbar {
    background: #fff;
    border-bottom: 1px solid #ccc;
    display: flex;
    gap: 8px;
    justify-content: center;
    padding: 8px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.preview-toolbar a,
.preview-toolbar button {
    background: #fff;
    border: 1px solid #222;
    color: #000;
    cursor: pointer;
    font: 14px Arial, sans-serif;
    padding: 6px 12px;
    text-decoration: none;
}

.text-center {
    text-align: center;
}

@media print {
    body {
        background: #fff;
        font-size: 11.5px;
    }

    .no-print,
    .preview-toolbar {
        display: none !important;
    }

    .a4-sheet {
        margin: 0 auto !important;
        width: 210mm !important;
        height: 297mm !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .paper-form {
        border: 0 !important;
        width: 100% !important;
        height: 100% !important;
        min-height: 297mm !important;
        padding: 6mm !important;
    }

    .paper-header {
        margin-bottom: 0 !important;
        padding-bottom: 0 !important;
    }

    .company-logo {
        width: 55px !important;
        height: 55px !important;
    }

    .cp-stamp {
        font-size: 44px !important;
    }

    .top-fields-section {
        margin-bottom: 6px !important;
        padding: 2px 0 !important;
    }

    .line-row {
        font-size: 11.5px !important;
        min-height: 18px !important;
    }

    .line-row .field-value {
        font-size: 12.5px !important;
        min-height: 15px !important;
    }

    .checkbox-label {
        font-size: 11px !important;
    }

    .box {
        width: 13px !important;
        height: 13px !important;
        font-size: 10px !important;
    }

    .paper-table th,
    .paper-table td {
        padding: 1.8px 4px !important;
        line-height: 1.15 !important;
    }

    .side-table td,
    .side-table th {
        padding: 1.8px 5px !important;
    }

    .side-table-cell {
        min-height: 17px !important;
        padding: 1.8px 5px !important;
    }

    .penalty-val-cell {
        height: 20px !important;
    }

    .section-caption {
        padding: 1px 0 !important;
    }

    .part1-layout + .section-caption,
    .part2-table + .section-caption {
        margin-top: 3mm !important;
    }

    .part3-table {
        margin-bottom: 3mm !important;
    }

    .signature-grid {
        gap: 6mm !important;
        margin-top: 5px !important;
    }

    .signature-title {
        font-size: 11.5px !important;
        margin-bottom: 18px !important;
    }

    .signature-draw-line {
        margin-bottom: 6px !important;
    }

    .signature-name-line {
        margin-bottom: 4px !important;
    }

    .signature-name-line .bracket {
        font-size: 11.5px !important;
    }

    .signature-name-line .name-text-wrapper {
        height: 12px !important;
    }

    .signature-name-line .name-text {
        bottom: -2px !important;
        font-size: 11.5px !important;
        padding: 0 4px !important;
    }

    .signature-position {
        font-size: 11.5px !important;
    }

    .paper-table th,
    .paper-table td,
    .top-grid,
    .section-caption,
    .summary-grid {
        border-color: #000 !important;
    }

    .app-container {
        display: block !important;
    }

    .main-content {
        padding: 0 !important;
        background: transparent !important;
    }

    /* "อื่นๆ" overlay — keep consistent in print */
    .other-dots {
        color: #aaa !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .other-text {
        font-size: 11.5px !important;
        color: #000 !important;
    }
}
