/* ═══════════════════════════════════════════════════════════════
   YOTATHAI — บัญชีค่าแรงงาน ว 480 (2569)
   Design: ราชการสมัยใหม่ · อ่านง่าย · เร็ว · พิมพ์ได้จริง
   ═══════════════════════════════════════════════════════════════ */

:root {
    --font: 'Sarabun', -apple-system, 'Segoe UI', Roboto, sans-serif;

    --navy-900: #0d2036;
    --navy-800: #14324f;
    --navy-700: #1c4368;
    --amber-500: #f0a500;
    --amber-600: #d99000;

    --bg: #f4f6f9;
    --bg-panel: #ffffff;
    --bg-soft: #eef2f6;
    --bg-hover: #f6f9fc;
    --border: #dde4ec;
    --border-strong: #c3cedb;
    --text: #1c2733;
    --text-soft: #5a6b7d;
    --text-faint: #8595a6;
    --accent: #14548c;
    --accent-soft: #e8f1f9;
    --amber-bg: #fff7e6;
    --amber-border: #f0d9a8;
    --amber-text: #7a5a00;
    --green: #1a7f4e;
    --red: #c0392b;
    --red-soft: #fdeeec;
    --shadow: 0 1px 3px rgba(13, 32, 54, .08), 0 4px 14px rgba(13, 32, 54, .05);
    --shadow-lg: 0 8px 40px rgba(13, 32, 54, .18);
    --radius: 10px;
    --radius-sm: 7px;
}

