/* CSS Variables & Theme setup */
:root {
    --primary-color: #4F46E5; /* Indigo 600 */
    --primary-hover: #4338ca;
    --secondary-color: #e0e7ff;
    --secondary-text: #3730a3;
    
    /* Light Theme */
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-glass: rgba(255, 255, 255, 0.7);
    --border-color: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --nav-active-bg: #f1f5f9;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    
    /* Stats Colors */
    --c-green: #10b981;
    --c-green-bg: #d1fae5;
    --c-orange: #f59e0b;
    --c-orange-bg: #fef3c7;
    --c-purple: #8b5cf6;
    --c-purple-bg: #ede9fe;
}

[data-theme='dark'] {
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-glass: rgba(30, 41, 59, 0.7);
    --border-color: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --nav-active-bg: #334155;
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    
    --primary-color: #6366f1; /* Indigo 500 */
    --primary-hover: #818cf8;
    --secondary-color: #312e81;
    --secondary-text: #c7d2fe;
    
    --c-green-bg: rgba(16, 185, 129, 0.2);
    --c-orange-bg: rgba(245, 158, 11, 0.2);
    --c-purple-bg: rgba(139, 92, 246, 0.2);
}

/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow: hidden; /* App container handles scroll */
}

/* App Layout */
#app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-header {
    height: 72px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
}
.logo-box {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 1.2rem;
    margin-right: 12px;
}
.brand { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.5px; }

.nav-menu { flex: 1; padding: 24px 12px; display: flex; flex-direction: column; gap: 8px; }
.nav-item {
    background: transparent; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: flex-start;
    padding: 12px 16px; border-radius: 12px;
    color: var(--text-muted); font-size: 1rem; font-weight: 500; font-family: inherit;
    transition: all 0.2s;
}
.nav-item i { font-size: 1.25rem; margin-right: 12px; }
.nav-item:hover { color: var(--text-main); background-color: var(--bg-base); }
.nav-item.active {
    color: var(--primary-color);
    background-color: var(--secondary-color);
}
[data-theme='dark'] .nav-item.active { color: var(--text-main); background-color: var(--primary-color); }

.sidebar-footer { padding: 20px; border-top: 1px solid var(--border-color); }
.user-profile { display: flex; align-items: center; gap: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.user-info { display: flex; flex-direction: column; }
.user-name { font-weight: 600; font-size: 0.9rem; }
.user-role { font-size: 0.75rem; color: var(--text-muted); }

/* Main Content */
.main-content {
    flex: 1; display: flex; flex-direction: column;
    position: relative; overflow: hidden;
}

.top-header {
    height: 72px; padding: 0 32px;
    display: flex; align-items: center; justify-content: space-between;
    background-color: var(--bg-surface-glass);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color); z-index: 5;
}
.page-title { font-size: 1.5rem; font-weight: 600; }

.views-container { flex: 1; overflow-y: auto; padding: 32px; position: relative; }
.view-section {
    display: none;
    animation: fadeIn 0.4s ease-out forwards;
}
.view-section.active { display: block; }

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

