@page {
    size: A4 portrait;
    margin: 8mm;
}

.print-toolbar {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.25rem;
    background: #ffffff;
    border-bottom: 1px solid #e3e8ef;
    position: sticky;
    top: 0;
    z-index: 20;
}

.print-toolbar .tb-back {
    color: #1d6fbf;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.print-toolbar .tb-back:hover { text-decoration: underline; }

/* Export dropdown */
.export-wrap { position: relative; }

.export-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    background: #1d6fbf;
    border: 1px solid #175a9c;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.15s;
}

.export-btn:hover { background: #175a9c; }
.export-wrap.open .caret { transform: rotate(180deg); }
.export-btn .caret { transition: transform 0.15s; font-size: 0.75rem; }

.export-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 190px;
    background: #fff;
    border: 1px solid #e3e8ef;
    border-radius: 9px;
    box-shadow: 0 8px 24px rgba(16,24,40,.14), 0 2px 6px rgba(16,24,40,.08);
    padding: 5px;
    z-index: 30;
}

.export-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.55rem 0.7rem;
    font-size: 0.88rem;
    color: #1c2733;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
}

.export-item:hover { background: #eaf3fc; color: #175a9c; }
.export-item .ei-ico { font-size: 1rem; width: 1.2rem; text-align: center; }

.export-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10;
    background: transparent;
}

/* ── The A4 sheet ─────────────────────────────────────── */
.ts-sheet {
    width: 194mm;
    margin: 8mm auto;
    padding: 4mm;
    background: #fff;
    color: #000;
    font-family: "Times New Roman", "TH Sarabun New", serif;
    font-size: 8.5pt;
    line-height: 1.15;
}

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

/* merge the seam between stacked tables */
table.ts.stack,
table.ts.inner {
    margin-top: -1px;
}

.ts td {
    border: 1px solid #000;
    padding: 2px 4px;
    vertical-align: middle;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.18;
}

/* Title band */
.ts .title {
    background: #c6e0b4;
    text-align: center;
    font-weight: bold;
    vertical-align: middle;
}

.ts .title .t1 { font-size: 15pt; letter-spacing: 1px; }
.ts .title .t2 { font-size: 13pt; margin-top: 2px; }

/* Green header cells */
.ts .green {
    background: #c6e0b4;
    font-weight: bold;
    text-align: center;
}

/* Field labels */
.ts .lbl {
    font-weight: bold;
    font-size: 7.5pt;
}

/* Value cells */
.ts .val {
    min-height: 14px;
    font-weight: normal;
}

.ts .val.c { text-align: center; }
.ts .sig { height: 34px; text-align: center; vertical-align: middle; }

.ts .unit { font-size: 7pt; }
.ts .hint { font-size: 6.5pt; font-weight: normal; font-style: italic; }

/* Vertical section labels */
.ts .vert {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    text-align: center;
    vertical-align: middle;
    font-weight: bold;
    font-size: 7.5pt;
    white-space: nowrap;
    background: #f2f2f2;
}

.ts .vert.sub {
    background: #fff;
    font-size: 7pt;
}

/* Body split panes hold nested tables edge-to-edge */
.body-split > tbody > tr > td.pane {
    border: none;
    padding: 0;
    vertical-align: top;
}

.body-split > tbody > tr > td.pane:first-child { border-right: 1px solid #000; }

/* Flare diagram */
.ts .diagram { text-align: center; vertical-align: middle; padding: 2px; }
.ts .tc-photo { width: 100%; height: auto; max-height: 80px; display: block; margin: 0 auto; }

/* Sketch boxes */
.ts .sketchbox {
    height: 44mm;
    vertical-align: top;
    position: relative;
    text-align: center;
}

.ts .sketchbox .lbl.left { text-align: left; display: block; }

.ts .sketchbox img {
    max-width: 100%;
    max-height: 40mm;
    display: block;
    margin: 1mm auto 0;
}

/* BEFORE BENDING photo + editable number overlay */
.ts .bb-figure {
    position: relative;
    display: block;
    width: 100%;
    line-height: 0;
    margin-top: 1mm;
}

.ts .bb-photo {
    width: 100%;
    height: auto;
    display: block;
}

/* white box sits over the printed "1082" box; shows the entered value */
.ts .bb-num {
    position: absolute;
    left: 22.5%;
    top: 68%;
    width: 26%;
    height: 20%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    font-family: "Times New Roman", serif;
    font-size: 13pt;
    line-height: 1;
    color: #000;
}

/* Record table */
.ts .rechead td {
    background: #f2f2f2;
    font-weight: bold;
    text-align: center;
    font-size: 7.5pt;
}

.ts-footer {
    margin-top: 2mm;
    font-size: 7.5pt;
    font-weight: bold;
}

/* ── Print ─────────────────────────────────────────────── */
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .ts-sheet {
        width: auto;
        margin: 0;
        padding: 0;
    }
    /* keep the green backgrounds when printing */
    .ts .title,
    .ts .green {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
