/* =====================================================================
   รอบ 28: ปรับหน้าแบบ "หน้าเดียวจบ" (fit-ops) — ใช้ร่วมกับ fit.css
   หน้า: ประวัติการขาย (Sales), ออเดอร์ออนไลน์ (Orders), รับ/โอน/ปรับสต็อก (Inventory),
         รายงาน (Reports), กะ/ลิ้นชักเงินสด (ShiftPage)
   prefix: .sla-* (ทับ sales.css เฉพาะใน .fit), .ord-*, .inv-*, .rep-*, .shf-*
   กฎทั้งหมดอยู่ใน @media screen เพื่อไม่ให้กระทบงานพิมพ์
   ===================================================================== */
@media screen {

  /* ---------- ส่วนร่วม: แถบตัวกรอง (ชิปซ้าย | วันที่ขวา) ---------- */
  .fit > .sla-cards, .fit > .sla-tabrow, .fit > .inv-readonly { flex: none; margin: 0; }
  .sla-bar, .ord-bar, .inv-bar, .rep-bar { justify-content: space-between; gap: 10px 16px; }
  .sla-dates, .ord-dates, .inv-dates, .rep-dates { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
  .fit-bar .field.inline input { min-height: 40px; padding: 6px 10px; }
  .fit .fit-empty-filter { border-style: dashed; }

  /* =================================================================
     ประวัติการขาย
     ================================================================= */
  .fit .sla-periods { margin: 0; padding: 0; align-items: center; }
  .fit .sla-cards { margin: 0; gap: 10px; }
  .fit .sla-card {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: 8px; row-gap: 0;
    padding: 9px 14px;
  }
  .fit .sla-card-label { grid-row: 1; grid-column: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .fit .sla-card-hint { grid-row: 1; grid-column: 2; text-align: right; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .fit .sla-card strong { grid-row: 2; grid-column: 1 / -1; font-size: 1.2rem; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .fit .sla-card.main strong { font-size: 1.3rem; }

  /* แท็บ + ยอดแยกตามวิธีชำระ แถวเดียว */
  .sla-tabrow { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px 18px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
  .sla-tabrow .sla-tabs { margin: 0; border-bottom: 0; }
  .sla-tabrow .sla-tabs button { min-height: 40px; padding: 6px 14px; }
  .sla-tabrow .sla-paysplit { margin: 0; padding: 0 2px 10px; justify-content: flex-end; gap: 4px 16px; }

  .fit .sla-bills td { padding-top: 9px; padding-bottom: 9px; }
  .sla-rscroll .sla-rsum { margin: 0 0 12px; padding: 12px 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
  .sla-rscroll .sla-rlist { padding-bottom: 6px; }

  /* =================================================================
     ออเดอร์ออนไลน์: จอคอม = รายการซ้าย | รายละเอียดขวา
     ================================================================= */
  .ord-dhead { display: none; }
  .ord-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; height: 100%; min-height: 200px; padding: 24px; text-align: center; color: var(--muted); }
  .ord-placeholder svg { opacity: .55; }
  .ord-placeholder p { margin: 0; max-width: 260px; }
  .ord-listpane .fit-empty-filter { padding: 18px 8px; }

  /* =================================================================
     รับ / โอน / ปรับสต็อก
     ================================================================= */
  .inv-fit .fit-search { width: 220px; }
  .inv-import-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
  .inv-actions { flex-wrap: nowrap; }
  .inv-types { display: flex; align-items: center; gap: 8px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .inv-types::-webkit-scrollbar { display: none; }
  .inv-types .chip { cursor: pointer; font: inherit; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px; }
  .inv-n { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--chip); color: var(--muted); font-size: .75rem; font-weight: 700; }
  .inv-types .chip.on .inv-n { background: rgba(255,255,255,.2); color: inherit; }
  .inv-import { display: flex; flex-direction: column; gap: 12px; }
  .inv-import p { margin: 0; }

  /* =================================================================
     รายงาน
     ================================================================= */
  .rep-quick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .rep-quick .chip { cursor: pointer; font: inherit; font-size: .9rem; }
  .rep-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 16px; align-items: start; }
  .rep-wide { grid-column: 1 / -1; }
  .rep-stats .fit-stat.rep-hl { background: var(--brand-tint); }
  .rep-stats .fit-stat.rep-hl strong { color: var(--brand-strong, var(--brand)); }
  .rep-sec { display: flex; flex-direction: column; min-width: 0; }
  .rep-sec > .fit-pane-head { margin: 0 0 8px; padding: 0 2px; }
  .rep-sec > .table-wrap, .rep-sec > .empty { margin: 0; }
  .rep-sec .table td { padding-top: 9px; padding-bottom: 9px; }

  /* =================================================================
     กะ / ลิ้นชักเงินสด
     ================================================================= */
  .shf-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
  .shf-grid > * { min-width: 0; }
  .shf-grid .panel { margin: 0; padding: 16px 18px; }
  .shf-grid .panel > h2 { font-size: 1.05rem; margin: 0 0 4px; }
  .shf-grid .panel > h2 + .muted { margin: 0 0 12px; }
  .shf-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

  .shf-live { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 12px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); font-size: .85rem; font-weight: 700; white-space: nowrap; }
  .shf-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 25%, transparent); }

  .shf-cur-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 24px; align-items: start; }
  .shf-nums { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .shf-nums + .shf-box:last-child { grid-column: 1 / -1; }
  .shf-note { font-size: .76rem; line-height: 1.35; font-weight: 400; }
  .shf-num { display: flex; flex-direction: column; gap: 1px; padding: 9px 12px; border-radius: 12px; background: var(--bg); min-width: 0; }
  .shf-num span { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .shf-num strong { font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .shf-box { min-width: 0; }
  .shf-box h3 { margin: 0 0 6px; font-size: .92rem; }
  .shf-box .cash-calc { max-width: none; }

  .shf-side .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
  .shf-move .form-grid > .field:last-child, .shf-close .form-grid > .field:last-child { grid-column: 1 / -1; }
  .shf-side .actions { margin-top: 12px; }
  /* รอบ 119: ประเภทนำเงินออก (รายจ่าย / ไม่ใช่รายจ่าย) + ป้ายประเภทในรายการเงินเข้า-ออก */
  .shf-move .form-grid > .shf-span { grid-column: 1 / -1; }
  .shf-kind button:disabled { color: var(--muted); background: var(--bg); cursor: not-allowed; }
  .shf-kind-hint { margin: -4px 0 0; }
  .shf-moves .detail-line > span:first-child { min-width: 0; overflow-wrap: anywhere; }
  .shf-mv-tag { display: inline-block; margin: 0 4px 0 2px; padding: 0 8px; font-size: .74rem; line-height: 1.6; border-radius: 999px; vertical-align: 1px; }
  .shf-mv-tag.is-exp { background: var(--warn-soft); color: inherit; }
  .shf-moves { margin-top: 12px; padding-top: 6px; border-top: 1px dashed var(--line); max-height: 240px; overflow: auto; overscroll-behavior: contain; }
  .shf-moves .detail-line { max-width: none; padding: 4px 0; gap: 12px; border-bottom: 1px solid var(--bg); }
  .shf-moves .detail-line > .num { flex: none; }
  .shf-close .heldb-shift-warn { margin: 0 0 12px; }
  .shf-close .form-grid { align-items: start; }

  .shf-hist-head { align-items: center; }
  .shf-hist-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
  .shf-hist-tools .field.inline input { min-height: 38px; padding: 5px 10px; }
  .shf-history .table-wrap { box-shadow: none; border-radius: 0; }
  .shf-history > .empty { margin: 0; }
  .shf-history .table td { padding-top: 9px; padding-bottom: 9px; }
}

/* ---------- จอคอม: พอดีจอ ---------- */
@media screen and (min-width: 1025px) {
  .rep-stats { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  /* ขาย: การ์ดสรุปแถวเดียว */
  .fit .sla-cards { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .sla-rscroll { padding: 2px 8px 8px; margin: 0 -8px; }

  /* ออเดอร์: รายละเอียดของการ์ดที่เปิด ย้ายไปแสดงในพื้นที่ขวา (DOM เดียวกับมือถือ) */
  .ord-split.fit-split.left { --ord-l: 400px; position: relative; grid-template-columns: var(--ord-l) minmax(0, 1fr); }
  .ord-listpane { padding: 12px; }
  .ord-listpane > .fit-scroll { margin: 0 -12px; padding: 0 12px 4px; }
  .ord-listpane .order-list { gap: 8px; }
  .ord-listpane .order-card { box-shadow: none; }
  .ord-listpane .order-card.open { background: var(--brand-tint); }
  .ord-split .order-card.open > .order-detail {
    position: absolute; top: 0; right: 0; bottom: 0; width: calc(100% - var(--ord-l) - 16px); z-index: 3;
    overflow: auto; overscroll-behavior: contain; padding: 0 22px 22px; border-top: 0;
    background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  }
  .ord-dhead {
    display: flex; align-items: center; gap: 10px 14px; position: sticky; top: 0; z-index: 2;
    margin: 0 -22px 6px; padding: 16px 14px 12px 22px; background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .ord-dhead-main { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
  .ord-dhead-no { font-size: 1.2rem; }
  .ord-dhead-total { font-size: 1.2rem; flex: none; }
  .ord-dhead-close { flex: none; width: 38px; height: 38px; border-radius: 999px; border: 0; background: var(--chip); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
  .ord-dhead-close:hover { background: var(--line); }
  .ord-split.has-open .ord-placeholder { visibility: hidden; }
  .ord-split .order-detail .detail-line { padding-left: 0; max-width: 460px; gap: 12px; }
  .ord-split .order-cols { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 8px 24px; }

  /* กะ: กะปัจจุบัน + ประวัติ ซ้าย | นำเงินเข้า-ออก + ปิดกะ ขวา (เลื่อนในคอลัมน์) */
  .shf-grid {
    flex: 1 1 auto; min-height: 0;
    grid-template-columns: minmax(0, 1fr) minmax(330px, 370px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "cur side" "hist side";
  }
  .shf-grid.no-shift { grid-template-rows: minmax(0, 1fr); grid-template-areas: "hist side"; }
  /* รอบ 133: ไม่มีสิทธิ์ดูประวัติกะ — มีกะ: กะปัจจุบัน | ขวา · ไม่มีกะ: ฟอร์มเปิดกะกลางจอ */
  .shf-grid.no-hist { grid-template-rows: auto; grid-template-areas: "cur side"; align-content: start; }
  .shf-grid.no-shift.no-hist { grid-template-columns: minmax(0, 560px); grid-template-areas: "side"; justify-content: center; }
  .shf-current { grid-area: cur; }
  .shf-side { grid-area: side; min-height: 0; overflow: auto; overscroll-behavior: contain; margin: 0 -8px; padding: 0 8px 8px; }
  .shf-history { grid-area: hist; min-height: 0; overflow: hidden; }
  .shf-by-m { display: none; }
  .shf-history .table td.r { white-space: nowrap; }
  .shf-history .table th, .shf-history .table td { padding-left: 10px; padding-right: 10px; }
}
/* จอคอมขนาดกลาง: ปุ่มนำเข้าเหลือแต่ไอคอน ให้หัวอยู่แถวเดียว */
@media screen and (min-width: 1025px) and (max-width: 1599px) {
  .inv-import-btn { padding-left: 11px; padding-right: 11px; }
  .inv-import-btn span { display: none; }
  .inv-fit .fit-search { width: 200px; }
}
@media screen and (min-width: 1500px) {
  .ord-split.fit-split.left { --ord-l: 460px; }
  .shf-grid { grid-template-columns: minmax(0, 1fr) 440px; }
}

/* ---------- แท็บเล็ต + มือถือ ---------- */
@media screen and (max-width: 1024px) {
  /* ออเดอร์: กลับเป็นการ์ดกางรายละเอียดใต้รายการแบบเดิม */
  .ord-side { display: none; }
  .ord-listpane { padding: 0; background: none; box-shadow: none; border: 0; border-radius: 0; }
  .rep-grid { grid-template-columns: minmax(0, 1fr); }
  .shf-by { display: none; }
}

@media screen and (max-width: 760px) {
  .sla-bar, .ord-bar, .inv-bar, .rep-bar { gap: 8px; }
  .sla-dates, .ord-dates, .inv-dates, .rep-dates { width: 100%; gap: 8px 10px; }
  .fit .sla-periods { width: 100%; }
  .fit .sla-card { padding: 10px 12px; }
  .fit .sla-card strong { font-size: 1.1rem; }
  .fit .sla-card.main strong { font-size: 1.4rem; }
  /* รอบ 98: คอลัมน์ + wrap = ลูกแตกไปคอลัมน์ข้าง ๆ เมื่อสูงจำกัด → nowrap */
  .sla-tabrow { flex-direction: column-reverse; flex-wrap: nowrap; align-items: stretch; border-bottom: 0; gap: 8px; }
  .sla-tabrow .sla-tabs { border-bottom: 1px solid var(--line); }
  .sla-tabrow .sla-paysplit { justify-content: flex-start; padding: 0; }

  .ord-bar .segmented.tabs { width: 100%; }
  /* ช่องค้นหาหดได้ ปุ่มข้างๆ ไม่ล้นจอ */
  .sla-fit .fit-tools .fit-search, .ord-fit .fit-tools .fit-search { min-width: 0; }
  .sla-fit .fit-tools > .btn, .ord-fit .fit-tools > .btn { padding-left: 12px; padding-right: 12px; }

  /* รับ/โอน/ปรับ: ช่องค้นหาเต็มแถว ปุ่มเอกสาร 2x2 */
  .inv-fit .fit-tools { flex-wrap: wrap; }
  .inv-fit .fit-search { width: 100%; flex: 1 1 100%; }
  .inv-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; }
  .inv-actions .btn { width: 100%; padding-left: 8px; padding-right: 8px; }
  .inv-types { width: 100%; }

  .rep-quick { width: 100%; }
  .rep-fit .fit-tools > .btn { flex: 1 1 auto; justify-content: center; }
  .rep-quick .chip { flex: 1 1 0; text-align: center; }

  .shf-grid .panel { padding: 14px; }
  .shf-side .form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .shf-history { background: none; box-shadow: none; padding: 0 !important; }
  .shf-hist-tools { width: 100%; }
  .shf-hist-tools .field.inline { flex: 1 1 140px; flex-direction: column; align-items: stretch; gap: 2px; }
  .shf-hist-tools .btn { flex: 1 1 100%; }
  .shf-nums { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shf-cur-grid { grid-template-columns: minmax(0, 1fr); }
}

/* รอบ 102: ลิงก์ไปหน้าโอนสินค้า (แทนปุ่มโอนทันที) + หัวช่องผู้จำหน่ายพร้อมปุ่ม "+ ผู้จำหน่ายใหม่" ในใบรับสินค้า */
@media screen {
  .inv-transfer-link { display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
  .inv-transfer-link svg { flex: none; }
  .inv-sup-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 8px; min-width: 0; }
  .inv-sup-head .link { font-weight: 600; text-decoration: none; font-size: .86rem; white-space: nowrap; }
  .inv-sup-head .link:hover { text-decoration: underline; }
}
