/* ================================================================
   R&B-Bird SMART SYSTEM v2.1 — Unified Design System
   หลักการ: Single Source of Truth — ทุกหน้าใช้ Token/Component ชุดนี้ชุดเดียว
   ห้ามสร้าง CSS Variable ชื่อใหม่ในไฟล์อื่น ให้ขยายจากไฟล์นี้เท่านั้น
   ================================================================ */

/* ================================================================
   1. CSS VARIABLES (Design Tokens)
   ================================================================ */
:root {
    /* Primary */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --primary-bg: rgba(99, 102, 241, 0.08);

    /* Neutrals */
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    /* Status */
    --success: #22c55e;
    --success-bg: #dcfce7;
    --warning: #eab308;
    --warning-bg: #fef9c3;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --info: #3b82f6;
    --info-bg: #dbeafe;

    /* Platform Brand Colors (ใช้ตัวแปรเดียวกันทุกหน้า ห้าม hardcode ซ้ำ) */
    --tiktok: #03033f;
    --tiktok-bg: #03033f0d;
    --shopee: #ee4d2d;
    --shopee-bg: #ee4d2d0d;
    --web: #7c3aed;
    --web-bg: #7c3aed0d;
    --other: #64748b;
    --other-bg: #64748b0d;

    /* Sizing */
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --topbar-height: 64px;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 20px;
    --radius-md: 12px;

    /* Shadows */
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.08);
    --shadow-xl: 0 20px 60px rgba(0,0,0,0.10);

    /* Transitions */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================================================================
   2. RESET & BASE
   ================================================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
    font-family: 'Prompt', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}
a { text-decoration: none; color: var(--primary); }
/* ✅ Bootstrap (โหลดก่อนไฟล์นี้) ตั้ง a:hover{text-decoration:underline} ไว้ — specificity เท่ากับ a:hover
   ของเรา (pseudo-class + element ทั้งคู่) ดังนั้นแค่ text-decoration:none บน .stat-card/.mc-card/.type-card เฉยๆ
   (specificity แค่ 1 class) เอาไม่อยู่ ต้องแก้ที่ a:hover ตรงๆ ถึงจะชนะทุกจุดที่การ์ดครอบด้วย <a> ทั้งระบบ */
a:hover { color: var(--primary-dark); text-decoration: none; }
img { max-width: 100%; }
button { font-family: inherit; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
::selection { background: var(--primary); color: #fff; }

/* ================================================================
   3. APP LAYOUT (Sidebar / Topbar / Main)
   ================================================================ */
.smart-app { display: flex; min-height: 100vh; }

.smart-sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-width); height: 100vh;
    background: var(--text); color: #fff;
    z-index: 1000; display: flex; flex-direction: column;
    transition: var(--transition); overflow: hidden;
}
/* ✅ ฟีเจอร์ย่อ/ขยาย Sidebar บน Desktop ถูกถอดออกแล้ว — Sidebar เปิดเต็มความกว้างตลอดบนคอม */

.sidebar-brand { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,0.06); min-height: 68px; }
.brand-logo { display: flex; align-items: center; gap: 0.6rem; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.3px; }
.brand-badge { font-size: 0.5rem; font-weight: 600; background: var(--primary); color: #fff; padding: 0.05rem 0.4rem; border-radius: 10px; text-transform: uppercase; }
/* ✅ ปุ่มย่อ/ขยาย Sidebar บน Desktop ถูกถอดออกตามที่ต้องการ — เก็บ Sidebar ให้เปิดเต็มตลอดบนคอม */

/* ✅ padding แนวนอนต้องเท่ากับ .sidebar-nav (0.75rem) ไม่งั้นขอบซ้าย-ขวาของบล็อกผู้ใช้กับเมนูด้านล่างจะเหลื่อมกัน */
.sidebar-user { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; border-bottom: 1px solid rgba(255,255,255,0.06); position: relative; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.8rem; flex-shrink: 0; }
.user-avatar span { color: #fff; }
.user-info { flex: 1; min-width: 0; line-height: 1.2; }
.user-name { display: block; font-weight: 500; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 0.65rem; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 0.3px; }
.user-status { width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--text); flex-shrink: 0; }
.user-status.online { background: var(--success); }
.user-status.offline { background: var(--danger); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.5rem 0.75rem; }
.nav-section { margin-bottom: 0.75rem; }
.nav-label { font-size: 0.55rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: rgba(255,255,255,0.25); padding: 0.3rem 0.6rem; display: block; }
.nav-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.6rem; border-radius: var(--radius-sm); color: rgba(255,255,255,0.5); transition: var(--transition); cursor: pointer; font-size: 0.82rem; position: relative; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.04); }
.nav-item.active { color: #fff; background: rgba(99,102,241,0.15); }
.nav-item.active::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 20px; background: var(--primary); border-radius: 0 3px 3px 0; }
.nav-item i { width: 20px; text-align: center; font-size: 0.95rem; flex-shrink: 0; }
/* ✅ label ต้องยอมหด+ตัดจบด้วย "..." เมื่อพื้นที่ไม่พอ (เช่น "นำเข้าจาก PDF" ที่ยาวกว่าเมนูอื่น) ไม่งั้น
   ตัวหนังสือจะขึ้นบรรทัดใหม่ในแถวเดียวกับ badge แล้วเหลื่อมทับกัน — badge เองต้อง flex-shrink:0 กันโดนบีบ */
