/* =====================================================================
   รอบ 46: ล็อต / วันหมดอายุ (โมดูล lots)
   - สีวันที่เหลือ: .lot-x หมดอายุ (แดง) / .lot-s ≤30 วัน (เหลือง) / .lot-ok / .lot-none
   - สินค้า: .lot-prod-box (สวิตช์ + อายุสินค้า), .lot-badge ในรายการ
   - รับเข้า: .lot-in (เลขล็อต + วันหมดอายุ) ใน Inventory / PoReceive
   - สต็อก: .lot-chip, .lot-stat, ลิ้นชัก .lot-sum/.lot-list
   - หน้า /expiry: .lot-fit, .lot-tabs, .lot-table, .lot-actbar, พิมพ์ A4 html[data-print="lot"] .lot-print
   ===================================================================== */

@media screen {
  :root { --lot-amber: var(--warn-text, #8A5A00); }

  /* ---------- ชิปวันที่เหลือ ---------- */
  .lot-days {
    display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 999px;
    font-size: .78rem; font-weight: 700; white-space: nowrap; background: var(--chip); color: var(--muted);
  }
  .lot-days.lot-x { background: var(--danger-soft); color: var(--danger); }
  .lot-days.lot-s { background: var(--warn-soft); color: var(--lot-amber); }
  .lot-days.lot-ok { background: var(--ok-soft); color: var(--ok); }

  /* ---------- สินค้า ---------- */
  .lot-prod-box {
    grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 20px;
    padding: 12px 14px; border: 1px dashed var(--line); border-radius: var(--radius-sm); background: var(--surface);
  }
  .lot-prod-box.on { border-style: solid; border-color: rgba(var(--brand-rgb), .35); background: var(--brand-tint); }
  .lot-switch { display: flex; align-items: center; gap: 12px; cursor: pointer; flex: 1 1 260px; min-width: 0; position: relative; }
  .lot-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
  .lot-switch-ui { flex: none; position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--line); transition: background .15s; }
  .lot-switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
  .lot-switch input:checked + .lot-switch-ui { background: var(--brand); }
  .lot-switch input:checked + .lot-switch-ui::after { transform: translateX(18px); }
  .lot-switch input:focus-visible + .lot-switch-ui { box-shadow: 0 0 0 3px var(--brand-soft); }
  .lot-switch-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
  .lot-switch-text small { font-size: .8rem; }
  .lot-shelf { flex: 0 1 240px; min-width: 0; margin: 0; }
  .lot-shelf-row { display: flex; align-items: center; gap: 8px; }
  .lot-shelf-row input { width: 110px; min-width: 0; }
  .lot-shelf small { font-size: .76rem; line-height: 1.35; }

  .lot-badge {
    display: inline-flex; align-items: center; gap: 3px; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
    background: var(--brand-soft); color: var(--brand-strong, var(--brand)); font-size: .7rem; font-weight: 700; vertical-align: middle; white-space: nowrap;
  }

  /* ---------- รับเข้า: เลขล็อต + วันหมดอายุ ---------- */
  .lot-in {
    grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px;
    margin: 6px 0 0 54px; padding: 8px 10px; border-radius: var(--radius-sm);
    background: var(--brand-tint); border: 1px solid rgba(var(--brand-rgb), .18);
  }
  .lot-in.need { background: var(--warn-soft); border-color: rgba(176, 120, 0, .35); }
  .lot-in-ico { display: inline-flex; align-self: center; color: var(--brand); }
  .lot-in-f { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 0 1 180px; }
  .lot-in-f .rcv-lbl { display: block; font-size: .74rem; font-weight: 600; color: var(--muted); }
  .lot-in-f input { width: 100%; min-width: 0; }
  .lot-req { color: var(--danger); font-weight: 800; }
  .lot-in-hint { align-self: center; font-size: .76rem; }
  .lot-in .lot-days { align-self: center; }
  .po-rc-lot td { padding-top: 0 !important; border-top: 0 !important; }
  .po-rc-lot .lot-in { margin: 0 0 4px; }
  .po-rc-lot.skip { opacity: .55; }

  /* ---------- สต็อก ---------- */
  .lot-chip {
    display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; padding: 2px 9px; min-height: 24px;
    border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted);
    font: inherit; font-size: .74rem; font-weight: 600; cursor: pointer; max-width: 100%;
  }
  .lot-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lot-chip:hover { border-color: var(--brand); color: var(--brand); }
  .lot-chip.lot-x { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
  .lot-chip.lot-s { background: var(--warn-soft); border-color: transparent; color: var(--lot-amber); }
  .lot-chip.lot-ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
  td .lot-chip { display: flex; width: fit-content; }
  .actions-cell .lot-btn { margin-right: 4px; }
  a.fit-stat.lot-stat { text-decoration: none; color: inherit; border: 1px solid transparent; }
  a.fit-stat.lot-stat strong { color: var(--lot-amber); }
  a.fit-stat.lot-stat.x strong { color: var(--danger); }
  a.fit-stat.lot-stat:hover { border-color: var(--brand); }

  /* ลิ้นชักล็อต */
  .lot-sum { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 14px; }
  .lot-sum > div { background: var(--chip); border-radius: var(--radius-sm); padding: 8px 10px; min-width: 0; }
  .lot-sum dt { font-size: .74rem; color: var(--muted); }
  .lot-sum dd { margin: 0; font-weight: 700; font-size: .92rem; overflow-wrap: anywhere; }
  .lot-sum .muted-v dd { color: var(--lot-amber); }
  .lot-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
  .lot-row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main days" "qty qty"; gap: 4px 10px; align-items: center;
    padding: 10px 12px; border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  }
  .lot-row.lot-x { border-left-color: var(--danger); }
  .lot-row.lot-s { border-left-color: #D99A1E; }
  .lot-row.lot-ok { border-left-color: var(--ok); }
  .lot-row-main { grid-area: main; display: flex; flex-direction: column; min-width: 0; }
  .lot-row-main strong { overflow-wrap: anywhere; }
  .lot-row .lot-days { grid-area: days; justify-self: end; }
  .lot-row-qty { grid-area: qty; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
  .lot-untracked-note {
    display: flex; gap: 8px; align-items: flex-start; margin: 14px 0 0; padding: 10px 12px; border-radius: var(--radius-sm);
    background: var(--warn-soft); color: var(--ink); font-size: .84rem; line-height: 1.45;
  }
  .lot-untracked-note svg { flex: none; color: var(--lot-amber); margin-top: 2px; }

  /* ---------- หน้า /expiry ---------- */
  .lot-bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 16px; }
  .lot-tabs { display: inline-flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--chip); }
  .lot-tab {
    display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px; border: 0; border-radius: 10px;
    background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
  }
  .lot-tab.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
  .lot-n { min-width: 24px; padding: 0 7px; border-radius: 999px; background: var(--surface); font-size: .76rem; line-height: 22px; text-align: center; }
  .lot-tab.on.x .lot-n { background: var(--danger); color: #fff; }
  .lot-tab.on.s .lot-n { background: #D99A1E; color: #fff; }
  .lot-days-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .lot-stats .lot-st { border: 1px solid transparent; text-align: left; font: inherit; color: inherit; cursor: default; }
  .lot-stats button.lot-st { cursor: pointer; }
  .lot-stats .lot-st small { font-size: .82rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .lot-stats .lot-st.x strong { color: var(--danger); }
  .lot-stats .lot-st.s strong { color: var(--lot-amber); }
  .lot-stats .lot-st.on { border-color: var(--brand); }

  .lot-table .lot-c-prod { min-width: 220px; }
  .lot-pick { display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; margin: 0; }
  .lot-pick input[type="checkbox"] { flex: none; width: 18px; height: 18px; accent-color: var(--brand); }
  .lot-prod-text { display: flex; flex-direction: column; min-width: 0; }
  .lot-prod-text strong { overflow-wrap: anywhere; }
  .lot-table tr.picked td { background: var(--brand-tint); }
  .lot-table tr.lot-x td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
  .lot-table tr.lot-s td:first-child { box-shadow: inset 4px 0 0 #D99A1E; }

  .lot-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; }
  .lot-empty-ico { display: inline-flex; width: 60px; height: 60px; align-items: center; justify-content: center; border-radius: 50%; background: var(--ok-soft); color: var(--ok); }

  .lot-actbar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-radius: var(--radius);
    background: var(--surface); box-shadow: var(--shadow-lg); border: 1px solid var(--line);
    position: sticky; bottom: 12px; z-index: 5;
  }
  .lot-actbar-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; line-height: 1.3; }
  .lot-actbar-text small { color: var(--muted); }
  .lot-wo-btn { display: inline-flex; align-items: center; gap: 6px; }

  .lot-confirm { display: flex; flex-direction: column; gap: 10px; }
  .lot-confirm p { margin: 0; }
  .lot-confirm-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 260px; overflow: auto; }
  .lot-confirm-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); }
  .lot-confirm-list li:first-child { border-top: 0; }
  .lot-confirm-list li > span { min-width: 0; overflow-wrap: anywhere; }
  .lot-confirm-list li small { display: block; }
  .lot-confirm-val { font-weight: 700; color: var(--danger); }
  .lot-confirm textarea { width: 100%; }

  .lot-data-hint { color: var(--brand-strong, var(--brand)); }

  /* ตัวอย่างพิมพ์บนจอ */
  .lot-paper .lot-plines td small { display: block; color: #666; }
  .lot-pcheck { width: 56px; }
  .lot-psum { margin-left: auto; max-width: 320px; }
}

