/* RESET BẢN LỀ VÀ FONT CHỮ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body.woo-pos-app {
    background-color: #f0f2f5;
    color: #2c3338;
    height: 100vh; /* Chiếm toàn bộ chiều cao màn hình */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Chống cuộn toàn trang */
}

/* HEADER */
.pos-header {
    background-color: #2271b1;
    color: #fff;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
}

.pos-header .logo { font-size: 18px; font-weight: bold; }
.pos-header a { text-decoration: none; font-size: 14px; }
.pos-header a:hover { text-decoration: underline; }

/* LAYOUT CHÍNH */
.pos-container {
    display: flex;
    flex: 1;
    height: calc(100vh - 50px);
}
.pos-sales-layout {
    display: flex;
    flex: 1;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

/* CỘT TRÁI: SẢN PHẨM (70%) */
.pos-products-area, .pos-products-panel {
    flex: 7;
    display: flex;
    flex-direction: column;
    padding: 15px;
    border-right: 1px solid #ddd;
    overflow: hidden;
}

.search-bar { margin-bottom: 15px; }
.search-bar input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 15px;
    outline: none;
}
.search-bar input:focus { border-color: #2271b1; box-shadow: 0 0 5px rgba(34,113,177,0.3); }

.product-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    overflow-y: auto; /* Cho phép cuộn danh sách SP */
    padding-right: 5px;
    align-content: flex-start;
}

