:root {
  /* --- Pastel Color Palette --- */
  --primary-pink: #FF9EB5;       
  --primary-pink-dark: #E88EA3;  
  --accent-mauve: #D16B88;       
  --bg-soft-pink: #FFF5F7;       
  --bg-white: #FFFFFF;           
  --border-pink: #FAD0D8;        
  --text-dark: #555555;          
  
  --pastel-green: #88D8B0;       
  --pastel-red: #FF8C94;         
  --pastel-yellow: #FFEEAD;      

  /* --- Sizing --- */
  --input-height: 48px;
  --radius-lg: 16px;
  --radius-md: 12px;
}

/* === Reset & Body === */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: 'Sarabun', sans-serif;
  background-color: var(--bg-soft-pink);
  color: var(--text-dark);
  line-height: 1.5;
  padding: 15px; /* พื้นที่ขอบจอโทรศัพท์ */
}

/* === Layout (ตรงกับ HTML .container .card) === */
.container {
  display: flex;
  justify-content: center;
}

.card {
  width: 100%;
  max-width: 500px;
  background: var(--bg-white);
  padding: 20px;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(255, 158, 181, 0.15); /* เงาสีชมพูฟุ้งๆ */
}

/* === Typography === */
h1 {
  font-size: 22px;
  color: var(--accent-mauve);
  margin: 0 0 5px 0;
  text-align: center;
}
p {
  font-size: 14px;
  color: #888;
  margin-bottom: 20px;
  text-align: center;
}

.sectionTitle h2 {
  font-size: 18px;
  color: var(--accent-mauve);
  margin-bottom: 5px;
  border-left: 4px solid var(--primary-pink);
  padding-left: 10px;
  text-align: left; /* จัดชิดซ้าย */
}
.sectionTitle span {
  display: block;
  font-size: 13px;
  color: #999;
  margin-bottom: 15px;
}

/* === Inputs (.field input) === */
.field { margin-bottom: 15px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--accent-mauve);
  font-size: 15px;
}
.field input, 
.field textarea {
  width: 100%;
  height: var(--input-height);
  padding: 0 15px;
  border: 2px solid var(--border-pink);
  border-radius: var(--radius-md);
  font-size: 16px;
  color: var(--text-dark);
  background: #fff;
  transition: 0.3s;
  font-family: inherit;
}
.field textarea {
  height: auto;
  padding: 12px 15px;
  resize: vertical;
}
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary-pink);
  box-shadow: 0 0 0 4px rgba(255, 158, 181, 0.2);
}

/* === Buttons (.primary, .secondary) === */
button {
  width: 100%;
  height: var(--input-height);
  border: none;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
  transition: 0.2s;
}
button.primary {
  background: var(--primary-pink);
  color: white;
  box-shadow: 0 4px 10px rgba(255, 158, 181, 0.4);
}
button.primary:active { transform: scale(0.98); }

button.secondary {
  background: white;
  border: 2px solid var(--primary-pink);
  color: var(--primary-pink);
}

/* === Status Badge === */
.badge {
  text-align: center;
  margin-bottom: 15px;
  padding: 8px;
  border-radius: var(--radius-md);
  background: #FFF;
  border: 1px dashed var(--border-pink);
}
.dot {
  height: 10px; width: 10px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}
.dot.warn { background-color: var(--pastel-yellow); }
.dot.err { background-color: var(--pastel-red); }
/* ถ้าสถานะ ok ให้จุดเขียว */
#statusBadge:not(:has(.warn)):not(:has(.err)) .dot {
   background-color: var(--pastel-green);
}

/* === Product Table (.productsWrap) === */
.thead {
  display: flex;
  background: var(--bg-soft-pink);
  padding: 10px;
  border-radius: 8px 8px 0 0;
  font-weight: bold;
  color: var(--accent-mauve);
  font-size: 14px;
}
.thead div:nth-child(1) { flex: 2; }
.thead div:nth-child(2), .thead div:nth-child(3) { flex: 1; text-align: center; }

.row {
  display: flex;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #f0f0f0;
  position: relative;
  /* เว้นที่ขวาไว้ให้ปุ่มลบ */
  padding-right: 40px !important; 
}
.pname { flex: 2; font-size: 15px; }
.cell { flex: 1; padding: 0 2px; }

.row input {
  width: 100%;
  height: 36px;
  text-align: center;
  border: 1px solid var(--border-pink);
  border-radius: 6px;
}

/* ปุ่มลบ (X) */
.btn-remove-row {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  background: var(--pastel-red);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0; /* แก้ปัญหา iOS */
}

