/* Formal document sheet — compact layout */
.doc-sheet {
    background: #fff;
    color: #0f172a;
    font-size: .82rem;
    line-height: 1.35;
}
.doc-sheet-print {
    padding: 10mm 10mm;
    min-height: 277mm;
    box-shadow: 0 4px 24px rgba(15, 23, 42, .12);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}
/* หน้าจอ preview: ดัน footer ลงล่าง */
.doc-sheet-print .doc-sheet-items-wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.doc-sheet-print .doc-sheet-table {
    flex: 0 0 auto;
    width: 100%;
    margin: 0 !important;
}
.doc-sheet-print .doc-sheet-items-spacer {
    flex: 1 1 auto;
    min-height: 1rem;
}
.doc-sheet-print .doc-sheet-bottom {
    flex-shrink: 0;
    margin-top: auto;
    padding-top: .45rem;
}
.doc-sheet-print .doc-sheet-bottom .doc-sheet-summary {
    margin-top: 0;
}
.demo-doc-preview .doc-sheet {
    border: none;
    padding: 0;
}
.doc-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    border-bottom: 2px solid #1e3a5f;
    padding-bottom: .55rem;
    margin-bottom: .65rem;
}
.doc-sheet-logo {
    max-height: 44px;
    max-width: 180px;
    object-fit: contain;
    margin-bottom: .35rem;
    display: block;
}
.doc-sheet-issuer-name {
    font-size: .95rem;
    font-weight: 700;
    color: #0f172a;
}
.doc-sheet-issuer-line {
    font-size: .74rem;
    color: #475569;
    margin-top: .1rem;
    line-height: 1.3;
}
.doc-sheet-title { text-align: right; min-width: 168px; flex-shrink: 0; }
.doc-sheet-type {
    font-size: 1.12rem;
    font-weight: 800;
    color: #1e3a5f;
    margin: 0 0 .2rem;
    letter-spacing: .02em;
}
.doc-sheet-type--dual {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .1rem;
    line-height: 1.15;
}
.doc-sheet-type--dual .doc-sheet-type-sub {
    font-size: .92em;
    font-weight: 700;
    color: #334155;
}
.doc-sheet-original {
    font-size: .72rem;
    font-weight: 600;
    color: #64748b;
    margin: 0 0 .25rem;
    letter-spacing: .04em;
}
.doc-sheet-meta-row {
    font-size: .76rem;
    display: flex;
    justify-content: flex-end;
    gap: .35rem;
    line-height: 1.35;
}
.doc-sheet-subject {
    margin-bottom: .45rem;
    padding: .35rem .55rem;
    background: #f8fafc;
    border-radius: 4px;
    font-size: .78rem;
}
.doc-sheet-parties {
    margin-bottom: .55rem;
    padding: .45rem .6rem;
    background: #fafbfc;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: .78rem;
}
.doc-sheet-parties--compact {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .15rem .35rem;
    padding: .35rem .55rem;
    background: #fafbfc;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: .78rem;
}
.doc-sheet-parties .doc-sheet-party-label {
    margin: 0 0 .2rem;
    font-size: .72rem;
    font-weight: 600;
    color: #64748b;
}
.doc-sheet-parties .doc-sheet-party-name {
    font-weight: 700;
    font-size: .88rem;
    margin-bottom: .15rem;
    line-height: 1.35;
}
.doc-sheet-parties .doc-sheet-party-line {
    font-size: .74rem;
    color: #475569;
    line-height: 1.45;
    margin-top: .1rem;
}
.doc-sheet-sum-note {
    font-size: .68rem;
    color: #64748b;
    margin: 0 0 .35rem;
    line-height: 1.35;
}
.doc-sheet-contact {
    overflow-wrap: anywhere;
    word-break: break-word;
}
.doc-sheet-issuer-line.doc-sheet-contact {
    overflow-wrap: anywhere;
    word-break: break-word;
}
.doc-sheet-parties .doc-sheet-party-address {
    white-space: normal;
    margin-top: .2rem;
}
.doc-sheet-parties--compact .doc-sheet-party-label {
    margin: 0;
    text-transform: none;
    letter-spacing: 0;
    font-size: .74rem;
}
.doc-sheet-parties--compact .doc-sheet-party-name {
    font-size: .84rem;
}
.doc-sheet-parties--compact .doc-sheet-party-meta {
    font-size: .72rem;
    color: #64748b;
}
.doc-sheet-parties--compact .doc-sheet-party-extra {
    width: 100%;
    font-size: .72rem;
    color: #64748b;
    line-height: 1.3;
}
.doc-sheet-party-label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #64748b;
    margin-bottom: .15rem;
}
.doc-sheet-party-name { font-weight: 700; font-size: .88rem; }
.doc-sheet-party-line { font-size: .76rem; color: #475569; }
.doc-sheet-table {
    font-size: .76rem;
    margin: .45rem 0 !important;
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #e8edf2;
}
.doc-sheet-table thead th {
    background: #f8fafc;
    font-weight: 600;
    border: 1px solid #e8edf2;
    border-bottom: 1px solid #dde4ec;
    padding: .28rem .4rem !important;
    font-size: .72rem;
    line-height: 1.25;
    vertical-align: middle;
    white-space: nowrap;
    color: #475569;
}
.doc-sheet-table td {
    border: none;
    border-bottom: 1px solid #eef2f6;
    vertical-align: top;
    padding: .28rem .4rem !important;
}
.doc-sheet-table tbody tr:last-child td {
    border-bottom: 1px solid #e8edf2;
}
.doc-item-detail {
    font-size: .7rem;
    color: #64748b;
    margin-top: .1rem;
    line-height: 1.3;
    white-space: pre-wrap;
    word-break: break-word;
}
.doc-sheet-summary {
    display: flex;
    justify-content: flex-end;
    margin-top: .45rem;
}
.doc-sheet-summary-box {
    min-width: 220px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: .4rem .6rem;
    background: #fafbfc;
}
.doc-sheet-sum-row {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    padding: .12rem 0;
    font-size: .78rem;
}
.doc-sheet-sum-before-disc {
    margin-top: .15rem;
    padding-top: .2rem;
    border-top: 1px dashed #cbd5e1;
    font-weight: 600;
    color: #334155;
}
.doc-sheet-sum-grand {
    margin-top: .25rem;
    padding-top: .3rem;
    border-top: 2px solid #1e3a5f;
    font-size: .88rem;
    color: #1e3a5f;
}
.doc-sheet-sum-thai {
    margin-top: .45rem;
    padding: .35rem .55rem;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    background: #f8fafc;
    font-size: .74rem;
    line-height: 1.4;
}
.doc-sheet-sum-thai-label {
    font-weight: 600;
    color: #475569;
    margin-right: .35rem;
    white-space: nowrap;
}
.doc-sheet-sum-thai-text {
    color: #0f172a;
}
.doc-sheet-notes {
    margin-top: .45rem;
    font-size: .74rem;
    color: #334155;
    line-height: 1.35;
}
.doc-sheet-notes + .doc-sheet-notes {
    margin-top: .25rem;
}
.doc-sheet-signatures {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.25rem;
    margin-top: 1.25rem;
    padding-top: .65rem;
}
.doc-sheet-signatures--issuer-only {
    display: flex;
    justify-content: flex-end;
    gap: 0;
}
.doc-sheet-signatures--issuer-only .doc-sig-block {
    width: 200px;
    max-width: 38%;
    min-height: 88px;
    flex-shrink: 0;
}
.doc-sheet-signatures--issuer-only .doc-sig-line {
    width: 100%;
}
.doc-sheet-signatures--issuer-only .doc-sig-space {
    height: 34px;
}
.doc-sig-block { text-align: center; min-height: 108px; }
.doc-sig-space {
    height: 40px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    margin-bottom: .15rem;
}
.doc-sheet-signatures--blank .doc-sig-space {
    height: 64px;
}
.doc-th-sub {
    font-weight: 400;
    font-size: .72em;
    opacity: .75;
}
.doc-sheet-signatures--blank.doc-sheet-signatures--issuer-only .doc-sig-space {
    height: 56px;
}
.doc-sig-img { max-height: 38px; max-width: 140px; object-fit: contain; }
.doc-sig-line {
    border-bottom: 1px solid #334155;
    margin: 0 auto .35rem;
    width: 85%;
}
.doc-sig-label { font-weight: 600; font-size: .76rem; }
.doc-sig-name { font-size: .74rem; margin-top: .1rem; }
.doc-sig-title { font-size: .7rem; color: #64748b; }
.doc-sig-date { font-size: .7rem; color: #64748b; margin-top: .25rem; }
.doc-sheet-footer {
    margin-top: .75rem;
    padding-top: .35rem;
    border-top: 1px solid #e2e8f0;
    text-align: center;
    font-size: .65rem;
    color: #94a3b8;
    letter-spacing: .01em;
    display: block;
    line-height: 1.45;
}
.doc-sheet-footer + .doc-platform-credit--print {
    margin-top: .2rem;
    padding-top: 0;
    border-top: none;
}
.issuer-sig-pad canvas {
    display: block;
    width: 100%;
    height: 120px;
    cursor: crosshair;
    touch-action: none;
}
@media print {
    /*
     * ดัน .doc-sheet-bottom (รวมเป็นเงิน → ลายเซ็น) ลงล่างหน้า
     * min-height = A4 ลบ margin @page (12mm บน+ล่าง) — ห้ามใส่ padding ซ้ำ
     */
    .doc-sheet-print {
        display: flex;
        flex-direction: column;
        min-height: calc(297mm - 24mm);
        padding: 0;
        box-shadow: none;
        border: none;
    }
    .doc-sheet-print .doc-sheet-items-wrap {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }
    .doc-sheet-print .doc-sheet-items-spacer {
        display: block;
        flex: 1 1 auto;
        min-height: 0;
    }
    .doc-sheet-print .doc-sheet-bottom {
        flex-shrink: 0;
        margin-top: auto;
        padding-top: .45rem;
    }
    .doc-sheet-signatures {
        margin-top: .85rem;
        page-break-inside: avoid;
    }
    .doc-sheet-sum-thai { background: #fff; }
    .doc-sheet-table thead th {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
