/* =========================================
   POS (เปิดบิลขาย) — สไตล์เฉพาะหน้านี้
   หมายเหตุ: ตัวแปรสี, body, .container, .header-row, .btn-action-top,
   .btn-back-*, .lock-badge, @keyframes fadeIn, .swal2-popup, .swal-shop-img
   ใช้ร่วมจาก ../style.css (ไฟล์กลาง) แล้ว จึงไม่ต้องเขียนซ้ำที่นี่
   ========================================= */

/* ===== กรอบหน้า POS กว้างขึ้น (เฉพาะหน้านี้) ===== */
.container { max-width: 900px; }

/* มือถือ: ลดขอบด้านข้าง (body + container) ให้เนื้อหากว้างขึ้น */
@media (max-width: 480px) {
    body { padding-left: 6px; padding-right: 6px; }
    .container { padding-left: 12px; padding-right: 12px; }
}

/* ===== แนะนำร้านต่อไป ===== */
#next-shop-wrapper {
    width: 100%; margin-bottom: 20px; display: none; animation: fadeIn 0.3s ease-in-out;
}
.next-shop-title {
    font-weight: 700; font-size: 15px; color: var(--primary-dark);
    margin-bottom: 12px; display: flex; align-items: center; gap: 8px; padding-left: 2px;
}
#next-shop-content {
    display: flex; flex-direction: column; gap: 10px; width: 100%;
}

/* ===== กล่องเลือกร้านค้า ===== */
.info-section {
    display: flex; flex-direction: column; margin-bottom: 15px;
    background-color: #ffffff; padding: 15px; border-radius: 8px;
    border: 1px solid var(--border-color); box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.section-label { font-weight: 700; font-size: 14px; color: var(--primary-dark); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }

.customer-select-group { display: flex; gap: 8px; width: 100%; align-items: stretch; }
.customer-select-group select {
    flex: 1; min-width: 0;
    padding: 10px 12px; font-size: 15px; font-family: 'Prompt'; font-weight: 500; color: #1e293b;
    border: 1px solid var(--border-color); border-radius: 8px; background-color: #f8fafc;
    outline: none; transition: all 0.2s ease; -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
    padding-right: 35px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
}
.customer-select-group select:focus { border-color: var(--primary-color); background-color: #fff; box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1); }

.btn-gps {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%); color: white;
    border: none; border-radius: 8px; padding: 0 12px; min-width: 65px; flex-shrink: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; transition: transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.2);
}
.btn-gps:active { transform: scale(0.95); box-shadow: 0 2px 5px rgba(15, 23, 42, 0.15); }
.btn-gps .gps-icon { font-size: 18px; line-height: 1; margin-bottom: 2px; }
.btn-gps .gps-text { font-size: 10px; font-family: 'Prompt'; font-weight: 600; letter-spacing: 0.5px; }