.nav-item > span:not(.nav-badge) { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .nav-badge { margin-left: auto; flex-shrink: 0; font-size: 0.55rem; font-weight: 600; background: var(--danger); color: #fff; padding: 0.05rem 0.5rem; border-radius: 10px; display: none; }
.nav-item .nav-badge.show { display: inline-block; }

.sidebar-footer { padding: 0.75rem 1.25rem; border-top: 1px solid rgba(255,255,255,0.06); }
.logout-btn { display: flex; align-items: center; gap: 0.6rem; color: rgba(255,255,255,0.4); font-size: 0.82rem; padding: 0.4rem 0.6rem; border-radius: var(--radius-sm); transition: var(--transition); cursor: pointer; }
.logout-btn:hover { color: var(--danger); background: rgba(239,68,68,0.1); }
.logout-btn i { width: 20px; text-align: center; }

.smart-main { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-height: 100vh; transition: var(--transition); max-width: 100%; overflow-x: hidden; }


.smart-topbar {
    height: var(--topbar-height); background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 500; gap: 1rem;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.mobile-menu-btn { display: none; background: none; border: none; font-size: 1.1rem; color: var(--text); cursor: pointer; padding: 0.3rem; }
.breadcrumb { font-size: 0.85rem; color: var(--text-secondary); font-weight: 500; }
.breadcrumb-item.active { color: var(--text); font-weight: 600; }

.search-box { display: flex; align-items: center; background: var(--bg); border-radius: var(--radius-sm); padding: 0.3rem 0.8rem; transition: var(--transition); border: 1px solid transparent; }
.search-box:focus-within { background: var(--surface); border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.08); }
.search-box i { color: var(--text-muted); font-size: 0.8rem; margin-right: 0.5rem; }
.search-box input { border: none; background: transparent; outline: none; font-size: 0.8rem; font-family: inherit; color: var(--text); width: 160px; }
.search-box input::placeholder { color: var(--text-muted); }

.topbar-btn { background: none; border: none; color: var(--text-secondary); font-size: 1.05rem; cursor: pointer; padding: 0.3rem 0.5rem; border-radius: var(--radius-sm); transition: var(--transition); position: relative; }
.topbar-btn:hover { background: var(--bg); color: var(--text); }
.topbar-btn .badge-dot { position: absolute; top: 0; right: 0; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); border: 2px solid var(--surface); display: none; }
.topbar-btn .badge-dot.show { display: block; }

.user-menu { position: relative; }
.user-menu-btn { display: flex; align-items: center; gap: 0.4rem; background: none; border: none; cursor: pointer; padding: 0.2rem 0.4rem; border-radius: var(--radius-sm); transition: var(--transition); }
.user-menu-btn:hover { background: var(--bg); }
.user-avatar-small { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.7rem; }
.user-menu-btn i { color: var(--text-muted); font-size: 0.7rem; }

.user-dropdown, .notification-dropdown { position: absolute; top: calc(100% + 0.5rem); right: 0; background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow-xl); min-width: 220px; border: 1px solid var(--border); display: none; z-index: 100; }
.user-dropdown.show, .notification-dropdown.show { display: block; animation: fadeDown 0.2s ease; }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.dropdown-header { padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.dropdown-header strong { display: block; font-size: 0.85rem; }
.dropdown-header small { color: var(--text-muted); font-size: 0.7rem; }
.dropdown-divider { height: 1px; background: var(--border); margin: 0.25rem 0; }
.dropdown-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 1rem; color: var(--text-secondary); font-size: 0.82rem; transition: var(--transition); }
.dropdown-item:hover { background: var(--bg); color: var(--text); }
.dropdown-item i { width: 18px; text-align: center; font-size: 0.8rem; }
.dropdown-item.text-danger { color: var(--danger); }
.dropdown-item.text-danger:hover { background: var(--danger-bg); }
.dropdown-body { max-height: 280px; overflow-y: auto; }
.notification-empty { padding: 2rem 1rem; text-align: center; color: var(--text-muted); }
.notification-empty i { font-size: 1.8rem; margin-bottom: 0.5rem; display: block; opacity: 0.4; }
.notification-empty p { font-size: 0.8rem; }

.smart-content { flex: 1; padding: 1.5rem; max-width: 100%; min-width: 0; width: 100%; }
.smart-footer { padding: 0.75rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 0.5rem; font-size: 0.7rem; color: var(--text-muted); align-items: center; }

/* ================================================================
   4. GLOBAL MODAL
   ================================================================ */
.smart-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 2000; display: flex; align-items: center; justify-content: center; }
.smart-modal-backdrop { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15,23,42,0.5); backdrop-filter: blur(4px); cursor: pointer; }
/* ✅ display:flex column กัน modal-footer โดน overflow:hidden ตัดหายตอนเนื้อหายาว (เดิม modal-body มี
   max-height:60vh ของตัวเองแยกต่างหาก ไม่ได้คำนวณรวมกับ header/footer จริง — ถ้ารวมกันเกิน max-height ของ
   container ส่วนที่เกิน (มักเป็นปุ่มใน footer) จะโดนตัดหายไปเฉยๆ) ให้ header/footer คงขนาดตามเนื้อหาเสมอ
   (flex-shrink:0) เหลือพื้นที่เท่าไหร่ modal-body ยืด/หดตามนั้น (flex:1, min-height:0 ให้ overflow-y ทำงานจริง) */
.modal-container { position: relative; background: var(--surface); border-radius: var(--radius); max-width: 640px; width: 92%; max-height: 80vh; box-shadow: var(--shadow-xl); overflow: hidden; animation: modalIn 0.25s ease; display: flex; flex-direction: column; }
/* ✅ SweetAlert2 z-index ค่าปกติ (1060) ต่ำกว่า .smart-modal (2000) — ถ้าเปิด Swal.fire() ขณะ openGlobalModal()
   ยังเปิดอยู่ (เช่น แจ้งเตือนกรอกข้อมูลไม่ครบตอนกดยืนยันในโมดัล) จะโผล่ไปอยู่หลังโมดัลจนกดอะไรไม่ได้เลย
   บังคับให้ swal2-container ลอยเหนือโมดัลเสมอ */
