/* ต้นแบบ inventory-buddy index.html <head> <style> */

    :root {
      --bg-main: #f5f5f2;
      --brand: #526b7a;
      --brand-hover: #445a68;
      --brand-soft: #eef2f4;
      --brand-ink: #ffffff;
      --bg-sidebar: #ffffff;
      --bg-card: #ffffff;
      --bg-topbar: #ffffff;
      --text-primary: #25272c;
      --text-secondary: #626973;
      --text-muted: #646d78;
      --border-color: #e1e3e6;
      --accent: #272a30;
      --accent-hover: #41464f;
      --accent-light: #edf1f5;
      --table-hover: #f4f6f8;
      --focus-color: #526b89;
      --danger: #d32f2f;
      --success: #2e7d32;
      --warning: #e65100;
      --badge-bg: #1a1a1a;
      --badge-text: #ffffff;
      --input-bg: #f7f8f8;
      --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
      --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
      --sidebar-width: 270px;
      --topbar-height: 60px;
      --radius: 10px;
      --radius-sm: 6px;
    }
    /* ═══ Company Switcher (Home) ═══ */
    .hcs-card {
      display: flex; align-items: center; gap: 10px;
      padding: 10px 12px; border-radius: 10px;
      border: 1.5px solid var(--border-color);
      background: var(--bg-card);
      cursor: pointer; transition: all 0.2s cubic-bezier(.25,.8,.25,1);
      text-align: left; width: 100%;
      font-family: 'Noto Sans Thai', sans-serif;
      position: relative; overflow: hidden;
    }
    .hcs-card:hover {
      border-color: #888;
      background: var(--accent-light);
      box-shadow: 0 4px 14px rgba(0,0,0,0.08);
      transform: translateY(-2px);
    }
    .hcs-card.hcs-active {
      border-color: #444444;
      /* background: linear-gradient(135deg, #dcdcdcab 0%, #d4d4d4d6 100%);
      box-shadow: 0 4px 16px rgba(99,102,241,0.12), 0 0 0 1px #c7d2fe inset; */
      pointer-events: none;
      transform: none;
    }
    .hcs-avatar {
      width: 36px; height: 36px; border-radius: 9px;
      background: var(--accent); color: var(--badge-text);
      display: flex; align-items: center; justify-content: center;
      font-size: 13px; font-weight: 700;
      flex-shrink: 0; letter-spacing: -0.5px;
      font-family: 'Noto Sans Thai', sans-serif;
      transition: box-shadow 0.2s;
    }
    .hcs-card-name {
      font-size: 12.5px; font-weight: 600; color: var(--text-primary);
      line-height: 1.4; overflow: hidden;
      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    }
    .hcs-card-status {
      font-size: 10px; color: var(--text-muted); margin-top: 3px;
      display: flex; align-items: center; gap: 4px;
    }
    .hcs-card.hcs-active .hcs-card-status { color: #444444; }
    /* active pill badge inside card */
    .hcs-active-pill {
      display: inline-flex; align-items: center; gap: 4px;
      background: #444444; color: #fff;
      font-size: 9.5px; font-weight: 700; letter-spacing: .3px;
      padding: 2px 8px; border-radius: 99px;
      text-transform: uppercase;
    }
    /* type tag (HQ/สาขา) — แยกจาก active pill โดยเจตนา ให้เป็น metadata เบาๆ ไม่แย่งความสนใจ */
    .hcs-type-tag {
      display: inline-flex; align-items: center; gap: 3px;
      font-size: 9.5px; font-weight: 600; letter-spacing: .2px;
      padding: 2px 7px; border-radius: 99px;
      border: 1px solid var(--border-color);
      color: var(--text-secondary);
      background: var(--bg-card);
      white-space: nowrap;
    }
    .hcs-type-tag i { font-size: 10px; }
    .hcs-type-tag.hcs-type-branch {
      color: #1565c0; border-color: #c7ddf5; background: #eef5fd;
    }
    .hcs-card-meta-row {
      display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px;
    }
    .hcs-card-switch-icon {
      margin-left: auto; flex-shrink: 0;
      width: 26px; height: 26px; border-radius: 6px;
      background: transparent; color: var(--text-muted);
      display: flex; align-items: center; justify-content: center;
      font-size: 14px; opacity: 0; transition: opacity .15s;
    }
    .hcs-card:hover .hcs-card-switch-icon { opacity: 1; color: var(--accent); }
    .hcs-card.hcs-active .hcs-card-switch-icon {
      opacity: 1; color: #444444;
      background: rgba(99,102,241,0.1);
    }
    #hcs-grid::-webkit-scrollbar { width: 4px; }
    #hcs-grid::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

    /* ═══ Global Company Search (topbar) ═══ */
    .gcs-wrap { position: relative; width: 100%; }
    .gcs-input-box { position: relative; }
    .gcs-input-box > i {
      position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
      font-size: 14px; color: var(--text-muted); pointer-events: none; transition: color .15s;
    }
    .gcs-input-box:focus-within > i { color: var(--accent); }
    .gcs-input {
      width: 100%; height: 34px; padding: 0 30px 0 32px; border: 1.5px solid var(--border-color);
      border-radius: 8px; font-size: 12.5px; background: var(--input-bg); color: var(--text-primary);
      font-family: 'Noto Sans Thai', sans-serif; outline: none; transition: all .15s ease;
    }
    .gcs-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,26,26,0.06); }
    .gcs-clear-btn {
      position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
      width: 22px; height: 22px; border: none; background: transparent; color: var(--text-muted);
      align-items: center; justify-content: center; border-radius: 6px; cursor: pointer; font-size: 13px;
    }
    .gcs-clear-btn:hover { background: var(--accent-light); color: var(--text-primary); }
    .gcs-dropdown {
      display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0;
      background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 10px;
      box-shadow: var(--shadow-md); z-index: 3000; max-height: 320px; overflow-y: auto;
      padding: 6px; animation: gcsFadeIn .14s ease;
    }
    @keyframes gcsFadeIn { from { opacity:0; transform:translateY(-4px); } to { opacity:1; transform:none; } }
    .gcs-dropdown::-webkit-scrollbar { width: 4px; }
    .gcs-dropdown::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
    .gcs-section-label {
      font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase;
      letter-spacing: .4px; padding: 6px 8px 4px;
    }
    .gcs-item {
      display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px;
      cursor: pointer; transition: background .12s ease; scroll-margin: 6px;
    }
    .gcs-item:hover, .gcs-item.gcs-item-highlight { background: var(--table-hover); }
    .gcs-item.gcs-item-active { cursor: default; background: var(--accent-light); }
    .gcs-avatar-sm {
      width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
      display: flex; align-items: center; justify-content: center;
      font-size: 11.5px; font-weight: 700; letter-spacing: -0.3px;
      font-family: 'Noto Sans Thai', sans-serif;
    }
    .gcs-item-body { flex: 1; min-width: 0; }
    .gcs-item-name {
      font-size: 12.5px; font-weight: 600; color: var(--text-primary);
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .gcs-item-sub { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; display: flex; align-items: center; gap: 4px; }
    .gcs-pill-active {
      display: inline-flex; align-items: center; gap: 3px; color: #2e7d32; font-weight: 700;
      font-size: 10px; text-transform: uppercase; letter-spacing: .3px;
    }
    .gcs-item-icon { flex-shrink: 0; font-size: 14px; color: var(--text-muted); opacity: 0; transition: opacity .12s; }
    .gcs-item:hover .gcs-item-icon, .gcs-item.gcs-item-highlight .gcs-item-icon { opacity: 1; color: var(--accent); }
    .gcs-item.gcs-item-active .gcs-item-icon { opacity: 1; color: #2e7d32; }
    .gcs-empty { padding: 24px 12px; text-align: center; color: var(--text-muted); font-size: 12px; }
    .gcs-empty i { font-size: 26px; display: block; margin-bottom: 6px; opacity: .4; }
    /* === Purchase Charges Section === */
    #gr-charges-section { animation: fadeInDown 0.18s ease; }
    @keyframes fadeInDown { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:none; } }
    #gr-charges-lines input[type="text"]:focus,
    #gr-charges-lines input[type="number"]:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px rgba(26,26,26,0.08); }

    /* === Financial Statements unified tab strip === */
    .fs-tabs-strip{display:flex;gap:2px;flex-wrap:wrap;position:relative;z-index:1}
    .fs-tab-btn{padding:9px 20px;font-size:13px;font-weight:600;background:var(--bg-main);border:1px solid var(--border-color);border-bottom:none;border-radius:8px 8px 0 0;cursor:pointer;color:var(--text-secondary);display:inline-flex;align-items:center;gap:6px;transition:all .15s ease;white-space:nowrap}
    .fs-tab-btn:hover{color:var(--text-primary)}
    .fs-tab-btn.active{background:var(--bg-card);color:var(--text-primary)}
    .fs-tab-btn i{font-size:15px}
    .fs-tabs-strip-top{display:flex;gap:2px;flex-wrap:wrap;background:rgba(0,0,0,0.04);border-radius:12px;padding:4px;width:fit-content;border:1px solid var(--border-color)}
    .fs-tabs-strip-top .fs-tab-btn{padding:8px 18px;font-size:13px;font-weight:500;border:none;background:transparent;cursor:pointer;color:var(--text-secondary);border-radius:9px;transition:all .2s}
    .fs-tabs-strip-top .fs-tab-btn:hover:not(.active){color:var(--text-primary)}
    .fs-tabs-strip-top .fs-tab-btn.active{font-weight:700;background:var(--bg-card);color:var(--text-primary);box-shadow:0 2px 4px rgba(0,0,0,0.08)}
    .fs-tabs-sticky-bar{position:sticky;top:var(--topbar-height);z-index:60;background:var(--bg-main);margin:0 -20px;padding:10px 20px 16px}
    body.topnav-mode .fs-tabs-sticky-bar{top:calc(var(--topbar-height) + 48px)}
    @media(max-width:768px){#br-match-columns{grid-template-columns:1fr!important}#br-move-summary-cards{grid-template-columns:repeat(2,1fr)!important}#br-selbar{left:16px!important}}
    @media(max-width:480px){#br-move-summary-cards{grid-template-columns:1fr!important}}

    [data-theme="dark"] {
      --bg-main: #181a1d;
      --brand: #9fb6c4;
      --brand-hover: #b9cbd6;
      --brand-soft: #2a3238;
      --brand-ink: #15191c;
      --bg-sidebar: #22252a;
      --bg-card: #22252a;
      --bg-topbar: #22252a;
      --text-primary: #eef0f2;
      --text-secondary: #b7bcc4;
      --text-muted: #9ba3ae;
      --border-color: #383d45;
      --accent: #e2e6eb;
      --accent-hover: #ffffff;
      --accent-light: #2c333d;
      --table-hover: #2a3038;
      --focus-color: #a8bdd6;
      --danger: #ef5350;
      --success: #66bb6a;
      --warning: #ffa726;
      --badge-bg: #f0f0f0;
      --badge-text: #111111;
      --input-bg: #292e35;
      --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
      --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    }

    * { box-sizing: border-box; transition: background-color 0.2s, border-color 0.2s, color 0.2s; }

    body {
      font-family: 'Noto Sans Thai', sans-serif;
      background: var(--bg-main);
      color: var(--text-primary);
      min-height: 100vh;
      margin: 0;
    }

    /* ─── Topbar ─── */
    .topbar {
      position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-height);
      background: var(--bg-topbar);
      border-bottom: 1px solid var(--border-color);
      display: flex; align-items: center; padding: 0 20px;
      z-index: 1000; gap: 12px;
      box-shadow: var(--shadow-sm);
    }
    .topbar-brand {
      font-family: 'Noto Sans Thai', sans-serif;
      font-weight: 600; font-size: 15px; letter-spacing: -0.5px;
      color: var(--text-primary); text-decoration: none;
      display: flex; align-items: center; gap: 8px;
    }
    .brand-dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; }
    .brand-logo { width: 24px; height: 24px; object-fit: contain; display: block; }
    [data-theme="dark"] .brand-logo { filter: invert(1) brightness(1.4); }
    .topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

    .btn-icon {
      width: 36px; height: 36px; border-radius: var(--radius-sm);
      border: 1px solid var(--border-color);
      background: transparent; color: var(--text-secondary);
      display: inline-flex; align-items: center; justify-content: center;
      cursor: pointer; font-size: 18px;
      transition: all 0.15s;
    }
    .btn-icon:hover { background: var(--accent-light); color: var(--text-primary); }

    .sidebar-toggle { display: flex; }

    /* ═══════════════════════════════════════════════
       SIDEBAR — Modern International ERP Style
       ─ inspired by Linear / Notion / SAP Fiori
    ═══════════════════════════════════════════════ */

    /* ── Container ── */
    .sidebar {
      position: fixed; top: var(--topbar-height); left: 0;
      width: var(--sidebar-width);
      height: calc(100vh - var(--topbar-height));
      background: var(--bg-sidebar);
      border-right: 1px solid var(--border-color);
      padding: 8px 0 24px;
      overflow-y: auto; overflow-x: hidden;
      z-index: 900;
      transition: transform 0.25s cubic-bezier(.4,0,.2,1), width 0.22s cubic-bezier(.4,0,.2,1);
      scrollbar-width: thin;
      scrollbar-color: var(--border-color) transparent;
    }
    /* MOBILE/TABLET: ซ่อน sidebar นอกจอเสมอ จนกว่าจะกด hamburger */
    @media (max-width: 991px) {
      /* บังคับให้ sidebar ใช้เป็นเมนูหลักเสมอบนจอเล็ก แม้ผู้ใช้จะตั้งค่า Desktop ไว้เป็น "เมนูด้านบน" (topnav-mode)
         ก็ตาม — เดิม body.topnav-mode .sidebar{display:none} มี specificity สูงกว่า .sidebar.mobile-open ทำให้กด
         hamburger แล้วเห็นแค่ backdrop แต่เมนูไม่ขึ้น ต้องบังคับกลับมาเป็น display:block ที่นี่ */
      body.topnav-mode .sidebar {
        display: block !important;
      }
      /* Drawer เต็มความสูงจอ (top:0) แทนที่จะเริ่มใต้ topbar (var(--topbar-height))
         เพราะ topbar บน mobile สูงถึง 108px (2 แถว) ทำให้เดิมเมนูเริ่มต่ำเกินไป เหลือช่องว่างเปล่าด้านบนเยอะ
         z-index ของ .sidebar (9999) สูงกว่า .topbar (1000) อยู่แล้ว จึงคลุมทับ topbar ได้พอดีตอนเปิดเมนู */
      .sidebar {
        transform: translateX(-110%) !important;
        top: 0 !important;
        height: 100vh !important;
        width: 82vw !important;
        max-width: 300px !important;
        z-index: 9999 !important;
        padding-top: 46px !important;
      }
      .sidebar.mobile-open {
        transform: translateX(0) !important;
      }
      #sidebar-mobile-close { display: flex !important; }
      .main-content {
        margin-left: 0 !important;
      }
      #mobile-sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        top: 0;
        background: rgba(0,0,0,0.45);
        z-index: 9998;
      }
      #mobile-sidebar-overlay.open {
        display: block !important;
      }
    }
    .sidebar::-webkit-scrollbar { width: 4px; }
    .sidebar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

    /* ── Collapsed (icon-only) ── */
    .sidebar.collapsed { width: 56px; }
    .sidebar.collapsed .sidebar-section-label { opacity: 0; width: 0; height: 0; padding: 0; margin: 0; overflow: hidden; }
    .sidebar.collapsed .nav-item-link { padding: 10px 0; justify-content: center; }
    .sidebar.collapsed .nav-item-link span.nav-label { display: none; }
    .sidebar.collapsed .nav-item-link i { width: 56px; text-align: center; font-size: 19px; margin: 0; }
    .sidebar.collapsed .nav-item-link { position: relative; }
    .sidebar.collapsed .nav-item-link:hover::after {
      content: attr(data-label);
      position: absolute; left: 62px; top: 50%;
      transform: translateY(-50%);
      background: #1a1a1a; color: #fff;
      padding: 5px 12px; border-radius: 7px;
      font-size: 12px; font-weight: 500; white-space: nowrap;
      pointer-events: none; z-index: 999;
      box-shadow: 0 4px 14px rgba(0,0,0,0.18);
    }
    .sidebar.collapsed .sidebar-group-header { justify-content: center; padding: 10px 0; }
    .sidebar.collapsed .sidebar-group-header .group-chevron { display: none; }
    .sidebar.collapsed .sidebar-group-header-left { justify-content: center; gap: 0; }
    .sidebar.collapsed .sidebar-group-items { max-height: 2000px !important; opacity: 1; }
    .sidebar.collapsed .sidebar-sub-header { display: none; }
    .sidebar.collapsed .sidebar-sub-items { max-height: 2000px !important; opacity: 1; padding-left: 0; }
    .sidebar.collapsed .sidebar-sub-items .nav-item-link { padding-left: 0; padding-top: 10px; padding-bottom: 10px; }
    .sidebar.collapsed .sidebar-sub-items .nav-item-link i { display: inline-block; }
    .sidebar.collapsed .sidebar-sub-items .nav-item-link::before { display: none; }

    /* ── Section label (tiny uppercase) ── */
    .sidebar-section-label {
      font-size: 10px; font-weight: 700; letter-spacing: 1px;
      text-transform: uppercase; color: var(--text-muted);
      padding: 6px 16px 2px;
      transition: opacity 0.15s;
      white-space: nowrap; overflow: hidden;
    }

    /* ══ LEVEL 1 — Group Header (ฝ่าย) ══ */
    .sidebar-group { overflow: hidden; margin-bottom: 2px; }
    .sidebar-group-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: 0 12px 0 12px; height: 40px; cursor: pointer;
      user-select: none; border-radius: 8px; margin: 0 6px;
      transition: background 0.14s;
      gap: 0;
    }
    .sidebar-group-header:hover { background: var(--accent-light); }
    .sidebar-group-header-left { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
    /* icon วง กลม เล็ก */
    .sidebar-group-header .group-icon {
      font-size: 15px;
      width: 28px; height: 28px;
      display: flex; align-items: center; justify-content: center;
      border-radius: 7px;
      background: var(--accent-light);
      color: var(--text-secondary);
      flex-shrink: 0;
      transition: background 0.14s, color 0.14s;
    }
    .sidebar-group-header .sidebar-section-label {
      padding: 0; margin: 0; text-transform: none;
      font-size: 13px; font-weight: 600; letter-spacing: 0;
      color: var(--text-primary); white-space: nowrap; overflow: hidden;
      text-overflow: ellipsis;
    }
    .sidebar-group-header .group-chevron {
      font-size: 13px; color: var(--text-muted);
      transition: transform 0.22s ease; flex-shrink: 0; margin-left: 4px;
    }
    .sidebar-group.collapsed .group-chevron { transform: rotate(-90deg); }
    .sidebar-group.collapsed .sidebar-group-header .sidebar-section-label { color: var(--text-secondary); }
    /* active group */
    .sidebar-group.active-group > .sidebar-group-header { background: var(--accent-light); }
    .sidebar-group.active-group > .sidebar-group-header .group-icon { background: var(--accent); color: #fff; }
    .sidebar-group.active-group > .sidebar-group-header .sidebar-section-label { color: var(--accent); }

    /* items wrapper */
    .sidebar-group-items {
      overflow: hidden;
      max-height: 2000px;
      transition: max-height 0.38s cubic-bezier(.4,0,.2,1), opacity 0.28s ease;
      opacity: 1;
      padding: 2px 0 4px;
    }
    .sidebar-group.collapsed .sidebar-group-items { max-height: 0 !important; opacity: 0; padding: 0; }

    /* ══ LEVEL 1 direct nav links (แดชบอร์ด ฯลฯ) ══ */
    .nav-item-link {
      display: flex; align-items: center; gap: 9px;
      padding: 4px 12px; min-height: 38px;
      color: var(--text-secondary);
      text-decoration: none; font-size: 13px; font-weight: 500;
      border-radius: 7px; margin: 1px 6px;
      transition: background 0.13s, color 0.13s;
      white-space: nowrap; border-left: none;
    }
    .nav-item-link .nav-label {
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
      line-height: 1.5; padding: 2px 0;
      display: inline-block;
    }
    .nav-item-link i { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }
    .nav-item-link:hover { color: var(--text-primary); background: var(--accent-light); }
    .nav-item-link.active {
      color: var(--accent); font-weight: 600;
      background: var(--accent-light);
    }
    .nav-item-link.active i { color: var(--accent); }
    .nav-label { transition: opacity 0.15s; }

    /* ══ LEVEL 2 — Sub-Group Header (งาน...) ══ */
    .sidebar-sub-group { margin-top: 1px; }
    .sidebar-sub-header {
      display: flex; align-items: center;
      padding: 4px 10px 4px 14px; min-height: 36px; cursor: pointer;
      user-select: none; border-radius: 7px; margin: 0 6px;
      transition: background 0.13s; gap: 8px;
    }
    .sidebar-sub-header:hover { background: var(--accent-light); }
    /* จุดกลมระดับ 2 */
    .sidebar-sub-header::before {
      content: '';
      width: 6px; height: 6px; border-radius: 50%;
      background: var(--border-color);
      flex-shrink: 0;
      transition: background 0.13s;
      border: 1.5px solid var(--text-muted);
    }
    .sidebar-sub-header:hover::before { background: var(--text-secondary); border-color: var(--text-secondary); }
    .sidebar-sub-group.active-sub .sidebar-sub-header::before { background: var(--accent); border-color: var(--accent); }
    .sidebar-sub-group.active-sub > .sidebar-sub-header { background: var(--accent-light); }
    .sidebar-sub-header .sidebar-section-label {
      flex: 1; padding: 2px 0; margin: 0;
      font-size: 12px; font-weight: 600; letter-spacing: 0;
      line-height: 1.5;
      text-transform: none; color: var(--text-secondary);
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
      transition: color 0.13s;
    }
    .sidebar-sub-header:hover .sidebar-section-label { color: var(--text-primary); }
    .sidebar-sub-group.active-sub .sidebar-sub-header .sidebar-section-label { color: var(--accent); }
    .sidebar-sub-header .sub-chevron {
      font-size: 12px; color: var(--text-muted);
      transition: transform 0.22s ease; flex-shrink: 0;
    }
    .sidebar-sub-group.collapsed .sub-chevron { transform: rotate(-90deg); }

    /* sub-items wrapper */
    .sidebar-sub-items {
      overflow: hidden;
      max-height: 1200px;
      transition: max-height 0.32s cubic-bezier(.4,0,.2,1), opacity 0.24s ease;
      opacity: 1; padding-left: 0;
    }
    .sidebar-sub-group.collapsed .sidebar-sub-items { max-height: 0 !important; opacity: 0; }

    /* ══ LEVEL 3 — Menu Items ══ */
    .sidebar-sub-items .nav-item-link {
      padding: 8px 10px 8px 28px; height: auto; min-height: 36px;
      margin: 1px 6px; font-size: 12.5px; font-weight: 400;
      color: var(--text-secondary); gap: 8px;
      border-radius: 6px; white-space: normal; word-break: break-word;
      align-items: center;
    }
    .sidebar-sub-items .nav-item-link .nav-label {
      padding: 2px 0; line-height: 1.55; display: inline-block;
    }
    .sidebar-sub-items .nav-item-link::before {
      content: '';
      width: 5px; height: 5px; border-radius: 50%;
      background: transparent;
      border: 1.5px solid var(--text-muted);
      flex-shrink: 0;
      align-self: center;
      transition: background 0.13s, border-color 0.13s;
    }
    .sidebar-sub-items .nav-item-link:hover::before { background: var(--text-secondary); border-color: var(--text-secondary); }
    .sidebar-sub-items .nav-item-link.active::before { background: var(--accent); border-color: var(--accent); }
    .sidebar-sub-items .nav-item-link:hover { color: var(--text-primary); background: var(--accent-light); }
    .sidebar-sub-items .nav-item-link.active { color: var(--accent); font-weight: 600; background: var(--accent-light); }
    .sidebar-sub-items .nav-item-link i { display: none; }



    /* ── No-transition helper (used on page load restore) ── */
    .sidebar.no-transition .sidebar-group-items,
    .sidebar.no-transition .sidebar-sub-items { transition: none !important; }

    /* ─── Topnav Mode ─── */
    body.topnav-mode .sidebar { display: none; }
    body.topnav-mode .main-content { margin-left: 0; margin-top: calc(var(--topbar-height) + 48px); padding-top: 4px; }
    body.topnav-mode .sidebar-toggle { display: none !important; }

    #topnav-fav-toggle {
      display: none;
      align-items: center; gap: 2px;
      margin-left: 8px; padding: 3px;
      border-radius: 20px; background: var(--accent-light);
      flex-shrink: 0;
    }
    body.topnav-mode #topnav-fav-toggle { display: inline-flex; }
    .topnav-fav-toggle-btn {
      border: none; background: transparent; cursor: pointer;
      font-family: 'Noto Sans Thai', sans-serif;
      font-size: 11px; font-weight: 700;
      padding: 5px 12px; border-radius: 16px;
      color: var(--text-secondary);
      display: inline-flex; align-items: center; gap: 4px;
      white-space: nowrap; transition: all .15s;
    }
    .topnav-fav-toggle-btn:hover { color: var(--text-primary); }
    .topnav-fav-toggle-btn.active { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }

    #topnav-bar { display: none;
      position: fixed; top: var(--topbar-height); left: 0; right: 0;
      height: 48px; background: var(--bg-sidebar);
      border-bottom: 1px solid var(--border-color);
      z-index: 960; overflow: visible; /* เหนือหน้าเอกสารแบบเต็มหน้า (950) เพื่อให้เมนู dropdown ไม่ถูกบัง — ต่ำกว่า modal จริง (1050+) */
      padding: 0 16px;
      align-items: center; gap: 4px;
    }
    body.topnav-mode #topnav-bar { display: flex; }

    .topnav-group {
      position: relative;
      display: flex;
      align-items: center;
    }
    .topnav-group-btn {
      display: flex; align-items: center; gap: 6px;
      padding: 6px 12px; border-radius: var(--radius-sm);
      background: transparent; border: none; cursor: pointer;
      font-size: 13px; font-weight: 600;
      color: var(--text-secondary);
      font-family: 'Noto Sans Thai', sans-serif;
      transition: all 0.15s; white-space: nowrap;
    }
    .topnav-group-btn:hover,
    .topnav-group-btn.active { color: var(--text-primary); background: var(--accent-light); }
    .topnav-group-btn i { font-size: 16px; }
    .topnav-group-btn .chevron { font-size: 12px; transition: transform 0.15s; }
    .topnav-group-btn.open .chevron { transform: rotate(180deg); }

    /* ─── Mega Menu Dropdown ─── */
    .topnav-dropdown {
      display: flex;
      position: absolute; top: calc(100% + 6px); left: 0;
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius); box-shadow: var(--shadow-md);
      z-index: 9999; padding: 16px;
      min-width: 220px;
      flex-direction: column;
      opacity: 0;
      transform: translateY(-6px);
      pointer-events: none;
      transition: opacity .18s ease, transform .18s ease;
      visibility: hidden;
    }
    .topnav-dropdown.open {
      opacity: 1;
      transform: translateY(0);
      pointer-events: auto;
      visibility: visible;
    }
    .topnav-dd-inner { display: flex; flex-direction: row; gap: 0; }
    .topnav-dd-footer { display: flex; justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--border-color); margin-top: 10px; }
    .topnav-dd-close-btn { padding: 5px 16px; font-size: 12px; font-weight: 600; background: var(--accent-light); border: 1px solid var(--border-color); border-radius: var(--radius-sm); cursor: pointer; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 5px; transition: all .15s; }
    .topnav-dd-close-btn:hover { background: var(--accent); color: var(--badge-text); border-color: var(--accent); }

    /* mega layout: columns side-by-side */
    .topnav-dd-col {
      display: flex; flex-direction: column;
      min-width: 200px; padding: 0 16px;
      border-right: 1px solid var(--border-color);
    }
    .topnav-dd-col:first-child { padding-left: 0; }
    .topnav-dd-col:last-child  { border-right: none; padding-right: 0; }

    .topnav-dd-section {
      display: block;
      width: max-content;
      font-size: 10px; font-weight: 700; letter-spacing: 0.8px;
      text-transform: uppercase;
      color: #6b7280;
      background: #f3f4f6;
      border: 1px solid #d1d5db;
      padding: 2px 8px; margin-top: 10px; margin-bottom: 2px;
      border-radius: 20px; white-space: nowrap;
    }
    [data-theme="dark"] .topnav-dd-section {
      background: #374151;
      color: #9ca3af;
      border-color: #4b5563;
    }
    .topnav-dd-col .topnav-dd-section:first-child { margin-top: 0; }

    .topnav-dd-item[hidden], .nav-item-link[hidden] { display: none !important; } /* R-041 ซ่อนเมนูมัดจำ */
    .topnav-dd-item {
      display: flex; align-items: center; gap: 8px;
      padding: 7px 8px; color: var(--text-secondary);
      text-decoration: none; font-size: 13px; font-weight: 500;
      cursor: pointer; transition: all 0.12s;
      white-space: nowrap; border-radius: var(--radius-sm);
    }
    .topnav-dd-item:hover { color: var(--text-primary); background: var(--accent-light); }
    .topnav-dd-item.active { color: var(--text-primary); background: var(--accent-light); font-weight: 600; }
    .topnav-dd-item i { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

    /* ─── Favorite Star System ─── */
    .topnav-edit-mode .topnav-dd-item {
      padding-right: 32px;
      position: relative;
    }
    .topnav-fav-star {
      display: none;
      position: absolute; right: 6px; top: 50%;
      transform: translateY(-50%);
      font-size: 15px; cursor: pointer;
      color: #d1d1c7;
      transition: color 0.15s, transform 0.15s;
      line-height: 1;
      background: none; border: none; padding: 2px 4px;
      border-radius: 4px;
    }
    .topnav-fav-star:hover { color: #f59e0b; transform: translateY(-50%) scale(1.2); }
    .topnav-fav-star.fav-active { color: #f59e0b; }
    .topnav-edit-mode .topnav-fav-star { display: flex; align-items: center; justify-content: center; }
    /* star shown permanently when item is favorite (even outside edit mode) */
    .topnav-dd-item .fav-star-badge {
      font-size: 13px; color: #f59e0b; margin-left: auto; flex-shrink: 0;
    }
    .topnav-dd-item .menu-badge-dashboard {
      display: inline-flex; align-items: center;
      padding: 1px 7px; border-radius: 20px;
      font-size: 10px; font-weight: 700; letter-spacing: 0.4px;
      background: #e8f0fe; color: #1a56db; border: 1px solid #c3d7fd;
      margin-left: 6px; flex-shrink: 0; vertical-align: middle;
      line-height: 1.5;
    }
    body.dark-mode .topnav-dd-item .menu-badge-dashboard {
      background: #1e3a6e; color: #93c5fd; border-color: #2d5a9e;
    }
    /* in edit mode, the interactive star button already shows the favorite state — hide the static badge to avoid showing two stars */
    .topnav-edit-mode .fav-star-badge { display: none; }
    /* pencil edit button: pinned inside the top-right corner of the dropdown panel, always visible.
       Toggles into a filled "บันทึก" (save) pill once edit mode is active. */
    .topnav-edit-btn {
      display: inline-flex; align-items: center; justify-content: center; gap: 4px;
      min-width: 24px; height: 24px; padding: 0; border-radius: 4px;
      background: none; border: none; cursor: pointer;
      color: var(--text-muted); font-size: 13px; font-weight: 600;
      font-family: 'Noto Sans Thai', sans-serif;
      transition: all 0.15s; white-space: nowrap;
      position: absolute; top: 12px; right: 12px;
      z-index: 2;
    }
    .topnav-edit-btn:hover { background: var(--accent-light); color: var(--text-primary); }
    .topnav-edit-btn .icon-save { display: none; align-items: center; gap: 4px; }
    .topnav-edit-btn.editing {
      height: auto; padding: 5px 12px; border-radius: 6px;
      background: #1a1a1a; color: #fff; font-size: 12px;
    }
    .topnav-edit-btn.editing:hover { background: #333; color: #fff; }
    .topnav-edit-btn.editing .icon-pencil { display: none; }
    .topnav-edit-btn.editing .icon-save { display: inline-flex; }

    #topnav-backdrop {
      display: none;
      position: fixed;
      top: calc(var(--topbar-height) + 48px);
      left: 0; right: 0; bottom: 0;
      z-index: 955;
      background: rgba(0,0,0,0);
      transition: background .2s ease;
      pointer-events: none;
    }
    #topnav-backdrop.open {
      display: block;
      pointer-events: auto;
      background: rgba(0,0,0,0.28);
    }

    /* ─── Main Content ─── */
    .main-content {
      margin-left: var(--sidebar-width);
      margin-top: var(--topbar-height);
      padding: 4px 20px 12px;
      transition: margin-left 0.22s ease;
    }
    .main-content.sidebar-collapsed {
      margin-left: 56px;
    }

    /* ─── Page Header ─── */
    .page-header {
      display: flex; align-items: center; gap: 12px;
      margin-bottom: 8px; flex-wrap: wrap;
    }
    .page-title {
      font-size: 20px; font-weight: 700; color: var(--text-primary);
      font-family: 'Noto Sans Thai', sans-serif; letter-spacing: -0.5px;
    }
    .page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
    .page-header-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

    /* ─── Home Hero ─── */
    /* ─── Home page full-height flex (sidebar mode) ─── */
    #page-home {
      min-height: calc(100vh - var(--topbar-height) - 8px);
      display: flex; flex-direction: column;
    }
    /* topnav mode: topbar + topnav bar (48px) */
    body.topnav-mode #page-home {
      min-height: calc(100vh - var(--topbar-height) - 48px - 8px);
    }

    .home-hero-wrap {
      position: relative; overflow: hidden; flex: 1;
      border-radius: var(--radius);
      background: linear-gradient(135deg, var(--bg-card) 0%, var(--accent-light) 100%);
      border: 1px solid var(--border-color);
      box-shadow: var(--shadow-md);
      padding: 44px 52px;
      margin-bottom: 14px;
      display: flex; align-items: center;
    }
    .home-hero-wrap > div { width: 100%; }
    .home-hero-badge {
      display: inline-flex; align-items: center; gap: 6px;
      background: var(--accent-light); color: var(--text-secondary);
      padding: 5px 12px; border-radius: 99px;
      font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
      margin-bottom: 16px;
    }
    .home-hero-title {
      font-size: 36px; font-weight: 800; line-height: 1.2;
      letter-spacing: -0.5px; color: var(--text-primary); margin-bottom: 12px;
    }
    .home-hero-sub {
      font-size: 14px; color: var(--text-secondary); max-width: 460px; line-height: 1.75;
    }
    .home-hero-svg { flex-shrink: 0; display: flex; justify-content: center; }

    /* topnav mode: hero ใหญ่ขึ้นอีก เพราะพื้นที่ content กว้างกว่า (ไม่มี sidebar) */
    body.topnav-mode .home-hero-wrap {
      padding: 60px 72px;
    }
    body.topnav-mode .home-hero-title { font-size: 46px; margin-bottom: 16px; }
    body.topnav-mode .home-hero-sub   { font-size: 16px; max-width: 560px; }
    body.topnav-mode .home-hero-badge { margin-bottom: 20px; font-size: 12px; padding: 6px 14px; }
    body.topnav-mode .home-hero-svg svg { width: 400px; height: 312px; }

    @media (max-height: 800px) {
      .home-hero-wrap { padding: 28px 40px; margin-bottom: 10px; }
      .home-hero-title { font-size: 28px; margin-bottom: 8px; }
      .home-hero-badge { margin-bottom: 10px; }
      .home-hero-sub { font-size: 12px; }
      .home-hero-svg svg { width: 220px; height: 172px; }
      body.topnav-mode .home-hero-wrap  { padding: 36px 52px; }
      body.topnav-mode .home-hero-title { font-size: 34px; }
      body.topnav-mode .home-hero-sub   { font-size: 13px; }
      body.topnav-mode .home-hero-svg svg { width: 300px; height: 234px; }
    }

    /* ─── Card ─── */
    .card-box {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
      overflow: hidden;
    }
    .card-box-header {
      padding: 16px 20px;
      border-bottom: 1px solid var(--border-color);
      display: flex; align-items: center; gap: 10px;
      border-radius: var(--radius) var(--radius) 0 0;
    }
    .card-box-title {
      font-size: 14px; font-weight: 600; color: var(--text-primary);
      font-family: 'Noto Sans Thai', sans-serif;
    }
    .card-box-body { padding: 20px; }

    /* ─── Settings pages: shared two-column layout (main + side) ─── */
    .settings-grid-2col {
      display: grid;
      grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr);
      gap: 20px;
      align-items: start;
      max-width: 1320px;
    }
    .settings-grid-2col .settings-col-main,
    .settings-grid-2col .settings-col-side {
      display: flex; flex-direction: column; gap: 20px;
    }
    .settings-grid-2col .settings-col-side { position: sticky; top: 12px; }
    @media (max-width: 980px) {
      .settings-grid-2col { grid-template-columns: 1fr; }
      .settings-grid-2col .settings-col-side { position: static; }
    }

    /* ─── Buttons ─── */
    .btn-solid {
      display: inline-flex; align-items: center; gap: 6px;
      padding: 8px 16px; border-radius: var(--radius-sm);
      font-size: 13px; font-weight: 600; cursor: pointer;
      border: none; text-decoration: none;
      transition: all 0.15s;
    }
    .btn-solid.btn-dark {
      background: var(--accent); color: var(--badge-text);
    }
    .btn-solid.btn-dark:hover { opacity: 0.85; }
    .btn-solid.btn-outline {
      background: transparent; color: var(--text-primary);
      border: 1px solid var(--border-color);
    }
    .btn-solid.btn-outline:hover { background: var(--accent-light); }

    /* ── Period Close ── */
    .period-type-card { transition: border-color 0.15s, box-shadow 0.15s; }
    .period-type-card:hover { box-shadow: var(--shadow-sm); }
    #period-module-lock-status > div { transition: background 0.15s; }
    #period-module-lock-status > div:not(.pml-head):hover { background: var(--accent-light); }
    .btn-solid.btn-danger-outline {
      background: transparent; color: var(--danger);
      border: 1px solid var(--danger);
    }

    /* ── GL Opening Balance chips ── */
    .gl-ob-chip {
      padding: 5px 14px; border-radius: 20px; font-size: 12px; font-weight: 600;
      border: 1px solid var(--border-color); background: transparent;
      color: var(--text-secondary); cursor: pointer; transition: all 0.15s;
      font-family: 'Noto Sans Thai', sans-serif;
    }
    .gl-ob-chip:hover { background: var(--accent-light); color: var(--text-primary); border-color: var(--accent); }
    .gl-ob-chip.gl-ob-chip-active {
      background: var(--accent); color: var(--badge-text);
      border-color: var(--accent);
    }
    /* GL OB summary cards responsive */
    @media (max-width: 900px) {
      #gl-ob-summary-cards { grid-template-columns: repeat(3,1fr) !important; }
    }
    @media (max-width: 600px) {
      #gl-ob-summary-cards { grid-template-columns: repeat(2,1fr) !important; }
    }

    /* ── Sidebar inside mobile drawer ── */
    /* ─── Mobile/Tablet Topbar: 2 rows ───
       ครอบคลุมทั้ง Mobile และ Tablet (จอ ≤991px) ให้ใช้เมนูแบบ Sidebar (hamburger + drawer) เสมอ
       แทนเมนูแบบ Topbar ด้านบน ไม่ว่าผู้ใช้จะตั้งค่าโหมดเมนูฝั่ง Desktop ไว้แบบใดก็ตาม */
    @media (max-width: 991px) {
      :root { --topbar-height: 108px; }

      .topbar {
        flex-wrap: wrap;
        height: auto !important;
        padding: 0 10px;
        row-gap: 0;
      }

      /* Row 1: hamburger ซ้ายสุดเสมอ -> brand -> site badge
         ใช้ !important ที่ margin-left เพื่อชนะ inline style="margin-left:auto" บนปุ่มเดิม */
      #topbar-mobile-hamburger { order: 1; margin-left: 0 !important; margin-right: 8px; display: inline-flex !important; }
      .topbar-brand            { order: 2; }
      .topbar-actions          { order: 3; }

      /* ซ่อน topnav toggle + sidebar toggle (ใช้ hamburger แทนเสมอบน mobile/tablet) */
      #topnav-fav-toggle,
      .sidebar-toggle { display: none !important; }

      /* ซ่อนปุ่มสลับรูปแบบเมนู (จอเล็กใช้ Sidebar เสมอ) — แต่ยังแสดงบริษัทปัจจุบันและผู้ใช้งาน */
      .tb-layout-switch { display: none !important; }

      /* ซ่อนช่องค้นหาแบบ desktop (ใช้แถวที่ 2 แทน) */
      .topbar > .gcs-desktop-wrap { display: none !important; }

      /* ซ่อน TOP NAV BAR ทุกกรณีบน mobile/tablet — บังคับใช้ Sidebar เป็นเมนูหลักเสมอ */
      #topnav-bar,
      body.topnav-mode #topnav-bar { display: none !important; }

      /* main-content ไม่ต้อง offset topnav-bar */
      body.topnav-mode .main-content {
        margin-top: var(--topbar-height) !important;
        margin-left: 0 !important;
      }

      /* Row 2: search bar เต็มความกว้าง */
      #topbar-search-row2 {
        order: 10;
        width: 100%;
        padding: 6px 0 8px;
        display: flex !important;
      }
    }

    /* ─── Desktop only (>991px) ─── */
    @media (min-width: 992px) {
      #topbar-mobile-hamburger { display: none !important; }
      #topbar-search-row2      { display: none !important; }
      #mobile-sidebar-overlay  { display: none !important; }
    }

    /* ─── Mobile sidebar overlay ─── */
    #mobile-sidebar-overlay {
      display: none; position: fixed; inset: 0;
      background: rgba(0,0,0,0.45); z-index: 9998;
    }
    #mobile-sidebar-overlay.open { display: block; }
    .btn-solid.btn-danger-outline:hover { background: var(--danger); color: #fff; }
    .btn-solid.btn-success {
      background: var(--success); color: #fff;
    }
    .btn-solid.btn-success:hover { opacity: 0.85; }
    .btn-solid i { font-size: 16px; }

    /* ─── Form ─── */
    .form-label-custom {
      font-size: 12px; font-weight: 600; letter-spacing: 0.5px;
      color: var(--text-secondary); text-transform: uppercase;
      margin-bottom: 5px; display: block;
    }
    .input-custom {
      width: 100%; padding: 9px 12px; font-size: 13px;
      background: var(--input-bg); border: 1px solid var(--border-color);
      border-radius: var(--radius-sm); color: var(--text-primary);
      font-family: 'Noto Sans Thai', sans-serif;
      outline: none; transition: border-color 0.15s;
    }
    .input-custom:focus { border-color: var(--accent); }
    .input-custom.no-focus-border:focus { border-color: var(--border-color) !important; transition: none; }
    .input-custom::placeholder { color: var(--text-muted); }
    .input-group-custom {
      display: flex;
    }
    .input-group-custom .input-custom {
      border-radius: var(--radius-sm) 0 0 var(--radius-sm);
      border-right: none;
    }
    .input-group-custom .btn-solid {
      border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
      padding: 9px 14px;
    }
    select.input-custom { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

    /* ─── Table ─── */
    .table-custom { width: 100%; border-collapse: collapse; font-size: 13px; }
    .table-custom thead th {
      padding: 10px 14px; background: var(--accent-light);
      color: var(--text-secondary); font-size: 11px; font-weight: 700;
      letter-spacing: 0.8px; text-transform: uppercase;
      border-bottom: 1px solid var(--border-color); text-align: left;
    }
    .table-custom tbody tr { border-bottom: 1px solid var(--border-color); }
    .table-custom tbody tr:hover { background: var(--table-hover); }
    #so-tbody tr:hover { background: transparent !important; }
    .table-custom tbody td { padding: 14px 16px; color: var(--text-primary); vertical-align: middle; }
    .table-custom tfoot td {
      padding: 10px 14px; background: var(--accent-light);
      font-weight: 700; border-top: 2px solid var(--border-color);
    }
    #modalSampleRequest .table-custom tbody td { padding: 8px 10px; }
    #modalSampleRequest .table-custom thead th { padding: 8px 10px; }

    /* ─── Badge ─── */
    .badge-custom {
      display: inline-flex; align-items: center; gap: 4px;
      padding: 3px 8px; border-radius: 20px;
      font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
    }
    .badge-dark { background: var(--badge-bg); color: var(--badge-text); }
    .badge-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); }

    /* ─── Tabs ─── */
    .tab-pills {
      display: flex; gap: 4px; padding: 4px;
      background: var(--accent-light); border-radius: var(--radius-sm);
      margin-bottom: 20px; flex-wrap: wrap;
    }
    .tab-pill {
      padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500;
      cursor: pointer; border: none; background: transparent;
      color: var(--text-secondary); transition: all 0.15s;
      display: flex; align-items: center; gap: 6px;
    }
    .tab-pill.active { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
    .tab-pill i { font-size: 16px; }
    .tab-content-panel { display: none; }
    .tab-content-panel.active { display: block; }

    /* ─── Product Code Row ─── */
    .product-row {
      display: flex; align-items: center; gap: 8px;
      padding: 8px 0; border-bottom: 1px solid var(--border-color);
    }
    .product-row:last-child { border-bottom: none; }
    .product-code {
      font-family: 'Noto Sans Thai', sans-serif; font-size: 12px;
      background: var(--accent-light); color: var(--text-primary);
      padding: 3px 8px; border-radius: 4px; font-weight: 600;
    }

    /* ─── PO Reference Card ─── */
    .po-ref-card {
      border: 1px solid var(--border-color); border-radius: var(--radius-sm);
      padding: 14px; background: var(--accent-light); cursor: pointer;
      transition: all 0.15s;
    }
    .po-ref-card:hover { border-color: var(--accent); }
    .po-ref-card.selected { border-color: var(--accent); background: var(--bg-card); box-shadow: 0 0 0 2px var(--accent); }
    .po-ref-code { font-family: 'Noto Sans Thai', sans-serif; font-size: 13px; font-weight: 700; }
    .po-ref-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

    /* ─── Divider ─── */
    .divider { border: none; border-top: 1px solid var(--border-color); margin: 16px 0; }

    /* ─── Responsive ─── */
    @media (max-width: 991px) {
      /* .sidebar-toggle ถูกซ่อนแทนที่ด้วย #topbar-mobile-hamburger บน mobile/tablet แล้ว (ดู @media (max-width:991px) ด้านบน) */
      .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 850; }
      .sidebar-overlay.open { display: block; }
    }
    @media (max-width: 575px) {
      .main-content { padding: 14px; }
      .page-header-actions { width: 100%; }
      .page-header-actions .btn-solid { flex: 1; justify-content: center; }
      .fs-tabs-sticky-bar { margin: 0 -14px; padding: 10px 14px 16px; }
    }

    /* ─── Scroll ─── */
    .table-responsive-custom { overflow-x: auto; }

    /* R-085 (#111): กัน margin-top ของเนื้อหาทะลุออกนอก body (เดิมทุกหน้าเลื่อนได้เกินอยู่ 108px แม้เนื้อหาสั้น) */
    body { display: flow-root; }

    /* ─── Sticky Table Header ─── */
    .table-responsive-custom,
    .table-responsive { overflow-x: auto; }
    .table-responsive-custom.sticky-table,
    .table-responsive.sticky-table {
      overflow-y: auto;
      max-height: var(--table-max-h, calc(100vh - 240px));
    }
    .table-responsive-custom.sticky-table thead th,
    .table-responsive.sticky-table thead th,
    .table-custom.sticky-thead thead th {
      position: sticky;
      top: 0;
      z-index: 3;
      background: var(--accent-light);
      box-shadow: 0 1px 0 var(--border-color);
    }

    /* ─── Animations ─── */
    @keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
    .page-view { animation: fadeIn 0.2s ease; }


    /* ── Select2 inside scrollable modal — ป้องกัน scroll ค้าง ── */
    #modalPayment .modal-body { overscroll-behavior: contain; }
    #modalPayment .select2-container { position: relative; z-index: 1; }
    #modalAPOPay .modal-body { overscroll-behavior: contain; }
    #modalAPOPay .select2-container { position: relative; z-index: 1; }

    /* ── Mapping Rule table — fix row height so inputs are fully visible ── */
    #modalMappingRule .table-responsive { max-height: 340px; overflow-y: auto; }
    #modalMappingRule table.table-sm td,
    #modalMappingRule table.table-sm th { padding-top: 7px !important; padding-bottom: 7px !important; vertical-align: middle !important; }
    #modalMappingRule table.table-sm .input-custom { padding: 5px 8px !important; font-size: 12px !important; height: auto !important; min-height: 32px; }
    #modalMappingRule table.table-sm select.input-custom { padding-right: 24px !important; }
    #modalAPPay .modal-body { overscroll-behavior: contain; }
    #modalAPPay .select2-container { position: relative; z-index: 1; }
    #modalApDepPay .modal-body { overscroll-behavior: contain; }
    #modalApDepPay .select2-container { position: relative; z-index: 1; }
    .select2-dropdown { z-index: 9999 !important; }

    /* ─── Select2 Custom Theme ─── */
    .select2-container { width: 100% !important; }
    .select2-container--default .select2-selection--single {
      height: 38px; border-radius: var(--radius-sm);
      border: 1px solid var(--border-color);
      background: var(--input-bg);
      display: flex; align-items: center;
      position: relative;
    }
    .select2-container--default .select2-selection--single .select2-selection__rendered {
      color: var(--text-primary); font-size: 13px;
      font-family: 'Noto Sans Thai', sans-serif;
      padding-left: 12px; line-height: 36px;
      padding-right: 28px;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
      flex: 1; min-width: 0; width: 100%;
    }
    .select2-container--default .select2-selection--single .select2-selection__placeholder {
      color: var(--text-muted);
    }
    .select2-container--default .select2-selection--single .select2-selection__arrow {
      height: 36px; right: 8px;
    }
    /* ── ปุ่ม × อยู่ซ้ายมือ ชิดข้อความ ── */
    .select2-container--default .select2-selection--single .select2-selection__clear {
      position: absolute;
      left: 8px;
      top: 50%;
      transform: translateY(-50%);
      float: none !important;
      margin: 0;
      padding: 0 2px;
      font-size: 15px;
      line-height: 1;
      color: var(--text-muted);
      z-index: 2;
    }
    .select2-container--default .select2-selection--single .select2-selection__clear:hover {
      color: var(--danger);
    }
    /* เมื่อมี × ให้ข้อความเยื้องขวาพอดี ไม่ทับกัน */
    .select2-container--default .select2-selection--single:has(.select2-selection__clear) .select2-selection__rendered {
      padding-left: 24px;
    }
    .select2-container--default.select2-container--open .select2-selection--single,
    .select2-container--default.select2-container--focus .select2-selection--single {
      border-color: var(--accent); outline: none; box-shadow: none;
    }
    .select2-dropdown {
      background: var(--bg-card); border: 1px solid var(--border-color);
      border-radius: var(--radius-sm); box-shadow: 0 4px 16px rgba(0,0,0,0.12);
      font-size: 13px; font-family: 'Noto Sans Thai', sans-serif;
    }
    .select2-container--default .select2-search--dropdown .select2-search__field {
      border: 1px solid var(--border-color); border-radius: var(--radius-sm);
      background: var(--input-bg); color: var(--text-primary);
      font-size: 13px; padding: 6px 10px; outline: none;
    }
    .select2-container--default .select2-results__option {
      color: var(--text-primary); padding: 8px 12px;
    }
    .select2-container--default .select2-results__option[aria-selected=true] {
      background: var(--accent); color: var(--badge-text);
    }
    .select2-container--default .select2-results__option--highlighted[aria-selected] {
      background: var(--accent-light); color: var(--text-primary);
    }
    .supplier-opt-name { font-weight: 600; font-size: 13px; }
    .supplier-opt-sub  { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
    .select2-container--default .select2-results__option--highlighted .supplier-opt-sub { color: var(--text-secondary); }
    /* ── buy-prod table: select2 ขนาด compact 32px สำหรับ dropdown "สินค้าที่แถม" ── */
    #rule-buy-prod-tbody .select2-container--default .select2-selection--single {
      height: 32px !important;
    }
    #rule-buy-prod-tbody .select2-container--default .select2-selection--single .select2-selection__rendered {
      font-size: 12px !important;
      line-height: 30px !important;
    }
    #rule-buy-prod-tbody .select2-container--default .select2-selection--single .select2-selection__arrow {
      height: 30px !important;
    }
    #rule-buy-prod-tbody .select2-container--default.select2-container--disabled .select2-selection--single {
      background: var(--accent-light) !important;
      opacity: 0.5;
      cursor: not-allowed;
    }
    /* ── Pick modal: select2 ใน table ให้สูง/font เหมือน input-custom (30px/12px) ── */
    #pick-lines-body .select2-container--default .select2-selection--single {
      height: 30px !important;
      background: var(--input-bg) !important;
      border-color: var(--border-color) !important;
    }
    #pick-lines-body .select2-container--default .select2-selection--single .select2-selection__rendered {
      font-size: 12px !important;
      line-height: 28px !important;
      color: var(--text-primary) !important;
    }
    #pick-lines-body .select2-container--default .select2-selection--single .select2-selection__arrow {
      height: 28px !important;
    }
    /* disabled state — เหมือนกันทั้ง row หลักและ split row */
    #pick-lines-body .select2-container--default.select2-container--disabled .select2-selection--single {
      background: var(--input-bg) !important;
      border-color: var(--border-color) !important;
      opacity: 0.5 !important;
      cursor: not-allowed !important;
    }
    #pick-lines-body .select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__rendered {
      color: var(--text-secondary) !important;
    }

    /* ── Deposit lines: fix grid overflow — รายละเอียดสินค้าห้ามขยาย ── */
    #dep-product-lines [id^="dep-line-"] .d-none.d-md-grid > div {
      min-width: 0;
      overflow: hidden;
    }
    #dep-product-lines .select2-container {
      min-width: 0 !important;
      width: 100% !important;
      max-width: 100% !important;
      box-sizing: border-box !important;
    }
    #dep-product-lines .select2-container--default .select2-selection--single {
      height: 38px !important;
      background: var(--input-bg) !important;
      border-color: var(--border-color) !important;
    }
    #dep-product-lines .select2-container--default .select2-selection--single .select2-selection__rendered {
      font-size: 13px !important;
      line-height: 36px !important;
      color: var(--text-primary) !important;
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      white-space: nowrap !important;
    }
    #dep-product-lines .select2-container--default .select2-selection--single .select2-selection__arrow {
      height: 36px !important;
    }
    /* ── AP Deposit lines: select2 UOM ให้สูง 30px/12px เหมือน input ── */
    #apdep-product-lines .select2-container--default .select2-selection--single {
      height: 30px !important;
      background: var(--input-bg) !important;
      border-color: var(--border-color) !important;
    }
    #apdep-product-lines .select2-container--default .select2-selection--single .select2-selection__rendered {
      font-size: 12px !important;
      line-height: 28px !important;
      color: var(--text-primary) !important;
    }
    #apdep-product-lines .select2-container--default .select2-selection--single .select2-selection__arrow {
      height: 28px !important;
    }
    /* ── AP Deposit modal: account select2 ── */
    #modalApDeposit .select2-container { position: relative; z-index: 1; }
    #modalApDeposit .modal-body { overscroll-behavior: contain; }

    .field-group { margin-bottom: 14px; }

    /* ─── Select2 Multi-select (Approval Settings) ─── */
    .apv-approver-select + .select2-container .select2-selection--multiple {
      min-height: 38px; border-radius: var(--radius-sm);
      border: 1px solid var(--border-color); background: var(--input-bg);
      padding: 4px 8px; cursor: pointer;
    }
    .apv-approver-select + .select2-container.select2-container--focus .select2-selection--multiple,
    .apv-approver-select + .select2-container.select2-container--open .select2-selection--multiple {
      border-color: var(--accent); outline: none; box-shadow: none;
    }
    .select2-container--default .select2-selection--multiple .select2-selection__choice {
      background: var(--accent); color: var(--badge-text);
      border: none; border-radius: 20px;
      padding: 1px 8px 1px 8px; font-size: 12px; font-weight: 600;
      margin: 2px 3px 2px 0;
    }
    .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
      color: var(--badge-text); opacity: 0.7; margin-right: 2px;
      border-right: none !important;
      padding-right: 0 !important;
    }
    .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
      opacity: 1; color: #fff;
    }
    .select2-container--default .select2-selection--multiple .select2-selection__choice__separator {
      display: none;
    }
    .select2-container--default .select2-selection--multiple .select2-selection__rendered {
      padding: 2px 4px;
    }
    .select2-container--default .select2-selection--multiple .select2-search__field {
      font-size: 12px; color: var(--text-primary);
    }

    /* ─── Picking Select2 ─── */
    .pick-main-sel + .select2-container .select2-selection--single,
    .pick-sub-sel  + .select2-container .select2-selection--single,
    .pick-lot-sel  + .select2-container .select2-selection--single {
      height: 30px; font-size: 12px;
    }
    .pick-main-sel + .select2-container .select2-selection--single .select2-selection__rendered,
    .pick-sub-sel  + .select2-container .select2-selection--single .select2-selection__rendered,
    .pick-lot-sel  + .select2-container .select2-selection--single .select2-selection__rendered {
      line-height: 28px; font-size: 12px;
    }
    .pick-main-sel + .select2-container .select2-selection--single .select2-selection__arrow,
    .pick-sub-sel  + .select2-container .select2-selection--single .select2-selection__arrow,
    .pick-lot-sel  + .select2-container .select2-selection--single .select2-selection__arrow {
      height: 28px;
    }
    /* disabled state */
    .pick-main-sel[disabled] + .select2-container .select2-selection--single,
    .pick-sub-sel[disabled]  + .select2-container .select2-selection--single,
    .pick-lot-sel[disabled]  + .select2-container .select2-selection--single {
      opacity: .45; cursor: not-allowed;
    }

    /* ─── PO Line Table (desktop) ─── */
    .po-lines-table-header,
    .po-line-desktop {
      display: grid;
      grid-template-columns: 30px minmax(160px,1.2fr) 55px 85px 85px 95px 60px 80px 95px 30px;
      gap: 6px;
      align-items: center;
      min-width: 800px;
    }
    .po-lines-table-header {
      padding: 7px 10px;
      background: var(--accent-light);
      border-radius: var(--radius-sm) var(--radius-sm) 0 0;
      border: 1px solid var(--border-color);
      font-size: 11px; font-weight: 700; letter-spacing: 0.7px;
      text-transform: uppercase; color: var(--text-secondary);
      position: sticky;
      top: -20px; /* offset modal-body padding */
      z-index: 10;
      box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    }
    .po-line-desktop {
      padding: 5px 10px;
      border: 1px solid var(--border-color);
      border-top: none;
      background: var(--bg-card);
      transition: background 0.12s;
    }
    .po-line-desktop:hover { background: var(--table-hover); }
    #po-product-lines > div:last-child .po-line-desktop {
      border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    }

    /* ─── Switch ─── */
    .form-switch-custom {
      display: inline-flex; align-items: center; gap: 10px; cursor: pointer;
    }
    .form-switch-custom input { display: none; }
    .switch-slider {
      width: 46px; height: 24px; background: #e2e8f0;
      border-radius: 30px; position: relative; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    }
    .switch-slider::before {
      content: ""; position: absolute; top: 3px; left: 3px;
      width: 18px; height: 18px; background: #fff;
      border-radius: 50%; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    }
    .form-switch-custom input:checked + .switch-slider { background: #10b981; }
    .form-switch-custom input:checked + .switch-slider::before { transform: translateX(22px); }
    .switch-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); min-width: 55px; }
    .form-switch-custom input:checked ~ .switch-label { color: #2f855a; }

    /* ─── PR Line Table (desktop) ─── */
    .pr-lines-table-header,
    .pr-line-desktop {
      display: grid;
      grid-template-columns: 30px 1fr 50px 60px 1fr 30px;
      gap: 6px;
      align-items: center;
      min-width: 560px;
    }
    .pr-lines-table-header {
      padding: 7px 10px;
      background: var(--accent-light);
      border-radius: var(--radius-sm) var(--radius-sm) 0 0;
      border: 1px solid var(--border-color);
      font-size: 11px; font-weight: 700; letter-spacing: 0.7px;
      text-transform: uppercase; color: var(--text-secondary);
      position: sticky;
      top: -20px;
      z-index: 10;
      box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    }
    .pr-line-desktop {
      padding: 5px 10px;
      border: 1px solid var(--border-color);
      border-top: none;
      background: var(--bg-card);
      transition: background 0.12s;
    }
    .pr-line-desktop:hover { background: var(--table-hover); }
    #pr-product-lines > div:last-child .pr-line-desktop {
      border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    }

    /* ─── PO Mobile Card ─── */
    .po-mobile-card {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-sm);
      padding: 12px;
      margin-bottom: 8px;
      box-shadow: var(--shadow-sm);
    }
    .po-mobile-card-header {
      display: flex; align-items: center; justify-content: space-between;
      margin-bottom: 10px;
    }
    .po-mobile-seq {
      font-family: 'Noto Sans Thai', sans-serif; font-weight: 700;
      font-size: 12px; background: var(--accent);
      color: var(--badge-text); padding: 2px 9px;
      border-radius: 4px;
    }
    .btn-icon-sm { width: 36px; height: 36px; font-size: 18px; }
    .po-mobile-grid {
      display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    }
    .po-mobile-total {
      margin-top: 10px; padding-top: 8px;
      border-top: 1px dashed var(--border-color);
      font-size: 13px; font-weight: 600; color: var(--text-secondary);
      text-align: right;
    }


