:root {
  --navy-900: #0d1f2d;
  --navy-800: #1a3d5c;
  --navy-700: #1e4f78;
  --navy-600: #2563a0;
  --navy-500: #3b82c4;
  --navy-400: #60a5d8;
  --navy-100: #dbeafe;
  --navy-50:  #eff6ff;
  --amber-600: #b45309;
  --amber-500: #d97706;
  --amber-100: #fef3c7;
  --amber-50:  #fffbeb;
  --red-500:   #dc2626;
  --red-100:   #fee2e2;
  --green-600: #16a34a;
  --green-100: #dcfce7;
  --green-50:  #f0fdf4;
  --purple-500:#7c3aed;
  --purple-100:#ede9fe;
  --teal-500:  #0d9488;
  --teal-100:  #ccfbf1;
  --text-main: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --surface: #ffffff;
  --surface-1: #f9fafb;
  --surface-2: #f3f4f6;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 15px; color: var(--text-main); background: var(--surface-1); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
.screen { height: 100%; }

.auth-wrap { max-width: 380px; margin: 0 auto; padding: 3rem 1.5rem; display: flex; flex-direction: column; gap: 12px; min-height: 100vh; justify-content: center; }
.auth-logo { font-size: 48px; text-align: center; }
.auth-title { font-size: 26px; font-weight: 700; text-align: center; color: var(--navy-800); }
.auth-sub { font-size: 14px; color: var(--text-secondary); text-align: center; margin-bottom: 8px; }
.auth-error { background: var(--red-100); color: var(--red-500); padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }

#app-screen { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.topbar { background: var(--navy-800); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 1rem; height: 54px; flex-shrink: 0; padding-top: env(safe-area-inset-top); }
.topbar-title { font-size: 16px; font-weight: 600; }
.icon-btn { background: none; border: none; color: rgba(255,255,255,0.8); cursor: pointer; padding: 6px; border-radius: 8px; display: flex; align-items: center; }
.main-content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 1rem; padding-bottom: 2rem; }

.bottom-nav { display: flex; background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0; padding-bottom: env(safe-area-inset-bottom); }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; background: none; border: none; color: var(--text-muted); font-size: 10px; cursor: pointer; font-family: inherit; }
.nav-item.active { color: var(--navy-600); }