/* Utilities / Glass UI */
.glass-panel {
    background: var(--bg-surface-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: var(--shadow-glass);
    padding: 24px; margin-bottom: 24px;
}
.hidden { display: none !important; }
.visually-hidden { position: absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); border:0; }
.mt-10 { margin-top: 10px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; border-radius: 10px; border: none; font-size: 0.9rem;
    font-weight: 600; cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.btn-primary { background-color: var(--primary-color); color: white; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
.btn-secondary { background-color: var(--bg-base); color: var(--text-main); border: 1px solid var(--border-color); }
.btn-secondary:hover { background-color: var(--border-color); }
.btn-icon { padding: 10px; border-radius: 50%; }
.btn-block { width: 100%; padding: 14px; font-size: 1rem; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 6px; }

/* Badges */
.badge { background: #ef4444; color: white; border-radius: 12px; padding: 2px 8px; font-size: 0.75rem; font-weight: bold; }

/* Toolbar & Searches */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.search-box {
    position: relative; width: 300px;
}
.search-box i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-box input {
    width: 100%; padding: 12px 14px 12px 40px; border-radius: 12px;
    border: 1px solid var(--border-color); background: var(--bg-surface);
    color: var(--text-main); font-family: inherit; transition: border 0.3s;
}
.search-box input:focus { border-color: var(--primary-color); outline: none; }
.toolbar-actions { display: flex; gap: 12px; }

/* Tab 1: Products Grid */
.products-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px;
}
.product-card {
    background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 16px;
    overflow: hidden; box-shadow: var(--shadow-sm); transition: transform 0.3s, box-shadow 0.3s;
    display: flex; flex-direction: column;
}
.product-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); border-color: var(--primary-hover); }
.p-image { 
    height: 180px; background: #e2e8f0; display: flex; align-items: center; justify-content: center;
    font-size: 3rem; color: #cbd5e1; position: relative; overflow: hidden;
}
.p-image img { width: 100%; height: 100%; object-fit: cover; }
.p-tag { position: absolute; top: 12px; right: 12px; background: rgba(0,0,0,0.6); color: white; padding: 4px 12px; border-radius: 30px; font-size: 0.75rem; backdrop-filter: blur(4px); }
.p-content { padding: 20px; display: flex; flex-direction: column; flex: 1; }
.p-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.p-sku { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 12px; font-family: monospace; }
.p-bottom { margin-top: auto; display: flex; justify-content: space-between; align-items: center; }
.p-price { font-size: 1.25rem; font-weight: 700; color: var(--primary-color); }
.p-add { width: 36px; height: 36px; border-radius: 12px; background: var(--secondary-color); color: var(--primary-color); display: flex; align-items: center; justify-content: center; border: none; cursor: pointer; transition: 0.2s; }
.p-add:hover { background: var(--primary-color); color: white; }

/* Tab 2: Two Pane Layout */
.two-pane-layout { display: flex; gap: 24px; height: calc(100vh - 160px); }
.pane { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; }
.pane-left { width: 350px; flex-shrink: 0; }
.pane-right { flex: 1; }
.pane-header { padding: 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--bg-base); }
.list-container { flex: 1; overflow-y: auto; padding: 12px; }
.c-item { padding: 16px; border-radius: 12px; cursor: pointer; transition: 0.2s; display: flex; flex-direction: column; margin-bottom: 8px; border: 1px solid transparent;}
.c-item:hover { background: var(--bg-base); }
.c-item.selected { background: var(--secondary-color); border-color: var(--primary-color); }
.c-name { font-weight: 600; font-size: 1rem; }
.c-meta { display: flex; gap: 12px; margin-top: 8px; font-size: 0.8rem; color: var(--text-muted); }
.stores-grid { padding: 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; overflow-y: auto; flex: 1; align-content: flex-start;}
.store-card { background: var(--bg-base); border: 1px solid var(--border-color); border-radius: 12px; padding: 16px; position: relative;}
.store-card h4 { font-size: 1rem; margin-bottom: 8px; padding-right: 30px;}
.store-card p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; display: flex; align-items: center; gap: 6px;}
.s-delete { position: absolute; right: 12px; top: 12px; color: #ef4444; background: none; border: none; cursor: pointer; padding: 4px; border-radius: 4px; }
.s-delete:hover { background: #fee2e2; }
.empty-state { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); padding: 40px; height: 100%;}
.empty-state i { font-size: 4rem; opacity: 0.2; margin-bottom: 16px; }

/* Tab 3: Dashboard Stats */
.dashboard { display: flex; flex-direction: column; gap: 24px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.stat-card { background: var(--bg-surface); padding: 24px; border-radius: 16px; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 20px; transition: transform 0.3s; }
.stat-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); }
.stat-icon { width: 64px; height: 64px; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 2rem; }
.bg-green { background: var(--c-green-bg); color: var(--c-green); }
.bg-orange { background: var(--c-orange-bg); color: var(--c-orange); }
.bg-purple { background: var(--c-purple-bg); color: var(--c-purple); }
.stat-content { display: flex; flex-direction: column; }
.stat-label { font-size: 0.9rem; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 1.8rem; font-weight: 700; margin-top: 4px; }