.radio-card {
  display:flex;
  align-items:center;
  gap:8px;
  padding:6px 12px;
  border:1px solid var(--border-color);
  border-radius:8px;
  font-size:12px;
  color:var(--text-primary);
  cursor:pointer;
  transition:all 0.2s ease;
}

.radio-card input {
  accent-color:var(--accent);
  margin:0;
}

.radio-card:hover {
  background:rgba(0,0,0,0.04);
}

.radio-card input:checked + span {
  font-weight:600;
}

/* ── ARO: modern segmented payment-term toggle ── */
.aro-term-toggle {
  display:inline-flex;
  background:#f1f3f5;
  border-radius:10px;
  padding:3px;
  gap:2px;
}
.aro-term-pill {
  display:flex;
  align-items:center;
  gap:6px;
  padding:8px 16px;
  border-radius:8px;
  font-size:12px;
  font-weight:600;
  color:var(--text-secondary);
  cursor:pointer;
  white-space:nowrap;
  transition:background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}
.aro-term-pill input { display:none; }
.aro-term-pill i { font-size:15px; color:var(--text-muted); transition:color 0.15s ease; }
.aro-term-pill.active,
.aro-term-pill:has(input:checked) {
  background:#fff;
  color:var(--text-primary);
  box-shadow:0 1px 3px rgba(0,0,0,0.14);
}
.aro-term-pill.active .ti-cash,
.aro-term-pill:has(input:checked) .ti-cash { color:#2e7d32; }
.aro-term-pill.active .ti-credit-card,
.aro-term-pill:has(input:checked) .ti-credit-card { color:#1565c0; }
.aro-term-pill.active .ti-calendar-stats,
.aro-term-pill:has(input:checked) .ti-calendar-stats { color:#e65100; }


    /* ── GR Lines table ── */
    .gr-lines-header,
    .gr-line-desktop {
      display: grid;
      grid-template-columns: 30px minmax(120px,1fr) 50px 50px 80px 80px 80px 55px 95px 30px;
      gap: 6px;
      align-items: center;
      min-width: 740px;
      width: 100%;
    }
    .gr-lines-header {
      padding: 7px 10px;
      background: var(--accent-light);
      border-radius: var(--radius-sm) var(--radius-sm) 0 0;
      border: 1px solid var(--border-color);
      font-size: 11px; font-weight: 700; letter-spacing: 0.7px;
      text-transform: uppercase; color: var(--text-secondary);
      position: sticky; top: -20px; z-index: 10;
      box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    }
    .gr-line-desktop {
      padding: 5px 10px;
      border: 1px solid var(--border-color);
      border-top: none;
      background: var(--bg-card);
      transition: background 0.12s;
    }
    .gr-line-group {
      border-radius: var(--radius-sm);
      border: 1px solid var(--border-color);
      margin-bottom: 8px;
      overflow: hidden;
    }
    .gr-line-group.has-po-banner {
      border-top: none;
    }
    .gr-line-group:last-child { margin-bottom: 0; }
    .gr-line-group .gr-line-desktop {
      border: none;
      border-radius: 0;
    }
    .gr-line-group { transition: border-color 0.15s; }
    .gr-line-group:hover { border-color: var(--text-muted); }
    .gr-line-row2 {
      background: var(--bg-card);
      transition: background 0.12s;
    }


    /* ─── Return Lines ─── */
    .ret-lines-header,
    .ret-line-row {
      display: grid;
      grid-template-columns: 28px 110px 96px minmax(120px,1fr) minmax(110px,140px) 100px 96px 72px 90px 80px 36px;
      gap: 8px;
      align-items: center;
    }
    .ret-lines-header {
      padding: 7px 10px;
      background: var(--accent-light);
      border-radius: var(--radius-sm) var(--radius-sm) 0 0;
      border: 1px solid var(--border-color);
      font-size: 11px; font-weight: 700; letter-spacing: 0.7px;
      text-transform: uppercase; color: var(--text-secondary);
      position: sticky; top: -20px; z-index: 10;
      box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    }
    .ret-line-row {
      padding: 7px 10px;
      border: 1px solid var(--border-color);
      border-top: none;
      background: var(--bg-card);
    }
    .ret-line-group {
      border-radius: var(--radius-sm);
      border: 1px solid var(--border-color);
      margin-bottom: 8px;
      overflow: hidden;
      transition: border-color 0.15s;
    }
    .ret-line-group:last-child { margin-bottom: 0; }
    .ret-line-group .ret-line-row { border: none; border-radius: 0; }
    .ret-line-group:hover { border-color: var(--text-muted); }
    /* ── PO Filter pills ── */
    .pof-btn {
      font-size: 11px; padding: 4px 11px; border-radius: 20px;
      border: 1px solid var(--border-color);
      background: transparent; color: var(--text-secondary);
      cursor: pointer; white-space: nowrap;
      font-family: 'Noto Sans Thai', sans-serif;
      transition: background 0.15s, color 0.15s;
    }
    .pof-btn:hover { background: var(--accent-light); }
    .pof-btn.pof-active {
      background: var(--accent); color: var(--badge-text);
      border-color: var(--accent);
    }

    /* ─── Flatpickr custom theme ─── */
    .flatpickr-calendar {
      font-family: 'Noto Sans Thai', sans-serif !important;
      background: var(--bg-card) !important;
      border: 1px solid var(--border-color) !important;
      border-radius: var(--radius) !important;
      box-shadow: 0 8px 24px rgba(0,0,0,0.14) !important;
    }
    .flatpickr-month {
      background: var(--bg-card) !important;
      color: var(--text-primary) !important;
      padding: 8px 0 4px !important;
    }
    .flatpickr-current-month {
      font-size: 14px !important;
      font-weight: 600 !important;
      color: var(--text-primary) !important;
    }
    .flatpickr-current-month .flatpickr-monthDropdown-months,
    .flatpickr-current-month input.cur-year {
      color: var(--text-primary) !important;
      background: transparent !important;
      font-family: 'Noto Sans Thai', sans-serif !important;
      font-weight: 600 !important;
      font-size: 14px !important;
    }
    .flatpickr-weekdays { background: var(--bg-card) !important; }
    span.flatpickr-weekday {
      background: var(--bg-card) !important;
      color: var(--text-muted) !important;
      font-size: 12px !important;
      font-weight: 600 !important;
    }
    .flatpickr-days { border-color: var(--border-color) !important; }
    .flatpickr-day {
      color: var(--text-primary) !important;
      border-radius: 50% !important;
      font-size: 13px !important;
    }
    .flatpickr-day:hover {
      background: var(--accent-light) !important;
      border-color: transparent !important;
    }
    .flatpickr-day.today {
      border-color: var(--accent) !important;
      font-weight: 700 !important;
    }
    .flatpickr-day.selected, .flatpickr-day.selected:hover {
      background: var(--accent) !important;
      border-color: var(--accent) !important;
      color: var(--badge-text) !important;
    }
    .flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay {
      color: var(--text-muted) !important;
      opacity: 0.5 !important;
    }
    .flatpickr-prev-month, .flatpickr-next-month {
      color: var(--text-primary) !important;
      fill: var(--text-primary) !important;
      padding: 8px 12px !important;
    }
    .flatpickr-prev-month:hover svg, .flatpickr-next-month:hover svg {
      fill: var(--accent) !important;
    }
    .flatpickr-input-custom { cursor: pointer !important; }

    /* ─── SweetAlert overrides ─── */
    .swal2-popup {
      font-family: 'Noto Sans Thai', sans-serif !important;
      border-radius: var(--radius) !important;
    }
    /* ── Product image upload ── */
    .prod-img-drag {
      background: var(--accent-light) !important;
      border-color: var(--accent) !important;
    }
    .prod-img-thumb {
      position:relative;width:80px;height:80px;border-radius:var(--radius-sm);
      overflow:hidden;border:1px solid var(--border-color);flex-shrink:0;
      background:var(--bg-main);cursor:pointer;
    }
    .prod-img-thumb img { width:100%;height:100%;object-fit:cover;display:block; }
    .prod-img-thumb .prod-img-del {
      position:absolute;top:3px;right:3px;width:20px;height:20px;border-radius:50%;
      background:rgba(0,0,0,0.65);border:none;cursor:pointer;
      display:flex;align-items:center;justify-content:center;
      color:#fff;font-size:11px;opacity:0;transition:opacity 0.15s;
    }
    .prod-img-thumb:hover .prod-img-del { opacity:1; }
    .prod-img-thumb:hover .prod-img-dl  { opacity:1; }
    .prod-img-thumb .prod-img-main-badge {
      position:absolute;bottom:0;left:0;right:0;
      background:rgba(26,26,26,0.75);color:#fff;
      font-size:9px;font-weight:700;text-align:center;padding:2px 0;letter-spacing:0.5px;
    }

    /* ── Product image lightbox ── */
    #prod-img-lightbox {
      display:none;position:fixed;inset:0;z-index:9999;
      background:rgba(0,0,0,0.88);
      align-items:center;justify-content:center;flex-direction:column;
    }
    #prod-img-lightbox.open { display:flex; }
    #prod-img-lightbox .lb-main-wrap {
      position:relative;display:flex;align-items:center;justify-content:center;
      width:100%;flex:1;min-height:0;padding:48px 56px;box-sizing:border-box;
    }
    #prod-img-lightbox .lb-img {
      max-width:100%;max-height:calc(100vh - 160px);
      object-fit:contain;border-radius:8px;
      box-shadow:0 8px 40px rgba(0,0,0,0.6);
      user-select:none;
    }
    #prod-img-lightbox .lb-btn {
      position:absolute;top:50%;transform:translateY(-50%);
      width:44px;height:44px;border-radius:50%;border:none;cursor:pointer;
      background:rgba(255,255,255,0.12);color:#fff;font-size:22px;
      display:flex;align-items:center;justify-content:center;
      transition:background 0.15s;backdrop-filter:blur(4px);
    }
    #prod-img-lightbox .lb-btn:hover { background:rgba(255,255,255,0.25); }
    #prod-img-lightbox .lb-prev { left:8px; }
    #prod-img-lightbox .lb-next { right:8px; }
    #prod-img-lightbox .lb-btn:disabled { opacity:0.2;cursor:default; }
    #prod-img-lightbox .lb-close {
      position:fixed;top:16px;right:16px;
      width:40px;height:40px;border-radius:50%;border:none;cursor:pointer;
      background:rgba(255,255,255,0.12);color:#fff;font-size:20px;
      display:flex;align-items:center;justify-content:center;
      transition:background 0.15s;backdrop-filter:blur(4px);z-index:1;
    }
    #prod-img-lightbox .lb-close:hover { background:rgba(255,255,255,0.3); }
    #prod-img-lightbox .lb-footer {
      width:100%;padding:0 16px 16px;box-sizing:border-box;
      display:flex;flex-direction:column;align-items:center;gap:10px;flex-shrink:0;
    }
    #prod-img-lightbox .lb-dots {
      display:flex;gap:6px;align-items:center;
    }
    #prod-img-lightbox .lb-dot {
      width:7px;height:7px;border-radius:50%;background:rgba(255,255,255,0.3);
      cursor:pointer;transition:background 0.15s,transform 0.15s;border:none;padding:0;
    }
    #prod-img-lightbox .lb-dot.active {
      background:#fff;transform:scale(1.3);
    }
    #prod-img-lightbox .lb-counter {
      font-size:12px;color:rgba(255,255,255,0.55);font-family:'Noto Sans Thai',sans-serif;
    }
    #prod-img-lightbox .lb-actions {
      display:flex;gap:8px;
    }
    #prod-img-lightbox .lb-action-btn {
      display:inline-flex;align-items:center;gap:5px;
      padding:5px 14px;border-radius:20px;border:1px solid rgba(255,255,255,0.25);
      background:rgba(255,255,255,0.08);color:rgba(255,255,255,0.8);
      font-size:12px;font-weight:600;cursor:pointer;transition:background 0.15s;
      font-family:'Noto Sans Thai',sans-serif;
    }
    #prod-img-lightbox .lb-action-btn:hover { background:rgba(255,255,255,0.18); }
    #prod-img-lightbox .lb-action-btn.danger { border-color:rgba(239,83,80,0.5);color:#ef9a9a; }
    #prod-img-lightbox .lb-action-btn.danger:hover { background:rgba(239,83,80,0.18); }

    /* ── Product document attachments ── */
    .prod-doc-item {
      display:flex;align-items:center;gap:10px;
      padding:8px 12px;background:var(--bg-card);
      border:1px solid var(--border-color);border-radius:var(--radius-sm);
      transition:background 0.12s;
    }
    .prod-doc-item:hover { background:var(--accent-light); }
    .prod-doc-icon {
      width:36px;height:36px;border-radius:var(--radius-sm);
      display:flex;align-items:center;justify-content:center;
      flex-shrink:0;font-size:20px;
    }
    .prod-doc-name {
      flex:1;min-width:0;font-size:13px;font-weight:600;
      white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--text-primary);
    }
    .prod-doc-meta { font-size:11px;color:var(--text-muted);margin-top:1px; }
    .prod-doc-actions { display:flex;gap:4px;flex-shrink:0; }

    /* ── ให้ SweetAlert ลอยอยู่เหนือ Bootstrap Modal เสมอ ── */
    .swal2-container {
      z-index: 999999 !important;
    }

    /* ── ซ่อน scrollbar บน tab-bar แต่ยังคง scroll ได้ ── */
    .tab-bar-scroll {
      scrollbar-width: none;
      -ms-overflow-style: none;
    }
    .tab-bar-scroll::-webkit-scrollbar {
      display: none;
    }
    [style*="overflow-x:auto"]:not(.table-responsive):not(.table-responsive-custom):not([id]) {
      scrollbar-width: none; /* Firefox */
      -ms-overflow-style: none; /* IE/Edge */
    }
    [style*="overflow-x:auto"]:not(.table-responsive):not(.table-responsive-custom):not([id])::-webkit-scrollbar {
      display: none; /* Chrome/Safari */
    }
    /* target tab bars specifically */
    [style*="overflow-x: auto"]:not(.table-responsive):not(.table-responsive-custom):not([id]) {
      scrollbar-width: none;
      -ms-overflow-style: none;
    }
    [style*="overflow-x: auto"]:not(.table-responsive):not(.table-responsive-custom):not([id])::-webkit-scrollbar {
      display: none;
    }

    /* ── scrollbar สำหรับ lines wrapper (QT / SO) ── */
    #qt-lines-wrapper::-webkit-scrollbar,
    #so-lines-wrapper::-webkit-scrollbar {
      height: 6px;
    }
    #qt-lines-wrapper::-webkit-scrollbar-track,
    #so-lines-wrapper::-webkit-scrollbar-track {
      background: transparent;
    }
    #qt-lines-wrapper::-webkit-scrollbar-thumb,
    #so-lines-wrapper::-webkit-scrollbar-thumb {
      background: var(--border-color);
      border-radius: 3px;
    }
    /* ── ป้องกัน body ติด overflow:hidden หลัง Swal ปิด ── */
    body:not(.modal-open) {
      overflow: unset !important;
      padding-right: 0 !important;
    }

    /* ─── Select2 dropdown — always on top of modal ─── */
    .select2-container--open .select2-dropdown {
      z-index: 9999 !important;
    }
  