/* === Search Dropdown (สำคัญ) === */
.search-wrapper { position: relative; }
.suggestions-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: #fff;
  border: 2px solid var(--border-pink);
  border-top: none;
  z-index: 99;
  max-height: 200px;
  overflow-y: auto;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.05);
  display: none;
}
.suggestion-item {
  padding: 12px 15px;
  border-bottom: 1px solid #f9f9f9;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}
.suggestion-item:hover { background: var(--bg-soft-pink); }
.add-icon { color: var(--pastel-green); font-weight: bold; }

/* Utility */
.hidden { display: none !important; }

/* --- Customer Layout (3 ช่อง: ชื่อ | กก. | กล่อง) --- */
.productsWrap.customer-grid .thead,
.productsWrap.customer-grid .row {
  display: flex !important; /* บังคับใช้ Flexbox */
  align-items: center;
  gap: 5px;
}
/* ซ่อนช่องที่เกินมา ถ้าเผลอหลุดมาในหน้าลูกค้า */
.productsWrap.customer-grid .cell.brand-col,
.productsWrap.customer-grid .cell.price-col {
  display: none !important;
}

/* --- Admin Layout (5 ช่อง: ชื่อ | กก. | กล่อง | แบรนด์ | ราคา) --- */
.productsWrap.admin-grid .thead,
.productsWrap.admin-grid .row {
  display: grid !important;
  /* กำหนดขนาด: ชื่อ | กก. | กล่อง | แบรนด์ | ราคา | ปุ่มลบ */
  grid-template-columns: 2fr 0.8fr 0.8fr 1.5fr 1fr 30px;
  gap: 5px;
}

/* --- History / Locked Rows --- */
.row.history {
  background-color: #f0f0f0;
  opacity: 0.7;
  border-left: 4px solid #999;
}
.row.history .pname {
  text-decoration: line-through;
  color: #888;
}
.row.history input {
  background-color: #e9ecef;
  color: #888;
  border: 1px solid #ccc;
}

.row.locked {
  background-color: #fff9db; /* สีเหลืองอ่อนให้รู้ว่าล็อคอยู่ */
  border-left: 4px solid #ffec99;
}
.row.locked input {
  background-color: #fff;
  pointer-events: none; /* ห้ามคลิก */
}

/* ปุ่มแก้ไข (รูปดินสอ หรือ ไขควง) */
.btn-edit-row {
  background: var(--pastel-yellow);
  color: #856404;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  width: 100%;
  height: 100%;
}
/* CSS สำหรับ Dropdown ค่าใช้จ่าย */
.expense-search-wrap {
    position: relative;
    width: 100%;
}
.expense-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 0 0 8px 8px; /* มุมมนด้านล่าง */
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15); /* เงานุ่มๆ */
    display: none;
}
.expense-suggestion-item {
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: #333;
}
.expense-suggestion-item:last-child {
    border-bottom: none;
}
.expense-suggestion-item:active { /* เวลากดบนมือถือ */
    background-color: #f0f8ff; 
}
.expense-suggestion-item .item-price {
    color: #d63384; /* สีชมพูตามธีม */
    font-weight: bold;
    font-size: 0.9em;
    background: #ffeef6;
    padding: 2px 8px;
    border-radius: 10px;
}

/* =========================================
   ส่วนตกแต่งพิเศษ: ช่องค้นหา (Search Box) - ฉบับเด่นทะลุจอ
   ========================================= */
#productSearch, #productSearchAdmin {
  /* 1. พื้นขาวโอโม่ สว่างสุดในหน้าจอ เพื่อดึงสายตา */
  background-color: #FFFFFF !important;
  
  /* 2. เส้นขอบหนา 3px สีม่วง Mauve (เข้มสุดในธีม) ตัดขอบให้คมกริบ */
  border: 3px solid var(--accent-mauve);
  
  /* 3. ทรงแคปซูล */
  border-radius: 50px; 
  
  /* 4. ไอคอนแบบ "Solid Badge" (วงกลมสีม่วง มีแว่นขยายสีขาวข้างใน) เด่นแน่นอน */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24' fill='none'%3E%3Ccircle cx='12' cy='12' r='12' fill='%23D16B88'/%3E%3Ccircle cx='11' cy='11' r='5' stroke='white' stroke-width='2'/%3E%3Cline x1='20' y1='20' x2='15' y2='15' stroke='white' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 8px center; /* ขยับไอคอนมาชิดซ้าย */
  background-size: 32px; /* ขยายไอคอนให้ใหญ่สะใจ */
  
  /* เว้นที่ข้อความให้ห่างจากไอคอนวงกลม */
  padding-left: 55px; 
  padding-right: 20px;
  
  /* 5. ปรับขนาดตัวหนังสือให้ใหญ่ขึ้นอีกนิด */
  font-size: 18px;
  color: var(--text-dark);
  font-weight: 700;
  
  /* 6. เงา Drop Shadow แบบ Deep Depth ให้ดูลอยสูงจากพื้น */
  box-shadow: 0 8px 25px rgba(209, 107, 136, 0.4); 
  
  /* Transition นุ่มๆ */
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* เอฟเฟกต์ตอนกด (Focus) - ขยายขนาดขึ้นเล็กน้อย */
#productSearch:focus, #productSearchAdmin:focus {
  transform: scale(1.05); /* เด้งขยายตัว 5% */
  border-color: var(--primary-pink); /* เปลี่ยนสีขอบเป็นสีสว่าง */
  box-shadow: 0 12px 30px rgba(209, 107, 136, 0.5); /* เงาใหญ่ขึ้น */
  outline: none;
}