.swal2-container { z-index: 2100 !important; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-container .modal-header { flex-shrink: 0; width: 100%; box-sizing: border-box; display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
.modal-container .modal-header h4 { font-size: 0.95rem; font-weight: 600; margin: 0; }
.modal-container .modal-close { background: none; border: none; font-size: 1.2rem; color: var(--text-muted); cursor: pointer; padding: 0.2rem; border-radius: 6px; transition: var(--transition); }
.modal-container .modal-close:hover { background: var(--bg); color: var(--text); }
/* ✅ width:100%+box-sizing:border-box บน body/footer — ถ้าไม่ใส่ ปุ่ม/เนื้อหาข้างในที่กว้างไม่พอจะพับ (เช่น
   footer หลายปุ่ม) ทำให้ flex item (body/footer) ขยายเกิน cross-axis ที่ .modal-container จัดให้จริง (ปัญหา
   min-width:auto เริ่มต้นของ flex item) จนล้นออกไปโดน overflow:hidden ของ container ตัดทิ้งเงียบๆ — ใส่
   width:100% บังคับให้กว้างเท่า container เป๊ะเสมอ ไม่ปล่อยให้เนื้อหาดันกว้างเกินได้อีก */
.modal-container .modal-body { flex: 1 1 auto; min-height: 0; width: 100%; box-sizing: border-box; padding: 1.25rem 1.5rem; overflow-y: auto; }
/* ✅ flex-wrap:wrap — เจอระหว่างตรวจบั๊กด้านบนว่า footer ที่มีหลายปุ่ม (เช่น modal รายละเอียดออเดอร์ 3 ปุ่ม)
   ล้นความกว้าง .modal-container ได้จริงบนจอมือถือแคบๆ (ไม่มี flex-wrap มาก่อน แถวเดียวยาวเกิน แล้วโดน
   overflow:hidden ของ container ตัดปุ่มขวาสุดหายไปเงียบๆ กดไม่ได้เลย) ให้ปุ่มตกบรรทัดใหม่แทนเมื่อไม่พอ */
.modal-container .modal-footer { flex-shrink: 0; flex-wrap: wrap; width: 100%; box-sizing: border-box; padding: 0.75rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.5rem; }

/* ================================================================
   5. BUTTONS (ครบทุกสถานะ — แก้ปัญหา .btn-success/.btn-danger หายไป)
   ================================================================ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.5rem 1.1rem; border-radius: var(--radius-sm); font-weight: 500; font-size: 0.82rem; border: none; cursor: pointer; transition: var(--transition); font-family: inherit; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 15px rgba(99,102,241,0.3); }
.btn-secondary { background: var(--border); color: var(--text-secondary); }
.btn-secondary:hover { background: var(--text-muted); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { background: var(--bg); border-color: var(--text-muted); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; box-shadow: 0 4px 15px rgba(34,197,94,0.3); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; box-shadow: 0 4px 15px rgba(239,68,68,0.3); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #ca8a04; }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #2563eb; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.72rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 0.95rem; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; gap: 0.3rem; }
.btn-icon { padding: 0.45rem; width: 32px; height: 32px; }

/* ✅ ปุ่มคัดลอกเลขอ้างอิงแพลตฟอร์ม (bill_order) — แทรกกลางบรรทัด text-muted เล็กๆ ในตาราง/การ์ด/modal ออเดอร์
   ไม่ใช้ .btn-icon เดิม (32px ใหญ่เกินไปเมื่ออยู่กลางบรรทัดข้อความขนาดเล็ก) */
.btn-copy-ref {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    margin-left: 0.25rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    vertical-align: middle;
    transition: var(--transition);
}
.btn-copy-ref:hover { background: rgba(99, 102, 241, 0.1); color: var(--primary); }

/* ================================================================
   6. BADGES (ครบทุกแพลตฟอร์ม/สถานะ — ของจริง ใช้ตัวแปรเดียวกันทุกหน้า)
   ================================================================ */
.badge-smart, .badge { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.15rem 0.6rem; border-radius: 20px; font-size: 0.68rem; font-weight: 600; white-space: nowrap; }
.badge-tiktok { background: var(--tiktok); color: #fff; }
.badge-shopee { background: var(--shopee); color: #fff; }
.badge-web { background: var(--web); color: #fff; }
.badge-other, .badge-secondary { background: var(--border); color: var(--text-secondary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
/* ✅ COD (เก็บเงินปลายทาง) — สีแดงทึบ + ตัวอักษรขาว ตั้งใจให้เข้มกว่า .badge-danger (พื้นอ่อน/ตัวอักษรแดง
   ใช้กับสถานะ "ยกเลิก") ให้เห็นชัดกว่าและไม่สับสนกันตอนออเดอร์เดียวกันมีทั้ง badge สถานะกับ badge COD */
.badge-cod { background: var(--danger); color: #fff; margin-left: 0.3rem; }

/* ================================================================
   6.1 ALERTS (Component กลาง — ใช้ได้ทุกหน้า ไม่ใช่แค่ Login)
   ================================================================ */
.alert { border-radius: var(--radius-sm); padding: 0.6rem 0.85rem; font-size: 0.82rem; display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }
.alert-info { background: var(--info-bg); color: var(--info); }
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.5px; margin: 0; display: flex; align-items: center; gap: 0.5rem; }
.page-subtitle { color: var(--text-muted); font-size: 0.82rem; margin: 0.2rem 0 0 0; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ================================================================
   8. STAT CARDS (Dashboard + Orders Stats)
   ================================================================ */
.stats-grid, .dashboard-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.25rem; margin-bottom: 1.5rem; }
.orders-page .stats-grid { grid-template-columns: repeat(5, 1fr); } /* ✅ หน้ารายการคำสั่งซื้อมีการ์ด "ยอดรวม" เพิ่มมาเป็น 5 ใบ */
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 1.1rem 1.4rem; border: 1px solid var(--border); transition: var(--transition); box-shadow: var(--shadow); display: flex; align-items: center; gap: 0.9rem; min-width: 0; overflow: hidden; text-decoration: none; color: inherit; } /* ✅ text-decoration/color เผื่อการ์ดเป็น <a> (คลิกเพื่อกรองสถานะ) */
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.stat-card .stat-content { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.stat-card .stat-number { font-size: 1.5rem; font-weight: 700; color: var(--text); letter-spacing: -0.5px; line-height: 1.2; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-card .stat-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; display: block; margin-top: 0.1rem; }
.stat-card .stat-change { font-size: 0.62rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 12px; display: inline-flex; align-items: center; gap: 0.2rem; margin-top: 0.3rem; }
.stat-card .stat-change.up { background: var(--success-bg); color: var(--success); }
.stat-card .stat-change.down { background: var(--danger-bg); color: var(--danger); }

/* ================================================================
   9. FILTER BAR (ใช้ token จริง ไม่ใช่ --gray-* ที่ไม่มีอยู่)
   ================================================================ */
.filter-bar { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 0.9rem 1.25rem; margin-bottom: 1.5rem; box-shadow: var(--shadow); }
.filter-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.85rem; }
.filter-group { display: flex; flex-direction: column; flex: 1; min-width: 150px; }
.filter-group label { font-size: 0.62rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 0.25rem; }
.filter-group .form-control { border: 1px solid var(--border); background: var(--bg); border-radius: var(--radius-sm); padding: 0.4rem 0.7rem; font-size: 0.8rem; outline: none; font-family: inherit; color: var(--text); transition: var(--transition); width: 100%; }
.filter-group .form-control:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-bg); }
.filter-group .input-group { display: flex; align-items: center; background: var(--bg); border-radius: var(--radius-sm); border: 1px solid var(--border); overflow: hidden; transition: var(--transition); }
.filter-group .input-group:focus-within { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-bg); }
.filter-group .input-group-text { padding: 0.3rem 0.6rem; color: var(--text-muted); font-size: 0.7rem; }
.filter-group .input-group .form-control { border: none; background: transparent; padding: 0.3rem 0.6rem 0.3rem 0; }
.filter-actions, .filter-quick { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.filter-quick { margin-top: 0.75rem; }
/* ✅ ปุ่ม "ค้นหา/ล้าง" ใน .filter-actions เดิมใช้ .btn-sm (padding 0.3rem/font 0.72rem) ซึ่งเตี้ยกว่า
   .filter-group .form-control (padding 0.4rem/font 0.8rem) ที่อยู่แถวเดียวกัน (.filter-row มี
   align-items:flex-end) ทำให้ปุ่มดูเตี้ยกว่า input/select ข้างๆ ชัดเจน — บังคับให้สูงเท่ากันตรงนี้ */
.filter-actions .btn { padding: 0.4rem 0.9rem; font-size: 0.8rem; }
@media (max-width: 768px) {
    .filter-row { flex-direction: column; align-items: stretch; }
    .filter-group { width: 100%; min-width: unset; }
    .filter-actions { width: 100%; }
    .filter-actions .btn { flex: 1; }
}

/* ================================================================
   10. SMART CARD / TABLE
   ================================================================ */
.card-smart, .card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card-smart .card-header, .card .card-header { padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; background: var(--surface-alt); }
.card-header h3, .card-header h4 { font-size: 0.85rem; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 0.4rem; }
.card-header .text-muted-sm { font-size: 0.65rem; color: var(--text-muted); }
.card-smart .card-body, .card .card-body { padding: 1rem 1.25rem; }
.card-smart .card-body.p-0, .card .card-body.p-0 { padding: 0; }

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table, .table-smart { width: 100%; min-width: max-content; border-collapse: collapse; font-size: 0.8rem; }
.table thead, .table-smart thead { background: var(--surface-alt); }
.table thead th, .table-smart thead th { padding: 0.5rem 0.85rem; font-weight: 600; color: var(--text-muted); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); text-align: left; }
.table tbody td, .table-smart tbody td { padding: 0.55rem 0.85rem; border-bottom: 1px solid var(--border); color: var(--text-secondary); vertical-align: middle; }
.table tbody tr:hover, .table-smart tbody tr:hover { background: var(--surface-alt); }
.table .text-center, .table-smart .text-center { text-align: center; }
.table .text-right, .table-smart .text-right { text-align: right; }
.table .fw-bold { font-weight: 600; }
.table-sm th, .table-sm td { padding: 0.4rem 0.6rem; font-size: 0.78rem; }

/* ✅ ปุ่มเลขหน้า — ไม่มี padding ซ้าย-ขวา (เดิมมี 1.25rem) เพราะไม่มีกรอบ/พื้นหลังเป็นกล่องของตัวเอง
   ใช้อยู่ในหน้า .orders-page ตรงๆ เสมอ (ไม่เคยอยู่ใน .card-body) การมี padding ซ้าย-ขวาเองจะทำให้เหลื่อม
   กับองค์ประกอบอื่นในหน้าเดียวกันที่ชิดขอบ .orders-page (เช่นกล่องค้นหา/การ์ดมือถือด้านบน) */
.pagination-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; padding: 0.85rem 0; }
.pagination-bar .page-info { font-size: 0.75rem; color: var(--text-muted); }
.pagination-bar .page-links { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.pagination-bar .page-links a, .pagination-bar .page-links span { min-width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); font-size: 0.78rem; border: 1px solid var(--border); color: var(--text-secondary); text-decoration: none; transition: var(--transition); cursor: pointer; } /* ✅ cursor:pointer ชัดเจน — เวอร์ชันแบ่งหน้าฝั่ง Client ไม่มี href (กันไม่ให้ browser พยายาม navigate จริง) เลยไม่ได้ cursor แบบลิงก์มาให้ฟรีๆ เหมือนเวอร์ชัน href */
.pagination-bar .page-links a:hover { background: var(--surface-alt); border-color: var(--text-muted); }
.pagination-bar .page-links .current { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pagination-bar .page-links .disabled { opacity: 0.4; pointer-events: none; }

.clickable { cursor: pointer; transition: var(--transition); padding: 0.1rem 0.4rem; border-radius: 6px; display: inline-block; }
.clickable:hover { background: var(--primary-bg); transform: scale(1.05); }

.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-info { color: var(--info) !important; }
.text-primary { color: var(--primary) !important; }
.text-muted { color: var(--text-muted) !important; }
.mb-3 { margin-bottom: 1rem; } .mt-3 { margin-top: 1rem; }
.py-4 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.d-block { display: block; }

/* ================================================================
   11. EMPTY STATE (ใช้ตอนตารางไม่มีข้อมูล)
   ================================================================ */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 2.2rem; opacity: 0.3; display: block; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.85rem; }

/* หน้าบัตรสะสมแต้ม (v2/loyalty) — คอลัมน์ "เงื่อนไข" ของโปรแกรมที่ปิดใช้งานตัดคำยาวให้พอดี ไม่ดันตาราง
   กว้างเกิน hover ดูข้อความเต็มได้จาก title attribute */
.text-loyalty-rules { max-width: 260px; font-size: 0.82rem; color: var(--text-muted); }
/* โปรแกรมที่เปิดใช้งานอยู่ — โชว์เงื่อนไขเต็มไม่ตัดคำ (สำคัญกว่าเพราะมีผลกับลูกค้าจริงตอนนี้) เผื่อพื้นที่
   กว้างขึ้นให้ข้อความหลายบรรทัดอ่านง่าย ไม่ใช้สีจางเหมือนโปรแกรมที่ปิดใช้งานเพราะเป็นข้อมูล active */
.text-loyalty-rules-active { max-width: 340px; color: var(--text); font-weight: 500; }

/* ================================================================
   12. LOADING SKELETON
   ================================================================ */
.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--surface-alt) 50%, var(--border) 75%); background-size: 200% 100%; animation: skeletonLoad 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeletonLoad { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.7); backdrop-filter: blur(2px); z-index: 3000; display: none; align-items: center; justify-content: center; }
.loading-overlay .spinner { width: 42px; height: 42px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   13. LOGIN PAGE (Split-Screen Design)
   ================================================================ */
.auth-screen { min-height: 100vh; display: flex; }

/* ---- ฝั่งซ้าย: Brand Panel ---- */
.auth-brand-panel {
    flex: 1.1; position: relative; overflow: hidden; display: flex; flex-direction: column;
    justify-content: center; padding: 4rem 3.5rem; color: #fff;
    background: radial-gradient(circle at 20% 20%, #312e81 0%, #0f172a 55%, #020617 100%);
}
.auth-blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.35; pointer-events: none; }
.auth-blob-1 { width: 380px; height: 380px; background: #6366f1; top: -120px; left: -80px; }
.auth-blob-2 { width: 320px; height: 320px; background: #8b5cf6; bottom: -100px; right: -60px; }
.auth-blob-3 { width: 200px; height: 200px; background: #22d3ee; top: 40%; right: 10%; opacity: 0.2; }

.auth-brand-logo { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 2.5rem; position: relative; z-index: 1; }
.auth-brand-logo img { width: 48px; height: 48px; border-radius: 14px; object-fit: contain; background: rgba(255,255,255,0.08); padding: 4px; }
.auth-brand-logo .name { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.3px; }
.auth-brand-logo .ver { font-size: 0.6rem; background: rgba(255,255,255,0.12); padding: 0.15rem 0.55rem; border-radius: 20px; margin-left: 0.4rem; font-weight: 600; }

.auth-headline { font-size: 2rem; font-weight: 700; line-height: 1.3; margin-bottom: 0.85rem; position: relative; z-index: 1; max-width: 460px; }
.auth-headline span { color: #a5b4fc; }
.auth-subtext { font-size: 0.9rem; color: rgba(255,255,255,0.55); margin-bottom: 2.5rem; position: relative; z-index: 1; max-width: 420px; line-height: 1.7; }

.auth-features { display: flex; flex-direction: column; gap: 1rem; position: relative; z-index: 1; }
.auth-feature { display: flex; align-items: center; gap: 0.75rem; }
.auth-feature .icon-wrap { width: 38px; height: 38px; border-radius: 11px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1); display: flex; align-items: center; justify-content: center; font-size: 0.95rem; color: #a5b4fc; flex-shrink: 0; }
.auth-feature .feature-text { font-size: 0.82rem; color: rgba(255,255,255,0.75); font-weight: 500; }

/* ---- ฝั่งขวา: Form Panel ---- */
.auth-form-panel { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--surface); padding: 2rem; }
.auth-form-wrap { width: 100%; max-width: 380px; animation: authFadeUp 0.5s ease; }
@keyframes authFadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

.auth-form-header { margin-bottom: 2rem; }
.auth-form-header h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.3rem; }
.auth-form-header p { font-size: 0.85rem; color: var(--text-muted); }

.auth-input-group { margin-bottom: 1.1rem; }
.auth-input-group label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 0.4rem; }
.auth-input-wrap { position: relative; display: flex; align-items: center; }
.auth-input-wrap i.input-icon { position: absolute; left: 0.85rem; color: var(--text-muted); font-size: 0.85rem; }
.auth-input-wrap input { width: 100%; border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 0.65rem 0.85rem 0.65rem 2.4rem; font-size: 0.88rem; font-family: inherit; outline: none; background: var(--surface-alt); transition: var(--transition); }
.auth-input-wrap input:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 4px var(--primary-bg); }
.auth-input-wrap input.is-invalid { border-color: var(--danger); }
.auth-input-wrap .toggle-pass-btn { position: absolute; right: 0.75rem; background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.85rem; padding: 0.2rem; }

.auth-row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.4rem; }
.switch-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.8rem; color: var(--text-secondary); user-select: none; }
.switch-track { width: 34px; height: 19px; background: var(--border); border-radius: 20px; position: relative; transition: var(--transition); flex-shrink: 0; }
.switch-track::after { content: ''; position: absolute; width: 15px; height: 15px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: var(--transition); box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.switch-input { display: none; }
.switch-input:checked + .switch-track { background: var(--primary); }
.switch-input:checked + .switch-track::after { transform: translateX(15px); }
.auth-forgot { font-size: 0.8rem; color: var(--primary); font-weight: 500; }

.auth-submit-btn { width: 100%; background: var(--primary-gradient); color: #fff; border: none; border-radius: var(--radius-sm); padding: 0.75rem; font-size: 0.9rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 0.5rem; transition: var(--transition); }
.auth-submit-btn:hover { box-shadow: 0 10px 30px rgba(99,102,241,0.35); transform: translateY(-1px); }
.auth-submit-btn:active { transform: translateY(0); }

.auth-divider { display: flex; align-items: center; gap: 0.75rem; margin: 1.5rem 0; color: var(--text-muted); font-size: 0.72rem; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.auth-footer-note { text-align: center; font-size: 0.75rem; color: var(--text-muted); display: flex; align-items: center; justify-content: center; gap: 0.4rem; }

/* ---- Mobile Brand Banner (แทน Brand Panel เต็มจอ) ---- */
.auth-mobile-banner { display: none; }

@media (max-width: 900px) {
    .auth-screen { flex-direction: column; min-height: 100vh; }
    .auth-brand-panel { display: none; }
    .auth-mobile-banner {
        display: flex; align-items: center; justify-content: center; gap: 0.6rem;
        padding: 1.75rem 1.5rem 1.25rem; background: var(--surface); flex-shrink: 0;
    }
    .auth-mobile-banner img { width: 40px; height: 40px; border-radius: 11px; }
    .auth-mobile-banner .name { font-weight: 700; font-size: 1.1rem; }
    .auth-mobile-banner .ver { font-size: 0.55rem; background: var(--primary-bg); color: var(--primary); padding: 0.1rem 0.5rem; border-radius: 20px; font-weight: 600; }
    .auth-form-panel { flex: 1; padding: 0.5rem 1.25rem 2rem; align-items: flex-start; }
}
@media (max-width: 400px) {
    .auth-form-header h1 { font-size: 1.3rem; }
}

.chart-box { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.chart-box .chart-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.75rem; display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.chart-hint { color: var(--text-muted); font-size: 0.65rem; font-weight: 400; flex-shrink: 0; margin-top: 0.1rem; }
.chart-box .chart-wrapper { position: relative; height: 280px; }
@media (max-width: 768px) {
    .chart-box { padding: 0.85rem; }
    .chart-box .chart-title { flex-direction: column; gap: 0.2rem; }
    .chart-hint { display: none; } /* ซ่อน hint บนมือถือ ประหยัดพื้นที่ */
    .chart-box .chart-wrapper { height: 220px; }
}

/* ================================================================
   15. RESPONSIVE
   ================================================================ */
/* ---- Sidebar Overlay (มือถือ) ---- */
.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.55);
    backdrop-filter: blur(2px); z-index: 999; opacity: 0; visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.sidebar-overlay.show { opacity: 1; visibility: visible; }

@media (max-width: 1024px) {
    .smart-sidebar { width: 0; overflow: hidden; transform: translateX(-100%); }
    .smart-sidebar.mobile-open {
        width: var(--sidebar-width); overflow-y: auto; transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }
    .smart-sidebar.mobile-open .nav-item span,
    .smart-sidebar.mobile-open .brand-name,
    .smart-sidebar.mobile-open .user-info { display: revert !important; }
    .smart-sidebar.mobile-open .nav-item { justify-content: flex-start !important; padding: 0.5rem 0.6rem !important; }
    .smart-main { margin-left: 0; }
    .mobile-menu-btn { display: block; }
    .search-box input { width: 100px; }
    .dashboard-grid, .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
    /* ✅ หน้าออเดอร์มี 5 การ์ด (เลขคี่) — 4 ใบแรกเข้าคู่ 2x2 ปกติ ใบสุดท้าย "ยอดรวม" ให้กินเต็มแถวแทนที่จะลอยครึ่งแถว */
    .orders-page .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .orders-page .stats-grid .stat-card:last-child { grid-column: 1 / -1; }
    .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .smart-content { padding: 0.75rem; }
    .smart-topbar { padding: 0 0.75rem; }
    .search-box input { width: 80px; }
    .breadcrumb { font-size: 0.72rem; }
    /* ✅ Modal ลอยกึ่งกลางจอเหมือน Desktop (ของเดิมเป็น bottom sheet ทำให้ดูติดขอบล่างเวลาเนื้อหาสั้น) */
    .modal-container { width: calc(100% - 1.5rem) !important; max-width: 480px !important; max-height: 85dvh !important; border-radius: var(--radius) !important; }
    /* Stat cards — เล็กลง padding/font */
    .dashboard-grid, .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
    .orders-page .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .orders-page .stats-grid .stat-card:last-child { grid-column: 1 / -1; }
    .stat-card { padding: 0.7rem 0.75rem; gap: 0.5rem; }
    .stat-card .stat-icon { width: 34px; height: 34px; font-size: 14px; border-radius: 9px; }
    .stat-card .stat-number { font-size: 1rem; }
    .stat-card .stat-label { font-size: 0.62rem; }
    .stat-card .stat-change { font-size: 0.56rem; padding: 0.1rem 0.4rem; }
    /* Page header — ปุ่มอยู่มุมบนขวาเสมอ ไม่ขึ้นแถวแยกให้เกะกะ */
    .page-header { align-items: flex-start; gap: 0.6rem; }
    .page-actions { flex-wrap: wrap; justify-content: flex-end; }
    .page-actions .btn { flex: 0 0 auto; padding: 0.4rem 0.65rem; font-size: 0.72rem; }
    /* Table */
    .table thead th, .table-smart thead th { padding: 0.35rem 0.4rem; font-size: 0.6rem; }
    .table tbody td, .table-smart tbody td { padding: 0.35rem 0.4rem; font-size: 0.68rem; }
    /* Card padding */
    .card .card-body { padding: 0.6rem; }
    .card .card-header { padding: 0.6rem 0.75rem; }
}
@media (max-width: 480px) {
    .smart-content { padding: 0.5rem; }
    .smart-topbar { padding: 0 0.6rem; }
    .search-box { display: none; }
    .stat-card .stat-number { font-size: 0.95rem; }
    .page-title { font-size: 1rem; }
    .login-container { padding: 1.25rem 1rem; }
}

/* ================================================================
   16. FLATPICKR CUSTOM
   ================================================================ */
.flatpickr-calendar { border-radius: 12px !important; box-shadow: 0 10px 40px rgba(0,0,0,0.12) !important; border: 1px solid var(--border) !important; font-family: 'Prompt', sans-serif !important; }
.flatpickr-day.selected { background: var(--primary) !important; border-color: var(--primary) !important; }
.flatpickr-day.today { border-color: var(--primary-light) !important; }
.flatpickr-day:hover { background: var(--primary-bg) !important; }
.flatpickr-months .flatpickr-month { color: var(--text) !important; }
.flatpickr-weekday { color: var(--text-muted) !important; }

/* ================================================================
   17. MOBILE CARD LIST — สลับตารางข้อมูลแน่นบนมือถือให้เป็นการ์ดแทน
   ใช้คู่กัน: <div class="table-responsive desktop-only-table">…table…</div>
            + <div class="mobile-card-list">…mc-card…</div>
   ================================================================ */
/* ✅ ไม่มี padding ซ้าย-ขวา (เดิมมี 0.65rem ทุกด้าน) — เพราะหน้าที่ใช้จริง (orders/index, pay, shipping,
   search ผ่าน partials/table.php) วางการ์ดไว้ตรงๆ ใน .orders-page ไม่มีการ์ดครอบ ถ้าเพิ่ม padding ซ้าย-ขวา
   เองอีกชั้น จะเหลื่อมกับกล่องค้นหา/หัวข้อ/ตัวหนังสือสรุปผลด้านบนที่ไม่มี padding ส่วนตัว (ดูเหลื่อมไม่ตรงกัน)
   ส่วนที่ใช้ใน .card-body.p-0 (เช่น dashboard) ยังต้องมี padding ซ้าย-ขวาอยู่ กันการ์ดชนขอบการ์ดแม่ —
   คืนให้เฉพาะ context นั้นด้านล่าง */
.mobile-card-list { display: none; flex-direction: column; gap: 0.45rem; padding: 0.65rem 0; }
.card-body.p-0 .mobile-card-list { padding: 0.65rem; }
/* ✅ .mc-toolbar/.pagination-bar เดียวกันเป๊ะกับ .mobile-card-list ด้านบน — ไม่มี margin/padding ซ้าย-ขวา
   โดยดีฟอลต์ (หน้าที่วางตรงๆ ใน .orders-page ไม่ต้องการ) แต่ลืมคืนให้ context .card-body.p-0 (เช่น
   products/stock/detail.php) ตอนเพิ่มมุมมองการ์ดมือถือให้ตารางในนั้น ทำให้แถบค้นหา/แบ่งหน้าชนขอบการ์ดแม่ */
.card-body.p-0 .mc-toolbar { margin-left: 0.65rem; margin-right: 0.65rem; }
.card-body.p-0 .pagination-bar { padding-left: 0.65rem; padding-right: 0.65rem; }
.mc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.55rem 0.7rem; text-decoration: none; color: inherit; display: block; } /* ✅ text-decoration/color/display เผื่อการ์ดเป็น <a> (เช่น import/index.php) — เหมือน .stat-card ด้านบน กันเส้นใต้ตอน hover */
.mc-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.4rem; padding-bottom: 0.4rem; border-bottom: 1px dashed var(--border); }
.mc-title { font-weight: 600; font-size: 0.78rem; color: var(--text); display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.mc-sub { font-size: 0.66rem; color: var(--text-muted); margin-top: 0.15rem; line-height: 1.45; }
.mc-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 0.22rem; flex-shrink: 0; }
.mc-date { font-size: 0.62rem; color: var(--text-muted); white-space: nowrap; }
.mc-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.3rem 0.6rem; }
.mc-stat { display: flex; flex-direction: column; min-width: 0; }
.mc-stat .lbl { font-size: 0.58rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 0.1rem; }
.mc-stat .val { font-size: 0.78rem; font-weight: 600; color: var(--text); }
.mc-stat--wide { grid-column: 1 / -1; }
.mc-note { display: block; font-size: 0.64rem; color: var(--text-muted); margin-top: 0.1rem; }
.mc-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; margin-top: 0.45rem; padding-top: 0.4rem; border-top: 1px dashed var(--border); flex-wrap: wrap; }

