:root {
      --primary: #2563eb;
      --bg: #f8fafc;
      --panel: #ffffff;
      --text: #0f172a;
      --text-muted: #64748b;
      --border: #e2e8f0;
      
      --danger: #ef4444;
      --success: #10b981;
      --warning: #f59e0b;

      --mode-sale: #2563eb;
      --mode-restock: #7c3aed;
      --mode-damage: #ef4444;
      --mode-return: #059669;

      --radius: 8px;
      --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    }

    /* DARK MODE OVERRIDES */
    [data-theme="dark"] {
      --bg: #0f172a;
      --panel: #1e293b;
      --text: #f1f5f9;
      --text-muted: #94a3b8;
      --border: #334155;
      --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    }

    body { margin: 0; font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); display: flex; height: 100vh; overflow: hidden; transition: background 0.3s; }
    * { box-sizing: border-box; }

    /* LAYOUT */
    .sidebar { width: 240px; background: #1e293b; color: white; display: flex; flex-direction: column; flex-shrink: 0; transition: transform 0.3s ease; z-index: 50; }
    
    /* BRAND & PLAN BADGE */
    .brand { padding: 20px 20px 10px 20px; font-weight: 700; font-size: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 70px; }
    .brand img { max-height: 40px; max-width: 100%; object-fit: contain; margin-bottom: 5px; }
    
    .plan-badge { 
      font-size: 10px; text-transform: uppercase; padding: 2px 8px; border-radius: 10px; font-weight: 800; letter-spacing: 0.5px; margin-top: 5px; background: #334155; color: #cbd5e1; border: 1px solid #475569;
    }
    .plan-badge.pro {
      background: linear-gradient(135deg, #fcd34d 0%, #f59e0b 100%);
      color: #78350f;
      border: 1px solid #fbbf24;
      box-shadow: 0 2px 10px rgba(245, 158, 11, 0.4);
      text-shadow: 0 1px 0 rgba(255,255,255,0.4);
    }

    .sb-menu { flex: 1; padding: 10px; overflow-y: auto; border-top: 1px solid #334155; margin-top: 10px; }
    .sb-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border: 0; background: transparent; color: #cbd5e1; font-weight: 500; font-size: 14px; text-align: left; cursor: pointer; border-radius: 6px; margin-bottom: 2px; }
    .sb-btn:hover { background: #334155; color: white; }
    .sb-btn.active { background: var(--primary); color: white; }
    .sb-divider { height: 1px; background: #334155; margin: 8px 0; }
    .sb-label { font-size: 11px; text-transform: uppercase; color: #64748b; font-weight: 700; padding: 10px 12px 4px; }
    .powered-by { font-size: 10px; color: #64748b; text-align: center; padding: 15px; border-top: 1px solid #334155; margin-top: auto; }
    
    /* Overlay for mobile sidebar */
    .sb-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 45; display: none; }
    .sb-overlay.show { display: block; }

    .main { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
    .topbar { background: var(--panel); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; gap: 15px; }
    .toggle-sb { display: none; background:none; border:none; font-size: 20px; cursor: pointer; color: var(--text); padding: 5px; }
    .action-btn { background: none; border: none; font-size: 18px; cursor: pointer; padding: 8px; border-radius: 50%; color: var(--text-muted); transition: background 0.2s; display: flex; align-items: center; justify-content: center; }
    .action-btn:hover { background: var(--bg); color: var(--primary); }
    .action-btn.rotating .spinner { border-color: var(--primary); border-top-color: transparent; }

    /* UI SWAP: Categories Bigger, Search fixed width */
    .category-scroll { flex: 1; display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; align-items: center; }
    .cat-pill { background: var(--panel); border: 1px solid var(--border); padding: 8px 16px; border-radius: 20px; font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; color: var(--text-muted); transition: all 0.2s; }
    .cat-pill:hover { border-color: var(--primary); color: var(--primary); }
    .cat-pill.active { background: var(--primary); border-color: var(--primary); color: white; }
    
    .search-wrap { width: 220px; position: relative; flex-shrink: 0; }
    .input-search { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); padding: 10px 12px; border-radius: var(--radius); font-size: 14px; outline: none; transition: all 0.2s; }
    .input-search:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.1); }
    
    .content { flex: 1; display: flex; overflow: hidden; }
    .grid-area { flex: 1; padding: 20px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; align-content: start; -webkit-overflow-scrolling: touch; }

    /* CARD */
    .p-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: transform 0.1s; display: flex; flex-direction: column; position: relative; }
    .p-card:active { transform: scale(0.98); }
    .p-card:hover { border-color: var(--text-muted); }
    
    /* Standard Image (for category view) */
    .p-img { height: 120px; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 12px; font-weight: 600; flex-shrink: 0; position: relative; }
    .p-img img { width: 100%; height: 100%; object-fit: cover; }
    
    /* Body */
    .p-body { padding: 12px; flex: 1; display: flex; flex-direction: column; }
    .p-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; height: 34px; overflow: hidden; line-height: 1.3; color: var(--text); }
    .p-meta { font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
    .p-price { font-weight: 700; color: var(--text); font-size: 14px; margin-top: auto; }
    
    .stock-tag { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 10px; color: var(--text); border: 1px solid var(--border); }
    .stock-tag.low { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
    .p-sku-small { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

    /* --- OVERLAYS FOR CATEGORY VIEW --- */
    .p-overlay-price { position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,0.7); color: white; padding: 4px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; z-index: 10; pointer-events: none; }
    .p-overlay-stock { position: absolute; top: 6px; right: 6px; background: rgba(255,255,255,0.9); color: #0f172a; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; border: 1px solid #e2e8f0; z-index: 10; pointer-events: none; }
    .p-overlay-stock.low { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

    /* PIN & CAT PILL */
    .p-overlay-cat { position: absolute; top: 6px; left: 6px; background: var(--primary); color: white; padding: 2px 8px; border-radius: 12px; font-size: 10px; font-weight: 600; z-index: 10; opacity: 0.9; }
    .p-pin-btn { position: absolute; top: 6px; left: 6px; z-index: 20; background: rgba(255,255,255,0.8); border: 1px solid #ccc; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; font-size: 12px; cursor: pointer; color: #94a3b8; transition: all 0.2s; user-select: none; -webkit-user-select: none; }
    .p-pin-btn.pinned { background: #fef3c7; color: #d97706; border-color: #f59e0b; }
    .p-card:hover .p-pin-btn, .p-pin-btn.pinned { opacity: 1; }
    .p-pin-btn { opacity: 0; }
    
    /* --- STYLES FOR 'ALL PRODUCTS' (NO IMG) VIEW --- */
    .p-card.no-img { min-height: 100px; justify-content: center; }
    .p-card.no-img .p-body { justify-content: center; height: 100%; }
    .p-card.no-img .p-name { font-size: 14px; height: auto; max-height: none; margin-bottom: 8px; }
    .p-card.no-img .p-row { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
    /* Pin button for no-img card */
    .p-card.no-img .p-pin-btn { top: 8px; right: 8px; left: auto; }
    
    /* CART */
    .cart-panel { width: 320px; background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 40; transition: transform 0.3s; }
    .cart-head { padding: 8px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap:8px; }
    
    /* Small Header Row */
    .cart-head-row { display: flex; justify-content: space-between; align-items: center; }
    .mode-badge { font-size: 10px; font-weight: 800; padding: 4px 8px; border-radius: 4px; color: white; }
    
    /* Multi-cart Tabs - Smaller & Upside */
    .cart-tabs { display: flex; gap: 4px; width: 100%; margin-bottom: 4px; }
    .c-tab { flex: 1; padding: 6px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; border-radius: 4px; font-size: 11px; font-weight: 600; color: var(--text-muted); transition: all 0.2s; text-align: center; }
    .c-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
    
    .cart-items { flex: 1; overflow-y: auto; padding: 10px; -webkit-overflow-scrolling: touch; }
    .cart-item { display: flex; gap: 10px; padding: 10px; border-bottom: 1px solid var(--border); }
    .ci-info { flex: 1; }
    .ci-name { font-size: 13px; font-weight: 600; margin-bottom: 2px; color: var(--text); }
    .ci-meta { font-size: 11px; color: var(--text-muted); }
    .qty-wrap { display: flex; align-items: center; background: var(--bg); border-radius: 6px; border: 1px solid var(--border); }
    .qty-btn { width: 32px; height: 32px; border: 0; background: transparent; cursor: pointer; font-weight: bold; color: var(--text); display: flex; align-items: center; justify-content: center; }
    .qty-val { width: 30px; text-align: center; font-size: 12px; font-weight: 600; border:0; background: transparent; color: var(--text); }
    
    .cart-footer { padding: 16px; border-top: 1px solid var(--border); background: var(--bg); }
    .input-row { display: flex; gap: 8px; margin-bottom: 8px; }
    .input-sm { 
      flex: 1 1 0; 
      min-width: 0; 
      padding: 8px; 
      border: 1px solid var(--border); 
      border-radius: 6px; 
      font-size: 13px; 
      outline: none; 
      height: 36px; 
      background: var(--panel); 
      color: var(--text);
    }
    
    /* Quick Cash Buttons */
    .quick-cash-btn { background: var(--panel); border: 1px solid var(--border); color: var(--text-muted); font-size: 11px; font-weight: 600; border-radius: 4px; cursor: pointer; padding: 0 8px; transition: all 0.1s; }
    .quick-cash-btn:active { background: var(--border); transform: translateY(1px); }

    .totals-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
    .totals-row.final { color: var(--text); font-weight: 800; font-size: 16px; margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px; }
    .btn-checkout { width: 100%; padding: 12px; background: var(--primary); color: white; border: 0; border-radius: var(--radius); font-weight: 600; cursor: pointer; margin-top: 12px; height: 44px; font-size: 14px; position: relative; }
    .btn-checkout:disabled { background: var(--text-muted); cursor: not-allowed; opacity: 0.7; }
    
    /* SPINNER */
    .spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #fff; animation: spin 1s ease-in-out infinite; vertical-align: middle; margin-right: 8px; }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* VIEWS */
    .view-panel { padding: 20px; width: 100%; max-width: 1000px; margin: 0 auto; overflow-y: auto; display: none; -webkit-overflow-scrolling: touch; color: var(--text); }
    .view-panel.active { display: block; }
    .simple-table { width: 100%; border-collapse: collapse; font-size: 13px; color: var(--text); }
    .simple-table th { text-align: left; padding: 10px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
    .simple-table td { padding: 10px; border-bottom: 1px solid var(--border); }

    /* DASHBOARD & EOD */
    .kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 20px; }
    .kpi-box { background: var(--panel); border: 1px solid var(--border); padding: 15px; border-radius: var(--radius); }
    .kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
    .kpi-val { font-size: 24px; font-weight: 700; color: var(--text); margin-top: 5px; display:flex; align-items:center; gap:8px; }
    
    .kpi-comp { font-size: 12px; font-weight: 500; }
    .comp-up { color: #10b981; }
    .comp-down { color: #ef4444; }
    .comp-neutral { color: #64748b; }

    .chart-container { 
      background: var(--panel); 
      border: 1px solid var(--border); 
      padding: 15px; 
      border-radius: var(--radius); 
      margin-bottom: 20px; 
      height: 320px; 
      position: relative; 
    }
    .chart-svg { width: 100%; height: 100%; display: block; }
    .chart-tooltip { position: absolute; background: #1e293b; color: white; padding: 4px 8px; border-radius: 4px; font-size: 11px; pointer-events: none; opacity: 0; transition: opacity 0.2s; }
    
    /* Receipt Style */
    .receipt { font-family: 'Courier New', Courier, monospace; border: 1px solid #ccc; padding: 20px; background: #fffaf0; color: #333; }
    .receipt h3 { text-align: center; border-bottom: 1px dashed #999; padding-bottom: 10px; margin-bottom: 10px; }
    .receipt-row { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 14px; }
    .receipt-hr { border-top: 1px dashed #999; margin: 10px 0; }

    /* CHART BAR CSS */
    .bar-row { display: flex; align-items: center; margin-bottom: 8px; font-size: 12px; }
    .bar-label { width: 100px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .bar-track { flex: 1; background: var(--bg); height: 8px; border-radius: 4px; overflow: hidden; margin: 0 10px; }
    .bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }
    .bar-val { width: 60px; text-align: right; font-weight: 600; color: var(--text); }

    /* SETTINGS LIST */
    .setting-item { display:flex; justify-content:space-between; align-items:center; padding:10px; border-bottom:1px solid var(--border); background:var(--panel); color: var(--text); }
    .setting-item:first-child { border-top-left-radius:8px; border-top-right-radius:8px; }
    .setting-item:last-child { border-bottom:0; border-bottom-left-radius:8px; border-bottom-right-radius:8px; }
    .del-btn { color: #ef4444; background:none; border:0; font-weight:600; cursor:pointer; padding:5px 10px; }
    
    .status-color-input { width: 30px; height: 30px; padding: 0; border: none; border-radius: 50%; overflow: hidden; cursor: pointer; background: none; }
    .status-color-input::-webkit-color-swatch-wrapper { padding: 0; }
    .status-color-input::-webkit-color-swatch { border: none; border-radius: 50%; border:1px solid rgba(0,0,0,0.1); }

    /* POP ANIMATION */
    @keyframes popfade {
      0% { transform: translate(-50%, 20px) scale(0.95); opacity: 0; }
      15% { transform: translate(-50%, 0) scale(1); opacity: 1; }
      85% { transform: translate(-50%, 0) scale(1); opacity: 1; }
      100% { transform: translate(-50%, -10px) scale(0.95); opacity: 0; }
    }
    .added-popup {
        position: fixed;
        bottom: 80px; 
        left: 50%;
        transform: translateX(-50%); 
        background: rgba(15, 23, 42, 0.95);
        color: white;
        padding: 12px 24px;
        border-radius: 50px; 
        z-index: 3000;
        pointer-events: none;
        animation: popfade 2s forwards; 
        display: flex; align-items: center; justify-content: center; gap: 8px;
        font-weight: 600;
        font-size: 14px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
        white-space: nowrap;
    }

    /* LOGIN & LOCKED CSS */
    .locked-feature { opacity: 0.5; pointer-events: none; position: relative; }
    .locked-icon { position: absolute; top:50%; left:50%; transform:translate(-50%,-50%); font-size:24px; }
    
    .pin-overlay { position: fixed; inset: 0; background: #0f172a; z-index: 5000; display: flex; align-items: center; justify-content: center; flex-direction: column; }
    .pin-box { width: 300px; padding: 20px; background: white; border-radius: 12px; text-align: center; }
    .pin-display { width: 100%; font-size: 32px; padding: 10px; text-align: center; margin-bottom: 20px; letter-spacing: 5px; border: 2px solid #e2e8f0; border-radius: 8px; background: #fff; color: #333; }
    .pin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
    .pin-btn { background: #f1f5f9; border: 0; padding: 15px; font-size: 20px; border-radius: 8px; cursor: pointer; color: #334155; font-weight: bold; }
    .pin-btn:active { background: #cbd5e1; }
    .pin-btn.enter { background: #2563eb; color: white; grid-column: span 3; }
    
    .user-info { padding: 15px; font-size: 12px; color: #94a3b8; border-top: 1px solid #334155; margin-top: auto; display:flex; justify-content:space-between; align-items:center; }
    .logout-btn { background:none; border:0; color:#ef4444; cursor:pointer; font-weight:bold; }
    
    /* CUSTOM FILE UPLOAD BUTTON */
    .file-btn-wrap { display: inline-block; position: relative; }
    .file-btn-wrap input[type="file"] { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

    /* MOBILE / TABLET OPTIMIZATION */
    @media (max-width: 900px) {
      .sidebar { 
        position: fixed; 
        height: 100%; 
        width: 260px; 
        max-width: 80vw;
        transform: translateX(-100%); 
        box-shadow: 2px 0 15px rgba(0,0,0,0.3); 
        z-index: 1001;
      }
      .sidebar.open { transform: translateX(0); }
      .toggle-sb { display: block; }
      
      .cart-panel { position: fixed; top: 0; right: 0; bottom: 0; height: 100%; transform: translateX(100%); width: 100%; max-width: 320px; box-shadow: -2px 0 10px rgba(0,0,0,0.1); }
      .cart-panel.open { transform: translateX(0); }
      .mob-cart-toggle { display: flex !important; }
      
      .topbar { flex-wrap: wrap; gap: 10px; padding: 10px; }
      .category-scroll { order: 2; width: 100%; margin: 0; flex-basis: 100%; }
      .search-wrap { order: 1; flex: 1; width: auto; }
      .toggle-sb, .mob-cart-toggle-btn { order: 0; }
      .action-btn { font-size: 20px; padding: 10px; } 

      .grid-area { padding: 10px; gap: 8px; grid-template-columns: repeat(3, 1fr); }
      .p-card { height: 100%; display: flex; flex-direction: column; background: var(--panel); }
      .p-img { aspect-ratio: 1 / 1; height: auto; width: 100%; background: var(--bg); flex-shrink: 0; position: relative; }
      .p-body { padding: 8px 6px; flex: 1; display: flex; flex-direction: column; justify-content: space-between; min-height: 0; }
      .p-name { font-size: 12px; font-weight: 600; line-height: 1.2; max-height: 2.4em; margin-bottom: 6px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; color: var(--text); flex-shrink: 0; }
      .p-meta { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 4px; flex-shrink: 0; }
      .stock-tag { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 2px 8px; font-size: 10px; font-weight: 700; color: var(--text-muted); align-self: flex-start; }
      .stock-tag.low { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
      .p-sku-small { font-size: 10px; color: var(--text-muted); display: block; margin-bottom:2px; }
      .p-price { font-size: 13px; font-weight: 700; margin-top: auto; color: var(--primary); flex-shrink: 0; }
      
      .view-panel { padding: 15px; }
      .sb-btn { padding: 15px; }
      .input-sm, .input-search { font-size: 16px; }
    }

    .mob-cart-toggle { display: none; position: fixed; bottom: 20px; right: 20px; background: var(--primary); color: white; width: 56px; height: 56px; border-radius: 50%; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(37,99,235,0.3); z-index: 60; font-size: 24px; cursor: pointer; }

    .toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1e293b; color: white; padding: 10px 20px; border-radius: 30px; font-size: 13px; z-index: 200; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
    .toast.show { opacity: 1; }
    .modal-overlay { position:fixed;inset:0;background:rgba(0,0,0,0.5);display:none;align-items:center;justify-content:center;z-index:2000; padding: 20px; }
    .modal-box { background:var(--panel); color:var(--text); padding:20px;border-radius:8px;width:100%;max-width:500px;max-height:90vh;overflow-y:auto; box-shadow: var(--shadow); position: relative; }
    .modal-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:15px; }
    .modal-head h3 { margin:0; font-size:16px; color: var(--text); }
