:root {
    --primary-color: #6200EA;
    --primary-hover: #3700b3;
    --secondary-color: #03DAC6;
    --bg-color: #F5F5FA;
    --card-bg: #FFFFFF;
    --text-color: #121212;
    --text-muted: #666;
    --border-color: #e0e0e0;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --radius-md: 0.5rem;
    --sidebar-width: 350px;
    --header-height: 70px;
}

#turbo-pos-app * {
    box-sizing: border-box;
}

#turbo-pos-app {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh; /* Fixed height, not min-height */
    overflow: hidden; /* Prevent app-level scroll */
    display: flex;
    flex-direction: column;
}

/* Ensure global scroll is killed if likely conflict with WP admin bar */
/* Ensure global scroll is killed only when POS is active */
body.turbo-pos-active {
    height: 100vh;
    margin: 0; 
    overflow: hidden; /* Prevent double scrollbars */
}

/* Header */
.turbo-pos-header {
    height: var(--header-height);
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 50;
}

.pos-brand h1 {
    font-size: 1.5rem;
    margin: 0;
    font-weight: 700;
    letter-spacing: 1px;
    color: white;
}

.pos-search-container {
    flex: 1;
    max-width: 600px;
    margin: 0 20px;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.search-input-wrapper input {
    width: 100%;
    padding: 10px 10px 10px 40px;
    border-radius: 20px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1rem;
    outline: none;
    transition: background 0.2s;
}

.search-input-wrapper input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.search-input-wrapper input:focus {
    background: rgba(255, 255, 255, 0.3);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.7;
}

.pos-user-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-role-badge {
    background: rgba(0,0,0,0.2);
    padding: 5px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
}

#pos-refresh-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#pos-refresh-btn:hover {
    background: rgba(255,255,255,0.1);
}

.pos-search-container {
    flex: 1;
    max-width: 600px;
    margin: 0 20px;
    display: flex; /* Align input and toggle side-by-side */
    align-items: center;
}

/* iOS Toggle Styles */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255,255,255,0.3);
    -webkit-transition: .4s;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    -webkit-transition: .4s;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--secondary-color); /* Use secondary color for active state */
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--secondary-color);
}

input:checked + .slider:before {
    -webkit-transform: translateX(20px);
    -ms-transform: translateX(20px);
    transform: translateX(20px);
}

/* Rounded sliders */
.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Main Layout */
.turbo-pos-main-layout {
    display: flex;
    flex: 1;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* Products Area */
.pos-products-area {
    flex: 1;
    padding: 0; /* Remove padding from parent so sticky bar touches edges */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.pos-category-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding: 20px 20px 10px 20px; /* Add padding here instead */
    position: sticky; /* Make it sticky */
    top: 0;
    background: var(--bg-color); /* Match background */
    z-index: 20; /* Ensure on top of products */
    flex-shrink: 0;
}

.pos-product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    padding: 0 20px 20px 20px; /* Add padding to grid */
}

.cat-tab {
    padding: 8px 16px;
    border: none;
    background: white;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-color);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}

.cat-tab.active, .cat-tab:hover {
    background: var(--primary-color);
    color: white;
}

.pos-product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
}

.pos-product-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.pos-product-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.product-image-placeholder {
    height: 120px;
    background: #e1e1e1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
}

.product-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.product-info h3 {
    margin: 0 0 5px;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
}

.product-info .sku {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 auto;
}

.product-info .price {
    margin-top: 10px;
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.1rem;
}

/* Sidebar Cart */
.pos-cart-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width); /* Fixed width */
    background: white;
    border-left: 1px solid var(--border-color);
    display: flex; /* Flex column to stack Header, List, Footer */
    flex-direction: column;
    max-height: 100%;
}

#pos-resize-handle:hover, #pos-resize-handle.active {
    background: var(--primary-color);
}

.cart-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.clear-cart-btn {
    background: transparent;
    border: none;
    color: #e53935;
    cursor: pointer;
    font-size: 0.9rem;
}

.cart-items-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    min-height: 0; /* CRITICAL: Allows flex child to shrink and show scrollbar */
}