/* ===== ปุ่ม "ตำแหน่ง" บนหัวเรื่อง (ตั้งพิกัดใหม่) ===== */
.btn-loc-recheck { background-color: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.btn-loc-recheck:hover { background-color: #dbeafe; border-color: #1d4ed8; }
/* ให้ปุ่มบนหัวเรื่องสูงเท่ากันทั้งคู่ (ตำแหน่ง = เมนูหลัก) */
.header-actions .btn-action-top { height: 38px; box-sizing: border-box; }
.header-actions .btn-loc-recheck { width: 42px; padding-left: 0; padding-right: 0; }
.header-actions .btn-loc-recheck i { font-size: 16px; }

/* ===== การ์ดข้อมูลลูกค้า ===== */
.customer-profile-card {
    background: #f8fafc; border: 1px solid var(--border-color); border-radius: 8px;
    padding: 10px 12px; margin-top: 10px; animation: fadeIn 0.2s ease-out;
    display: flex; flex-direction: column; gap: 8px;
}
.cust-header-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; flex-wrap: nowrap; }
.cust-info-left { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; justify-content: center; overflow: hidden; }
.cust-name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cust-name { font-size: 15px; font-weight: 700; color: var(--primary-dark); line-height: 1.2; margin: 0; padding: 0; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; display: flex; align-items: center; gap: 5px;}
.detail-value { padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; border: 1px solid transparent; height: fit-content; white-space: nowrap;}
.val-red { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.val-green { background: #f0fdfa; color: #0d9488; border-color: #99f6e4; }

.action-group { display: flex; gap: 6px; margin: 0; flex-shrink: 0; justify-content: flex-end; align-items: center; }

/* ปุ่ม Action แบบมินิมอล (สีขาว/สว่าง) */
.btn-icon-minimal {
    width: 44px; height: 44px; border-radius: 8px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: all 0.15s ease; border: 1px solid var(--border-color); font-family: 'Prompt';
}
.btn-icon-minimal:active { transform: scale(0.95); }
.btn-icon-minimal .icon { font-size: 18px; line-height: 1; }
.bg-nav { background-color: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.bg-photo { background-color: #f0fdfa; color: #0d9488; border-color: #99f6e4; }
.bg-missing { background-color: #f8fafc; color: #94a3b8; border-color: #e2e8f0; }
.bg-danger { background-color: #fef2f2; color: #dc2626; border-color: #fca5a5; }

/* ===== ตารางสินค้า (cart) ===== */
#product-section { width: 100%; }
table thead { display: none; }
table, tbody, tr, td { display: block; width: 100%; box-sizing: border-box; }
table { border: none; margin-bottom: 15px; }

#cart-body tr {
    background: #fff; border: 1px solid var(--border-color); border-left: 3px solid var(--primary-color);
    border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
    display: grid; grid-template-columns: 1.2fr 1fr; gap: 4px 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02); align-items: center;
}
#cart-body tr.empty-stock-row {
    display: block; padding: 0; border: none; box-shadow: none; background: transparent; margin-bottom: 15px;
}
#cart-body td:nth-child(1) {
    grid-column: 1 / 2; grid-row: 1 / 3;
    font-size: 15px; font-weight: 600; color: var(--primary-dark); text-align: left;
    display: flex; flex-direction: column; gap: 2px;
}
#cart-body td:nth-child(2) { display: none; }
#cart-body td:nth-child(3) {
    grid-column: 2 / 3; grid-row: 1 / 2;
    display: flex; align-items: center; justify-content: flex-end; gap: 6px;
}
#cart-body td:nth-child(3)::before { content: "จำนวน:"; font-size: 12px; color: var(--text-muted); font-weight: 600; }
#cart-body td:nth-child(4) {
    grid-column: 2 / 3; grid-row: 2 / 3; text-align: right; border: none;
    padding: 0; font-size: 13px; color: var(--text-muted);
}
#cart-body td:nth-child(4)::before { content: "รวม: "; color: var(--text-muted); }
#cart-body td:nth-child(4) strong { color: var(--success-color); font-size: 14px; font-weight: 700; }

.price-input { display: none; }
.qty-input {
    border: 2px solid var(--border-color); font-weight: 700; color: var(--primary-dark);
    width: 80px !important; padding: 6px; font-size: 16px; font-family: 'Prompt';
    border-radius: 6px; text-align: center; outline: none; box-sizing: border-box; background: #f8fafc;
}
.qty-input:focus { box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1); border-color: var(--primary-color); background: #ffffff;}
.qty-input:disabled { background-color: #f1f5f9; border-color: #e2e8f0; color: #94a3b8; width: 80px !important; }

/* ===== ช่อง "แถมฟรี" (เฉพาะร้านที่เปิดของแถม) ===== */
.free-qty-wrap { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.free-qty-label { font-size: 12px; font-weight: 600; color: #b45309; display: inline-flex; align-items: center; gap: 4px; }
.free-input {
    width: 60px !important; padding: 4px 6px; font-size: 14px; font-weight: 700;
    font-family: 'Prompt'; text-align: center; border: 1.5px solid #fcd34d;
    border-radius: 6px; background: #fffbeb; color: #b45309; outline: none;
}
.free-input:focus { box-shadow: 0 0 0 3px rgba(217,119,6,0.15); border-color: #d97706; }
.free-input:disabled { background: #f1f5f9; border-color: #e2e8f0; color: #94a3b8; }

/* ===== ส่วนชำระเงิน / บิลค้าง ===== */
.checkout-section {
    display: flex; flex-direction: column; gap: 15px;
    padding: 15px; border-radius: 8px; background-color: #f8fafc;
    border: 1px solid var(--border-color); margin-bottom: 15px;
}
.outstanding-box {
    background-color: #fef2f2; padding: 15px; border-radius: 8px; border: 1px solid #fca5a5;
    margin-bottom: 15px; display: none;
}
.outstanding-row { padding: 8px 0; }
.outstanding-row:not(:last-child) { border-bottom: 1px solid #fecaca; }
.outstanding-box label { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; cursor: pointer; margin: 0; }
.label-credit { color: #dc2626; }
.label-bill { color: #d97706; }
.outstanding-box input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; }
.check-credit { accent-color: #dc2626; }
.check-bill { accent-color: #d97706; }
.outstanding-input-group {
    margin-top: 10px; margin-left: 30px; padding: 10px; background: #fff; border-radius: 8px; border: 1px solid var(--border-color);
}
.outstanding-detail { font-size: 13px; margin-bottom: 8px; font-weight: 500;}

.bill-list-item {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px; border-bottom: 1px solid #f1f5f9; cursor: pointer;
}
.bill-list-item:last-child { border-bottom: none; }
.bill-list-item input[type="checkbox"] { width: 18px; height: 18px; }
.bill-amt { font-size: 14px; font-weight: 700; }

.payment-row { display: flex; gap: 8px; width: 100%; align-items: flex-end;}
.payment-group { flex: 1; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.payment-group label { font-size: 13px; font-weight: 600; white-space: nowrap; color: var(--primary-dark); }
.payment-select {
    padding: 10px 8px; font-size: 14px; font-family: 'Prompt'; font-weight: 500; color: #1e293b;
    border: 1px solid var(--border-color); border-radius: 8px; background-color: #fff;
    width: 100%; box-sizing: border-box; text-overflow: ellipsis; overflow: hidden; outline: none;
}
.payment-select:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1); }

.qr-section {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 15px; background-color: #f8fafc; border: 1px dashed var(--border-color); border-radius: 8px;
    margin-top: 10px; animation: fadeIn 0.3s ease-in-out;
}
.qr-section img { max-width: 200px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); border: 1px solid var(--border-color); }
.qr-instruction { font-size: 14px; color: var(--primary-dark); font-weight: 600; text-align: center; }
.bank-details { font-size: 15px; color: var(--text-dark); text-align: center; margin-top: 5px; line-height: 1.5; background: #fff; padding: 12px; border-radius: 8px; border: 1px solid var(--border-color); width: 100%; box-sizing: border-box;}

.summary-section { text-align: center; width: 100%; margin-top: 10px; background: #ffffff; padding: 15px; border-radius: 8px; border: 1px solid var(--border-color); box-sizing: border-box;}
.sum-current { font-size: 14px; color: var(--text-muted); margin-bottom: 5px; font-weight: 500; }
.total-label { font-size: 16px; color: var(--primary-dark); font-weight: 700; }
.total-amount { color: var(--success-color); font-size: 34px; font-weight: 700; margin-left: 5px; }

.btn-save {
    background-color: var(--primary-color); color: white; border: none;
    padding: 16px; width: 100%; border-radius: 8px; cursor: pointer;
    font-family: 'Prompt'; font-size: 18px; font-weight: 700;
    box-shadow: 0 4px 10px rgba(30, 58, 138, 0.25); transition: all 0.2s ease;
    margin-bottom: 0; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-save:hover { background-color: var(--primary-dark); }
.btn-save:active { transform: scale(0.98); }
.btn-save:disabled { background-color: #94a3b8; cursor: not-allowed; box-shadow: none; transform: none; }

.btn-setup {
    display: inline-block; background: linear-gradient(135deg, #475569 0%, #334155 100%); color: white;
    padding: 8px 18px; border-radius: 6px; text-decoration: none; font-size: 14px; font-weight: 600;
    margin-top: 10px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); transition: 0.2s;
}
.btn-setup:hover { background: linear-gradient(135deg, #334155 0%, #1e293b 100%); transform: translateY(-2px); }