/* ---- การ์ดแบบกระชับ (เช่น สินค้าขายดี) — 2 บรรทัด/รายการ ---- */
.mobile-card-list--tight { gap: 0.4rem; padding: 0.6rem; }
.mc-card--compact { padding: 0.55rem 0.75rem; }
.mc-row-top { display: flex; align-items: center; gap: 0.5rem; }
.mc-rank { font-size: 0.68rem; font-weight: 700; color: var(--text-muted); flex-shrink: 0; }
.mc-name { flex: 1; min-width: 0; font-size: 0.8rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-profit { font-size: 0.82rem; font-weight: 700; flex-shrink: 0; white-space: nowrap; }
.mc-row-sub { font-size: 0.66rem; color: var(--text-muted); margin-top: 0.25rem; line-height: 1.5; }

/* ---- Pagination การ์ด (เช่น รายงานการสั่งซื้อที่มีจำนวนมาก) ---- */
.mc-pagination { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.85rem; }
.mc-pagination .mc-page-info { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; white-space: nowrap; }

/* ---- ค้นหาในลิสต์การ์ด (คู่กับ data-search บน .mc-card) ---- */
.mc-search { display: none; position: relative; margin: 0.85rem 0.85rem 0.65rem; }
.mc-search i { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.75rem; }
.mc-search input { width: 100%; height: 36px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 0.75rem 0 2.15rem; font-size: 0.8rem; font-family: inherit; outline: none; background: var(--bg); color: var(--text); transition: var(--transition); }
.mc-search input:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-bg); }