/* ปรับสี Placeholder ให้เป็นสีเทาเข้มขึ้น จะได้อ่านง่ายกว่าสีชมพูจางๆ */
#productSearch::placeholder, #productSearchAdmin::placeholder {
  color: #999; 
  font-weight: normal;
  font-size: 16px;
}

/* ======================================================
   🔥 FIX: CUSTOMER CARD LAYOUT (แก้สไตล์การ์ดลูกค้า)
   ====================================================== */

/* 1. ยกเลิก Flex แนวนอนของเดิม ให้เรียงลงมาเป็นแนวตั้งแทน */
.row.customer-card {
  display: block !important; /* บังคับให้เป็น Block เพื่อให้ div ข้างในเรียงลงล่าง */
  padding: 15px !important;
  height: auto !important;
  background: #fff;
  border: 1px solid #ffdde5; /* ขอบสีชมพูอ่อนๆ */
  box-shadow: 0 4px 12px rgba(0,0,0,0.03); /* เงาจางๆ ให้ดูลอย */
  border-radius: 12px;
  margin-bottom: 15px;
}

/* 2. ปรับหัวข้อชื่อสินค้า */
.row.customer-card .pname {
  font-size: 18px;
  font-weight: bold;
  color: var(--accent-mauve);
  margin-bottom: 0;
}

/* 3. แก้ปุ่มลบ (X) ให้ไม่ลอยมั่ว */
.row.customer-card .btn-remove-row {
  position: static !important; /* ยกเลิก position absolute */
  transform: none !important;
  width: 32px;
  height: 32px;
  background: #fff0f3; /* พื้นหลังแดงอ่อน */
  color: var(--pastel-red);
  border: 1px solid var(--pastel-red);
  border-radius: 8px;
}

/* 4. ปรับช่องกรอก กิโล/กล่อง ให้ใหญ่และกดง่าย */
.row.customer-card input.wKg,
.row.customer-card input.wBox {
  height: 45px !important; /* สูงขึ้น กดง่าย */
  font-size: 18px !important;
  font-weight: bold;
  color: var(--text-dark);
  text-align: center;
  border: 2px solid #eee;
  border-radius: 8px;
  background: #fdfdfd;
}
.row.customer-card input.wKg:focus,
.row.customer-card input.wBox:focus {
  border-color: var(--primary-pink);
  background: #fff;
}

/* 5. ปรับช่องหมายเหตุ */
.row.customer-card input.wRemark {
  height: 40px !important;
  margin-top: 5px;
  border: 1px dashed #ccc;
  background: #fafafa;
  text-align: left !important;
  padding-left: 10px;
  font-size: 14px;
  width: 100%;
}
.row.customer-card input.wRemark:focus {
  border-color: var(--accent-mauve);
  background: #fff;
}

/* 6. ซ่อน Header เดิมของตาราง (เพราะเราเปลี่ยนเป็น Card แล้ว Header ไม่จำเป็นสำหรับลูกค้า) */
#productsCustomer .thead {
    display: none !important;
}

/* =========================================
   ✨ PROFESSIONAL CARD DESIGN
   ========================================= */

/* หัวข้อรายการ */
.list-header {
    font-size: 14px;
    color: #888;
    margin: 15px 0 10px 5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* สถานะว่าง (Empty State) */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    background: #fff;
    border-radius: 16px;
    border: 2px dashed #eee;
    color: #aaa;
}

/* การ์ดสินค้า */
.pro-card {
    background: #fff;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 15px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04); /* เงานุ่มมาก */
    border: 1px solid rgba(0,0,0,0.03);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

/* เส้นตกแต่งด้านซ้าย (Accent Bar) */
.pro-card::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--primary-pink); /* ใช้สีธีม */
    opacity: 0.7;
}

.pro-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.08);
}

