:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-app: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #2d3748;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #f59e0b;
    --danger: #ef4444;
    --success: #10b981;
    --glass: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Tajawal', sans-serif;
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: grid;
    grid-template-columns: 240px 1fr 380px;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2.5rem;
}

.categories {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cat-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 1rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: right;
}

.cat-item i {
    font-size: 1.2rem;
}

.cat-item:hover {
    background: var(--glass);
    color: var(--text-main);
}

.cat-item.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.programmer-credits {
    margin-top: auto;
    padding: 1rem;
    background: var(--glass);
    border-radius: 12px;
    text-align: center;
    font-size: 0.85rem;
}

.programmer-credits span {
    color: var(--accent);
    display: block;
    margin-top: 0.25rem;
}

/* Main Content */
.main-content {
    background: var(--bg-app);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.search-box {
    position: relative;
    width: 350px;
}

.search-box i {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 0.75rem 2.8rem 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-sidebar);
    color: white;
    outline: none;
    transition: border-color 0.3s;
}

.search-box input:focus {
    border-color: var(--primary);
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.5rem;
}

.product-card {
    background: var(--bg-sidebar);
    border-radius: 16px;
    padding: 1rem;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.product-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.product-card .img-placeholder {
    width: 100%;
    height: 120px;
    background: var(--glass);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.product-card h4 {
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.product-card .price {
    color: var(--accent);
    font-weight: 700;
}

/* Cart Panel */
.cart-panel {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.cart-items {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.cart-item {
    display: grid;
    grid-template-columns: 50px 1fr auto;
    gap: 1rem;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.cart-item-info h5 {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.cart-item-info p {
    color: var(--accent);
    font-size: 0.85rem;
}

.qty-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--glass);
    padding: 0.4rem;
    border-radius: 8px;
}

.qty-btn {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-summary {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px dashed var(--border);
}

.summary-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.summary-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.25rem;
    font-weight: 700;
    margin: 1.5rem 0;
    color: var(--text-main);
}

.btn-primary {
    width: 100%;
    padding: 1rem;
    border-radius: 12px;
    border: none;
    background: var(--primary);
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    transition: color 0.3s;
}

.btn-icon:hover {
    color: var(--danger);
}

.empty-cart-msg {
    text-align: center;
    margin-top: 4rem;
    color: var(--text-muted);
}

.empty-cart-msg i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    color: #333;
    padding: 2rem;
    border-radius: 20px;
    width: 400px;
    max-height: 90vh;
    overflow-y: auto;
}

.receipt-paper {
    padding: 1rem;
}

.receipt-header {
    text-align: center;
    margin-bottom: 1rem;
}

.receipt-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.receipt-table th {
    text-align: right;
    border-bottom: 1px solid #ddd;
    padding-bottom: 0.5rem;
}

.receipt-table td {
    padding: 0.5rem 0;
}

.receipt-total-section {
    border-top: 1px solid #ddd;
    padding-top: 1rem;
    text-align: left;
}

.receipt-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: #666;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn-secondary {
    flex: 1;
    padding: 0.75rem;
    border-radius: 10px;
    border: 1px solid #ddd;
    background: #f8fafc;
    cursor: pointer;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 80px 1fr 300px;
    }
    .sidebar .logo span, .sidebar .cat-item span, .sidebar .programmer-credits p {
        display: none;
    }
    .sidebar {
        padding: 1rem 0.5rem;
        align-items: center;
    }
    .cat-item {
        justify-content: center;
        padding: 1rem;
    }
}

@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        height: 100vh;
        overflow: hidden;
    }

    .sidebar {
        flex-direction: row;
        height: 60px;
        position: fixed;
        bottom: 0;
        width: 100%;
        z-index: 100;
        padding: 0;
        border-right: none;
        border-top: 1px solid var(--border);
        justify-content: space-around;
        background: var(--bg-sidebar);
    }

    .sidebar .logo {
        display: none;
    }

    .categories {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        gap: 0;
    }

    .cat-item {
        flex-direction: column;
        gap: 4px;
        border-radius: 0;
        flex: 1;
    }

    .cat-item i {
        font-size: 1.2rem;
    }

    .cat-item span {
        display: block !important;
        font-size: 0.7rem;
    }

    .sidebar .programmer-credits {
        display: none;
    }

    .main-content {
        padding: 1rem;
        padding-bottom: 70px; /* Space for bottom nav */
    }

    .top-bar {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .search-box {
        width: 100%;
    }

    .cart-panel {
        position: fixed;
        right: -100%;
        top: 0;
        width: 100%;
        height: 100vh;
        z-index: 1000;
        transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        background: var(--bg-sidebar); /* Use sidebar bg for consistency */
        display: flex; 
        flex-direction: column;
        padding: 1.5rem;
    }

    .cart-panel.active {
        right: 0;
    }

    .cart-header {
        padding-top: 1rem;
    }

    .btn-cart-toggle {
        display: flex !important; /* Force display */
        position: fixed;
        bottom: 80px;
        right: 20px; /* Changed from left to right for RTL flow */
        width: 60px;
        height: 60px;
        border-radius: 50%;
        background: var(--primary);
        color: white;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5);
        z-index: 1500; /* Extremely high z-index */
        border: 2px solid white;
        cursor: pointer;
        animation: pulse 2s infinite;
    }

    @keyframes pulse {
        0% { transform: scale(1); }
        50% { transform: scale(1.1); }
        100% { transform: scale(1); }
    }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 1rem;
    }

    .product-card .img-placeholder {
        height: 90px;
        font-size: 2rem;
    }

    .product-card h4 {
        font-size: 0.9rem;
    }
}

.btn-cart-toggle {
    display: none;
}

.mobile-only {
    display: none;
}

#cartCountBadge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
}

    @keyframes scanMove {
        0% { top: 0; }
        100% { top: 100%; }
    }
}

/* Settings & Admin Styles */
.settings-container {
    background: var(--bg-sidebar);
    border-radius: 20px;
    padding: 2rem;
    border: 1px solid var(--border);
    animation: fadeIn 0.3s ease;
}

.settings-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.tab-btn {
    background: var(--glass);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th {
    text-align: right;
    padding: 1rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.admin-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.form-group input, .form-group select {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-app);
    color: white;
}

.sales-total-box {
    background: var(--glass);
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--primary);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media print {
    body * { visibility: hidden; }
    #printableReceipt, #printableReceipt * { visibility: visible; }
    #printableReceipt { position: absolute; left: 0; top: 0; width: 100%; }
}