/* ---- แถบเครื่องมือเหนือลิสต์การ์ด: เลือกทั้งหมด + ค้นหา (มือถือเท่านั้น) ---- */
/* ✅ ไม่มี margin ซ้าย-ขวา (เดิมมี 0.85rem) — เหตุผลเดียวกับ .mobile-card-list/.pagination-bar ด้านบน */
.mc-toolbar { display: none; align-items: center; gap: 0.6rem; margin: 0.85rem 0 0.65rem; }
.mc-toolbar .mc-search { display: flex; flex: 1; margin: 0; }
.mc-select-all { display: flex; align-items: center; gap: 0.35rem; font-size: 0.7rem; color: var(--text-secondary); white-space: nowrap; cursor: pointer; flex-shrink: 0; user-select: none; }
.mc-select-all input { width: 17px; height: 17px; flex-shrink: 0; cursor: pointer; }

.mc-empty { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }
.mc-empty i { font-size: 1.8rem; opacity: 0.35; display: block; margin-bottom: 0.5rem; }
.mc-empty p { font-size: 0.8rem; }

@media (max-width: 768px) {
    .desktop-only-table { display: none; }
    .mobile-card-list { display: flex; }
    .mobile-only-search { display: block; }
    .mc-toolbar { display: flex; }
}

