/* --- Overlay Logic (Global) --- */
.pos-screen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99;
    /* Cao hơn hầu hết các thành phần, kể cả sticky header */
    background: transparent;
    cursor: default;
}

/* --- Popup Card Style --- */
.pos-popup-card {
    background: #fff;
    border: 1px solid #ddd;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 10px;
    margin-top: 5px;
}

/* --- Form Elements trong Popup --- */
.pos-form-group {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 12px;
}

.pos-form-label {
    width: 80px;
    font-weight: 600;
    color: #555;
    flex-shrink: 0;
}

.pos-form-input {
    flex-grow: 1;
}

/* --- Toggle Group --- */
.pos-toggle-group {
    display: flex;
    border: 1px solid #ccc;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.pos-toggle-btn {
    flex: 1;
    text-align: center;
    padding: 5px;
    cursor: pointer;
    font-size: 11px;
    background: #f9f9f9;
    transition: 0.2s;
}

.pos-toggle-btn.active {
    background: var(--color-primary, #337ab7);
    color: #fff;
    font-weight: bold;
}

/* --- Sửa lại Action Buttons (Đảm bảo không bị che) --- */
/* Class này bạn đã có, nhưng tôi thêm z-index để chắc chắn nó nổi lên */
.product-cell {
    position: relative;
    z-index: 1;
}

.pos-w500-up {
    font-weight: 500;
    text-transform: uppercase;
}

/* --- 1. MẶC ĐỊNH: Mở xuôi xuống dưới (Cho các dòng ở giữa) --- */
.pos-popup-wrapper {
    position: absolute;
    top: 100%;
    /* Mở xuống */
    bottom: auto;
    right: 0;
    z-index: 100;
    min-width: 320px;
    margin-top: -30px;
    margin-bottom: 0;
    /* Hiệu ứng mặc định */
    transform-origin: top right;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* --- 2. LOGIC ĐÁY: 3 dòng cuối cùng mở NGƯỢC LÊN TRÊN --- */
.table tbody tr:nth-last-child(-n+3) .pos-popup-wrapper {
    top: auto;
    /* Hủy mở xuống */
    bottom: 100%;
    /* Neo đáy */
    margin-top: 0;
    margin-bottom: 5px;

    /* Bóng đổ ngược lên */
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.15);
    transform-origin: bottom right;
}

/* --- 3. LOGIC ƯU TIÊN CAO NHẤT: 3 dòng ĐẦU TIÊN luôn mở XUỐNG DƯỚI --- */
/* Sử dụng !important để ghi đè logic số 2 nếu bảng có ít dòng (VD: Bảng 5 dòng) */
.table tbody tr:nth-child(-n+3) .pos-popup-wrapper {
    top: 100% !important;
    bottom: auto !important;
    margin-top: -30px !important;
    margin-bottom: 0 !important;
    /* Khôi phục bóng đổ xuống */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2) !important;
    transform-origin: top right !important;
}


/* --- 2. Search Group Wrapper --- */
/* Phải có z-index cao hơn Overlay để input vẫn gõ được */
.pos-search-group {
    width: 100%;
    height: 36px;
    position: relative;
    z-index: 210;
}

/* --- 3. Input Styles --- */
.pos-search-input {
    height: 36px !important;
    border-radius: 3px !important;
    position: relative;
    z-index: 902;
    /* Đảm bảo input luôn nổi trên cùng */
}

/* --- 4. Result Dropdown (Kết quả tìm kiếm) --- */
.pos-result-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 55vh;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    border-radius: 0 0 4px 4px;
    z-index: 1000;
    margin-top: 1px;
}

/* Item sản phẩm */
.pos-product-item {
    display: flex;
    padding: 8px 10px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.1s;
}

.pos-product-item:hover {
    background-color: #f2f8fd;
}

/* Ảnh sản phẩm */
.pos-product-img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border: 1px solid #eee;
    border-radius: 4px;
    margin-right: 12px;
    flex-shrink: 0;
}

/* Thông tin text */
.pos-product-info {
    flex-grow: 1;
    font-size: 13px;
    line-height: 1.5;
}

/* --- 5. Settings Dropdown --- */
/* Menu xổ xuống từ icon settings */
.pos-settings-menu {
    margin-top: 2px;
    border-radius: 3px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    min-width: 180px;
    right: 0;
    left: auto;
    /* Căn phải */
}

/* Nút icon settings trong input-group-btn */
.pos-btn-settings {
    height: 36px;
    border-left: 0;
    background: #eee;
    color: #555;
}

.pos-btn-settings:hover,
.pos-btn-settings:focus {
    background: #e0e0e0;
    outline: none;
}