:root {
    --bg-main: #f4f7f6; --bg-surface: #ffffff; --bg-surface-elevated: #f8fafc;
    --text-primary: #0f172a; --text-secondary: #64748b; --accent-color: #2563eb;
    --border-color: #e2e8f0; --glass-bg: rgba(255, 255, 255, 0.9);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.05); --shadow-md: 0 8px 24px rgba(0,0,0,0.08);
    --radius-lg: 16px; --radius-md: 12px; --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --danger: #ef4444; --success: #10b981;
}

[data-theme="dark"] {
    --bg-main: #0b1120; --bg-surface: #1e293b; --bg-surface-elevated: #334155;
    --text-primary: #f8fafc; --text-secondary: #94a3b8; --accent-color: #3b82f6;
    --border-color: #334155; --glass-bg: rgba(30, 41, 59, 0.9);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Tajawal', sans-serif; background: var(--bg-main); color: var(--text-primary); transition: var(--transition-fast); padding-bottom: 80px; overflow-x: hidden; }

.glass-effect { background: var(--glass-bg); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }

.main-header { position: sticky; top: 0; z-index: 100; padding: 15px 20px; border-bottom: 1px solid var(--border-color); }
.header-container { display: flex; justify-content: space-between; align-items: center; max-width: 1200px; margin: 0 auto; }
.logo { font-size: 24px; font-weight: 900; } .logo span { color: var(--accent-color); }

.desktop-nav { display: none; }
.icon-btn { background: var(--bg-surface-elevated); border: 1px solid var(--border-color); color: var(--text-primary); cursor: pointer; padding: 8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

.view-section { display: none; animation: fadeIn 0.3s ease; max-width: 1200px; margin: 0 auto; }
.view-section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.hero-carousel { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 15px; padding: 20px; scrollbar-width: none; scroll-behavior: smooth; }
.hero-carousel::-webkit-scrollbar { display: none; }
.carousel-slide { flex: 0 0 90%; scroll-snap-align: start; border-radius: var(--radius-lg); background: var(--bg-surface); border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); display: flex; align-items: center; padding: 15px; position: relative; overflow: hidden; min-height: 120px; }
.offer-img { width: 90px; height: 90px; border-radius: var(--radius-md); overflow: hidden; flex-shrink: 0; border: 1px solid var(--border-color); background: var(--bg-surface-elevated); display: flex; align-items: center; justify-content: center; }
.offer-img img { width: 100%; height: 100%; object-fit: cover; }
.offer-info { flex: 1; padding-right: 15px; display: flex; flex-direction: column; justify-content: center; }
.offer-info h3 { font-size: 15px; font-weight: 800; color: var(--text-primary); line-height: 1.4; margin-bottom: 5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.offer-badge { display: inline-block; background: rgba(239, 68, 68, 0.1); color: var(--danger); font-size: 10px; font-weight: 800; padding: 3px 8px; border-radius: 6px; margin-bottom: 5px; width: max-content; }
.offer-price { font-size: 18px; font-weight: 900; color: var(--accent-color); }
.offer-price span { font-size: 11px; color: var(--text-secondary); font-weight: 600; }

.sticky-top { position: sticky; top: 67px; z-index: 90; }
.search-filter-container { display: flex; gap: 10px; padding: 15px 20px; border-bottom: 1px solid var(--border-color); }
#brandSelect { width: 120px; padding: 0 10px; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); color: var(--text-primary); font-family: inherit; font-size: 13px; font-weight: 700; outline: none; }
.search-box { flex: 1; position: relative; display: flex; align-items: center; }
.search-box svg { position: absolute; right: 12px; color: var(--text-secondary); }
.search-box input { width: 100%; padding: 12px 40px 12px 15px; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); font-family: inherit; color: var(--text-primary); font-size: 14px; outline: none; transition: 0.2s; }
.search-box input:focus, #brandSelect:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }

.categories-nav { padding: 15px 0 5px; }
.categories-list { display: flex; gap: 10px; padding: 0 20px; overflow-x: auto; scrollbar-width: none; }
.categories-list::-webkit-scrollbar { display: none; }
.category-btn { background: var(--bg-surface); color: var(--text-secondary); border: 1px solid var(--border-color); padding: 8px 16px; border-radius: 20px; font-family: inherit; font-size: 13px; font-weight: 700; white-space: nowrap; cursor: pointer; transition: var(--transition-fast); }
.category-btn.active { background: var(--text-primary); color: var(--bg-surface); border-color: var(--text-primary); }

.section-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px 15px; }
.section-header h2 { font-size: 18px; font-weight: 800; }
.badge { background: var(--bg-surface); border: 1px solid var(--border-color); padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; }