/* ✅ หมายเหตุออเดอร์ขึ้นบรรทัดใหม่ได้แล้ว (เดิมเป็น input บรรทัดเดียว) — ใช้กับทุกจุดที่แสดงหมายเหตุ
   HTML/JS ที่ escape ค่าไว้แล้วยังคง \n อยู่ในข้อความปกติ (esc()/safeEsc() ไม่ตัดขึ้นบรรทัดใหม่ทิ้ง)
   แค่ browser ไม่ยอมเรนเดอร์ \n เป็นบรรทัดใหม่เฉยๆ ถ้าไม่มี white-space ครอบไว้ */
.note-multiline { white-space: pre-line; }

/* ================================================================
   18. BULK ACTION BAR — แถบดำเนินการลอยด้านล่าง ใช้ตอนเลือกหลายรายการ
   (แทนปุ่ม static บนหัวหน้า ที่บนมือถือ/รายการยาวๆ ต้องเลื่อนกลับขึ้นไปกดถึงจะเจอ)
   ================================================================ */
.bulk-action-bar {
    position: fixed; left: 50%; bottom: 1.25rem; transform: translate(-50%, 150%);
    background: var(--text); color: #fff; border-radius: var(--radius);
    box-shadow: var(--shadow-xl); padding: 0.75rem 1rem; z-index: 1500;
    display: flex; align-items: center; gap: 1rem; opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease; max-width: calc(100% - 2rem);
}
.bulk-action-bar.show { transform: translate(-50%, 0); opacity: 1; }
.bulk-action-bar .bulk-count { font-size: 0.82rem; white-space: nowrap; }
.bulk-action-bar .bulk-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
@media (max-width: 480px) {
    .bulk-action-bar { flex-direction: column; align-items: stretch; gap: 0.6rem; width: calc(100% - 2rem); }
    .bulk-action-bar .bulk-actions { justify-content: stretch; }
    .bulk-action-bar .bulk-actions .btn { flex: 1; }
}
/* ✅ กันแถบลอยด้านล่างบังรายการสุดท้ายของลิสต์ตอนแถบโผล่มา (toggle ผ่าน JS เวลาเลือก ≥1 รายการ) */
.smart-content.has-bulk-bar { padding-bottom: 6rem; }

