/* Modal Core Styles */
.k-modal {
    position: fixed;  /* ตำแหน่งคงที่เต็มหน้าจอ */
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;  /* แสดงด้านบนสุดของหน้า */
    background-color: rgba(0, 0, 0, 0.5);  /* พื้นหลังโปร่งใส */
    backdrop-filter: blur(2px);  /* เบลอพื้นหลัง */
    display: none;  /* ซ่อนไว้เป็นค่าเริ่มต้น */
    overflow: hidden;
}

.k-modal.show {
    display: flex !important;  /* แสดง Modal เมื่อมี class 'show' */
    align-items: center;  /* จัดให้อยู่กึ่งกลางแนวตั้ง */
    justify-content: center;  /* จัดให้อยู่กึ่งกลางแนวนอน */
}

.k-modal-content {
    position: relative;
    width: 400px;
    max-width: calc(100vw - 32px);  /* รองรับการย่อหน้าจอ */
    margin: auto;
    background: white;
    border-radius: 8px;  /* มุมโค้ง */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);  /* เงา */
    z-index: 1;
}

.k-modal-header {
    position: sticky;
    top: 0;
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid #e9ecef;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 2;
}

.k-modal-body {
    padding: 20px;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
}

.k-modal-footer {
    position: sticky;
    bottom: 0;
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e9ecef;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    z-index: 2;
}

/* Form Elements */
.k-form-group {
    margin-bottom: 20px;
}

.k-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #2c3e50;
    font-size: 14px;
}

.k-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    transition: border-color 0.2s;
}

.k-input:focus {
    border-color: #4a90e2;
    outline: none;
}

.k-form-group.has-error .k-input {
    border-color: #dc3545;
}

.k-form-feedback {
    font-size: 12px;
    color: #dc3545;
    margin-top: 5px;
}

/* Buttons */
.k-btn {
    padding: 10px 16px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 80px;
    transition: background-color 0.2s;
}

.k-btn-primary {
    background: #007bff;
    color: white;
}

.k-btn-primary:hover {
    background: #0056b3;
}

.k-btn-secondary {
    background: #6c757d;
    color: white;
}

.k-btn-secondary:hover {
    background: #5a6268;
}

/* Sub-row Editing */
.button-group {
    display: flex;
    gap: 4px;
}

.k-edit-btn, .k-print-btn {
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: white;
}

.k-edit-btn {
    background-color: #4a90e2;
}

.k-edit-btn:hover {
    background-color: #357abd;
}

.k-save-btn {
    background-color: #28a745;
    color: white;
}

.k-save-btn:hover {
    background-color: #218838;
}

.k-cancel-btn {
    background-color: #dc3545;
    color: white;
}

.k-cancel-btn:hover {
    background-color: #c82333;
}

.edit-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

/* Scrollbar */
.k-modal-body::-webkit-scrollbar {
    width: 6px;
}

.k-modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.k-modal-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.k-modal-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}


/* Mobile Responsiveness */
@media (max-width: 480px) {
    .k-modal-content {
        width: 100%;
        margin: 0;
        min-height: 100vh;  /* เต็มความสูงหน้าจอ */
        border-radius: 0;  /* ไม่มีมุมโค้ง */
    }

    .k-modal-header,
    .k-modal-footer {
        border-radius: 0;
    }

    .k-btn {
        flex: 1;
    }
}