.page-title { font-size: 20px; font-weight: 700; color: var(--navy-800); margin-bottom: 1rem; }
.section-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 1.25rem 0 0.5rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem; margin-bottom: 12px; box-shadow: var(--shadow); }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 1rem; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px; box-shadow: var(--shadow); }
.summary-card .val { font-size: 20px; font-weight: 700; line-height: 1; }
.summary-card .lbl { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.val-navy   { color: var(--navy-600); }
.val-green  { color: var(--green-600); }
.val-red    { color: var(--red-500); }
.val-amber  { color: var(--amber-500); }
.val-teal   { color: var(--teal-500); }

.field { margin-bottom: 12px; }
label { font-size: 13px; font-weight: 500; color: var(--text-secondary); display: block; margin-bottom: 5px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text-main); font-size: 15px; font-family: inherit; appearance: none; -webkit-appearance: none; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--navy-500); }
textarea { resize: vertical; min-height: 60px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.btn-primary { background: var(--navy-700); color: #fff; border: none; border-radius: var(--radius); padding: 12px 20px; font-size: 15px; font-weight: 600; font-family: inherit; cursor: pointer; }
.btn-primary:active { background: var(--navy-800); }
.btn-ghost { background: transparent; color: var(--navy-600); border: 1.5px solid var(--navy-400); border-radius: var(--radius); padding: 11px 20px; font-size: 15px; font-weight: 500; font-family: inherit; cursor: pointer; }
.btn-sm { background: var(--surface-2); color: var(--text-main); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; font-family: inherit; cursor: pointer; }
.btn-whatsapp { background: #25d366; color: #fff; border: none; border-radius: var(--radius); padding: 12px 20px; font-size: 15px; font-weight: 600; font-family: inherit; cursor: pointer; width: 100%; margin-top: 8px; }
.full { width: 100%; }

.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-navy   { background: var(--navy-100);   color: var(--navy-700); }
.badge-green  { background: var(--green-100);  color: var(--green-600); }
.badge-amber  { background: var(--amber-100);  color: var(--amber-600); }
.badge-red    { background: var(--red-100);    color: var(--red-500); }
.badge-teal   { background: var(--teal-100);   color: var(--teal-500); }
.badge-purple { background: var(--purple-100); color: var(--purple-500); }

.inner-tabs { display: flex; border-bottom: 1.5px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.inner-tab-btn { flex-shrink: 0; padding: 10px 14px; background: none; border: none; border-bottom: 2.5px solid transparent; margin-bottom: -1.5px; font-size: 13px; font-weight: 500; color: var(--text-muted); cursor: pointer; font-family: inherit; white-space: nowrap; }
.inner-tab-btn.active { color: var(--navy-600); border-bottom-color: var(--navy-500); }

.date-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.date-row input[type=date] { width: auto; padding: 8px 10px; font-size: 14px; }

/* Customer rows */
.customer-row { display: flex; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--border); gap: 10px; cursor: pointer; }
.customer-row:last-child { border-bottom: none; }
.customer-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--navy-100); color: var(--navy-700); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.customer-name { font-size: 14px; font-weight: 500; flex: 1; }
.balance-due { color: var(--red-500); font-weight: 600; font-size: 13px; }
.balance-ok  { color: var(--green-600); font-weight: 600; font-size: 13px; }

/* Delivery input table */
.del-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.del-table th { background: var(--surface-2); padding: 8px 6px; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; border-bottom: 1px solid var(--border); white-space: nowrap; }
.del-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.del-table tr:last-child td { border-bottom: none; }
.del-table input[type=number] { width: 60px; padding: 5px 6px; font-size: 13px; text-align: center; border: 1.5px solid var(--border-strong); border-radius: 6px; background: var(--surface); }
.del-table input[type=number]:focus { border-color: var(--navy-500); outline: none; }
.del-table .cust-name { font-weight: 500; font-size: 13px; min-width: 90px; }
.totals-row td { font-weight: 700; font-size: 13px; background: var(--navy-50); padding: 8px 4px; }

/* Ledger */
.ledger-row { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 8px; font-size: 13px; }
.ledger-row:last-child { border-bottom: none; }
.ledger-desc { flex: 1; }
.ledger-amt { font-weight: 600; white-space: nowrap; }
.income  { color: var(--green-600); }
.expense { color: var(--red-500); }

/* Product pills */
.product-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 1rem; }
.product-pill { padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; border: 1.5px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text-secondary); }
.product-pill.active { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 200; align-items: flex-end; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 20px 20px 0 0; padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom)); width: 100%; max-height: 92vh; overflow-y: auto; }
.modal-handle { width: 36px; height: 4px; background: var(--border-strong); border-radius: 2px; margin: 0 auto 1rem; }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 1rem; color: var(--navy-800); }
.modal-footer { display: flex; gap: 8px; margin-top: 1rem; }
.modal-footer .btn-ghost { flex: 1; }
.modal-footer .btn-primary { flex: 2; }

.toast { position: fixed; bottom: calc(80px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px); background: var(--navy-800); color: #fff; padding: 10px 20px; border-radius: 20px; font-size: 13px; font-weight: 500; opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; white-space: nowrap; z-index: 300; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.fab { position: fixed; bottom: calc(72px + env(safe-area-inset-bottom) + 12px); right: 16px; width: 52px; height: 52px; border-radius: 50%; background: var(--navy-700); color: #fff; border: none; font-size: 26px; cursor: pointer; box-shadow: var(--shadow-md); display: flex; align-items: center; justify-content: center; z-index: 100; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); font-size: 14px; }
.empty-state .empty-icon { font-size: 36px; margin-bottom: 8px; }
.loading { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 14px; }
.search-bar { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border-strong); border-radius: var(--radius); font-size: 15px; font-family: inherit; margin-bottom: 1rem; outline: none; }
.search-bar:focus { border-color: var(--navy-500); }
.month-selector { display: flex; align-items: center; gap: 10px; margin-bottom: 1rem; }
.month-selector select { flex: 1; }

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1rem; padding: 0 1rem; }