/* ================================================================
   19. STAT CARDS — ตัวย่อขนาดกะทัดรัด (ใช้ตอนการ์ดมีหลายใบในหน้าเดียว
   ไม่อยากให้เด่นเท่าการ์ดหลักของแดชบอร์ด เช่นการ์ดสรุปแพลตฟอร์มหน้ารอชำระเงิน)
   ================================================================ */
.stats-grid--compact .stat-card { padding: 0.7rem 0.9rem; gap: 0.6rem; }
.stats-grid--compact .stat-card .stat-icon { width: 34px; height: 34px; font-size: 14px; border-radius: 9px; }
.stats-grid--compact .stat-card .stat-number { font-size: 1.05rem; }
.stats-grid--compact .stat-card .stat-label { font-size: 0.62rem; }
@media (max-width: 768px) {
    .stats-grid--compact .stat-card { padding: 0.55rem 0.65rem; gap: 0.45rem; }
    .stats-grid--compact .stat-card .stat-icon { width: 28px; height: 28px; font-size: 12px; }
    .stats-grid--compact .stat-card .stat-number { font-size: 0.9rem; }
}

/* ✅ .orders-page คือคลาส page-shell ใช้ร่วมกันทั้งระบบ (ไม่ได้เจาะจงแค่โมดูลออเดอร์) —
   กฎ `.orders-page .stats-grid` (5 คอลัมน์ desktop, ใบสุดท้ายเต็มแถวตอนมือถือ) ออกแบบไว้สำหรับ
   หน้าออเดอร์ที่มี 5 การ์ด (คี่) เท่านั้น หน้าอื่นที่ใช้ .orders-page เป็น shell แต่มีการ์ดจำนวนคู่
   (เช่น v2/products/stock/detail มี 4 ใบ) ต้องเติมคลาส stats-grid--fixed4 กันไม่ให้ไปชนกฎนั้น */
