:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --header-height: 60px;
    --sidebar-width: 250px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 0.5rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

/* Layout */
.app-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
    background-color: #eff6ff;
    /* light blue 50 */
    color: var(--primary-color);
}

.nav-item i {
    font-size: 1.25rem;
}

button.mobile-close {
    display: none;
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    height: var(--header-height);
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    display: none;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-primary);
    padding: 0.5rem;
    margin-right: 0.5rem;
}

.content-area {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
}

/* POS Layout */
.pos-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    height: 100%;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    align-content: start;
}

.product-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--primary-color);
}

.product-image {
    width: 100%;
    height: 120px;
    background-color: #f1f5f9;
    border-radius: calc(var(--radius) - 2px);
    object-fit: cover;
}

.product-info h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.product-price {
    color: var(--primary-color);
    font-weight: 700;
}

.product-stock {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Cart Section */
.cart-section {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}

.cart-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #f1f5f9;
}

.cart-item-details {
    flex: 1;
}

.cart-item-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.cart-item-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-qty {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-primary);
    font-weight: 600;
}

.btn-qty:hover {
    background-color: #f8fafc;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-qty:active {
    transform: scale(0.95);
}

.cart-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background-color: #f8fafc;
}

.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

/* Global Buttons */
.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2), 0 2px 4px -1px rgba(37, 99, 235, 0.1);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3), 0 4px 6px -2px rgba(37, 99, 235, 0.1);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    padding: 0.75rem 1.5rem;
    background-color: white;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background-color: #f8fafc;
    border-color: var(--text-secondary);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary:active {
    transform: translateY(0);
}

.btn-danger {
    padding: 0.5rem 1rem;
    background-color: white;
    color: var(--danger-color);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-danger:hover {
    background-color: #fee2e2;
    border-color: var(--danger-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(239, 68, 68, 0.2);
}

.btn-danger:active {
    transform: translateY(0);
}

.btn-edit {
    padding: 0.5rem 1rem;
    background-color: white;
    color: var(--primary-color);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    margin-right: 0.5rem;
    transition: all 0.2s ease;
}

.btn-edit:hover {
    background-color: #eff6ff;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.btn-edit:active {
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        /* display: none; */
        /* Mobile menu to be implemented if needed used hamburger */
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 250px;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: var(--shadow);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: block;
    }

    .menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .menu-overlay.active {
        display: block;
        opacity: 1;
    }

    /* General Layout Adjustments */
    .content-area {
        padding: 1rem;
        padding-bottom: 80px;
        /* Space for bottom nav/actions on mobile */
    }

    .header {
        padding: 0 1rem;
    }

    .pos-layout {
        grid-template-columns: 1fr;
        padding-bottom: 80px;
        /* Space for collapsed cart */
    }

    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .cart-section {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 85vh;
        border-radius: 1.5rem 1.5rem 0 0;
        box-shadow: 0 -4px 20px -5px rgb(0 0 0 / 0.2);
        z-index: 100;
        transform: translateY(calc(100% - 70px));
        /* Show only header */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: white;
        display: flex;
        flex-direction: column;
    }

    .cart-section.open {
        transform: translateY(0);
    }

    /* Add a handle visual cue */
    .cart-header {
        cursor: pointer;
        background: var(--primary-color);
        color: white;
        border-radius: 1.5rem 1.5rem 0 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem 1.5rem !important;
        /* Override standard padding */
    }

    .cart-header::after {
        content: "▲";
        /* Up arrow initially */
        font-size: 0.8rem;
        transition: transform 0.3s;
    }

    .cart-section.open .cart-header::after {
        transform: rotate(180deg);
    }

    /* Adjust cart content when collapsed */
    .cart-items {
        opacity: 0;
        /* Hide items when transition happens if needed, or just let them be covered */
        transition: opacity 0.2s;
    }

    .cart-section.open .cart-items {
        opacity: 1;
    }

    /* Form Adjustments */
    .two-col {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Responsive Tables (Card View) */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        background: white;
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        margin-bottom: 1rem;
        padding: 1rem;
        box-shadow: var(--shadow-sm);
    }

    td {
        border: none;
        position: relative;
        padding-left: 0;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
    }

    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        text-align: left;
        margin-right: 1rem;
    }

    /* Hide empty placeholder rows on mobile if needed */
    td[colspan] {
        text-align: center;
        display: block;
        width: 100%;
    }

    /* Horizontal Scroll for Filters */
    .filter-scroll-container {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
        /* Space for scrollbar if visible */
        max-width: 100%;
    }

    .filter-scroll-container::-webkit-scrollbar {
        height: 4px;
        /* Thin scrollbar */
    }

    .filter-scroll-container::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 4px;
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--surface-color);
    padding: 0;
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-family: inherit;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Receipt Printing */
@media print {
    body * {
        visibility: hidden;
    }

    #receipt-area,
    #receipt-area * {
        visibility: visible;
    }

    #receipt-area {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }

    @page {
        margin: 0;
        size: auto;
    }
}

/* Hidden Receipt Area */
#receipt-area {
    display: none;
    /* Hidden on screen */
    width: 58mm;
    /* Standard thermal width */
    padding: 10px;
    background: white;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    color: black;
}

.receipt-header {
    text-align: center;
    margin-bottom: 10px;
    border-bottom: 1px dashed black;
    padding-bottom: 5px;
}

.receipt-title {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 5px;
}

.receipt-info {
    font-size: 10px;
    margin-bottom: 2px;
}

.receipt-items {
    width: 100%;
    margin-bottom: 10px;
}

.receipt-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
}

.item-name {
    width: 100%;
    margin-bottom: 2px;
}

.item-details {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding-left: 10px;
}

.receipt-total {
    border-top: 1px dashed black;
    padding-top: 5px;
    margin-top: 5px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    margin-bottom: 5px;
}

.receipt-footer {
    text-align: center;
    margin-top: 10px;
    font-size: 10px;
}