:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #dfe2e7;
    --text: #1d2330;
    --muted: #6b7280;
    --primary: #1f6f5c;
    --primary-ink: #ffffff;
    --danger: #b42318;
    --danger-bg: #fdecea;
    --warn: #8a5a00;
    --warn-bg: #fff4d6;
    --ok: #1f6f5c;
    --ok-bg: #e3f3ee;
    --side: #18212f;
    --side-ink: #c9d1dd;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    /* IBM Plex Sans Thai (Google Fonts, โหลดใน App.razor) — ออฟไลน์ใช้ฟอนต์ในเครื่องแทน */
    font-family: "IBM Plex Sans Thai", "Leelawadee UI", Tahoma, "Noto Sans Thai", system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 0 0 .75rem; }
td, .stat strong, .count, .badge { font-variant-numeric: tabular-nums; }
p { margin: .25rem 0 .75rem; }
code, .mono { font-family: "IBM Plex Mono", Consolas, "Cascadia Mono", monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.neg { color: var(--danger); }
.warn-text { color: var(--warn); }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side {
    width: 220px; flex-shrink: 0; background: var(--side); color: var(--side-ink);
    display: flex; flex-direction: column; padding: 1rem .75rem; gap: 2px;
    /* ตรึงเมนูไว้เต็มความสูงจอ — เนื้อหาเลื่อนได้ เมนูไม่เลื่อนตาม */
    position: sticky; top: 0; align-self: flex-start; height: 100vh; overflow-y: auto;
}
.side a { color: var(--side-ink); text-decoration: none; padding: .55rem .75rem; border-radius: 6px; }
.side a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.brand { font-size: 1.3rem; font-weight: 700; color: #fff; padding: .25rem .75rem 1rem; }
.brand span, .login-box h1 span { color: #5fc4a8; }
.nav-group { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; opacity: .6; padding: 1rem .75rem .25rem; }
.user { margin-top: auto; padding: .75rem; border-top: 1px solid rgba(255,255,255,.1); }
.user small { display: block; opacity: .6; margin-bottom: .5rem; }
.content { flex: 1; padding: 1rem 2rem 1.25rem; min-width: 0; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
/* หัวหน้ากระชับ: ชื่อหน้า + คำอธิบายตัวเล็กอยู่บรรทัดเดียวกัน (ยาวเกินค่อยขึ้นบรรทัดใหม่) */
.page-head > div:has(> h1) { display: flex; align-items: baseline; gap: .15rem .75rem; flex-wrap: wrap; min-width: 0; }
.page-head h1 { margin: 0; font-size: 1.3rem; }
.page-head h1 + p { margin: 0; font-size: .82rem; }
.toolbar { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.toolbar label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: 2px; }

/* controls */
input, select {
    font: inherit; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); min-width: 0;
}
input:focus, select:focus { outline: 2px solid #9bd3c3; border-color: var(--primary); }
input[type=search] { min-width: 260px; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; }

.btn {
    font: inherit; display: inline-block; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--border);
    background: #fff; color: var(--text); cursor: pointer; text-decoration: none; text-align: center; white-space: nowrap;
}
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: .2rem .55rem; font-size: .82rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

/* panels & forms */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem 1rem; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.form-grid label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); padding-top: 1.3rem; }
.actions { display: flex; gap: .5rem; margin-top: .75rem; }
.validation-errors { color: var(--danger); margin: .5rem 0 0; padding-left: 1.2rem; }
.validation-message { color: var(--danger); font-size: .82rem; }
.req { color: var(--danger); font-weight: 600; }
.field-warn { color: var(--warn); font-size: .82rem; }
.danger-text { color: var(--danger); }
/* แถวที่กดลบ — ขีดฆ่าไว้จนกว่าจะบันทึก (ปุ่มเลิกทำไม่ขีดฆ่า) */
tr.row-removed > td, tbody.row-removed > tr > td { text-decoration: line-through; opacity: .5; }
tr.row-removed > td input, tr.row-removed > td select,
tbody.row-removed > tr > td input, tbody.row-removed > tr > td select { text-decoration: line-through; background: transparent; }
tr.row-removed > td:last-child, tr.row-removed > td.sup-del { text-decoration: none; opacity: 1; }
tr.row-danger > td, tbody.row-danger > tr > td { background: var(--danger-bg); }
/* ผู้จัดจำหน่าย 2 บรรทัดต่อราย — กว้างพอดีกรอบ ไม่เลื่อนแนวนอน */
/* ผู้จัดจำหน่าย: grid แทนตาราง — กรอบกว้างพอ = 1 แถว, แคบ = 2 บรรทัดต่อราย (container query ตามความกว้างของกรอบ ไม่ใช่จอ) */
.sup-grid { container: sup / inline-size; background: #fff; border: 1px solid var(--border); border-radius: 6px; margin-bottom: .5rem; }
.sup-line {
    display: grid; gap: .3rem .35rem; align-items: center; padding: .35rem .5rem; border-bottom: 1px solid var(--border); font-size: .86rem;
    grid-template-columns: 1.4rem minmax(0, 1.5fr) minmax(0, .75fr) minmax(0, 1.15fr) minmax(0, .85fr) minmax(0, 1.05fr) minmax(0, 1.1fr) 2rem;
    grid-template-areas: "pri sup sku unit price vat base del";
}
.sup-line:last-child { border-bottom: 0; }
.sup-head { font-size: .74rem; color: var(--muted); font-weight: 600; background: var(--bg, #f8f9fb); line-height: 1.2; align-items: end; }
.sup-line .c-pri { grid-area: pri; } .sup-line .c-sup { grid-area: sup; } .sup-line .c-sku { grid-area: sku; }
.sup-line .c-unit { grid-area: unit; } .sup-line .c-price { grid-area: price; } .sup-line .c-vat { grid-area: vat; }
.sup-line .c-base { grid-area: base; } .sup-line .c-del { grid-area: del; text-align: right; }
.sup-line .sup-note { grid-column: 1 / -1; }
.sup-line input:not([type=radio]), .sup-line select { width: 100%; min-width: 0; font-size: .86rem; padding: .3rem .35rem; }
/* ลูกศรของ select วาดเอง — ลูกศรของเบราว์เซอร์กินที่ ~20px ทำให้ "ลัง (×36)" / "ไม่มี VAT" ถูกตัด */
.sup-line select, .pc-table select {
    appearance: none; -webkit-appearance: none; padding-right: 1rem; text-overflow: ellipsis;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .35rem center; background-size: .55rem;
}
.sup-line input[type=radio] { width: auto; margin: 0; }
.sup-line .supplier-picker .combo-box { min-height: 0; padding: 0 .2rem; flex-wrap: nowrap; }
.sup-line .supplier-picker .combo-box input { text-overflow: ellipsis; padding: .3rem .15rem; }
.sup-line .supplier-picker .combo-caret { padding: 0 .1rem; }
.sup-line .d-block { display: block; }
.sup-line .num { text-align: right; }
.sup-line .c-base .small { font-size: .74rem; white-space: nowrap; }
.sup-line .icon-btn { padding: .15rem .45rem; min-width: 0; }
/* กรอบแคบมาก (จอมือถือ/แท็บเล็ตแนวตั้ง) → 2 บรรทัดต่อผู้จัดจำหน่าย */
@container sup (max-width: 599px) {
    .sup-line {
        grid-template-columns: 1.4rem repeat(4, minmax(0, 1fr)) 2rem;
        grid-template-areas: "pri sup sup sku sku del" ". unit price vat base .";
    }
}
.sup-line.row-removed > :not(.c-del) { opacity: .5; text-decoration: line-through; }
.sup-line.row-danger { background: var(--danger-bg); }
.sup-line select:disabled { background: #f3f4f6; color: var(--muted); cursor: not-allowed; }
.sup-line .cell-warn input { background: var(--warn-bg); }
.unit-in-use { display: inline-flex; flex-direction: column; align-items: flex-end; gap: .1rem; }
td.cell-warn { background: var(--warn-bg); }
/* กำไร % ข้างราคากลาง */
.margin { margin-left: .4rem; padding: 0 .4rem; border-radius: 999px; font-size: .78rem; background: var(--ok-bg); color: var(--ok); font-variant-numeric: tabular-nums; }
.margin.neg { background: var(--danger-bg); color: var(--danger); }
.margin.none { background: #eceef2; color: var(--muted); }
.invalid { border-color: var(--danger); }
.error { color: var(--danger); background: var(--danger-bg); padding: .5rem .75rem; border-radius: 6px; }
.notice { color: var(--ok); background: var(--ok-bg); padding: .5rem .75rem; border-radius: 6px; }
.notice.warn { color: var(--warn); background: var(--warn-bg); }
.key-panel { border-color: #e0b84c; background: #fffaf0; }
.key-panel pre { background: #fff; border: 1px dashed #e0b84c; padding: .75rem; overflow-x: auto; user-select: all; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.stat span { display: block; color: var(--muted); font-size: .85rem; }
.stat strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }

/* tables */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; margin-bottom: .75rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono { white-space: nowrap; }
.page-head .toolbar { max-width: 100%; }
table.clickable tbody tr:not(.detail) { cursor: pointer; }
table.clickable tbody tr:not(.detail):hover { background: #f6f8fa; }
tr.open { background: #eef6f3 !important; }
tr.refund td { background: #fff8f7; }
tr.inactive td { color: var(--muted); }
tr.detail > td { background: #fbfcfd; padding: .75rem 1.25rem 1rem; }
table.inner { background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.row-actions { white-space: nowrap; text-align: right; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; background: #eceef2; color: #374151; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

/* master-detail + category tree */
/* หน้าที่มี md-layout พอดีจอ: ตัวหน้าไม่เลื่อน กรอบหมวด / กรอบรายละเอียด เลื่อนภายในตัวเอง */
.content:has(> .md-layout) { height: 100vh; display: flex; flex-direction: column; }
.md-layout {
    display: grid; grid-template-columns: 280px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 1rem;
    flex: 1; min-height: 0;
}
/* .detail = กรอบรายละเอียดของหน้าแบบ md-layout (ไม่ใช่ tr.detail แถวขยายในตาราง) */
.tree-panel, .detail:not(tr) {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .75rem; min-height: 0; overflow-y: auto;
}
.tree-panel input[type=search] { width: 100%; min-width: 0; margin-bottom: .5rem; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree li { padding-left: calc((var(--depth, 1) - 1) * 18px); }
.tree-row { display: flex; align-items: center; border-radius: 6px; }
.tree-row:hover { background: #f3f5f7; }
.tree-row.selected { background: var(--ok-bg); }
.tree-row.selected .tree-label { color: var(--primary); font-weight: 600; }
.tree-row.inactive .tree-label { color: var(--muted); }
.twisty {
    width: 22px; height: 30px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: .85rem; padding: 0;
}
span.twisty { cursor: default; }
.tree-label {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: .4rem; text-align: left;
    border: 0; background: transparent; font: inherit; color: var(--text); padding: .35rem .4rem; cursor: pointer;
}
.tree-label .count {
    margin-left: auto; font-size: .75rem; color: var(--muted); background: #eef0f3; border-radius: 999px; padding: 0 .45rem;
    font-variant-numeric: tabular-nums;
}
.tree-label .badge { font-size: .7rem; padding: 0 .35rem; }
.warn-text { color: var(--warn) !important; }
.tree-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.btn.danger { color: var(--danger); border-color: #f1c4bf; }
.btn.danger:hover { background: var(--danger-bg); }
/* กรอบรายละเอียด: หัว (ชื่อหมวด / ค้นหา / เส้นทางสินค้า) อยู่กับที่ เลื่อนเฉพาะ detail-body */
.detail:not(tr) { min-width: 0; padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.detail-head {
    display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap;
    padding: .75rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.detail-body { flex: 1; min-height: 0; overflow: auto; padding: 0 1rem 1rem; }
.detail-body > .panel:first-child { padding-top: 1rem; }
/* อยู่ในกรอบแล้ว ไม่ต้องมีกรอบซ้อน */
.detail-body > .panel, .detail-body > .table-wrap { border: 0; border-radius: 0; padding-left: 0; padding-right: 0; margin-bottom: 0; }
.detail-body > .panel + .panel, .detail-body > .panel + .table-wrap { border-top: 1px solid var(--border); padding-top: 1rem; }
/* หัวตารางรายการค้างไว้ตอนเลื่อน (ตารางต้องไม่เป็นกล่องเลื่อนเอง ให้ detail-body เลื่อนแทน) */
.detail-body > .table-wrap { overflow: visible; margin: 0 -1rem; }
.detail-body > .table-wrap thead th { position: sticky; top: 0; z-index: 2; }
.detail-body > .table-wrap th:first-child, .detail-body > .table-wrap td:first-child { padding-left: 1rem; }
.crumb { margin: 0; font-size: 1.15rem; }

@media (max-width: 900px) {
    .content:has(> .md-layout) { height: auto; display: block; }
    .md-layout { grid-template-columns: 1fr; grid-template-rows: none; }
    .tree-panel, .detail:not(tr), .detail-body { overflow: visible; }
    /* จอแคบทั้งหน้าเลื่อน → หัวกรอบ (ปุ่มบันทึก / ยกเลิก) ติดขอบบน */
    .detail-head { position: sticky; top: 0; z-index: 5; background: var(--surface); }
}
.form-error { margin: .75rem 0 0; }

/* form sub-sections (barcodes, branch prices) */
/* ไม่ตัดขอบ (ให้ tooltip ⓘ แสดงเต็ม) — ตารางที่อาจกว้างเกินห่อด้วย .table-scroll แทน */
.sub-section { margin-top: 1rem; padding-top: .75rem; border-top: 1px dashed var(--border); }
.table-scroll { overflow-x: auto; }
.sub-section h3 { font-size: .95rem; margin: 0 0 .25rem; }
table.compact th, table.compact td { padding: .3rem .5rem; vertical-align: middle; }
table.compact input { width: 100%; min-width: 90px; }
table.compact input.wide-input { min-width: 240px; }
table.compact + .btn { margin-top: .5rem; }
label.block { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin-top: .75rem; }
textarea { font: inherit; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; resize: vertical; }

/* branch price editor (only branches with a different price) */
.bp-editor { padding: .35rem 0; }
.bp-add { margin-top: .5rem; padding: .75rem; border: 1px solid var(--border); border-radius: 8px; background: #fafbfc; }
.bp-add-head { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .5rem; }
.bp-add-head label { display: flex; flex-direction: column; gap: 2px; font-size: .8rem; color: var(--muted); }
.bp-add-head input[type=search] { min-width: 240px; }
.bp-add-head input[type=number] { width: 120px; }
.bp-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .15rem .75rem;
    max-height: 220px; overflow-y: auto; padding: .25rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.bp-list label, .bp-all { display: flex; gap: .4rem; align-items: center; font-size: .88rem; cursor: pointer; padding: .15rem 0; }
.bp-all { margin: .25rem 0; font-weight: 600; }
tr.bp-row > td { background: #f6faf8; padding: .35rem .75rem .75rem; }
.bp-editor > .btn { margin-top: .4rem; }
.modal.modal-wide { max-width: 600px; }
.bp-modal { max-height: calc(100vh - 2rem); display: flex; flex-direction: column; }
.bp-modal .bp-add-head label.grow { flex: 1; }
.bp-modal .bp-add-head input[type=search] { width: 100%; min-width: 0; }
.bp-modal .bp-list { max-height: 320px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.bp-list label.picked { color: var(--primary); font-weight: 600; }
.bp-modal-foot { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-top: .75rem; }
.bp-modal-foot .actions { margin-top: 0; }
.bp-modal-foot .actions .btn { flex: 0 0 auto; }
.bp-modal .field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin-top: .6rem; }
.bp-modal .price-input { width: 160px; }

/* searchable multi-select dropdown (combobox) */
.combo { position: relative; color: var(--text); }
.combo-box {
    display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; min-height: 2.4rem;
    border: 1px solid var(--border); border-radius: 6px; padding: .25rem .4rem; background: #fff; cursor: text;
}
.combo-box:focus-within { outline: 2px solid #9bd3c3; border-color: var(--primary); }
.combo-box input { border: 0; outline: none; flex: 1; min-width: 180px; padding: .2rem; background: transparent; }
.combo-box input:focus { outline: none; }
.combo-caret { color: var(--muted); padding: 0 .3rem; pointer-events: none; }
.chip {
    display: inline-flex; align-items: center; gap: .15rem; background: var(--ok-bg); color: var(--primary);
    border-radius: 999px; padding: .1rem .15rem .1rem .6rem; font-size: .85rem; font-weight: 600;
}
.chip button { border: 0; background: transparent; cursor: pointer; color: inherit; padding: 0 .35rem; font-size: .8rem; }
.chip button:hover { color: var(--danger); }
.combo-list {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60; list-style: none; margin: 0; padding: .25rem 0;
    background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .15);
    max-height: 280px; overflow-y: auto;
}
.combo-list li { padding: .45rem .75rem; cursor: pointer; display: flex; gap: .5rem; font-size: .9rem; }
.combo-list li.active { background: var(--ok-bg); }
.combo-list li > strong, .combo-list li > .badge { flex-shrink: 0; white-space: nowrap; }
.combo-list li > .badge { align-self: center; margin-left: auto; }
.combo-list li.all { font-weight: 600; color: var(--primary); border-bottom: 1px solid var(--border); }
.combo-list li.hint { color: var(--muted); cursor: default; font-size: .82rem; }
.btn.active { background: var(--ok-bg); border-color: var(--primary); color: var(--primary); }
.nowrap { white-space: nowrap; }
.warn-notice { color: var(--warn); background: var(--warn-bg); }

/* product list: one line per row */
table.product-list th, table.product-list td { white-space: nowrap; vertical-align: middle; padding-top: .5rem; padding-bottom: .5rem; }
table.product-list td.center, table.product-list th.center { text-align: center; }
/* ความกว้างคอลัมน์คงที่ — ตารางวาดเฉพาะแถวที่มองเห็น ถ้าให้กว้างตามเนื้อหา คอลัมน์จะขยับไปมาตอนเลื่อน */
/* ความกว้างตามคอลัมน์ (ไม่ใช้ลำดับ เพราะคอลัมน์หมวดซ่อนได้) */
table.product-list { table-layout: fixed; min-width: 1010px; }
table.product-list.with-cat { min-width: 1170px; }
table.product-list .col-sku { width: 130px; }
table.product-list .col-name { width: 230px; }
table.product-list .col-cat { width: 160px; }
table.product-list .col-type { width: 100px; }
table.product-list .col-scan { width: 140px; }
table.product-list .col-price { width: 120px; }
table.product-list .col-bp { width: 80px; }
table.product-list .col-sup { width: 140px; }
table.product-list .col-vat { width: 48px; }
table.product-list .col-status { width: 96px; }
/* ผู้จัดจำหน่าย / ภาษี / สถานะ ตรึงขอบขวา (offset = ผลรวมความกว้างคอลัมน์ทางขวา)
   ลบ 1rem = padding ของ .detail-body (sticky นับจากขอบใน padding) ให้ชิดขอบกรอบจริง ไม่เหลือช่องให้คอลัมน์ที่เลื่อนอยู่โผล่ */
table.product-list .pin { position: sticky; z-index: 1; background: var(--surface); }
table.product-list thead .pin { z-index: 3; background: #fafbfc; }
table.product-list .col-status { right: -1rem; }
table.product-list .col-vat { right: calc(96px - 1rem); }
table.product-list .col-sup { right: calc(144px - 1rem); box-shadow: inset 1px 0 0 var(--border), -6px 0 6px -6px rgba(0,0,0,.18); }
table.clickable.product-list tbody tr:not(.detail):hover > td.pin { background: #f6f8fa; }
table.product-list tbody tr.open > td.pin { background: #eef6f3; }
.list-count { margin: 0 0 .4rem; }
.search-box { display: flex; }
.search-box input[type=search] { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.search-box select { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 0; background: #f6f8fa; font-size: .85rem; }
table.product-list td { overflow: hidden; text-overflow: ellipsis; }
/* ชื่อ/หมวดยาวตัดด้วย … (ดูเต็มที่ tooltip) */
table.product-list .col-name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
table.product-list .col-cat { max-width: 160px; overflow: hidden; text-overflow: ellipsis; font-size: .85rem; }
table.product-list .col-sup { max-width: 160px; overflow: hidden; text-overflow: ellipsis; font-size: .85rem; }
.type-tag { display: inline-block; font-size: .78rem; padding: .05rem .5rem; border-radius: 4px; border: 1px solid transparent; }
.type-tag.unit { background: #eef2f7; color: #475569; }
.type-tag.weight { background: #fff4e5; color: #9a5b00; }
.type-tag.multi { background: #ede9fe; color: #5b21b6; }
.type-tag.set { background: #e0f2fe; color: #075985; }
.vat-tag {
    display: inline-grid; place-items: center; width: 1.4rem; height: 1.4rem; border-radius: 4px;
    font-size: .75rem; font-weight: 700;
}
.vat-tag.vat { background: var(--ok-bg); color: var(--ok); }
.vat-tag.exempt { background: #eceef2; color: #4b5563; }
.status { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; }
.status::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: #9ca3af; }
.status.on { color: var(--ok); }
.status.on::before { background: #22a06b; }
.status.off { color: var(--muted); }

/* excel import */
.import-kinds { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.import-kind {
    display: flex; flex-direction: column; gap: .2rem; text-align: left; font: inherit; cursor: pointer;
    padding: .7rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
}
.import-kind span { font-size: .8rem; color: var(--muted); }
.import-kind:hover { border-color: var(--primary); }
.import-kind.active { border-color: var(--primary); background: var(--ok-bg); box-shadow: inset 3px 0 0 var(--primary); }
.import-steps { margin: 0; padding-left: 1.2rem; display: grid; gap: .6rem; }
.import-steps input[type=file] { margin-left: .5rem; }
.import-progress { margin-top: .75rem; }
.progress-steps { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem 1.25rem; font-size: .85rem; color: var(--muted); }
.progress-steps li::before { content: "○"; margin-right: .35rem; }
.progress-steps li.done { color: var(--ok); }
.progress-steps li.done::before { content: "✓"; }
.progress-steps li.current { color: var(--text); font-weight: 600; }
.progress-steps li.current::before { content: "●"; color: var(--primary); }
.progress-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--primary); transition: width .3s ease; }
.import-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.import-head h2 { margin: 0; }
.import-chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.import-filter { display: flex; align-items: center; gap: .4rem; margin: .75rem 0 .5rem; }
.import-table td { vertical-align: top; }
.import-table tr.row-error td { background: #fff6f5; }
.error-text { color: var(--danger); font-size: .85rem; }

/* breadcrumb in product editor */
nav.crumb { display: flex; align-items: center; flex-wrap: wrap; gap: .15rem; font-size: 1.1rem; }
.crumb-link {
    border: 0; background: transparent; font: inherit; color: var(--primary); cursor: pointer;
    padding: .15rem .35rem; border-radius: 6px;
}
.crumb-link:hover { background: var(--ok-bg); text-decoration: underline; }
.crumb-link.back { font-size: 1.2rem; color: var(--muted); margin-right: .25rem; }
.crumb-sep { color: var(--muted); }
.crumb-current { font-weight: 700; padding: .15rem .35rem; }
.tree-row.editing:not(.selected) { box-shadow: inset 3px 0 0 var(--primary); }

/* modal (unsaved changes) */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50;
    display: grid; place-items: center; padding: 1rem;
}
.modal {
    width: 100%; max-width: 420px; background: var(--surface); border-radius: 12px;
    padding: 1.25rem 1.5rem; box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.modal h2 { margin-bottom: .5rem; }
.modal .actions .btn { flex: 1; }
.btn-link { border: 0; background: transparent; font: inherit; color: var(--muted); cursor: pointer; margin-top: .75rem; padding: 0; text-decoration: underline; }

/* login */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-box { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; }
.login-box h1 { font-size: 1.8rem; }
.login-box label { display: flex; flex-direction: column; gap: 4px; margin-bottom: .75rem; font-size: .85rem; color: var(--muted); }
.dev-note { margin-top: 1rem; font-size: .85rem; color: var(--warn); background: var(--warn-bg); padding: .5rem .75rem; border-radius: 6px; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: .75rem 1.25rem; background: var(--warn-bg); color: var(--warn); z-index: 100; }
#blazor-error-ui .reload { margin-left: .5rem; }

@media (max-width: 760px) {
    .shell { flex-direction: column; }
    /* จอแคบ: เมนูเป็นแถวต่อกันด้านบน สูงเท่าที่ใช้ (ไม่ตรึงเต็มจอ ไม่งั้นแถวถูกยืดห่างกันจนเต็มหน้าจอ) */
    .side { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; align-content: flex-start;
            position: static; height: auto; overflow: visible; padding: .5rem; }
    .side a { padding: .4rem .6rem; }
    .brand { padding: .25rem .75rem; }
    .nav-group { display: none; }
    .user { margin-top: 0; border-top: 0; margin-left: auto; }
    .content { padding: 1rem; }
}
.import-table tr.row-current td { background: #f1f8f3; }

/* ---------------------------------------------------------------- กำลังโหลด */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes appear { to { opacity: 1; } }

.spinner {
    width: 16px; height: 16px; flex-shrink: 0; border-radius: 50%;
    border: 2px solid var(--ok-bg); border-top-color: var(--primary); animation: spin .7s linear infinite;
}
.loading { animation: rise .25s ease backwards; }
.loading-head { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .9rem; margin-bottom: .75rem; flex-wrap: wrap; }
.detail-head .loading-head { margin: 0; min-height: 38px; }
.loading-slow { opacity: 0; animation: appear .4s ease 4s forwards; font-size: .8rem; }
.loading-inline { display: inline-flex; align-items: center; gap: .5rem; color: var(--muted); }

/* แท่งจำลองข้อมูล มีแสงวิ่งผ่าน */
.sk {
    border-radius: 6px; height: 12px; width: var(--w, 100%);
    background: linear-gradient(90deg, #eceff3 25%, #f7f8fa 50%, #eceff3 75%) 0 0 / 200% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
}
.sk-input { height: 36px; width: 100%; margin: .15rem 0 .6rem; }
.sk-big { height: 26px; width: 70%; margin-top: .5rem; }
.sk-tree .sk-line { margin: .75rem .5rem; }
.sk-table { background: var(--surface); }
.sk-row { display: grid; grid-template-columns: 1.2fr 2fr 1fr 1fr 1fr; gap: 1.25rem; padding: .85rem .75rem; border-bottom: 1px solid var(--border); animation: rise .3s ease backwards; animation-delay: var(--delay, 0ms); }
.sk-row-head { background: #fafbfc; }
.sk-row-head .sk { height: 9px; }
.sk-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .5rem 1rem; }

/* เนื้อหาที่เพิ่งโหลดเสร็จค่อยๆ ปรากฏ (เฉพาะตอนแทรกเข้ามาใหม่ Blazor ไม่วาดซ้ำส่วนที่ไม่เปลี่ยน) */
.content > .md-layout:not(.loading), .content > .table-wrap, .content > .stats, .content > .panel { animation: rise .3s ease backwards; }

/* แถบความคืบหน้าบางๆ ด้านบนตอนเปลี่ยนหน้า (js/nav-progress.js) */
#nav-progress {
    position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 1000; pointer-events: none;
    background: linear-gradient(90deg, var(--primary), #5fc4a8); box-shadow: 0 0 8px rgba(95, 196, 168, .6); opacity: 0;
}
#nav-progress.run { opacity: 1; width: 80%; transition: width 8s cubic-bezier(.1, .7, .2, 1); }
#nav-progress.done { opacity: 0; width: 100%; transition: width .2s ease, opacity .4s ease .2s; }

@media (prefers-reduced-motion: reduce) {
    .sk, .spinner, .loading, .sk-row, .content > * { animation: none !important; }
    #nav-progress { transition: none !important; }
}

/* แถบแจ้ง "แก้ที่นี่แล้วส่งลงสาขาในรอบ sync ถัดไป" + เวลา sync ล่าสุด (หน้าสินค้า) */
.sync-note {
    display: flex; align-items: center; gap: .4rem .75rem; flex-wrap: wrap; margin: 0 0 .75rem;
    padding: .5rem .85rem; border: 1px solid #b9dccf; border-left: 4px solid var(--primary); border-radius: 6px;
    background: var(--ok-bg); color: var(--text); font-size: .88rem;
}
.sync-note-icon { color: var(--primary); font-size: 1.05rem; line-height: 1; }
.sync-note-time { color: var(--muted); font-size: .82rem; }


/* ⓘ — รายละเอียดเพิ่มเติม ชี้เมาส์หรือโฟกัสด้วยคีย์บอร์ดแล้วแสดง */
.info-tip {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 1.1rem; height: 1.1rem; margin-left: .2rem; border-radius: 50%; cursor: help;
    color: var(--primary); font-style: normal; font-size: .85rem; vertical-align: text-bottom; outline: none;
}
.info-tip:focus-visible { box-shadow: 0 0 0 2px #9bd3c3; }
.info-tip::after {
    content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%);
    z-index: 30; width: max-content; max-width: 300px; padding: .5rem .65rem; border-radius: 6px;
    background: #1d2330; color: #fff; font-size: .8rem; line-height: 1.45; white-space: pre-line; text-align: left;
    box-shadow: 0 4px 14px rgba(0,0,0,.18); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .12s;
}
.info-tip:hover::after, .info-tip:focus::after { opacity: 1; visibility: visible; }

select.vat-select { width: auto; }
.price-split { display: block; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.bp-modal .field select.vat-select { align-self: flex-start; }
.vat-summary { display: block; margin-top: .2rem; }
.vat-summary .link-btn { margin-left: .25rem; background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; }
.sub-section.flash { animation: flash-bg 1.2s ease-out; }
@keyframes flash-bg { from { background: var(--warn-bg); } to { background: transparent; } }
.supplier-picker .combo-box input { min-width: 0; }
.company-warn { margin-bottom: 1rem; }
.company-warn ul { margin: .35rem 0 0 1.1rem; padding: 0; }
input.branch-no { width: 6.5rem; }
input.branch-no.invalid { border-color: var(--danger); }
tr.row-warn td { background: var(--warn-bg); }
.bp-modal-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.bp-modal-row .field { flex: 0 0 auto; }
select.vat-differs { border-color: var(--warn); background: var(--warn-bg); }
.form-subhead { font-size: .95rem; margin: 1.25rem 0 .5rem; padding-top: .75rem; border-top: 1px dashed var(--border); }
.cost-locked { display: flex; align-items: center; gap: .3rem; }
.cost-locked input[readonly] { background: #f3f4f6; color: var(--text); text-align: right; cursor: default; }
.cost-locked a { font-size: .74rem; white-space: nowrap; }

/* ใบปรับราคาทุน */
.crumbs { margin: 0; font-size: .85rem; }
.pc-filters { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem; }
.pc-filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .82rem; color: var(--muted); }
.pc-filters select, .pc-filters input { min-width: 11rem; }
.stepper { display: flex; list-style: none; padding: 0; margin: 0 0 1rem; gap: .25rem; flex-wrap: wrap; }
.stepper li { flex: 1; min-width: 7rem; text-align: center; padding: .4rem .5rem; border-radius: 6px; background: #eceef2; color: var(--muted); font-size: .85rem; position: relative; }
.stepper li.done { background: var(--ok-bg); color: var(--ok); }
.stepper li.done::before { content: "✓ "; }
.stepper li.current { background: var(--primary); color: #fff; font-weight: 600; }
.stepper li.off { opacity: .45; }
.stepper li.cancelled { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.pc-head { align-items: start; }
.pc-head .pc-note { grid-column: 1 / -1; }
.quick-times { display: flex; gap: .75rem; font-size: .8rem; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; }
.pc-tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pc-adjust { display: inline-flex; align-items: center; gap: .35rem; margin-left: auto; }
.pc-adjust input { width: 6rem; }
.pc-table-wrap { overflow-x: auto; }
.pc-table { font-size: .86rem; }
.pc-table th, .pc-table td { padding: .4rem .45rem; vertical-align: middle; }
.pc-table th { white-space: normal; line-height: 1.2; }
.pc-table td.pc-product { min-width: 10.5rem; }
.pc-table .pc-product .mono { white-space: nowrap; }
.pc-table select, .pc-table input { font-size: .84rem; padding: .3rem .35rem; }
.pc-table select { padding-right: 1rem; }
.pc-table .cost-input { width: 5.5rem; text-align: right; }
.pc-table .sell-cell { display: inline-flex; flex-direction: column; gap: .2rem; }
.pc-table .sell-input { width: 5rem; text-align: right; }
.pc-table .d-block { display: block; }
.pc-table tr.row-over td { background: var(--warn-bg); }
.pc-table tr.row-same td { opacity: .6; }
.pct { font-weight: 600; font-variant-numeric: tabular-nums; }
.pct.up { color: var(--danger); }
.pct.down { color: var(--ok); }
.strong { font-weight: 700; }
.pc-summary { margin-top: 1rem; }
.pc-summary .stat .small { display: block; font-size: .78rem; color: var(--muted); }
.stat.stat-warn { border-color: var(--warn); background: var(--warn-bg); }
.stat.stat-danger { border-color: var(--danger); background: var(--danger-bg); }
.pc-actions { align-items: center; flex-wrap: wrap; gap: .5rem; }
.pc-actions .return-reason { width: 16rem; }
.pc-events ul { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.pc-events li { padding: .3rem 0; border-bottom: 1px dashed var(--border); }
.pc-import-list { max-height: 50vh; overflow: auto; }
.sup-tabs-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.sup-tabs-actions { display: flex; gap: .4rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: .45rem .75rem; cursor: pointer; font: inherit; color: var(--muted); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.sparkline polyline { stroke: var(--muted); }
.sparkline.up polyline, .sparkline.up circle { stroke: var(--danger); fill: var(--danger); }
.sparkline.down polyline, .sparkline.down circle { stroke: var(--ok); fill: var(--ok); }
.sparkline polyline { fill: none !important; }
.cost-history tr.current td { font-weight: 600; }

/* ผู้ใช้ระบบ / เปลี่ยนรหัสผ่าน */
.panel.narrow { max-width: 480px; }
.form-grid.single { grid-template-columns: 1fr; }
.panel h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.side .user a.small { display: inline-block; padding: 0; margin: 0 0 .5rem; color: inherit; opacity: .85; background: none; }

/* ใบรับสินค้า (GRN) */
.grn-add { align-items: center; }
.grn-product-picker { flex: 1 1 26rem; max-width: 40rem; }
.grn-table .qty-input { width: 5rem; text-align: right; }
.grn-table tfoot td { border-top: 1px solid var(--border); font-weight: 500; }
.grn-table tfoot tr.grand td { font-weight: 700; font-size: .95rem; }
.grn-actions { flex-wrap: wrap; align-items: center; }
.grn-confirm { flex-basis: 100%; margin: 0 0 .5rem; padding: .6rem .8rem; border-radius: 6px; background: var(--warn-bg); }
.grn-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem 1rem; margin: 0; }
.grn-info dt { font-size: .8rem; color: var(--muted); }
.grn-info dd { margin: .15rem 0 0; }
.grn-info .wide { grid-column: 1 / -1; }
.grn-diff { background: var(--warn-bg); border-color: transparent; }
.grn-diff p { margin: 0 0 .5rem; }

/* นิติบุคคล */
tr.group-row th { background: var(--bg, #f4f5f7); text-align: left; font-weight: 600; padding-top: .6rem; }
tr.group-row .mono, tr.group-row .badge { margin-left: .5rem; font-weight: 400; }
tr.subtotal-row th { font-weight: 600; border-top: 1px solid var(--border); }
.entity-list .entity-meta { display: flex; flex-wrap: wrap; gap: .25rem .75rem; font-size: .82rem; color: var(--muted); }
.branch-entity select { max-width: 16rem; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.section-head h2 { margin: 0; }
.entity-form { margin-top: 1rem; }

/* แก้ทุนในตาราง (กล่องลอย ใช้ได้ทั้งในตารางและในฟอร์มสินค้า) */
.qc-open { display: inline-block; font-size: .8rem; margin-top: .15rem; }
.modal.qc-panel { max-width: 440px; text-align: left; white-space: normal; }
.qc-panel .qc-head { margin: -.25rem 0 .75rem; }
.qc-panel p { margin: .5rem 0 0; }
.qc-fields { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.qc-fields select { flex: 1 1 9rem; }
.qc-fields input { flex: 1 1 8rem; text-align: right; }
.qc-preview { display: flex; flex-wrap: wrap; gap: .25rem .75rem; margin-top: .5rem; }
.qc-panel .actions { margin-top: .75rem; }

/* ใบโปรโมชัน */
.panel > label.check { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.pm-tiers { width: auto; margin-bottom: .5rem; }
.pm-tiers input, .pm-tiers select { width: 11rem; }
.pm-items { margin-top: .5rem; }

/* ตรวจนับสาขา */
tr.warn-row td { background: var(--warn-bg); }
table.clickable tr.selected td { background: var(--ok-bg); }
.panel .qty-input { width: 7rem; text-align: right; }
.big-number { font-size: 1.4rem; }

/* ---------------- ใบสั่งซื้อ (พิมพ์) ---------------- */
.po-print { max-width: 820px; margin: 0 auto; padding: 1.5rem; background: #fff; color: #111; text-align: left; }
.po-print h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
.po-print h1 small { font-size: .8rem; color: #666; font-weight: normal; }
.po-print h2 { font-size: .95rem; margin: 0 0 .25rem; color: #555; }
.po-print-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid #111; padding-bottom: .75rem; }
.po-print-meta th { text-align: left; padding-right: .75rem; font-weight: normal; color: #555; }
.po-print-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1rem 0; }
.po-print-lines { width: 100%; border-collapse: collapse; }
.po-print-lines th, .po-print-lines td { border: 1px solid #999; padding: .3rem .4rem; font-size: .9rem; }
.po-print-lines .num { text-align: right; }
.po-print-sign { display: flex; justify-content: space-between; margin-top: 3rem; text-align: center; }
.po-print-tools { text-align: right; margin-bottom: 1rem; }
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .po-print { padding: 0; }
}

/* ลูกหนี้ระหว่างสาขา */
.pc-filters label.check { flex-direction: row; align-items: center; gap: .4rem; align-self: flex-end; padding-bottom: .5rem; color: var(--text); }
.pc-filters label.check input { min-width: 0; }
.ar-nowrap { white-space: nowrap; }
.ar-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .ar-parties { grid-template-columns: 1fr; } }
.ar-totals td { padding: .2rem .5rem; }

/* สินค้าชุด */
.set-slot { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; margin: .6rem 0; background: var(--surface); }
.set-slot.selectable { border-left: 3px solid #0284c7; }
.set-slot.fixed { border-left: 3px solid #94a3b8; }
.set-slot-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.set-slot-head label { display: flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--muted); }
.set-slot-head .spacer { flex: 1; }
.set-slot-name { min-width: 14rem; font-weight: 600; }
.set-num { width: 6rem; }
.set-items { width: 100%; }
.set-add { position: relative; margin-top: .4rem; max-width: 28rem; }
.set-add input { width: 100%; }
.set-summary { margin: .75rem 0; }

/* เมนูซ้าย: กลุ่มพับได้ + ย่อแถบ (js/side-nav.js) */
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding-bottom: .75rem; }
.brand-row .brand { padding: .25rem .75rem; white-space: nowrap; }
.side-toggle {
    flex-shrink: 0; width: 36px; height: 36px; border: 0; border-radius: 8px; cursor: pointer;
    background: rgba(255,255,255,.08); color: #fff; font-size: 1.1rem; line-height: 1;
}
.side-toggle:hover { background: rgba(255,255,255,.16); }
.side-body { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-sec { border-radius: 8px; }
.nav-sec > summary {
    list-style: none; cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: space-between;
    padding: .55rem .75rem; margin-top: .35rem; border-radius: 6px;
    font-size: .78rem; font-weight: 600; letter-spacing: .04em; color: var(--side-ink); opacity: .75;
}
.nav-sec > summary::-webkit-details-marker { display: none; }
.nav-sec > summary::after { content: "▸"; font-size: .8rem; transition: transform .15s; }
.nav-sec[open] > summary::after { transform: rotate(90deg); }
.nav-sec > summary:hover { background: rgba(255,255,255,.06); opacity: 1; }
.nav-sec.has-active > summary { opacity: 1; color: #fff; }
.nav-sec > a { display: block; padding-left: 1.5rem; }
.nav-sec[open] { padding-bottom: .25rem; }

/* แถบย่อ: เหลือแค่ปุ่มขยาย เนื้อหาเต็มจอ */
.nav-collapsed .side { width: 60px; padding: 1rem .6rem; }
.nav-collapsed .side .brand, .nav-collapsed .side-body { display: none; }
.nav-collapsed .brand-row { justify-content: center; }

@media (max-width: 760px) {
    /* จอแคบ: เมนูเรียงลงตามปกติ (แทนแถวต่อกัน) กดปุ่มเพื่อพับทั้งแถบ */
    .side { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
    .side-body { flex-direction: column; }
    .nav-sec > a { padding-left: 1.5rem; }
    .nav-collapsed .side { width: auto; padding: .5rem; }
    .nav-collapsed .brand-row { justify-content: space-between; }
    .nav-collapsed .side .brand { display: block; }
    .side .user { margin-left: 0; }
}

/* รูปแบบการพิมพ์ (แม่แบบพิมพ์) */
.pl-settings { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .pl-settings { grid-template-columns: 1fr; } }
.pl-checks { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; margin: .5rem 0; }
.pl-checks label.check, .pl-settings label.check { flex-direction: row; align-items: center; gap: .4rem; display: flex; }
.pl-logo-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.pl-logo-preview { max-height: 48px; max-width: 140px; border: 1px solid var(--border); border-radius: 6px; padding: 2px; background: #fff; }
.pl-preview { position: sticky; top: 1rem; }
.pl-preview-box { border: 1px solid var(--border); border-radius: var(--radius); background: #e5e7eb; padding: .75rem; max-height: 80vh; overflow: auto; }
.pl-preview-box .pl-doc { box-shadow: 0 1px 4px rgba(0,0,0,.15); margin-bottom: 1rem; }

/* แม่แบบเอกสาร */
.plain-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.template-pick { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: .5rem; }

/* รูปสินค้า + เมนูสินค้าด่วน */
.hit-list { list-style: none; margin: .25rem 0 .75rem; padding: 0; max-height: 16rem; overflow-y: auto; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; }
.hit-list li { display: flex; gap: .5rem; align-items: center; padding: .35rem .6rem; border-bottom: 1px solid var(--border, #e2e8f0); }
.hit-list li:last-child { border-bottom: 0; }
.pimg { display: flex; gap: .75rem; align-items: flex-start; }
.pimg-thumb { width: 96px; height: 96px; border: 1px solid var(--border, #e2e8f0); border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #f8fafc; flex-shrink: 0; }
.pimg-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pimg-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.pimg-actions p { flex-basis: 100%; margin: 0; }
.pimg.compact .pimg-thumb { width: 56px; height: 56px; }
.pimg.compact .pimg-actions { flex-direction: column; align-items: flex-start; }
table.qm-items td { vertical-align: middle; }