/* ส่วนหัวการ์ด (ชื่อ + ปุ่มลบ) */
.pro-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
    padding-left: 8px; /* เว้นที่ให้เส้นตกแต่ง */
}

.pro-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #333;
    line-height: 1.4;
    padding-right: 10px;
}

.pro-btn-delete {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0; /* Override เดิม */
    width: auto;
    height: auto;
}

.pro-btn-delete:hover {
    color: #dc3545;
    background: #fff5f5;
}

/* กริดแบ่งช่องน้ำหนัก/จำนวน */
.pro-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
    padding-left: 8px;
}

.pro-input-group {
    display: flex;
    flex-direction: column;
}

.pro-label {
    font-size: 0.8rem;
    color: #999;
    margin-bottom: 4px;
    font-weight: 500;
}

.pro-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.pro-input {
    width: 100%;
    padding: 10px 35px 10px 12px; /* เว้นขวาไว้ใส่หน่วย */
    font-size: 1.1rem !important;
    font-weight: 600;
    color: #444;
    border: 1px solid #eee;
    border-radius: 10px;
    background: #f9f9f9;
    transition: 0.2s;
    text-align: right; /* ตัวเลขชิดขวา */
}

/* ค้นหา .pro-input อันเดิม แล้วแก้เป็นอันนี้ครับ */
.pro-input {
    width: 100%;
    /* 🔥 แก้ตรงนี้: เปลี่ยนจาก 35px เป็น 60px เพื่อให้มีที่เหลือเยอะๆ */
    padding: 10px 60px 10px 12px; 
    
    font-size: 1.1rem !important;
    font-weight: 600;
    color: #444;
    border: 1px solid #eee;
    border-radius: 10px;
    background: #f9f9f9;
    transition: 0.2s;
    text-align: right; /* ตัวเลขชิดขวา */
}.pro-input:focus {
    background: #fff;
    border-color: var(--primary-pink);
    box-shadow: 0 0 0 3px rgba(255, 158, 181, 0.15);
    outline: none;
}

/* ค้นหา .pro-unit อันเดิม แล้วแก้เป็นอันนี้ครับ */
.pro-unit {
    position: absolute;
    /* 🔥 แก้ตรงนี้: ขยับจาก 12px เป็น 15px */
    right: 15px; 
    
    font-size: 0.85rem;
    color: #aaa;
    pointer-events: none;
    top: 50%; /* จัดกึ่งกลางแนวตั้ง */
    transform: translateY(-50%); /* จัดกึ่งกลางแนวตั้ง */
}

/* ช่องหมายเหตุ */
.pro-remark-wrapper {
    position: relative;
    margin-top: 5px;
    margin-left: 8px;
}

.pro-icon-edit {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #bbb;
    pointer-events: none;
}

.pro-remark {
    width: 100%;
    padding: 10px 10px 10px 36px; /* เว้นซ้ายให้ไอคอน */
    font-size: 0.95rem;
    color: #555;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 20px; /* ทรงแคปซูล */
    transition: 0.2s;
}

.pro-remark:focus {
    border-color: #ddd;
    background: #fcfcfc;
}
.pro-remark::placeholder {
    color: #ccc;
}

/* สไตล์สำหรับช่องพิมพ์ข้อความ (เช่น แบรนด์) */
.pro-input-text {
    width: 100%;
    /* padding ปกติ ไม่ต้องเว้นขวาเยอะเหมือนช่องตัวเลข */
    padding: 10px 12px; 
    
    font-size: 1rem;
    color: #444;
    border: 1px solid #eee;
    border-radius: 10px;
    background: #fff;
    text-align: left; /* ชิดซ้ายให้อ่านง่าย */
    transition: 0.2s;
}

.pro-input-text:focus {
    border-color: var(--primary-pink);
    box-shadow: 0 0 0 3px rgba(255, 158, 181, 0.15);
    outline: none;
}

/* เพิ่มต่อท้ายไฟล์ style.css เดิม */

/* ทำให้ Section เป็นการ์ดมนสวย */
.section {
    background: #fff;
    border-radius: 16px; /* มน 16px ตามสั่ง */
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #eee;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03); /* เงาจางๆ */
}

/* สีพาสเทลสำหรับแต่ละส่วน (จะถูก JS เรียกใช้) */
.section-products {
    background-color: #fff3e0; /* ส้มอ่อน */
    border-color: #ffe0b2;
}

.section-customer {
    background-color: #e3f2fd; /* ฟ้าอ่อน */
    border-color: #bbdefb;
}

.section-transport {
    background-color: #f3e5f5; /* ม่วงอ่อน */
    border-color: #e1bee7;
}

.section-expense {
    background-color: #ffebee; /* ชมพูอ่อน */
    border-color: #ffcdd2;
}