/* =============================================
   SPICE PRO MANAGER — MAIN STYLESHEET
   Mobile-First Design System
   ============================================= */

:root {
    --primary: #1a3c2e;
    --primary-light: #2d6647;
    --primary-lighter: #3d8a60;
    --accent: #e8841a;
    --accent-light: #f5a84a;
    --accent-lighter: #ffd49a;
    --danger: #e53e3e;
    --danger-light: #fff5f5;
    --success: #38a169;
    --success-light: #f0fff4;
    --warning: #d69e2e;
    --warning-light: #fffff0;
    --info: #3182ce;
    --info-light: #ebf8ff;
    --bg: #f4f6f4;
    --bg-card: #ffffff;
    --bg-header: #1a3c2e;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #a0aec0;
    --border: #e2e8f0;
    --border-dark: #cbd5e0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --font: 'Plus Jakarta Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --header-h: 60px;
    --bottom-nav-h: 68px;
    --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-tap-highlight-color: transparent; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---- APP LOADER ---- */
.app-loader {
    position: fixed; inset: 0;
    background: var(--primary);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s, visibility 0.5s;
}
.app-loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-content { text-align: center; color: white; }
.loader-icon {
    font-size: 56px;
    margin-bottom: 20px;
    animation: loaderPulse 1.2s ease-in-out infinite alternate;
}
.loader-icon i { color: var(--accent); }
@keyframes loaderPulse { from { transform: scale(1); } to { transform: scale(1.15); } }
.loader-bar {
    width: 200px; height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px; margin: 16px auto 12px;
    overflow: hidden;
}
.loader-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    animation: loaderProgress 1.5s ease-in-out forwards;
}
@keyframes loaderProgress { from { width: 0 } to { width: 100% } }
.loader-content p { font-size: 13px; opacity: 0.7; letter-spacing: 1px; text-transform: uppercase; }

/* ---- TOP HEADER ---- */
.top-header {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--primary);
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.header-inner {
    display: flex; align-items: center; height: 100%;
    padding: 0 16px; gap: 12px;
}
.menu-btn {
    background: none; border: none; cursor: pointer;
    display: flex; flex-direction: column; gap: 4px; padding: 6px;
    border-radius: 6px;
}
.menu-btn span {
    display: block; width: 22px; height: 2px;
    background: rgba(255,255,255,0.85); border-radius: 2px;
    transition: var(--transition);
}
.header-brand {
    display: flex; align-items: center; gap: 10px;
    flex: 1; overflow: hidden;
}
.brand-icon { color: var(--accent); font-size: 22px; flex-shrink: 0; }
.header-logo { height: 32px; object-fit: contain; }
.brand-name {
    color: white; font-weight: 700; font-size: 16px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
    background: rgba(255,255,255,0.1); border: none;
    color: white; width: 36px; height: 36px;
    border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition); font-size: 14px;
}
.icon-btn:hover { background: rgba(255,255,255,0.2); }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--accent); color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; cursor: pointer;
    flex-shrink: 0;
}

/* ---- SIDEBAR ---- */
.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 200; opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
}
.sidebar-overlay.active { opacity: 1; pointer-events: all; }
.sidebar {
    position: fixed; top: 0; left: -280px; bottom: 0;
    width: 280px; background: var(--bg-card);
    z-index: 201; display: flex; flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    overflow-y: auto;
}
.sidebar.open { transform: translateX(280px); }
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px; background: var(--primary); flex-shrink: 0;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 12px; color: white;
}
.sidebar-brand i { font-size: 24px; color: var(--accent); }
.sidebar-brand strong { display: block; font-size: 14px; }
.sidebar-brand small { font-size: 11px; opacity: 0.7; }
.sidebar-close {
    background: rgba(255,255,255,0.1); border: none;
    color: white; width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.sidebar-user {
    display: flex; align-items: center; gap: 12px;
    padding: 16px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.sidebar-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--primary); color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.sidebar-user strong { font-size: 14px; display: block; }
.sidebar-user small { color: var(--text-muted); font-size: 12px; }
.sidebar-nav { list-style: none; padding: 8px 0; flex: 1; }
.sidebar-nav .nav-section {
    padding: 12px 16px 6px;
    font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
    text-transform: uppercase; color: var(--text-muted);
}
.sidebar-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; color: var(--text-secondary);
    text-decoration: none; font-weight: 500; font-size: 14px;
    transition: var(--transition); border-radius: 0;
}
.sidebar-nav a:hover { background: var(--bg); color: var(--primary); }
.sidebar-nav a.active {
    background: linear-gradient(90deg, #e8f5ee, transparent);
    color: var(--primary); border-left: 3px solid var(--primary);
    font-weight: 600;
}
.sidebar-nav a i { width: 20px; text-align: center; font-size: 16px; }
.logout-link { color: var(--danger) !important; }

/* ---- MAIN CONTENT ---- */
.main-content {
    margin-top: var(--header-h);
    padding-bottom: calc(var(--bottom-nav-h) + 16px);
    min-height: calc(100vh - var(--header-h));
}
.page-container { padding: 16px; max-width: 800px; margin: 0 auto; }

/* ---- BOTTOM NAVIGATION ---- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: white;
    border-top: 1px solid var(--border);
    display: flex; align-items: stretch;
    z-index: 100;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
}
.nav-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 4px;
    text-decoration: none; color: var(--text-muted);
    font-size: 10px; font-weight: 500; padding: 8px 0;
    transition: var(--transition); position: relative;
}
.nav-item i { font-size: 20px; }
.nav-item.active { color: var(--primary); }
.nav-item.active i { color: var(--primary); }
.nav-item.active::before {
    content: ''; position: absolute; top: 0; left: 20%; right: 20%;
    height: 3px; background: var(--primary); border-radius: 0 0 3px 3px;
}
.nav-center-btn {
    flex: 1.2; position: relative;
}
.center-btn-inner {
    width: 50px; height: 50px; border-radius: 50%;
    background: var(--primary); color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; box-shadow: 0 4px 12px rgba(26,60,46,0.4);
    margin-bottom: 2px; margin-top: -12px;
    transition: var(--transition);
}
.nav-center-btn:hover .center-btn-inner,
.nav-center-btn.active .center-btn-inner { background: var(--primary-light); }

/* ---- PAGE HEADER ---- */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; gap: 12px;
}
.page-header h1 {
    font-size: 20px; font-weight: 800; color: var(--primary);
    display: flex; align-items: center; gap: 10px;
}
.page-header h1 i { color: var(--accent); font-size: 18px; }