/* ── Movement Accordion ── */
.mov-accordion-body {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 9999px;
  opacity: 1;
}
.mov-accordion-body.mov-acc-collapsed {
  max-height: 0 !important;
  opacity: 0;
  pointer-events: none;
}
.mov-accordion-header:hover {
  background: var(--accent-light) !important;
  filter: brightness(0.97);
}

.badge-notify {
  background: #ef4444;
  color: white;
  font-size: 15px;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.badge-notify-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ef4444;
  color: white;
  font-size: 15px;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  border: 2px solid white;
}

/* ── Custom ── */
.module-badge{
    display:inline-flex;
    align-items:center;
    gap:6px;
    padding:6px 12px;
    background:#eef4ff;
    color:#2563eb;
    border:1px solid #bfdbfe;
    border-radius:8px;
    font-size:12px;
    font-weight:600;
}

/* ── Payment Collection table — balance layout ───────────────────────── */
#pay-so-section .table-custom { width: 100%; }
#pay-table-body > tr > td {
  vertical-align: top;
  padding-top: 10px;
  padding-bottom: 10px;
}
/* Col 1 — checkbox: keep its 40px slot even when the <td> is empty
   (paid rows render an empty <td></td> which otherwise collapses to 0
   and shifts every cell one column left of its header) */