.orders-page .stats-grid.stats-grid--fixed4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1024px) {
    .orders-page .stats-grid.stats-grid--fixed4 { grid-template-columns: repeat(2, 1fr); }
    .orders-page .stats-grid.stats-grid--fixed4 .stat-card:last-child { grid-column: auto; }
}

/* ================================================================
   20. CUSTOM SEARCHABLE DROPDOWN (.cs-*) — ย้ายมาจาก orders/add.php เดิม (ใช้แค่จังหวัด/เลือกสินค้า)
   ตอนนี้เป็น global component ผูกอัตโนมัติกับ <select> ทุกตัวทั่วระบบผ่าน smart-system.js
   (makeCustomSelect()) ไม่ต้องพึ่ง library ภายนอก (Select2 ฯลฯ) ใช้ CSS variable ธีมเดิมอยู่แล้ว
   จึงรองรับ dark/light mode ทันทีไม่ต้องเพิ่มอะไร — @keyframes fadeDown ใช้ตัวที่มีอยู่แล้วด้านบน
   ================================================================ */
.cs-wrap { position: relative; display: block; }
/* ✅ padding/font-size ให้ตรงกับ .filter-group .form-control ทั่วไป (ไม่ตั้ง min-height ตายตัว
   ปล่อยให้สูงตามเนื้อหา/padding เหมือน input/button ข้างเคียงในแถวเดียวกันตามธรรมชาติ) — ถ้าหน้าไหน
   ใช้ .form-control ขนาดใหญ่กว่านี้ (เช่น orders/add.php ที่มี .ao-layout .form-control ของตัวเอง)
   ต้อง override .cs-display เฉพาะหน้านั้นเพิ่ม ไม่งั้น select/input ในแถวเดียวกันจะสูงไม่เท่ากัน */
.cs-display {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.4rem 0.7rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--bg); cursor: pointer;
    font-size: 0.8rem; color: var(--text);
    transition: var(--transition); user-select: none; gap: 0.4rem;
}
.cs-display:hover { border-color: var(--text-muted); }
.cs-wrap.open .cs-display {
    border-color: var(--primary); background: var(--surface);
    box-shadow: 0 0 0 3px var(--primary-bg);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-bottom-color: transparent;
}
.cs-display .cs-val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-placeholder { color: var(--text-muted); }
.cs-arrow { color: var(--text-muted); font-size: 0.65rem; flex-shrink: 0; transition: transform 0.2s; }
.cs-wrap.open .cs-arrow { transform: rotate(180deg); }
.cs-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 9000;
    background: var(--surface); border: 1.5px solid var(--primary); border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm); box-shadow: var(--shadow-xl);
    min-width: 100%;
}
.cs-wrap.open .cs-dropdown { display: block; animation: fadeDown 0.15s ease; }
.cs-search-wrap {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
}
.cs-search-wrap i { color: var(--text-muted); font-size: 0.72rem; flex-shrink: 0; }
.cs-search { border: none; outline: none; font-size: 0.8rem; font-family: inherit; flex: 1; background: transparent; color: var(--text); }
.cs-search::placeholder { color: var(--text-muted); }
.cs-options { max-height: 200px; overflow-y: auto; }
.cs-option { padding: 0.4rem 0.75rem; font-size: 0.8rem; cursor: pointer; transition: background 0.1s; line-height: 1.4; }
.cs-option:hover, .cs-option.focused { background: var(--primary-bg); color: var(--primary); }
.cs-option.selected { background: var(--primary-bg); color: var(--primary); font-weight: 600; }
.cs-no-result { padding: 0.75rem; text-align: center; color: var(--text-muted); font-size: 0.75rem; }
/* ⚠️ รู้ไว้ก่อนใช้งานจริง: select ที่อยู่ใน openGlobalModal() (equipment/parcel add, ปรับสต็อก, ยืนยันจัดส่ง ฯลฯ)
   ตัว .modal-body มี overflow-y:auto (ต้องมีไว้ให้ modal เนื้อหายาวเลื่อนได้) ซึ่งจะ clip dropdown ลอยนี้ถ้า
   modal ต้อง scroll จริงและ select อยู่ใกล้ขอบล่างพอดี (เคสส่วนใหญ่ modal สั้นพอไม่เจอปัญหานี้) — ถ้าเจอเคส
   ที่ dropdown โดนตัดจริง ให้แจ้งมาแก้เฉพาะจุดทีหลัง (ยังไม่แก้ตอนนี้เพราะทดสอบเองไม่ได้ ไม่อยากเดา CSS มั่ว)