/* --- 1. โครงสร้างพื้นฐานและการป้องกันการ Refresh (Global Styles) --- */
html {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: 'Prompt', sans-serif;
    background-color: #f0f2f5;
    margin: 0;
    padding: 0;
    color: #333;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* Container หุ้มการเลื่อนแนวตั้ง */
.app-scroll-wrapper {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
    box-sizing: border-box;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    background: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    user-select: text;
    -webkit-user-select: text;
}

/* --- 2. ส่วนหัวข้อและข้อความ --- */
h2 { text-align: center; color: #2c3e50; margin-bottom: 20px; }
h3 { margin-top: 0; color: #2c3e50; }
label { display: block; margin-top: 15px; font-weight: 600; font-size: 14px; }
.date-helper { font-size: 15px; color: #0056b3; display: block; margin-top: 4px; }
.button-span-style { color: #004d00 !important; font-weight: 900 !important; }

/* ปุ่มเริ่มบันทึกข้อมูลโค (ปุ่มหลักหน้าแรก) */
.btn-enter {
    font-family: 'Prompt', sans-serif;
    width: 100%;
    padding: 16px;
    margin-top: 25px;
    border: none;
    border-radius: 12px;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    background: linear-gradient(135deg, #28a745 0%, #218838 100%); /* สีเขียวเหนี่ยวทรัพย์ */
    color: white;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* เอฟเฟกต์ตอน Hover หรือแตะบนมือถือ */
.btn-enter:hover {
    transform: translateY(-2px); /* ลอยขึ้นนิดนึง */
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
}

.btn-enter:active {
    transform: translateY(1px); /* กดแล้วยุบลง */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* เพิ่มอนิเมชั่นให้ลูกศรขยับได้นิดๆ */
.btn-enter span {
    transition: transform 0.3s ease;
}

.btn-enter:hover span {
    transform: translateX(5px); /* ลูกศรขยับไปทางขวาเวลาชี้ */
}

/* ปุ่มเพิ่มรายการโค (Add to List) */
.btn-add-cow {
    width: 100%;
    padding: 15px;
    margin-top: 20px;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    /* ไล่เฉดสีส้มทองสดใส */
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(245, 124, 0, 0.3);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* เอฟเฟกต์ตอนชี้หรือแตะ */
.btn-add-cow:hover {
    background: linear-gradient(135deg, #ffa726 0%, #fb8c00 100%);
    box-shadow: 0 6px 15px rgba(245, 124, 0, 0.4);
    transform: translateY(-1px);
}

/* เอฟเฟกต์ตอนกด */
.btn-add-cow:active {
    transform: translateY(1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    filter: brightness(0.9);
}

/* สไตล์เฉพาะสำหรับไอคอนเครื่องหมายบวก */
.btn-add-cow i {
    font-size: 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ปุ่มยืนยันข้อมูลทั้งหมด (Final Submit) */
.btn-submit {
    width: 100%;
    padding: 18px;
    margin-top: 30px;
    border: none;
    border-radius: 15px;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    /* ไล่เฉดสีม่วงไปทางน้ำเงิน ให้ดูหรูหราและสำคัญ */
    background: linear-gradient(135deg, #6f42c1 0%, #4e2a84 100%);
    color: white;
    box-shadow: 0 6px 20px rgba(111, 66, 193, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* เอฟเฟกต์ตอน Hover หรือแตะ */
.btn-submit:hover {
    background: linear-gradient(135deg, #7e57c2 0%, #5e35b1 100%);
    box-shadow: 0 8px 25px rgba(111, 66, 193, 0.5);
    transform: scale(1.02); /* ขยายใหญ่ขึ้นนิดนึงให้ดูเด่น */
}

/* เอฟเฟกต์ตอนกด */
.btn-submit:active {
    transform: scale(0.98); /* ยุบลงเล็กน้อย */
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

/* อนิเมชั่นเบาๆ ให้ปุ่มดูมีชีวิต (Optional) */
@keyframes pulse-purple {
    0% { box-shadow: 0 0 0 0 rgba(111, 66, 193, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(111, 66, 193, 0); }
    100% { box-shadow: 0 0 0 0 rgba(111, 66, 193, 0); }
}

#submitBtn {
    animation: pulse-purple 2s infinite; /* ใส่แอนิเมชั่นชีพจรเพื่อให้รู้ว่าต้องกดปุ่มนี้ */
}

/* --- 3. องค์ประกอบฟอร์ม (Inputs, Selects, Buttons) --- */
input, select { 
    width: 100%; 
    padding: 12px; 
    margin-top: 5px; 
    border: 1px solid #ddd; 
    border-radius: 8px; 
    box-sizing: border-box; 
    font-size: 16px; 
}

input:disabled, select:disabled { background-color: #e9ecef; color: #6c757d; }

/* กล่อง Checkbox Wrapper */
.checkbox-wrapper {
    margin-top: 15px;
    padding: 10px;
    background: #fff3cd;
    border-radius: 8px;
    border: 1px solid #ffeeba;
    display: none;
}

#check-has-calf { background-color: #e3f2fd; border: 1px solid #90caf9; }

.checkbox-label { display: flex; align-items: center; cursor: pointer; font-weight: bold; margin: 0; }
.checkbox-label input { width: 20px; height: 20px; margin-right: 10px; }

/* ปุ่มต่างๆ */
.btn { 
    width: 100%; 
    padding: 14px; 
    margin-top: 20px; 
    border: none; 
    border-radius: 8px; 
    font-size: 18px; 
    font-weight: bold; 
    cursor: pointer; 
    transition: 0.3s; 
}

.btn-primary { background-color: #007bff; color: white; }
.btn-warning { background-color: #ffc107; color: #333; margin-top: 15px; }
.btn-submit { background-color: #6f42c1; color: white; margin-top: 30px; }
.btn-calc { 
    background-color: #17a2b8; 
    color: white; 
    padding: 4px 10px; 
    font-size: 12px; 
    border-radius: 5px; 
    border: none; 
    cursor: pointer; 
    margin-left: 5px; 
}

/* ส่วนขยายแม่โคและการผสม */
#mother-cow-info { 
    display: none; 
    background-color: #f8f9fa; 
    padding: 15px; 
    border-radius: 8px; 
    margin-top: 10px; 
    border-left: 5px solid #1f5dda; 
}

/* ส่วนขยายแม่โคและการผสม */
#mating-data-section { 
    display: none; 
    background-color: #f8f9fa; 
    padding: 15px; 
    border-radius: 8px; 
    margin-top: 10px; 
    border-left: 5px solid #e4ce07; 
}

/* --- 4. การแสดงผลรายการโค (Cattle List Display) --- */
#cattle-list-display { margin-top: 25px; border-top: 1px solid #eee; padding-top: 10px; }
.cattle-group-title { font-size: 14px; color: #666; margin-top: 10px; font-weight: bold; }

.cattle-item { 
    padding: 15px; 
    margin-bottom: 10px; 
    border-radius: 8px; 
    position: relative; 
    border-left: 5px solid #ccc; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.05); 
}

.type-mom    { background-color: #e3f2fd; border-left-color: #007bff; }
.type-heifer { background-color: #fce4ec; border-left-color: #e91e63; }
.type-calf   { background-color: #e8f5e9; border-left-color: #4caf50; }

.item-header {
    display: flex;
    justify-content: space-between; /* ชื่ออยู่ซ้ายสุด ปุ่มอยู่ขวาสุด */
    align-items: center; /* จัดให้อยู่กึ่งกลางแนวตั้งพร้อมกัน */
    gap: 10px;
    margin-bottom: 8px;
}

/* จัดการกลุ่มปุ่มไม่ให้ซ้อนกัน */
.header-actions {
    display: flex;
    gap: 5px; /* ระยะห่างระหว่างปุ่ม */
    flex-shrink: 0; /* ป้องกันปุ่มถูกบีบจนเบี้ยว */
}

.item-detail { font-size: 13px; color: #444; margin-top: 5px; line-height: 1.6; }
/* ตกแต่งปุ่มให้ขนาดพอดีกัน */
.btn-slip, .btn-action {
    padding: 6px 10px;
    border-radius: 15px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap; /* ป้องกันข้อความขึ้นบรรทัดใหม่ในปุ่ม */
}

.btn-slip {
    background-color: #e3f2fd;
    color: #1976d2;
}

.btn-action {
    background-color: #faf9f9;
    color: #333;
}

/* ซ่อนรายละเอียดไว้ก่อน */
.item-detail {
    display: none;
    padding-top: 10px;
    border-top: 1px dashed #eee;
    margin-top: 5px;
    animation: fadeIn 0.3s ease-in-out;
}

/* คลาสที่จะเติมเข้าไปเมื่อต้องการโชว์ */
.item-detail.show {
    display: block;
}

/* ทำให้ส่วนหัวกดได้ และมี Effect เวลาเอาเมาส์ชี้ */
.item-header {
    cursor: pointer;
    transition: background-color 0.2s;
}
.item-header:hover {
    background-color: rgba(0,0,0,0.02); /* ไฮไลท์จางๆ เวลามีเมาส์ */
}

/* ไอคอนลูกศร */
.toggle-icon {
    display: inline-block;
    width: 20px;
    text-align: center;
    transition: transform 0.2s;
    font-size: 12px;
    color: #666;
}

/* ถ้ามีการเปิด ให้หมุนลูกศรลง */
.expanded .toggle-icon {
    transform: rotate(90deg);
}

/* Animation ตอนเปิด */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}


/* --- 5. สถานะระบบและการจัดการหน้า (System State) --- */
.page { display: none; }
.active { display: block; }
#loading { 
    display: none; 
    position: fixed; 
    top:0; left:0; 
    width:100%; height:100%; 
    background: rgba(255,255,255,0.9); 
    z-index: 999; 
    text-align: center; 
    padding-top: 50vh; 
    font-size: 20px; 
}

/* --- 6. ส่วน Popup (Qty Adjuster & Helpers) --- */
.qty-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 15px; }
.qty-btn {
    width: 45px; height: 45px;
    border: 1px solid #ddd;
    background-color: #f8f9fa;
    border-radius: 8px;
    font-size: 20px;
    font-weight: bold;
    color: #007bff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.qty-btn:active { background-color: #e2e6ea; }
.qty-input { width: 80px !important; margin: 0 !important; text-align: center; }

.swal-input-group { text-align: left; margin-bottom: 10px; }

/* --- 7. Tooltip (Help Icons) --- */
.tooltip-icon1, .tooltip-icon2, .tooltip-icon3, .tooltip-icon4, .tooltip-icon5, .tooltip-icon6 {
    display: inline-block;
    background-color: #0051BA;
    color: white;
    border-radius: 50%;
    width: 18px; height: 18px;
    text-align: center;
    font-size: 12px;
    line-height: 18px;
    cursor: default;
    position: relative;
    flex-shrink: 0;
    vertical-align: middle;
}

.tooltip-icon1::after { content: "ใส่ชื่อและนามสกุลของเกษตรกร"; }
.tooltip-icon2::after { content: "เป็นเลขชื่อผู้ใช้ของแอพ iFarmer+ เช่น 7001001234 ต้องระบุให้ถูกต้อง"; }
.tooltip-icon3::after { content: "กรณีจำวันเกิดไม่ได้ ให้กดช่วยคำนวน และลองเดาอายุเป็นปีและเดือน"; }
.tooltip-icon4::after { content: "อายุน้อยกว่า 1 ปี=ลูกโค//อายุ 1 ปีขึ้นไป=โคสาว//เคยมีลูกแล้ว=แม่โค "; }
.tooltip-icon5::after { content: "เลือกประเภทฟาร์มให้ถูกต้อง เนื่องจากให้ช่องทางขึ้นทะเบียนคนละระบบ "; }
.tooltip-icon6::after { content: "เคยคลอดลูกมาแล้วกี่ครั้ง ไม่นับที่อยู่ในท้องตอนนี้"; }

[class^="tooltip-icon"]::after {
    white-space: pre-line;
    position: absolute;
    top: -8px;
    left: 110%;
    background-color: #333;
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    width: 200px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 999;
}
[class^="tooltip-icon"]:hover::after { opacity: 1; }

/* --- 8. ใบตรวจสอบข้อมูล (Slip Section) --- */
.slip-container {
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 15px;
    text-align: left;
    font-size: 14px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin-bottom: 10px;
}
.slip-header {
    text-align: center;
    font-weight: bold;
    color: #007bff;
    border-bottom: 2px dashed #eee;
    padding-bottom: 10px;
    margin-bottom: 10px;
    font-size: 16px;
}
.slip-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #f9f9f9; }
.slip-label { color: #666; font-weight: 600; }
.slip-value { color: #333; font-weight: bold; text-align: right; }
.slip-section {
    margin-top: 10px;
    padding-top: 5px;
    border-top: 1px solid #eee;
    font-size: 13px; color:#555;
    background: #f8f9fa;
    padding: 5px;
    border-radius: 5px;
}

/* จัดกล่องสายพันธุ์ให้อยู่บรรทัดเดียวกัน */
.breed-row {
    display: flex;
    gap: 10px; /* ระยะห่างระหว่างกล่อง */
    width: 100%;
    margin-top: 5px;
}

/* กรอบข้อความคำแนะนำ (Comment Card) */
.comment-card {
    display: block;              /* ปรับให้เป็น Block เพื่อจัดกึ่งกลางได้ */
    margin: 15px auto;           /* เว้นระยะบน-ล่าง และจัดกึ่งกลางซ้าย-ขวา */
    padding: 10px;               /* ระยะห่างจากข้อความถึงขอบกรอบ */
    border: 1px solid #333333;   /* เส้นขอบสีดำบางๆ (ปรับเป็น #ddd ได้ถ้าอยากให้จางลง) */
    border-radius: 16px;         /* ขอบมนสวยงาม */
    text-align: center;          /* จัดข้อความข้างในให้อยู่ตรงกลาง */
    background-color: #f5f5f5;   /* พื้นหลังขาวสะอาด */
    max-width: 90%;              /* ไม่ให้กว้างจนเต็มหน้าจอเกินไป */
    line-height: 1.6;            /* เว้นบรรทัดให้อ่านง่าย */
    color: #555;                 /* สีตัวอักษรเทาเข้ม สบายตา */
}

/* --- โครงสร้างหลักของ Modal --- */
.modal { 
    display: none; 
    position: fixed; 
    z-index: 2000; /* ให้สูงกว่าทุกอย่าง */
    left: 0; top: 0; 
    width: 100%; height: 100%; 
    background-color: rgba(0,0,0,0.6); 
    backdrop-filter: blur(4px); /* ทำพื้นหลังเบลอแบบ iOS */
}

.modal-content { 
    background-color: #ffffff; 
    margin: 10% auto; 
    padding: 0; 
    border-radius: 20px; 
    width: 90%; 
    max-width: 450px; 
    box-shadow: 0 15px 30px rgba(0,0,0,0.3);
    overflow: hidden;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* --- ส่วนหัว Modal --- */
.modal-header { 
    padding: 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

.modal-header h3 { margin: 0; color: #333; font-size: 1.2rem; }

/* --- ส่วนเนื้อหา --- */
.modal-body { padding: 20px; }

.breed-row-item { 
    display: flex; 
    gap: 8px; 
    margin-bottom: 12px; 
    align-items: center; 
    background: #fdfdfd;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid #f0f0f0;
}

.breed-row-item select {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 8px;
    font-size: 14px;
    outline: none;
}

/* --- ปุ่มต่างๆ --- */
.btn-add-row-inside {
    background-color: #e7f1ff;
    color: #007bff;
    border: 1px dashed #007bff;
    border-radius: 10px;
    padding: 10px;
    width: 100%;
    cursor: pointer;
    font-weight: 600;
    margin: 10px 0;
    transition: 0.2s;
}

.btn-add-row-inside:hover { background-color: #cfe2ff; }

.btn-remove-row { 
    background: #fff0f0; 
    color: #ff4d4d; 
    border: 1px solid #ffd6d6; 
    border-radius: 8px; 
    padding: 8px 12px; 
    cursor: pointer; 
}

/* --- ส่วนท้ายและผลรวม --- */
.total-box {
    margin-top: 15px; 
    padding: 15px; 
    background: #f1f3f5; 
    border-radius: 12px; 
    text-align: center;
    font-size: 1.1rem;
}

.modal-footer {
    padding: 15px 20px;
    background: #f8f9fa;
    display: flex;
    gap: 10px;
}

.btn-confirm { flex: 2; background: #28a745; color: white; border: none; padding: 12px; border-radius: 10px; font-weight: 600; cursor: pointer; }
.btn-cancel { flex: 1; background: #6c757d; color: white; border: none; padding: 12px; border-radius: 10px; font-weight: 600; cursor: pointer; }

.summary-container {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    border: 1px solid #ddd;
}

/* สีตามประเภทโค (อ้างอิงตามที่คุณเคยมี) */
.badge-mom { background-color: #fff3e0; color: #e65100; border-color: #ffb74d; }
.badge-heifer { background-color: #f3e5f5; color: #7b1fa2; border-color: #ce93d8; }
.badge-calf { background-color: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; }


.btn-copy-all {
    background-color: #802d06;
    color: #f4f2f2; /* สีส้มตามธีมปุ่มเพิ่มรายการ */
    border: 1px solid #080807;
    padding: 5px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-copy-all:hover {
    background-color: #900404;
    color: rgb(245, 243, 243);
}

.btn-copy-all:active {
    transform: scale(0.95);
}

.btn-calc {
    background-color: #f7f8f9; /* สีฟ้าจางๆ ดูสะอาด */
    color: #0c0c0c;            /* สีไอคอนสีฟ้าเข้ม */
    border: 1.5px solid #101010;
    padding: 8px 12px;
    border-radius: 8px;        /* ขอบมนดูเป็นมิตร */
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(250, 250, 251, 0.1);
}

/* เมื่อเมาส์ชี้ (Hover) */
.btn-calc:hover {
    background-color: #007bff;
    color: white;
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

/* เมื่อกดปุ่ม (Active) - สำคัญมากสำหรับมือถือ */
.btn-calc:active {
    transform: scale(0.92);    /* ปุ่มยุบลงเล็กน้อย */
    box-shadow: 0 1px 2px rgba(246, 247, 248, 0.2);
}

/* ตกแต่งไอคอนข้างใน */
.btn-calc i {
    font-size: 1.1rem;
}