.products-grid { display: flex; flex-direction: column; gap: 12px; padding: 0 20px 20px; }

.product-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 12px; display: flex; gap: 15px; box-shadow: var(--shadow-sm); position: relative; cursor: pointer; }
.product-image { width: 90px; height: 90px; background: var(--bg-surface-elevated); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; border: 1px solid var(--border-color); }
.product-image img { width: 100%; height: 100%; object-fit: cover; }

.product-details { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.product-name { font-size: 14px; font-weight: 800; color: var(--text-primary); line-height: 1.4; margin-bottom: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; padding-left: 25px;}
.product-tech { font-family: monospace; font-size: 11px; color: var(--text-secondary); margin-bottom: 8px; }

.price-container { display: flex; align-items: baseline; gap: 8px; margin-top: auto; flex-wrap: wrap; }
.new-price { font-size: 16px; font-weight: 800; color: var(--accent-color); }
.new-price span { font-size: 11px; }
.old-price { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-decoration: line-through; }

.qty-badge { position: absolute; top: 12px; left: 12px; font-size: 10px; font-weight: 700; background: rgba(16, 185, 129, 0.1); color: var(--success); padding: 3px 8px; border-radius: 6px; }
.qty-badge.danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.fav-btn { position: absolute; bottom: 12px; left: 12px; background: var(--bg-surface-elevated); border: 1px solid var(--border-color); width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); cursor: pointer; transition: 0.2s; z-index: 2; }
.fav-btn.active { color: var(--danger); border-color: rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.05); }
.fav-btn.active svg { fill: var(--danger); }