/* Upload area */
.upload-area { border: 2px dashed var(--border-color); border-radius: 16px; padding: 40px; text-align: center; cursor: pointer; transition: background 0.3s, border-color 0.3s; }
.upload-area:hover { background: var(--bg-base); border-color: var(--primary-color); }
.upload-area i { font-size: 3rem; color: var(--text-muted); margin-bottom: 16px; display: block; }
.spinner { border: 3px solid rgba(0,0,0,0.1); border-top: 3px solid var(--primary-color); border-radius: 50%; width: 24px; height: 24px; animation: spin 1s linear infinite; margin: 0 auto 10px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.ai-status { text-align: center; margin-top: 20px; color: var(--primary-color); font-weight: 500; }
[data-theme='dark'] .spinner { border-color: rgba(255,255,255,0.1); border-top-color: var(--primary-hover); }

/* Table */
.data-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border-color); }
.data-table th { background: var(--bg-base); color: var(--text-muted); font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px;}

/* Cart Sidebar */
.cart-panel { position: absolute; right: 0; top: 0; bottom: 0; width: 400px; background: var(--bg-surface-glass); backdrop-filter: blur(20px); border-left: 1px solid var(--border-color); box-shadow: -10px 0 30px rgba(0,0,0,0.1); z-index: 50; display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
.cart-panel:not(.hidden) { transform: translateX(0); display: flex !important; }
.cart-header { padding: 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.cart-customer-select { padding: 20px 24px; background: var(--bg-base); border-bottom: 1px solid var(--border-color); }
.cart-items { flex: 1; overflow-y: auto; padding: 24px; }
.cart-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; padding: 16px; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 12px; }
.ci-info h5 { font-size: 0.95rem; margin-bottom: 4px; }
.ci-info p { font-size: 0.8rem; color: var(--primary-color); font-weight: 600; }
.ci-actions { display: flex; align-items: center; gap: 12px; }
.qty-input { width: 50px; text-align: center; padding: 6px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-base); color: var(--text-main); }
.btn-remove { color: #ef4444; background: none; border: none; cursor: pointer; font-size: 1.2rem; }
.cart-footer { padding: 24px; border-top: 1px solid var(--border-color); background: var(--bg-surface); }
.cart-total { display: flex; justify-content: space-between; font-size: 1.2rem; font-weight: bold; margin-bottom: 20px; }
.empty-cart { text-align: center; color: var(--text-muted); padding: 40px 0; }

/* Modals & Forms */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal { width: 500px; max-width: 90vw; background: var(--bg-surface); border-radius: 20px; border: 1px solid var(--border-color); box-shadow: var(--shadow-glass); overflow: hidden; animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border-color); background: var(--bg-base); display: flex; justify-content: flex-end; gap: 12px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 8px; font-size: 0.9rem; font-weight: 500; color: var(--text-muted); }
.form-input { width: 100%; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-base); color: var(--text-main); font-family: inherit; font-size: 0.95rem; transition: border 0.2s; }
.form-input:focus { outline: none; border-color: var(--primary-color); }
.row { display: flex; gap: 16px; } .col { flex: 1; }

/* Toast */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 12px; }
.toast { background: var(--text-main); color: var(--bg-surface); padding: 12px 20px; border-radius: 8px; font-size: 0.9rem; font-weight: 500; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-md); animation: slideInX 0.3s forwards; }
@keyframes slideInX { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