/* ---- CARDS ---- */
.card {
    background: var(--bg-card); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border);
    overflow: hidden;
}
.card-header {
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 700; color: var(--primary); }
.card-body { padding: 16px; }

/* ---- STAT CARDS ---- */
.stats-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 12px; margin-bottom: 16px;
}
.stat-card {
    background: var(--bg-card); border-radius: var(--radius);
    padding: 14px; border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex; align-items: flex-start; gap: 12px;
    animation: fadeIn 0.4s ease forwards;
}
.stat-icon {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.stat-icon.green { background: #e6f9ef; color: var(--success); }
.stat-icon.orange { background: #fff3e0; color: var(--accent); }
.stat-icon.red { background: #fff5f5; color: var(--danger); }
.stat-icon.blue { background: #ebf8ff; color: var(--info); }
.stat-icon.purple { background: #f3e8ff; color: #805ad5; }
.stat-label { font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 18px; font-weight: 800; color: var(--text-primary); font-family: var(--font-mono); }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 18px; border-radius: var(--radius-sm);
    font-family: var(--font); font-weight: 600; font-size: 14px;
    cursor: pointer; border: none; transition: var(--transition);
    text-decoration: none; white-space: nowrap; line-height: 1;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-light); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
    background: transparent; color: var(--primary);
    border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 8px; border-radius: 8px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- FORMS ---- */
.form-group { margin-bottom: 14px; }
.form-label {
    display: block; font-size: 12px; font-weight: 700;
    color: var(--text-secondary); margin-bottom: 6px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.form-control, .form-select {
    width: 100%; padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font); font-size: 14px;
    color: var(--text-primary); background: white;
    transition: var(--transition); outline: none;
    -webkit-appearance: none;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,60,46,0.1);
}
.form-control::placeholder { color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-group { position: relative; }
.input-group .form-control { padding-left: 40px; }
.input-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); font-size: 14px;
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ---- BADGE / STATUS ---- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 700; letter-spacing: 0.3px;
}
.badge-paid { background: var(--success-light); color: var(--success); }
.badge-due { background: var(--danger-light); color: var(--danger); }
.badge-partial { background: var(--warning-light); color: var(--warning); }
.badge-pending { background: #f7fafc; color: var(--text-muted); }
.badge-delivered { background: var(--success-light); color: var(--success); }
.badge-cancelled { background: var(--danger-light); color: var(--danger); }

/* ---- TABLE ---- */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
thead th {
    background: var(--bg); padding: 10px 12px;
    font-size: 11px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border); text-align: left;
}
tbody td {
    padding: 12px; border-bottom: 1px solid var(--border);
    font-size: 13px; vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }

/* ---- FILTER BAR ---- */
.filter-bar {
    background: white; border-radius: var(--radius);
    border: 1px solid var(--border); padding: 12px;
    margin-bottom: 14px;
    display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end;
}
.filter-bar .form-group { margin: 0; flex: 1; min-width: 120px; }

/* ---- LIST ITEMS ---- */
.list-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-bottom: 1px solid var(--border);
    text-decoration: none; color: inherit; transition: var(--transition);
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: #fafafa; }
.list-avatar {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
}
.list-body { flex: 1; min-width: 0; }
.list-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.list-right { text-align: right; flex-shrink: 0; }
.list-amount { font-family: var(--font-mono); font-weight: 700; font-size: 14px; }
.list-due { color: var(--danger); }

/* ---- ALERT ---- */
.alert {
    padding: 12px 14px; border-radius: var(--radius-sm);
    font-size: 13px; display: flex; align-items: flex-start; gap: 10px;
    margin-bottom: 14px;
}
.alert i { font-size: 16px; margin-top: 1px; flex-shrink: 0; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #c6f6d5; }
.alert-danger { background: var(--danger-light); color: var(--danger); border: 1px solid #fed7d7; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #fefcbf; }
.alert-info { background: var(--info-light); color: var(--info); border: 1px solid #bee3f8; }

/* ---- TOAST ---- */
.toast-container {
    position: fixed; bottom: calc(var(--bottom-nav-h) + 16px);
    right: 16px; z-index: 1000;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    background: #1a202c; color: white;
    padding: 12px 16px; border-radius: 10px;
    font-size: 13px; font-weight: 500;
    box-shadow: var(--shadow-lg); max-width: 300px;
    display: flex; align-items: center; gap: 10px;
    animation: toastIn 0.3s ease;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---- MODAL ---- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 300; display: flex; align-items: flex-end; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal {
    background: white; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%; max-width: 600px; max-height: 92vh;
    overflow-y: auto; transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal-header {
    padding: 16px; display: flex; align-items: center;
    justify-content: space-between; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: white; z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
    background: var(--bg); border: none; width: 32px; height: 32px;
    border-radius: 50%; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
}
.modal-body { padding: 16px; }
.modal-footer {
    padding: 14px 16px; border-top: 1px solid var(--border);
    display: flex; gap: 10px; position: sticky; bottom: 0;
    background: white;
}
.modal-footer .btn { flex: 1; justify-content: center; }

/* ---- LOADING ---- */
.loading-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,0.8);
    z-index: 500; display: flex; align-items: center; justify-content: center;
}
.spinner {
    width: 40px; height: 40px; border: 3px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- EMPTY STATE ---- */
.empty-state {
    text-align: center; padding: 40px 16px;
    color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ---- PRODUCT ITEMS (sale form) ---- */
.product-row {
    background: var(--bg); border-radius: var(--radius-sm);
    padding: 12px; margin-bottom: 8px; position: relative;
}
.product-row .remove-btn {
    position: absolute; top: 8px; right: 8px;
    background: var(--danger-light); color: var(--danger);
    border: none; border-radius: 6px; padding: 4px 8px;
    font-size: 12px; cursor: pointer;
}

/* ---- QUICK STATS TABS ---- */
.tab-bar {
    display: flex; background: white; border-radius: var(--radius);
    border: 1px solid var(--border); overflow: hidden;
    margin-bottom: 14px;
}
.tab-btn {
    flex: 1; padding: 10px; font-family: var(--font);
    font-size: 12px; font-weight: 600; border: none;
    background: none; cursor: pointer; color: var(--text-muted);
    transition: var(--transition); border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: #f0f9f4; }

/* ---- LOW STOCK BADGE ---- */
.low-stock { color: var(--danger) !important; }
.stock-bar {
    height: 4px; background: var(--border); border-radius: 2px; margin-top: 4px;
}
.stock-fill {
    height: 100%; border-radius: 2px; background: var(--success);
    transition: width 0.5s ease;
}
.stock-fill.low { background: var(--danger); }
.stock-fill.medium { background: var(--warning); }

/* ---- ANIMATIONS ---- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.35s ease forwards; }

/* ---- UTILITIES ---- */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }
.text-accent { color: var(--accent); }
.fw-bold { font-weight: 700; }
.font-mono { font-family: var(--font-mono); }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 16px; }
.d-flex { display: flex; } .align-center { align-items: center; }
.gap-1 { gap: 8px; } .gap-2 { gap: 12px; }
.w-100 { width: 100%; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 10px; }

/* ---- RESPONSIVE DESKTOP ---- */
@media (min-width: 768px) {
    .page-container { padding: 24px; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    .stat-card { padding: 20px; }
    .form-row { grid-template-columns: 1fr 1fr 1fr; }
    .modal { border-radius: var(--radius-lg); align-self: center; max-height: 85vh; }
    .modal-overlay { align-items: center; }
    .main-content { padding-bottom: 24px; }
    .bottom-nav { display: none; }
}

/* ---- PRINT ---- */
@media print {
    .top-header, .sidebar, .bottom-nav, .modal-overlay, #appLoader,
    .btn, .filter-bar { display: none !important; }
    .main-content { margin: 0; padding: 0; }
    .page-container { padding: 0; }
}