#pay-so-section .table-custom th:first-child,
#pay-so-section .table-custom td:first-child {
  width: 40px !important;
  min-width: 40px;
  text-align: center;
  box-sizing: border-box;
}
#pay-so-section .table-custom td:first-child:empty::after {
  content: "\00a0";
  display: inline-block;
  width: 18px;
}
/* Col 2 — เอกสาร (TXN/ใบกำกับ): keep IDs on one line */
#pay-so-section .table-custom th:nth-child(2),
#pay-so-section .table-custom td:nth-child(2) {
  width: 170px;
  min-width: 170px;
  box-sizing: border-box;
}
#pay-so-section .table-custom td:nth-child(2) > div { min-width: 0; }
#pay-so-section .table-custom td:nth-child(2) span,
#pay-so-section .table-custom td:nth-child(2) div {
  white-space: nowrap;
  word-break: keep-all;
  overflow-wrap: normal;
}
/* Col 3 — เลขที่ใบขาย (SO), Col 4 — เลขที่ใบจัดส่ง (DL) */
#pay-so-section .table-custom th:nth-child(3),
#pay-so-section .table-custom td:nth-child(3),
#pay-so-section .table-custom th:nth-child(4),
#pay-so-section .table-custom td:nth-child(4) {
  width: 120px;
  min-width: 120px;
  box-sizing: border-box;
  white-space: nowrap;
}
/* Col 5 — ลูกค้า: flexible, allow wrap on long names */
#pay-so-section .table-custom td:nth-child(5) > div > div:first-child {
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
}
/* Col 6 — เลขที่ใบกำกับ / เลขที่ใบเสร็จ */
#pay-so-section .table-custom th:nth-child(6),
#pay-so-section .table-custom td:nth-child(6) {
  width: 140px;
  min-width: 140px;
  box-sizing: border-box;
  white-space: nowrap;
}
/* status badge aligned right under remaining amount */
#pay-so-section .table-custom td:nth-child(9) > div:nth-child(2) {
  text-align: right;
}