.profile-container { padding: 20px; }
.profile-header { text-align: center; margin-bottom: 20px; }
.profile-header h2 { font-size: 22px; font-weight: 800; margin-bottom: 5px; }
.profile-header p { font-size: 13px; color: var(--text-secondary); }
.client-info-card { background: linear-gradient(135deg, var(--accent-color), #1e40af); border-radius: var(--radius-lg); padding: 20px; color: #fff; display: flex; align-items: center; gap: 15px; box-shadow: var(--shadow-md); margin-bottom: 20px; }
.client-avatar { width: 50px; height: 50px; background: rgba(255,255,255,0.2); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.client-details { flex: 1; }
.client-details h3 { font-size: 18px; font-weight: 800; margin-bottom: 2px; }
.client-details p { font-size: 12px; opacity: 0.8; font-family: monospace; }
.client-debt { text-align: left; background: rgba(0,0,0,0.2); padding: 10px 15px; border-radius: 12px; }
.client-debt span { display: block; font-size: 10px; opacity: 0.8; margin-bottom: 2px; }
.client-debt strong { font-size: 16px; font-weight: 900; color: #fca5a5; }

.invoices-list { display: flex; flex-direction: column; gap: 12px; }
.invoice-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 15px; box-shadow: var(--shadow-sm); cursor: pointer; }
.invoice-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; border-bottom: 1px dashed var(--border-color); padding-bottom: 10px; }
.invoice-num { font-weight: 800; font-size: 14px; }
.invoice-date { font-size: 11px; color: var(--text-secondary); }
.invoice-card-body { display: flex; justify-content: space-between; align-items: center; }
.invoice-total { font-size: 16px; font-weight: 900; color: var(--accent-color); }
.inv-status { font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 6px; }
.inv-status.success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.inv-status.warning { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.inv-status.danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.sheet-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 998; backdrop-filter: blur(2px); }
.sheet-overlay.open { opacity: 1; pointer-events: all; }
.bottom-sheet { position: fixed; bottom: 0; left: 0; right: 0; background-color: var(--bg-surface); border-radius: 24px 24px 0 0; padding: 20px; z-index: 999; transform: translateY(100%); transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1); box-shadow: 0 -10px 40px rgba(0,0,0,0.2); max-height: 85vh; overflow-y: auto; }
.bottom-sheet.open { transform: translateY(0); }
.sheet-handle { width: 40px; height: 5px; background-color: var(--border-color); border-radius: 10px; margin: 0 auto 20px; }
.sheet-details-img { width: 100%; height: 250px; background: var(--bg-surface-elevated); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; overflow: hidden; margin-bottom: 20px; border: 1px solid var(--border-color); }
.sheet-details-img img { width: 100%; height: 100%; object-fit: contain; }
.sheet-details-title { font-size: 20px; font-weight: 800; margin-bottom: 5px; line-height: 1.4; }
.sheet-tech-name { font-size: 12px; color: var(--text-secondary); font-family: monospace; margin-bottom: 15px; display: block; }
.sheet-details-price { font-size: 24px; font-weight: 800; color: var(--accent-color); margin-bottom: 20px; }
.sheet-specs { background: var(--bg-surface-elevated); border-radius: var(--radius-md); padding: 15px; margin-bottom: 20px; border: 1px solid var(--border-color); }
.sheet-specs li { list-style: none; display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border-color); font-size: 14px; }
.sheet-specs li:last-child { border-bottom: none; }
.sheet-specs span:first-child { color: var(--text-secondary); }
.sheet-specs span:last-child { font-weight: 700; }
.btn-primary { width: 100%; padding: 16px; background-color: var(--accent-color); color: #fff; border: none; border-radius: var(--radius-md); font-family: inherit; font-size: 16px; font-weight: 700; cursor: pointer; transition: 0.2s; }
.btn-primary:active { transform: scale(0.98); }

.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; border-top: 1px solid var(--border-color); display: flex; justify-content: space-around; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); z-index: 100; }
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 5px; cursor: pointer; color: var(--text-secondary); font-size: 11px; font-weight: 700; transition: var(--transition-fast); }
.nav-item.active { color: var(--accent-color); }

.toast-container { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 10px; pointer-events: none; width: 90%; max-width: 300px; }
.toast { background: var(--text-primary); color: var(--bg-surface); padding: 12px 20px; border-radius: 30px; font-size: 13px; font-weight: 700; box-shadow: var(--shadow-md); animation: slideDown 0.3s; text-align: center; }

.skeleton { background: linear-gradient(90deg, var(--bg-surface-elevated) 25%, var(--border-color) 50%, var(--bg-surface-elevated) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 8px; }

@media (min-width: 768px) {
    body { padding-bottom: 0; }
    .bottom-nav { display: none; }
    
    .desktop-nav { display: flex; align-items: center; gap: 25px; }
    .desktop-nav .nav-item { flex-direction: row; font-size: 15px; color: var(--text-secondary); position: relative; padding: 5px 0; }
    .desktop-nav .nav-item:hover { color: var(--text-primary); }
    .desktop-nav .nav-item.active { color: var(--accent-color); }
    .desktop-nav .nav-item.active::after { content: ''; position: absolute; bottom: -5px; left: 0; right: 0; height: 3px; background: var(--accent-color); border-radius: 3px; }

    .hero-carousel { gap: 20px; padding: 25px 20px; }
    .carousel-slide { flex: 0 0 calc(25% - 15px); min-height: 100px; padding: 12px; }
    .offer-img { width: 70px; height: 70px; }
    .offer-info h3 { font-size: 13px; }
    .offer-price { font-size: 15px; }

    .products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 15px; }
    
    .bottom-sheet { width: 500px; left: 50%; transform: translate(-50%, 100%); border-radius: 24px 24px 0 0; }
    .bottom-sheet.open { transform: translate(-50%, 0); }
}