@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.05), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.1);
  --radius: 20px;
  --radius-sm: 12px;
  --nav-height: 72px;
  --header-height: 64px;
}

[data-theme="dark"] {
  --primary-light: #312e81;
  --success-light: #064e3b;
  --danger-light: #7f1d1d;
  --warning-light: #78350f;
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow-md: 0 4px 6px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; padding: 0; }

html, body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .3s, color .3s;
  overscroll-behavior-y: contain;
}

body { padding-bottom: calc(var(--nav-height) + 20px); }

/* ===== HEADER ===== */
.app-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-height);
  background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.app-header .logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; letter-spacing: -.4px; }
.app-header .logo .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 10px var(--primary); }
.header-actions { display: flex; gap: 10px; align-items: center; }

.net-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  background: var(--success-light); color: var(--success);
  transition: all .3s ease;
}
.net-pill.off { background: var(--danger-light); color: var(--danger); }
.net-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.net-pill .dot { animation: pulse 2s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--bg); color: var(--text);
  display: grid; place-items: center; cursor: pointer;
  font-size: 18px; transition: all .2s ease;
}
.icon-btn:active { transform: scale(0.9); background: var(--border); }

/* ===== MAIN CONTAINER ===== */
main { padding: 16px; max-width: 640px; margin: 0 auto; }

/* ===== PAGE TRANSITIONS ===== */
.page { display: none; }
.page.active { display: block; animation: slideUpFade .35s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  transition: transform .2s, box-shadow .2s;
}

.card-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-muted); margin-bottom: 14px;
}

/* ===== STATS ===== */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.stat-card {
  background: var(--bg-elevated); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-md); border: 1px solid var(--border);
  position: relative; overflow: hidden;
  transition: transform .2s ease;
}
.stat-card:active { transform: scale(0.98); }
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--primary);
}
.stat-card.green::before { background: var(--success); }
.stat-card.orange::before { background: var(--warning); }
.stat-card.red::before { background: var(--danger); }
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 700; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.3px; }
.stat-card .value { font-size: 24px; font-weight: 800; letter-spacing: -.8px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; font-weight: 500; }

/* ===== FORMS ===== */
input, select, textarea, button { font-family: inherit; font-size: 15px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; letter-spacing: .3px; text-transform: uppercase; }
input, select, textarea {
  width: 100%; padding: 14px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--bg); color: var(--text);
  transition: all .2s ease; font-weight: 500;
}
input:focus, select:focus, textarea:focus { 
  outline: none; 
  border-color: var(--primary); 
  background: var(--bg-elevated);
  box-shadow: 0 0 0 4px var(--primary-light);
}