[data-theme="dark"] {
    --bg: #0f1720;
    --bg-panel: #17222e;
    --bg-soft: #1d2a38;
    --bg-hover: #1f2e3e;
    --border: #263646;
    --border-strong: #33465a;
    --text: #e6edf4;
    --text-soft: #9fb1c2;
    --text-faint: #6c7f92;
    --accent: #58a6dd;
    --accent-soft: #16283a;
    --amber-bg: #2a2110;
    --amber-border: #4d3d15;
    --amber-text: #e8bf66;
    --green: #4cc38a;
    --red: #e5695a;
    --red-soft: #331b18;
    --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, .5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ─────────── Buttons ─────────── */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    border-radius: var(--radius-sm);
    padding: 8px 14px; font-size: 14px; font-weight: 600;
    border: 1px solid transparent; transition: .15s;
    text-decoration: none; color: inherit; white-space: nowrap;
}
.btn-primary { background: var(--amber-500); border-color: var(--amber-600); color: #241a00; }
.btn-primary:hover { background: var(--amber-600); }
.btn-outline { background: var(--bg-panel); border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: #d7e3ee; border-color: rgba(255,255,255,.25); }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-danger { background: var(--red-soft); color: var(--red); border-color: var(--red); }
.btn.icon-only { padding: 8px; }
.mini-btn {
    background: var(--bg-soft); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 4px 10px; font-size: 14px; color: var(--text-soft);
}
.mini-link { background: none; border: none; color: var(--accent); font-size: 12.5px; text-decoration: underline; }
.danger-link { background: none; border: none; color: var(--red); font-size: 12.5px; text-decoration: underline; margin-top: 6px; }

/* ─────────── Topbar ─────────── */
.topbar { background: linear-gradient(135deg, var(--navy-900), var(--navy-800) 55%, var(--navy-700)); color: #fff; }
.topbar-inner {
    max-width: 1560px; margin: 0 auto; padding: 14px 20px;
    display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }
.brand-logo { width: 42px; height: 42px; border-radius: 9px; background: #fff; object-fit: contain; padding: 3px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 17px; }
.brand-text small { font-size: 11.5px; color: #b9cbdc; }
.doc-title { flex: 1; min-width: 260px; }
.doc-title h1 { font-size: 16.5px; font-weight: 700; line-height: 1.35; }
.doc-ref { font-size: 12.5px; color: #b9cbdc; margin-top: 2px; }
.doc-ref strong { color: var(--amber-500); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

[data-theme="light"] .icon-sun, :root:not([data-theme="dark"]) .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: block; }

/* ─────────── Search bar ─────────── */
.searchbar {
    background: var(--bg-panel); border-bottom: 1px solid var(--border);
    padding: 14px 20px 10px;
    position: sticky; top: 0; z-index: 40;
    box-shadow: var(--shadow);
}
.searchbar-inner { max-width: 1560px; margin: 0 auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.search-box {
    flex: 1; min-width: 260px; max-width: 720px;
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-soft); border: 1.5px solid var(--border-strong);
    border-radius: 12px; padding: 9px 14px; transition: .15s;
}
.search-box:focus-within { border-color: var(--accent); background: var(--bg-panel); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box svg { color: var(--text-faint); }
.search-box input {
    flex: 1; border: none; outline: none; background: transparent;
    font-size: 15.5px; color: var(--text);
}
.search-box input::-webkit-search-cancel-button { display: none; }
.clear-btn { background: var(--border); border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 11px; color: var(--text-soft); }
.search-kbd {
    border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px;
    padding: 1px 7px; font-size: 12px; color: var(--text-faint); font-family: inherit;
}
.result-stat { font-size: 13px; color: var(--text-soft); }
.result-stat strong { color: var(--accent); }

.section-chips {
    max-width: 1560px; margin: 10px auto 0;
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
    scrollbar-width: none;
}
.section-chips::-webkit-scrollbar { display: none; }
.chip {
    border: 1px solid var(--border-strong); background: var(--bg-panel);
    border-radius: 999px; padding: 5px 14px; font-size: 13px; font-weight: 600;
    color: var(--text-soft); white-space: nowrap; transition: .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
[data-theme="dark"] .chip.active { background: var(--accent); border-color: var(--accent); color: #08131d; }

/* ─────────── Layout (2 คอลัมน์: เนื้อหา + แผงข้าง ปรับความกว้างได้) ─────────── */
:root { --side-w: 340px; }
.layout {
    max-width: 1560px; margin: 18px auto; padding: 0 20px;
    display: grid; grid-template-columns: minmax(320px, 1fr) 18px minmax(280px, var(--side-w));
    align-items: start;
}
.panel-label {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 13px; font-weight: 700; letter-spacing: .2px; color: var(--text-soft);
    text-transform: uppercase; margin-bottom: 8px;
}

/* ─────────── ตัวลากปรับความกว้าง ─────────── */
.col-resizer {
    position: relative; cursor: col-resize; align-self: stretch;
    touch-action: none;
}
.col-resizer::before {
    content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px;
    background: var(--border-strong); border-radius: 2px; transition: background .12s, width .12s;
}
.col-resizer:hover::before, .col-resizer.dragging::before, .col-resizer:focus-visible::before {
    background: var(--accent); width: 3px; left: 7.5px;
}
.col-resizer.dragging { cursor: col-resize; }
.col-resizer.dragging ~ * { pointer-events: none; }

/* ─────────── แผงข้าง: แท็บ (หมวดหมู่งาน/กระดาษทด) + เนื้อหา ───────────
   .side-col คือ grid item เดียว (กันปัญหา CSS grid row-span กับคอลัมน์เนื้อหาที่ยาวมาก)
   ข้างในเป็น flex column ปกติ: แท็บ + แผง sticky ไปด้วยกัน */
.side-col {
    position: sticky; top: 86px; max-height: calc(100vh - 110px);
    display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.side-tabs { flex-shrink: 0; display: flex; gap: 6px; }
.side-tab {
    flex: 1; border: 1px solid var(--border-strong); background: var(--bg-panel);
    border-radius: var(--radius-sm); padding: 9px 10px;
    font-size: 13.5px; font-weight: 700; color: var(--text-soft);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    box-shadow: var(--shadow); line-height: 1.3;
}
.side-tab.active { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
[data-theme="dark"] .side-tab.active { background: var(--accent); border-color: var(--accent); color: #08131d; }
.side-tab-label { display: inline-flex; align-items: center; gap: 6px; }
.tab-badge {
    background: var(--amber-500); color: #241a00; font-size: 11px; font-weight: 700;
    border-radius: 999px; padding: 1px 8px;
}
.side-tab.active .tab-badge { background: rgba(255,255,255,.25); color: #fff; }
[data-theme="dark"] .side-tab.active .tab-badge { background: rgba(8,19,29,.3); color: #08131d; }
.side-tab-total { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.side-tab.active .side-tab-total { color: rgba(255,255,255,.75); }
[data-theme="dark"] .side-tab.active .side-tab-total { color: rgba(8,19,29,.7); }

.side {
    background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow);
    flex: 1; min-height: 0;
    display: flex; flex-direction: column;
}
.side-close-mobile { display: none; }
.side-body { padding: 14px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-body[hidden] { display: none; }
.tree { overflow-y: auto; font-size: 14px; }
.tree-node { margin: 1px 0; }
.tree-row {
    display: flex; align-items: center; gap: 6px; width: 100%;
    padding: 6px 8px; border-radius: var(--radius-sm);
    background: none; border: none; text-align: left; color: var(--text);
    font-size: 13.5px; line-height: 1.35;
}
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.tree-caret { width: 14px; text-align: center; color: var(--text-faint); font-size: 10px; transition: transform .15s; flex-shrink: 0; }
.tree-caret.open { transform: rotate(90deg); }
.tree-caret.leaf { visibility: hidden; }
.tree-code { color: var(--accent); font-weight: 700; flex-shrink: 0; }
.tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-count { font-size: 11px; color: var(--text-faint); background: var(--bg-soft); border-radius: 999px; padding: 1px 7px; flex-shrink: 0; }
.tree-children { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 6px; }

/* ─────────── Content / cards ─────────── */
.content { min-width: 0; }
.results { display: flex; flex-direction: column; gap: 12px; }

.sec-heading {
    display: flex; align-items: baseline; gap: 10px;
    margin: 14px 2px 2px; padding-bottom: 6px; border-bottom: 2px solid var(--border-strong);
}
.sec-heading:first-child { margin-top: 0; }
.sec-heading .sec-code {
    background: var(--navy-800); color: #fff; border-radius: 7px;
    font-size: 14px; font-weight: 700; padding: 2px 11px;
}
[data-theme="dark"] .sec-heading .sec-code { background: var(--accent); color: #08131d; }
.sec-heading h2 { font-size: 17px; font-weight: 700; }
.sec-heading .sec-count { font-size: 12.5px; color: var(--text-faint); margin-left: auto; }

.card {
    background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.card-head { padding: 11px 16px 9px; display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.card-code {
    color: var(--accent); font-weight: 700; font-size: 14.5px;
    background: var(--accent-soft); border-radius: 6px; padding: 0 8px;
}
.card-title { font-size: 15px; font-weight: 700; }
.card-crumb { width: 100%; font-size: 12px; color: var(--text-faint); }
.card-note {
    margin: 0 16px 10px; padding: 7px 12px; font-size: 13px;
    background: var(--amber-bg); border: 1px solid var(--amber-border);
    border-radius: var(--radius-sm); color: var(--amber-text);
}
.card-note p + p { margin-top: 3px; }

table.rows { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rows th {
    text-align: left; font-size: 12px; color: var(--text-faint); font-weight: 600;
    padding: 6px 12px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
    background: var(--bg-soft);
}
table.rows td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.rows tr:last-child td { border-bottom: none; }
table.rows tr:hover td { background: var(--bg-hover); }
.td-name { color: var(--text); }
.td-name .sub-label { font-weight: 600; }
.td-note { color: var(--text-soft); font-size: 13px; }
.td-unit { white-space: nowrap; color: var(--text-soft); text-align: center; }
.td-price { white-space: nowrap; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.td-add { text-align: right; white-space: nowrap; }
.add-btn {
    border: 1px solid var(--border-strong); background: var(--bg-panel);
    color: var(--accent); border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 700; padding: 4px 12px; transition: .12s;
}
.add-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.add-btn.added { background: var(--green); border-color: var(--green); color: #fff; }
mark { background: #ffe58a; color: inherit; border-radius: 3px; padding: 0 1px; }
[data-theme="dark"] mark { background: #7a5a00; }

.group-label td { background: var(--bg-soft); font-weight: 700; font-size: 13.5px; color: var(--text-soft); }

/* ─────────── แถวที่แก้ไขตัวเลข / ควรตรวจสอบ ─────────── */
tr.has-fix td { background: rgba(26, 127, 78, .05); }
tr.has-warn td { background: rgba(240, 165, 0, .07); }
.row-flag {
    margin-top: 5px; padding: 5px 9px; border-radius: var(--radius-sm);
    font-size: 12px; line-height: 1.45; border: 1px solid;
}
.row-flag.fix { background: rgba(26, 127, 78, .09); border-color: rgba(26, 127, 78, .35); color: var(--green); }
.row-flag.warn { background: var(--amber-bg); border-color: var(--amber-border); color: var(--amber-text); }
.row-flag strong { font-weight: 700; }
.row-flag s { opacity: .8; }
.price-badge {
    display: inline-block; margin-left: 4px; width: 15px; height: 15px; line-height: 15px;
    border-radius: 50%; font-size: 10px; text-align: center; vertical-align: 2px;
    background: var(--green); color: #fff; font-weight: 700;
}
.price-badge.warn { background: var(--amber-500); color: #241a00; }

.load-more-wrap { text-align: center; margin: 18px 0; }
.empty-state { text-align: center; padding: 60px 30px; color: var(--text-soft); }
.empty-icon { font-size: 40px; margin-bottom: 10px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }
.empty-hint {
    margin: 14px auto 0; max-width: 520px; font-size: 13px;
    background: var(--amber-bg); border: 1px solid var(--amber-border); color: var(--amber-text);
    padding: 8px 14px; border-radius: var(--radius-sm);
}
.ad-slot { margin-top: 18px; min-height: 0; }

/* ─────────── กระดาษทด (ในแท็บ) ─────────── */
.project-row { display: flex; gap: 6px; flex-shrink: 0; }
.project-row select {
    flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--bg-soft); color: var(--text); padding: 6px 8px; font-size: 13.5px;
}
.boq-body { flex: 1; overflow-y: auto; padding-top: 10px; margin-top: 2px; }
.boq-empty { text-align: center; color: var(--text-soft); padding: 26px 6px; font-size: 13.5px; }
.boq-empty .hint { margin-top: 8px; color: var(--text-faint); font-size: 12.5px; }
.demo-add {
    display: inline-block; border: 1px solid var(--border-strong); border-radius: 5px;
    padding: 0 7px; color: var(--accent); font-weight: 700; font-size: 12px;
}
.boq-item {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 9px 10px; margin-bottom: 8px; background: var(--bg-soft);
}
.boq-item-name { font-size: 13px; font-weight: 600; line-height: 1.4; }
.boq-item-code { color: var(--accent); font-weight: 700; }
.boq-item-note { font-size: 12px; color: var(--text-soft); margin-top: 1px; }
.boq-item-row { display: flex; align-items: center; gap: 7px; margin-top: 7px; }
.qty-input {
    width: 78px; border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
    padding: 4px 8px; font-size: 14px; text-align: right; background: var(--bg-panel); color: var(--text);
}
.qty-input:focus { outline: none; border-color: var(--accent); }
.boq-unitprice { font-size: 12.5px; color: var(--text-soft); flex: 1; }
.boq-line-total { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.boq-del { background: none; border: none; color: var(--text-faint); font-size: 15px; padding: 2px 5px; }
.boq-del:hover { color: var(--red); }
.side-foot { flex-shrink: 0; border-top: 1px solid var(--border); padding: 12px 14px; text-align: center; }
.boq-total-row {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 14px; margin-bottom: 10px;
}
.boq-total-row strong { font-size: 19px; color: var(--green); font-variant-numeric: tabular-nums; }
.boq-actions { display: flex; gap: 7px; }
.boq-actions .btn { flex: 1; justify-content: center; padding: 8px 6px; font-size: 13.5px; }

/* ─────────── Footer ─────────── */
.footer { border-top: 1px solid var(--border); margin-top: 30px; background: var(--bg-panel); }
.footer-inner { max-width: 1560px; margin: 0 auto; padding: 22px 20px 30px; font-size: 13.5px; }
.footer .muted { color: var(--text-faint); font-size: 12.5px; margin-top: 4px; }
.footer-links { display: flex; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.footer-links a { color: var(--accent); text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }

/* ─────────── Modal ─────────── */
.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(10, 20, 32, .55); backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
    background: var(--bg-panel); border-radius: 14px; box-shadow: var(--shadow-lg);
    width: 100%; max-width: 680px; max-height: 86vh; display: flex; flex-direction: column;
}
.modal-sm { max-width: 460px; }
.modal-xs { max-width: 380px; }
.modal-actions-end { justify-content: flex-end; }
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; }
.close-btn { background: var(--bg-soft); border: none; border-radius: 50%; width: 30px; height: 30px; color: var(--text-soft); }
.modal-body { padding: 18px 22px; overflow-y: auto; font-size: 14px; }
.modal-body h3 { font-size: 14.5px; margin: 14px 0 6px; color: var(--accent); }
.modal-body h3:first-child { margin-top: 0; }
.modal-body ol, .modal-body ul { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-soft); display: block; margin-bottom: 6px; }
.text-input {
    width: 100%; border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
    padding: 9px 12px; font-size: 15px; background: var(--bg-soft); color: var(--text);
}
.text-input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ─────────── Toast ─────────── */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
    background: var(--navy-900); color: #fff; border-radius: 999px;
    padding: 9px 20px; font-size: 14px; box-shadow: var(--shadow-lg);
    animation: toast-in .25s ease;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* ─────────── Scrollbars ─────────── */
.tree::-webkit-scrollbar, .boq-body::-webkit-scrollbar { width: 8px; }
.tree::-webkit-scrollbar-thumb, .boq-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

/* ─────────── Responsive ───────────
   >900px: แผงข้าง (แท็บ+เนื้อหา) sticky อยู่ในคอลัมน์ที่ 2 เสมอ
   ≤900px: แท็บกลายเป็นแถบล่างคงที่ (bottom nav) ส่วนแผงเนื้อหาเลื่อนขึ้นมาเต็มจอเมื่อแตะแท็บ */
@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; margin-top: 12px; padding-bottom: 76px; }
    .col-resizer { display: none; }

    /* .side-tabs กับ .side เป็น sibling กันภายใต้ .side-col (ไม่ใช่ลูกของกันเอง)
       เพื่อไม่ให้ transform ของ .side ตอนเปิด/ปิด พา .side-tabs (bottom nav) หายไปด้วย */
    .side-col { position: static; max-height: none; display: contents; }

    .side-tabs {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 95;
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
        background: var(--bg-panel); border-top: 1px solid var(--border-strong);
        box-shadow: 0 -4px 20px rgba(0,0,0,.12); border-radius: 0;
    }
    .side-tab { box-shadow: none; }

    .side {
        position: fixed; inset: 0; z-index: 90; border-radius: 0;
        max-height: none; top: 0;
        padding-bottom: calc(64px + env(safe-area-inset-bottom));
        transform: translateY(100%); transition: transform .2s ease;
        visibility: hidden;
    }
    .side.mobile-open { transform: translateY(0); visibility: visible; }
    .side-close-mobile {
        display: flex; align-items: center; justify-content: center;
        position: absolute; top: 10px; right: 10px; z-index: 1;
    }
}
@media (max-width: 860px) {
    .topbar-inner { gap: 12px; padding: 12px 16px; }
    .doc-title h1 { font-size: 14.5px; }
    .topbar-actions .btn span { display: none; }
    .searchbar { padding: 10px 14px 8px; }
    .search-kbd { display: none; }
    table.rows th:nth-child(1) { display: none; }
    table.rows td.td-name { display: block; border-bottom: none; padding-bottom: 0; }
    .footer-inner { padding-bottom: 20px; }
}

/* ═══════════════ PRINT ═══════════════
   กันโฆษณา/องค์ประกอบแปลกปลอมหลุดเข้าไปในเอกสารพิมพ์ (เช่น Google Auto Ads ที่ฝัง
   ตัวเองเป็น element แยกนอก .layout) ด้วยแพทเทิร์น "print only this element":
   ซ่อนทุกอย่างในหน้าด้วย visibility แล้วเปิดเฉพาะ .print-sheet ที่ตำแหน่งสัมบูรณ์ */
.print-sheet { display: none; }
@media print {
    @page { size: A4; margin: 14mm 12mm; }
    body * { visibility: hidden; }
    .print-sheet, .print-sheet * { visibility: visible; }
    body { background: #fff; font-size: 12.5px; }
    .print-sheet {
        display: block; color: #000;
        position: absolute; left: 0; top: 0; width: 100%; margin: 0; padding: 0;
    }
    /* หัวกระดาษแบบหัวจดหมาย: โลโก้ช้างซ้าย ชื่อองค์กร แล้วเส้นคาด */
    .print-sheet .p-head {
        display: flex; align-items: center; gap: 10px;
        padding-bottom: 7px; border-bottom: 1.6px solid #14324f; margin-bottom: 12px;
    }
    .print-sheet .p-logo { width: 42px; height: 42px; object-fit: contain; flex-shrink: 0; }
    .print-sheet .p-head-org { line-height: 1.3; }
    .print-sheet .p-head-org strong { font-size: 15px; display: block; color: #14324f; }
    .print-sheet .p-head-org span { font-size: 10px; color: #555; }
    .print-sheet h1 { font-size: 15.5px; text-align: center; margin-bottom: 3px; line-height: 1.4; }
    .print-sheet .p-sub { text-align: center; font-size: 12px; margin-bottom: 2px; }
    .print-sheet .p-meta { display: flex; justify-content: space-between; font-size: 12px; margin: 10px 0 6px; }
    .print-sheet table { width: 100%; border-collapse: collapse; font-size: 11.8px; }
    .print-sheet th, .print-sheet td { border: .6px solid #444; padding: 3.5px 6px; vertical-align: top; }
    .print-sheet th { background: #eef1f5; font-weight: 700; text-align: center; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .print-sheet td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
    .print-sheet td.ctr { text-align: center; }
    .print-sheet tr.p-sec td { background: #f5f7fa; font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .print-sheet tr.p-total td { font-weight: 700; background: #eef1f5; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .print-sheet .p-note { font-size: 11px; margin-top: 8px; }
    /* ช่องลงนามแบบเอกสารราชการ: ลงชื่อ / (ชื่อตัวบรรจง) / ตำแหน่ง / บทบาทในคณะกรรมการ */
    .print-sheet .p-sign { margin-top: 26px; page-break-inside: avoid; }
    .print-sheet .p-sign-lead { font-size: 11.5px; text-indent: 2.5em; line-height: 1.75; margin-bottom: 24px; }
    .print-sheet .p-sign-row { display: flex; justify-content: space-between; gap: 14px; }
    .print-sheet .p-sign-block { width: 32%; font-size: 11.5px; }
    .print-sheet .sig-line, .print-sheet .sig-pos { display: flex; align-items: flex-end; gap: 4px; }
    .print-sheet .sig-line { margin-bottom: 3px; }
    .print-sheet .sig-pos { margin-top: 7px; }
    .print-sheet .lbl { flex-shrink: 0; }
    .print-sheet .dots { flex: 1; border-bottom: 1px dotted #333; height: 1px; }
    .print-sheet .sig-name { text-align: center; padding: 0 6px; white-space: nowrap; }
    .print-sheet .dots-in { display: inline-block; width: 78%; border-bottom: 1px dotted #333; height: 1px; vertical-align: 3px; }
    .print-sheet .sig-role { text-align: center; margin-top: 8px; font-weight: 700; font-size: 11px; }
    .print-sheet .p-credit { margin-top: 18px; font-size: 10px; color: #666; text-align: right; }
}