.empty-state-cart {
    text-align: center;
    color: var(--text-muted);
    margin-top: 40px;
}

.cart-footer-summary {
    padding: 20px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.summary-row.total {
    font-weight: 700;
    font-size: 1.2rem;
    margin-top: 10px;
    border-top: 1px dashed var(--border-color);
    padding-top: 10px;
}

.cart-actions {
    margin-top: 20px;
}

.checkout-btn, #reserve-order-btn {
    width: 100%;
    border: none;
    color: white;
    padding: 15px;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}

.checkout-btn {
    background: var(--primary-color);
}

.checkout-btn:hover {
    background: var(--primary-hover);
}

#reserve-order-btn {
    background: #FF9800;
}

#reserve-order-btn:hover {
    background: #474747;
}

/* Cart Item Styling */
.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #eee;
    padding: 10px 0;
    gap: 10px;
}

.cart-item-left {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    gap: 10px;
}

.item-name {
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.cart-item-thumb {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid #eee;
    flex-shrink: 0;
}

.cart-item-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pos-price-input {
    width: 70px;
    padding: 5px;
    border: 1px solid #ddd;
    border-radius: 5px;
    text-align: right;
    font-weight: 600;
    color: var(--primary-color);
}

.item-line-total {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 50px;
    text-align: right;
}

.remove-item-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(229, 57, 53, 0.1);
    color: #e53935;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    transition: all 0.2s;
}

.remove-item-btn:hover {
    background: #e53935;
    color: white;
}

/* Variable Product Styles */
.pos-variations-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.pos-var-pill {
    display: flex;
    align-items: center;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 15px;
    padding: 2px 8px 2px 2px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
    max-width: 100%;
}

.pos-var-pill:hover {
    background: white;
    border-color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}

.pos-var-pill img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-right: 6px;
    object-fit: cover;
}

.pos-var-pill span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #333;
}

.pos-product-card.variable-product {
    border: 1px solid var(--primary-color); /* Highlight variables */
    background: #f9f9ff;
}

/* Sticky Cart Layout Tweaks */
.turbo-pos-main-layout {
    /* Ensure it takes full height minus header */
    height: calc(100vh - 70px);
    overflow: hidden; /* Prevent body scroll */
}

/* Make products list scrollable independently */
.pos-products-area {
    overflow-y: auto; 
    height: 100%;
    flex: 1;
}

/* Sidebar structure */
.pos-cart-sidebar {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Contain children */
}

.cart-items-container {
    flex: 1; /* Takes available space */
    overflow-y: auto; /* Scrollable */
}

.cart-footer-summary {
    flex-shrink: 0; /* Sticky at bottom */
    background: #fff;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05); /* Visual separation */
    z-index: 10;
    margin-bottom: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    .turbo-pos-main-layout {
        flex-direction: column;
        height: auto;
    }
    .pos-cart-sidebar {
        width: 100%;
        height: 50vh;
    }
}

/* Payment Popup Styles */
.pos-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none; /* Controlled by JS */
    align-items: center;
    justify-content: center;
}

.pos-popup-content {
    background: white;
    width: 100%;
    max-width: 500px;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.pos-popup-content h2 {
    margin-top: 0;
    margin-bottom: 20px;
    text-align: center;
    color: #333;
}

.payment-methods-grid {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.pm-btn {
    flex: 1;
    padding: 15px;
    border: 2px solid #ddd;
    background: #f9f9f9;
    font-weight: 600;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: #555;
}

.pm-btn:hover {
    background: #eee;
    border-color: #ccc;
}

.pm-btn.active {
    border-color: var(--primary-color);
    background: rgba(98, 0, 234, 0.05);
    color: var(--primary-color);
}

.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.pos-input {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-sizing: border-box;
}

.popup-actions {
    display: flex;
    gap: 15px;
}

.popup-actions button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 1rem;
}

#cancel-payment-btn {
    background: #e0e0e0;
    color: #333;
}

#finalize-payment-btn {
    background: #4CAF50;
    color: white;
}

#finalize-payment-btn:hover {
    background: #43a047;
}

#cancel-payment-btn:hover {
    background: #d5d5d5;
}