/* ===== BUTTONS (with press feedback) ===== */
.btn {
  width: 100%; padding: 14px; border-radius: var(--radius-sm); border: none;
  background: var(--primary); color: white; font-weight: 700; font-size: 15px;
  cursor: pointer; transition: all .15s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: var(--shadow-sm);
}
.btn:active { transform: scale(0.96); background: var(--primary-hover); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn.secondary { background: var(--bg-elevated); color: var(--text); border: 1.5px solid var(--border); box-shadow: none; }
.btn.secondary:active { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.danger:active { background: #dc2626; }
.btn.success { background: var(--success); }
.btn.success:active { background: #059669; }
.btn.ghost { background: transparent; color: var(--primary); box-shadow: none; }
.btn.ghost:active { background: var(--primary-light); }
.btn.sm { padding: 10px 16px; font-size: 13px; width: auto; border-radius: 8px; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ===== SEARCH & SUGGEST ===== */
.search-wrap { position: relative; }
.search-wrap input { padding-left: 44px; font-size: 16px; }
.search-wrap .icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 18px; pointer-events: none; }
.suggest {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--bg-elevated); border-radius: var(--radius-sm);
  border: 1px solid var(--border); box-shadow: var(--shadow-xl);
  max-height: 300px; overflow-y: auto; z-index: 30;
  animation: popIn .2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes popIn { from { opacity: 0; transform: scale(0.95) translateY(-10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.suggest-item { padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .15s; }
.suggest-item:last-child { border-bottom: none; }
.suggest-item:active { background: var(--primary-light); }
.suggest-item .name { font-weight: 700; font-size: 15px; }
.suggest-item .meta { font-size: 13px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

/* ===== CART ITEMS ===== */
.cart-item {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--border);
  animation: slideRight .3s ease;
}
@keyframes slideRight { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: translateX(0); } }
.cart-item:last-child { border-bottom: none; }
.cart-item .name { font-weight: 700; font-size: 15px; }
.cart-item .sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; font-weight: 500; }
.qty-stepper {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg); border-radius: 999px; padding: 4px;
  border: 1px solid var(--border);
}
.qty-stepper button {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--bg-elevated); color: var(--text);
  font-size: 18px; font-weight: 800; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm); transition: all .1s;
}
.qty-stepper button:active { transform: scale(0.85); background: var(--primary); color: white; }
.qty-stepper .qty { min-width: 28px; text-align: center; font-weight: 800; font-size: 15px; }
.cart-item .price { font-weight: 800; font-size: 16px; text-align: right; letter-spacing: -0.5px; }

/* ===== TOTALS ===== */
.totals { border-top: 2px dashed var(--border); margin-top: 16px; padding-top: 16px; }
.total-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 14px; font-weight: 500; }
.total-row.grand { font-size: 24px; font-weight: 800; color: var(--primary); padding-top: 16px; border-top: 1px solid var(--border); margin-top: 8px; letter-spacing: -0.8px; }

/* ===== INVOICE LIST ===== */
.invoice-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 0; border-bottom: 1px solid var(--border); cursor: pointer;
  transition: transform .1s;
}
.invoice-item:last-child { border-bottom: none; }
.invoice-item:active { transform: scale(0.98); opacity: .8; }
.invoice-item .left { display: flex; flex-direction: column; gap: 4px; }
.invoice-item .inv-no { font-weight: 800; font-size: 15px; letter-spacing: -0.3px; }
.invoice-item .cust { font-size: 14px; color: var(--text); font-weight: 600; }
.invoice-item .meta { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.invoice-item .amount { font-weight: 800; font-size: 18px; color: var(--primary); letter-spacing: -0.5px; }
.invoice-item .badge { font-size: 10px; padding: 4px 10px; border-radius: 999px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; display: inline-block; width: fit-content; }

/* ===== FILTER CHIPS ===== */
.filter-bar { display: flex; gap: 10px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 4px; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  padding: 10px 18px; border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--bg-elevated); font-size: 14px; font-weight: 700; white-space: nowrap;
  cursor: pointer; color: var(--text-muted); transition: all .2s;
}
.filter-chip:active { transform: scale(0.95); }
.filter-chip.active { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 4px 10px var(--primary-light); }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: var(--nav-height);
  background: color-mix(in srgb, var(--bg-elevated) 90%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex; justify-content: space-around; align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: none; cursor: pointer; padding: 8px 12px;
  color: var(--text-muted); transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-item .icon { font-size: 22px; transition: transform .2s; }
.nav-item .label { font-size: 10px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; }
.nav-item.active { color: var(--primary); }
.nav-item.active .icon { transform: translateY(-2px) scale(1.1); }
.nav-item:active .icon { transform: scale(0.85); }

/* ===== FAB ===== */
.fab {
  position: fixed; bottom: calc(var(--nav-height) + 20px); right: 20px;
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--primary); color: white; font-size: 28px;
  box-shadow: 0 8px 20px var(--primary-light);
  cursor: pointer; z-index: 45;
  display: grid; place-items: center;
  transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
}
.fab:active { transform: scale(0.85); }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: calc(var(--nav-height) + 24px); left: 50%; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 14px 24px; border-radius: 999px;
  font-size: 14px; font-weight: 700; opacity: 0; transition: all .3s cubic-bezier(0.16, 1, 0.3, 1); z-index: 100;
  pointer-events: none; white-space: nowrap; box-shadow: var(--shadow-xl);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== EMPTY STATE ===== */
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.empty .icon { font-size: 56px; margin-bottom: 16px; opacity: .4; }
.empty .title { font-weight: 800; font-size: 18px; margin-bottom: 6px; color: var(--text); letter-spacing: -0.5px; }
.empty .desc { font-size: 14px; font-weight: 500; }

/* ===== SHEET ===== */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .3s;
  backdrop-filter: blur(4px);
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 70;
  background: var(--bg-elevated); border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .4s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,.1);
}
.sheet.show { transform: translateY(0); }
.sheet-handle { width: 48px; height: 5px; background: var(--border); border-radius: 999px; margin: 0 auto 20px; }

/* ===== SPLASH ===== */
#splash {
  position: fixed; inset: 0; z-index: 999; background: var(--primary);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  color: white; transition: opacity .5s cubic-bezier(0.16, 1, 0.3, 1);
}
#splash .logo { font-size: 72px; margin-bottom: 16px; animation: bounceIn .8s; }
#splash h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
#splash p { opacity: .8; margin-top: 8px; font-size: 15px; font-weight: 500; }
@keyframes bounceIn { 0% { transform: scale(0.5); opacity: 0; } 60% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }

/* ===== CHART BARS ===== */
.chart-bars { 
  display: flex; 
  align-items: flex-end; 
  gap: 8px; 
  height: 120px; 
  padding-top: 12px; 
  margin-bottom: 10px;
}
.chart-bar {
  flex: 1; 
  background: linear-gradient(to top, var(--primary), var(--primary-light));
  border-radius: 6px 6px 2px 2px; 
  min-height: 4px; 
  position: relative;
  transition: height .4s cubic-bezier(0.16, 1, 0.3, 1);
}
.chart-bar .day { 
  position: absolute; 
  bottom: -24px; 
  left: 50%; 
  transform: translateX(-50%);
  font-size: 11px; 
  color: var(--text-muted); 
  font-weight: 700; 
}