/* จอคอม: แถบตัดของติดล่างของหน้า */
@media screen and (min-width: 1025px) {
  .lot-fit .fit-body { flex: 1 1 auto; min-height: 0; }
}

/* มือถือ */
@media screen and (max-width: 760px) {
  .lot-in { margin-left: 0; }
  .lot-in-f { flex: 1 1 140px; }
  .lot-prod-box { padding: 10px 12px; }
  .lot-sum { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .lot-sum > div { padding: 6px 8px; }
  /* รอบ 98: คอลัมน์ + wrap = แต่ละบรรทัดกว้างตามเนื้อหา → แถวชิปเลื่อนไม่ได้และล้นจอ → nowrap */
  .lot-bar { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .lot-tabs { display: flex; }
  .lot-tab { flex: 1 1 0; justify-content: center; padding: 0 8px; }
  .lot-days-chips { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .lot-stats { grid-template-columns: 1fr 1fr; }
  .lot-stats .lot-st:last-child { display: none; }
  .lot-table .lot-c-prod { min-width: 0; }
  .lot-actbar { bottom: calc(84px + env(safe-area-inset-bottom)); padding: 10px 12px; gap: 8px; }
  .lot-actbar-text { flex: 1 1 100%; }
  .lot-actbar .btn { flex: 1 1 0; justify-content: center; padding-left: 10px; padding-right: 10px; }
  .lot-actbar .lot-wo-btn { flex: 2 1 0; }
  .lot-table tr.lot-x td:first-child, .lot-table tr.lot-s td:first-child { box-shadow: none; }
  .lot-table tr.lot-x { border-left: 4px solid var(--danger); }
  .lot-table tr.lot-s { border-left: 4px solid #D99A1E; }
  .lot-tools .fitc-ico-btn span { display: none; }
}

/* ---------- พิมพ์ A4 ---------- */
@page lot-a4 { size: A4; margin: 12mm; }
@media print {
  html[data-print="lot"]:has(.lot-print), html[data-print="lot"]:has(.lot-print) body {
    margin: 0 !important; padding: 0 !important; height: auto !important; overflow: visible !important;
    background: #fff !important; color: #111 !important; page: lot-a4;
  }
  html[data-print="lot"]:has(.lot-print) body *:not(:has(.lot-print)):not(.lot-print):not(.lot-print *) { display: none !important; }
  html[data-print="lot"]:has(.lot-print) body *:has(.lot-print) {
    display: block !important; position: static !important; inset: auto !important;
    margin: 0 !important; padding: 0 !important; border: 0 !important; border-radius: 0 !important;
    width: auto !important; max-width: none !important; min-width: 0 !important;
    height: auto !important; min-height: 0 !important; max-height: none !important;
    overflow: visible !important; background: none !important; box-shadow: none !important; transform: none !important;
    animation: none !important; zoom: 1 !important;
  }
  html[data-print="lot"] .lot-print, html[data-print="lot"] .lot-print * { visibility: visible !important; }
  html[data-print="lot"] .lot-print { display: block !important; position: static !important; }
  html[data-print="lot"] .lot-paper {
    max-width: none !important; margin: 0 !important; padding: 0 !important; box-shadow: none !important; border-radius: 0 !important;
    font-size: 10pt; gap: 4mm;
  }
  html[data-print="lot"] .lot-plines { font-size: 9pt; }
  html[data-print="lot"] .lot-plines thead { display: table-header-group; }
  html[data-print="lot"] .lot-plines td small { display: block; color: #555; }
  html[data-print="lot"] .lot-pcheck { width: 14mm; border-bottom: 1px dotted #999; }
  html[data-print="lot"] .lot-psum { margin-left: auto; max-width: 80mm; }
}

/* ---------- ใบรับสินค้า (GRN) / คืนสินค้าผู้จำหน่าย ---------- */
.grn-plot { display: block; font-size: .85em; color: #555; }
@media screen {
  .lot-grn-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; font-size: .78rem; color: var(--muted); }
  .lot-grn-line svg { color: var(--brand); flex: none; }
  .lot-sr { display: flex; align-items: center; gap: 6px; margin-top: 6px; max-width: 100%; color: var(--brand); }
  .lot-sr svg { flex: none; }
  .lot-sr select { flex: 1 1 auto; min-width: 0; max-width: 100%; font-size: .82rem; padding-top: 4px; padding-bottom: 4px; }
}