/* THẺ SẢN PHẨM */
.product-card {
    background: #fff;
    border: 1px solid #e2e4e7;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    display: flex;
    flex-direction: column;
}
.product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border-color: #2271b1;
}
.product-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-bottom: 1px solid #eee;
}
.product-card .info { padding: 10px; flex: 1; display: flex; flex-direction: column; }
.product-card h4 { font-size: 13px; margin-bottom: 5px; color: #1d2327; flex: 1; line-height: 1.3; }
.product-card .price { color: #d63638; font-weight: bold; font-size: 14px; margin-bottom: 3px; }
.product-card .stock { font-size: 11px; color: #646970; }

/* CỘT PHẢI: GIỎ HÀNG (30%) */
.pos-cart-area, .pos-cart-panel {
    flex: 3;
    background: #fff;
    display: flex;
    flex-direction: column;
    min-width: 320px;
    height: 100%;
}

.customer-select {
    padding: 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    gap: 10px;
}
.customer-select input { flex: 1; padding: 10px; border: 1px solid #ccc; border-radius: 4px; }

.cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* Dòng sản phẩm trong giỏ */
.cart-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #f0f0f0;
}
.cart-row-name { flex: 2; font-size: 13px; font-weight: 500; }
.cart-row-qty { flex: 1; display: flex; align-items: center; gap: 5px; }
.cart-row-qty input { width: 40px; text-align: center; padding: 4px; border: 1px solid #ccc; border-radius: 3px; }
.cart-row-price { flex: 1; text-align: right; color: #d63638; font-weight: bold; font-size: 14px; }
.btn-remove-item { background: none; border: none; color: #a00; font-size: 16px; cursor: pointer; padding: 0 5px; margin-left: 10px; }

/* KHU VỰC THANH TOÁN (Đáy giỏ hàng) */
.checkout-panel {
    padding: 20px;
    border-top: 2px dashed #ddd;
    background: #fafafa;
}
.total-row {
    display: flex;
    justify-content: space-between;
    font-size: 18px;
    margin-bottom: 15px;
    color: #1d2327;
}
.total-row strong { font-size: 24px; color: #2271b1; }

/* NÚT BẤM */
.btn {
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}
.btn-primary { background: #2271b1; color: #fff; }
.btn-primary:hover { background: #135e96; }
.btn-block { display: block; width: 100%; padding: 15px; font-size: 16px; text-transform: uppercase; font-weight: bold; }

/* CSS MÀN HÌNH KHÓA PIN */
#pos-lock-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(34, 113, 177, 0.95); /* Màu xanh làm mờ nền */
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.lock-box {
    background: #fff;
    padding: 40px;
    border-radius: 8px;
    width: 350px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.lock-box h2 { color: #1d2327; margin-bottom: 10px; }
#pos_pin_input {
    width: 100%;
    padding: 15px;
    font-size: 24px;
    text-align: center;
    letter-spacing: 10px;
    border: 2px solid #ccc;
    border-radius: 5px;
}
#pos_pin_input:focus { border-color: #2271b1; outline: none; }

@media (max-width: 480px) {
    /* Main Layout */
    .pos-wrapper {
        flex-direction: column !important;
    }
    
    /* Sidebar as top navigation bar */
    .pos-sidebar {
        width: 100% !important;
        height: 45px !important;
        padding-top: 0 !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 0 10px !important;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
    }
    
    .pos-sidebar .logo {
        display: none !important;
    }
    
    .pos-nav-tabs {
        flex-direction: row !important;
        width: 100% !important;
        height: 100% !important;
        margin: 0 !important;
        gap: 10px !important;
        justify-content: center !important;
    }
    
    .nav-tab {
        padding: 0 15px !important;
        border-left: none !important;
        border-bottom: 3px solid transparent !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 5px !important;
        height: 100% !important;
        font-size: 11px !important;
    }
    
    .nav-tab.active {
        border-left: none !important;
        border-bottom-color: #ffc107 !important;
        background: none !important;
        color: #ffc107 !important;
    }
    
    .nav-tab i {
        display: inline-block !important;
        font-size: 14px !important;
        margin-bottom: 0 !important;
        margin-right: 2px !important;
    }
    
    /* Top Bar */
    .pos-top-bar {
        height: auto !important;
        padding: 4px 8px !important;
        flex-wrap: nowrap !important;
        gap: 6px !important;
        justify-content: space-between !important;
    }
    
    #btn-new-order, #btn-show-orders {
        margin-right: 0 !important;
        font-size: 11px !important;
        padding: 4px 8px !important;
        flex: 1 !important;
        text-align: center !important;
        height: 28px !important;
    }
    
    .user-info {
        display: none !important; /* Hide user-info on mobile to save space */
    }
    
    /* Sales Tab Layout: 90vh strict height */
    .pos-sales-layout {
        display: flex !important;
        flex-direction: column !important;
        height: 90vh !important;
        max-height: 90vh !important;
        width: 100% !important;
        overflow: hidden !important;
    }
    
    /* Products Panel taking exactly 30vh */
    .pos-products-area, .pos-products-panel {
        flex: none !important;
        width: 100% !important;
        height: 30vh !important;
        max-height: 30vh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        border-right: none !important;
        border-bottom: 2px solid #2271b1 !important;
    }

    .pos-products-area > div:first-child, .pos-products-panel > div:first-child {
        flex: 1 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
    }
    
    /* Cart Panel taking exactly 60vh */
    .pos-cart-area, .pos-cart-panel {
        position: static !important;
        flex: none !important;
        width: 100% !important;
        height: 60vh !important;
        max-height: 60vh !important;
        z-index: auto !important;
        background: #fff !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        border-left: none !important;
        box-shadow: none !important;
    }
    

    
    /* Search Bar Layout */
    .search-bar {
        display: flex !important;
        flex-direction: column !important;
        gap: 4px !important;
        margin-bottom: 6px !important;
    }
    
    #pos_search {
        width: 100% !important;
        font-size: 11px !important;
        padding: 4px 6px !important;
    }
    
    #pos_sort_filter {
        width: 100% !important;
        font-size: 11px !important;
        padding: 4px 6px !important;
        height: 28px !important;
    }
    
    #btn-show-add-product-sales {
        font-size: 11px !important;
        padding: 4px 6px !important;
        height: 28px !important;
        width: 100% !important;
    }
    
    /* Product Grid converted to a single column vertical list */
    .product-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        padding: 4px !important;
    }
    
    /* Product card horizontal list row */
    .product-card {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        height: 60px !important;
        padding: 4px !important;
        position: relative !important;
        gap: 8px !important;
        border-radius: 4px !important;
        border: 1px solid #eee !important;
        background: #fff !important;
    }
    
    .product-card img {
        width: 50px !important;
        height: 50px !important;
        object-fit: cover !important;
        border-radius: 4px !important;
        flex-shrink: 0 !important;
        border-bottom: none !important;
    }
    
    .product-card .info {
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        flex: 1 !important;
        min-width: 0 !important;
    }
    
    .product-card h4 {
        font-size: 11px !important;
        margin: 0 0 2px 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        line-height: 1.2 !important;
        color: #1d2327 !important;
    }
    
    .product-card .price {
        font-size: 10px !important;
        margin: 0 !important;
        color: #d63638 !important;
        font-weight: bold !important;
    }
    
    /* Position the stock badge absolutely on the top right */
    .product-card div[style*="position: absolute"] {
        position: absolute !important;
        top: 2px !important;
        right: 2px !important;
        font-size: 9px !important;
        padding: 1px 4px !important;
        border-radius: 3px !important;
        box-shadow: none !important;
        z-index: 2 !important;
    }
    
    /* Custom Service Panel */
    .custom-item-bar {
        padding: 8px !important;
    }
    
    .custom-item-bar h4 {
        font-size: 11px !important;
        margin-bottom: 4px !important;
    }
    
    .custom-item-bar .custom-item-inputs {
        display: flex !important;
        flex-direction: column !important;
        gap: 4px !important;
    }
    
    #custom_item_name, #custom_item_unit, #custom_item_qty, #custom_item_cost, #custom_item_price {
        width: 100% !important;
        min-width: 0 !important;
        padding: 4px !important;
        font-size: 10px !important;
        height: 26px !important;
        box-sizing: border-box !important;
        margin: 0 !important;
        border-radius: 3px !important;
    }
    
    #btn-add-custom-item {
        width: 100% !important;
        margin-top: 2px !important;
        padding: 6px !important;
        font-size: 11px !important;
        height: auto !important;
    }
    
    /* Order metadata type & date inputs */
    .order-meta-row {
        padding: 5px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 4px !important;
    }
    
    #pos_order_type, #pos_created_date {
        width: 100% !important;
        font-size: 10px !important;
        padding: 4px !important;
        margin: 0 !important;
        height: 26px !important;
        box-sizing: border-box !important;
    }
    
    /* Customer search/select */
    .customer-select {
        padding: 5px !important;
        display: flex !important;
        gap: 4px !important;
    }
    
    #pos_customer_search {
        font-size: 10px !important;
        padding: 4px !important;
        height: 26px !important;
        box-sizing: border-box !important;
    }
    
    #btn-show-add-customer {
        font-size: 10px !important;
        padding: 4px 8px !important;
        height: 26px !important;
        white-space: nowrap !important;
        box-sizing: border-box !important;
    }
    
    /* Cart Items list */
    .cart-items {
        padding: 4px !important;
        flex: 1 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
    }
    
    /* Stacking details inside each cart row for extremely narrow viewports */
    .cart-row {
        display: block !important;
        position: relative !important;
        padding: 6px !important;
        border-bottom: 1px solid #f0f0f0 !important;
    }
    
    .cart-row > div:first-child {
        display: block !important;
        font-size: 11px !important;
        padding-right: 20px !important;
        margin-bottom: 4px !important;
        font-weight: 500 !important;
    }
    
    .cart-row > div:first-child div {
        margin-top: 2px !important;
        font-size: 10px !important;
    }
    
    .cart-qty-input {
        width: 35px !important;
        font-size: 10px !important;
        padding: 2px !important;
        display: inline-block !important;
        height: 22px !important;
        box-sizing: border-box !important;
        text-align: center !important;
        border: 1px solid #ccc !important;
        border-radius: 3px !important;
    }
    
    .cart-price-input {
        width: 65px !important;
        font-size: 10px !important;
        padding: 2px !important;
        display: inline-block !important;
        height: 22px !important;
        box-sizing: border-box !important;
        text-align: right !important;
        margin-left: 4px !important;
        color: #d63638 !important;
        font-weight: bold !important;
        border: 1px solid #ccc !important;
        border-radius: 3px !important;
    }
    
    .btn-remove-cart-item {
        position: absolute !important;
        top: 2px !important;
        right: 2px !important;
        font-size: 16px !important;
        padding: 0 !important;
        margin: 0 !important;
        background: none !important;
        border: none !important;
        color: #a00 !important;
        cursor: pointer !important;
        line-height: 1 !important;
    }
    
    /* Checkout Panel at the bottom */
    .checkout-panel {
        padding: 8px !important;
    }
    
    .checkout-panel > div {
        display: block !important;
        margin-bottom: 6px !important;
    }
    
    .checkout-panel label, .checkout-panel span {
        display: block !important;
        font-size: 10px !important;
        font-weight: bold !important;
        margin-bottom: 2px !important;
        text-align: left !important;
        color: #333 !important;
    }
    
    .checkout-panel input, .checkout-panel select {
        width: 100% !important;
        max-width: 100% !important;
        padding: 4px !important;
        font-size: 10px !important;
        height: 26px !important;
        box-sizing: border-box !important;
        text-align: left !important;
        border: 1px solid #ccc !important;
        border-radius: 4px !important;
    }
    
    /* Specific styling for Discount Row */
    .discount-row {
        display: block !important;
        margin-bottom: 6px !important;
    }
    .discount-row span {
        display: block !important;
        font-size: 10px !important;
        font-weight: bold !important;
    }
    .discount-row div {
        position: relative !important;
        display: block !important;
    }
    .discount-row input {
        width: 100% !important;
        padding-right: 20px !important;
        font-size: 11px !important;
        color: #d63638 !important;
        font-weight: bold !important;
    }
    .discount-row span[style*="position: absolute"] {
        position: absolute !important;
        right: 5px !important;
        top: 4px !important;
        font-weight: bold !important;
        font-size: 11px !important;
        display: inline !important;
        margin: 0 !important;
        color: #333 !important;
    }
    
    /* Total Row display */
    .total-row {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        font-size: 12px !important;
        margin-bottom: 6px !important;
        border-top: 1px solid #eee !important;
        padding-top: 6px !important;
    }
    .total-row span {
        font-size: 11px !important;
        font-weight: bold !important;
        margin: 0 !important;
    }
    .total-row strong {
        font-size: 14px !important;
        color: #2271b1 !important;
    }
    
    /* Split payment cash input */
    #pos_split_payment_area {
        display: none;
        flex-direction: column !important;
    }
    
    /* Cash change text */
    span#pos-change-text {
        font-size: 9px !important;
        display: block !important;
        text-align: right !important;
        margin-bottom: 4px !important;
    }
    
    /* Notes textarea */
    .checkout-panel textarea#pos_note {
        width: 100% !important;
        font-size: 10px !important;
        padding: 4px !important;
        height: 32px !important;
        box-sizing: border-box !important;
        border: 1px solid #ccc !important;
        border-radius: 4px !important;
    }
    
    /* Action Buttons in Checkout */
    .checkout-actions {
        display: flex !important;
        flex-direction: column !important;
        gap: 4px !important;
        width: 100% !important;
    }
    
    #btn-print-draft, #btn-process-checkout {
        width: 100% !important;
        padding: 8px !important;
        font-size: 11px !important;
        height: auto !important;
        box-sizing: border-box !important;
        text-align: center !important;
    }
    
    #btn-process-checkout {
        font-size: 12px !important;
        font-weight: bold !important;
    }
    
    /* Lock Screen on Mobile */
    .lock-box {
        width: 95% !important;
        padding: 15px !important;
    }
    
    /* Modals on Mobile */
    .pos-modal-content {
        width: 95% !important;
        padding: 12px !important;
    }
    
    /* Inventory tab table overflow */
    #tab-inventory {
        padding: 8px !important;
    }
    
    #tab-inventory table {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
    }
}