/* ===== DESIGN TOKENS ===== */
:root {
  --navy: #1a237e;
  --navy-dark: #0d1554;
  --navy-light: #283593;
  --blue: #1565c0;
  --blue-light: #1976d2;
  --blue-pale: #e3f2fd;
  --orange: #e65100;
  --orange-light: #ff6d00;
  --orange-pale: #fff3e0;
  --red: #c62828;
  --red-pale: #ffebee;
  --green: #2e7d32;
  --green-pale: #e8f5e9;
  --surface: #ffffff;
  --surface-alt: #f5f7fa;
  --surface-card: #ffffff;
  --border: #e8ecf0;
  --border-light: #f0f2f5;
  --text-primary: #1a1f36;
  --text-secondary: #5f6b7a;
  --text-muted: #9aa3ad;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.14), 0 4px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --font: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --header-h: 60px;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); color: var(--text-primary); background: var(--surface-alt); }
button { font-family: var(--font); cursor: pointer; border: none; outline: none; }
input { font-family: var(--font); outline: none; }
a { text-decoration: none; color: inherit; }

/* ===== APP SHELL ===== */
.app-shell {
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--surface-alt);
  position: relative;
  display: flex;
  flex-direction: column;
}
@media (min-width: 768px) {
  .app-shell { box-shadow: 0 0 60px rgba(0,0,0,0.15); }
  body { display: flex; justify-content: center; align-items: flex-start; background: #dde3ed; }
}

/* ===== TOPBAR ===== */
.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.topbar-title { flex: 1; font-size: 18px; font-weight: 600; color: var(--text-primary); }
.topbar-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  transition: background 0.15s;
  border: none;
}
.topbar-icon:hover { background: var(--surface-alt); }
.back-btn { background: none; border: none; color: var(--text-secondary); font-size: 26px; cursor: pointer; display: flex; align-items: center; line-height: 1; padding: 0 4px 0 0; }

/* ===== PAGE CONTENT ===== */
.page-content { flex: 1; overflow-y: auto; padding: 16px; }

/* ===== SIDEBAR ===== */
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 300; opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.sidebar-overlay.open { opacity: 1; pointer-events: all; }
.sidebar {
  position: fixed; top: 0; left: -290px; bottom: 0; width: 290px;
  background: var(--surface); z-index: 400;
  display: flex; flex-direction: column;
  transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  max-width: 480px;
}
.sidebar.open { left: 0; }
.sidebar-header {
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 100%);
  padding: 36px 20px 20px;
}
.sidebar-logo { font-size: 28px; font-weight: 800; color: #fff; letter-spacing: -0.5px; }
.sidebar-logo span { color: rgba(255,255,255,0.45); font-weight: 300; }
.sidebar-powered-row { display: flex; align-items: center; margin-top: 4px; }
.sidebar-powered { font-size: 10px; color: rgba(255,255,255,0.4); letter-spacing: 1px; text-transform: uppercase; flex: 1; }
.sidebar-version { font-size: 10px; color: rgba(255,255,255,0.3); }
.sidebar-body { flex: 1; overflow-y: auto; padding: 10px 0; }
.sidebar-section { font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; padding: 14px 20px 5px; }
.sidebar-item {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 20px; font-size: 14px; font-weight: 500; color: var(--text-primary);
  cursor: pointer; background: transparent; width: 100%; text-align: left;
  border: none; transition: background 0.15s;
}
.sidebar-item:hover { background: var(--surface-alt); }
.sidebar-item.active { background: var(--blue-pale); color: var(--blue); font-weight: 600; }
.si-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; background: var(--surface-alt); flex-shrink: 0; }
.sidebar-item.active .si-icon { background: #bbdefb; }
.sidebar-divider { height: 1px; background: var(--border); margin: 6px 0; }

/* ===== AUTH ===== */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(160deg, var(--navy-dark) 0%, var(--navy) 40%, var(--blue) 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
}
.auth-logo-area {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; padding: 40px 24px 20px; width: 100%;
}
.auth-logo {
  width: 72px; height: 72px; background: rgba(255,255,255,0.15);
  border-radius: 24px; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.25);
}
.auth-brand { font-size: 32px; font-weight: 700; color: #fff; letter-spacing: -0.5px; }
.auth-brand span { color: rgba(255,255,255,0.5); font-weight: 300; }
.auth-tagline { font-size: 12px; color: rgba(255,255,255,0.5); letter-spacing: 1.5px; text-transform: uppercase; }
.auth-card {
  width: 100%; background: var(--surface);
  border-radius: 28px 28px 0 0; padding: 32px 24px 44px;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.2);
}
.auth-card-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.auth-card-sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 24px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; display: block; }
.form-input {
  width: 100%; padding: 13px 16px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; color: var(--text-primary); background: var(--surface);
  transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--blue); }
.form-input::placeholder { color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn-primary {
  width: 100%; padding: 14px;
  background: var(--navy); color: #fff;
  border-radius: var(--radius-sm); font-size: 15px; font-weight: 600;
  border: none; cursor: pointer; transition: background 0.2s, transform 0.1s;
  margin-top: 4px;
}
.btn-primary:hover { background: var(--navy-dark); }
.btn-primary:active { transform: scale(0.99); }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; }
.divider::before, .divider::after { content:''; flex:1; height:1px; background:var(--border); }
.divider span { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.btn-google {
  width: 100%; padding: 13px; background: var(--surface);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; color: var(--text-primary);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.btn-google:hover { background: var(--surface-alt); border-color: var(--blue); }
.auth-footer { text-align: center; margin-top: 18px; font-size: 14px; color: var(--text-secondary); }
.auth-footer a { color: var(--blue); font-weight: 600; cursor: pointer; }

/* ===== HOME ===== */
.profile-card {
  background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%);
  border-radius: var(--radius); padding: 20px;
  display: flex; align-items: center; gap: 16px;
  color: #fff; margin-bottom: 20px; box-shadow: var(--shadow-md);
}
.profile-avatar {
  width: 54px; height: 54px; border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
  border: 2px solid rgba(255,255,255,0.3); flex-shrink: 0;
}
.profile-name { font-size: 18px; font-weight: 700; }
.profile-meta { font-size: 12px; opacity: 0.75; margin-top: 3px; display: flex; flex-direction: column; gap: 3px; }
.profile-meta span { display: flex; align-items: center; gap: 5px; }

.section-label { font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 12px; }
.quick-actions { display: flex; gap: 10px; margin-bottom: 24px; flex-wrap: wrap; }
.qa-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 16px; background: var(--surface-card);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
}
.qa-btn:hover { border-color: var(--blue); box-shadow: var(--shadow-md); }
.qa-btn .icon { width: 36px; height: 36px; border-radius: 50%; background: var(--blue-pale); display: flex; align-items: center; justify-content: center; font-size: 18px; }

.company-card { background: var(--surface-card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; box-shadow: var(--shadow-sm); }
.company-title { text-align: center; padding: 14px 16px; font-size: 16px; font-weight: 700; border-bottom: 1px solid var(--border); color: var(--navy); }
.company-row { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border-light); }
.company-row:last-child { border-bottom: none; }
.company-row-icon { width: 32px; height: 32px; border-radius: 8px; background: var(--blue-pale); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; margin-top: 2px; }
.company-row-label { font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.company-row-value { font-size: 14px; font-weight: 500; color: var(--text-primary); margin-top: 2px; font-family: var(--font-mono); }

/* ===== ITEMS ===== */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 12px;
  margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.search-bar input { flex: 1; border: none; padding: 12px 0; font-size: 14px; background: transparent; color: var(--text-primary); }
.search-bar input::placeholder { color: var(--text-muted); }
.scan-btn {
  padding: 9px 14px; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; color: var(--text-secondary);
  display: flex; align-items: center; gap: 6px; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: border-color 0.15s; white-space: nowrap;
}
.scan-btn:hover { border-color: var(--blue); color: var(--blue); }
.item-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  display: flex; align-items: flex-start; gap: 12px;
  box-shadow: var(--shadow-sm); transition: box-shadow 0.15s;
}
.item-card:hover { box-shadow: var(--shadow-md); }
.item-avatar {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 2px; line-height: 1.3; }
.item-code { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.item-prices { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.item-price .lbl { font-size: 11px; color: var(--text-muted); }
.item-price .val { font-size: 11px; font-weight: 600; color: var(--text-primary); }
.item-unp { font-size: 12px; font-weight: 700; color: var(--blue); margin-top: 3px; }
.item-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.btn-check-stock {
  padding: 7px 11px; background: var(--blue); color: #fff;
  border-radius: 6px; font-size: 11px; font-weight: 600; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 5px; transition: background 0.15s; white-space: nowrap;
}
.btn-check-stock:hover { background: var(--blue-light); }
.btn-check-offers {
  padding: 7px 11px; background: var(--orange); color: #fff;
  border-radius: 6px; font-size: 11px; font-weight: 600; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 5px; transition: background 0.15s; white-space: nowrap;
}
.btn-check-offers:hover { background: var(--orange-light); }

/* ===== POPUP / BOTTOM SHEET ===== */
.popup-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 500; opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
  display: flex; align-items: flex-end; justify-content: center;
}
.popup-overlay.open { opacity: 1; pointer-events: all; }
@media (min-width: 768px) { .popup-overlay { align-items: center; } }
.popup-sheet {
  background: var(--surface); border-radius: 24px 24px 0 0;
  width: 100%; max-width: 480px; max-height: 90vh;
  overflow-y: auto; transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 8px 0 40px;
}
.popup-overlay.open .popup-sheet { transform: translateY(0); }
@media (min-width: 768px) {
  .popup-sheet {
    border-radius: 20px; max-height: 80vh; max-width: 440px;
    transform: scale(0.95); opacity: 0;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s;
    margin: 0 20px;
  }
  .popup-overlay.open .popup-sheet { transform: scale(1); opacity: 1; }
}
.popup-handle { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 14px; }
@media (min-width: 768px) { .popup-handle { display: none; } }
.popup-title {
  background: var(--navy); color: #fff;
  text-align: center; padding: 12px 20px;
  font-size: 14px; font-weight: 700; letter-spacing: 0.3px;
}
.popup-content { padding: 16px 20px; }

/* ===== CHECK STOCK ===== */
.stock-search {
  display: flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 0 12px; margin-bottom: 14px;
}
.stock-search input { flex: 1; border: none; padding: 11px 0; font-size: 13px; background: transparent; }
.stock-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stock-table th { background: var(--surface-alt); padding: 10px 12px; text-align: left; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.stock-table td { padding: 11px 12px; border-bottom: 1px solid var(--border-light); vertical-align: top; line-height: 1.4; }
.stock-table tr:last-child td { border-bottom: none; }
.stock-qty { font-weight: 700; color: var(--blue); font-family: var(--font-mono); }

/* ===== FILTER ===== */
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.filter-tile {
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; transition: border-color 0.15s, background 0.15s; text-align: center; background: var(--surface);
}
.filter-tile:hover, .filter-tile.active { border-color: var(--blue); background: var(--blue-pale); }
.ft-icon { font-size: 22px; }
.ft-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }

/* ===== CUSTOMERS ===== */
.customer-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  display: flex; align-items: flex-start; gap: 12px;
  box-shadow: var(--shadow-sm); cursor: pointer; transition: box-shadow 0.15s;
}
.customer-card:hover { box-shadow: var(--shadow-md); }
.customer-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.customer-info { flex: 1; min-width: 0; }
.customer-name { font-size: 13px; font-weight: 700; line-height: 1.3; margin-bottom: 4px; }
.customer-meta { font-size: 11px; color: var(--text-muted); display: flex; flex-direction: column; gap: 2px; }
.customer-code { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--green); font-weight: 600; margin-top: 5px; }
.balance-col { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; }
.balance-label { font-size: 10px; color: var(--text-muted); margin-bottom: 3px; }
.balance-chip {
  padding: 5px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 700; white-space: nowrap; font-family: var(--font-mono);
}
.balance-chip.negative { background: var(--red-pale); color: var(--red); }
.balance-chip.positive { background: var(--red-pale); color: var(--red); }

/* ===== PENDING INVOICES ===== */
.pi-header {
  background: var(--navy); color: #fff;
  padding: 14px 16px; text-align: center;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
}
.pi-summary { background: var(--surface-card); padding: 12px 16px; border-bottom: 1px solid var(--border); }
.pi-summary-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 13px; }
.pi-summary-row .lbl { color: var(--text-secondary); }
.pi-summary-row .val { font-weight: 600; font-family: var(--font-mono); }
.pi-summary-row .val.orange { color: var(--orange); }
.pi-summary-row .val.blue { color: var(--blue); }
.invoice-card { background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius); margin: 12px 16px; overflow: hidden; box-shadow: var(--shadow-sm); }
.invoice-head { background: var(--surface-alt); padding: 10px 14px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); }
.invoice-head-num { font-size: 14px; font-weight: 700; color: var(--navy); }
.invoice-body { padding: 12px 14px; }
.invoice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.ifl { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px; }
.ifv { font-size: 13px; font-weight: 600; color: var(--text-primary); font-family: var(--font-mono); }
.ifv.orange { color: var(--orange); }
.unauth-btn {
  width: 100%; background: var(--orange-pale); border: 1.5px solid var(--orange);
  border-radius: 8px; padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; margin-bottom: 10px;
}
.u-lbl { font-size: 10px; font-weight: 700; color: var(--orange); text-transform: uppercase; }
.u-val { font-size: 14px; font-weight: 700; color: var(--orange); font-family: var(--font-mono); }
.net-payable-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 0; border-top: 1px solid var(--border); }
.npl { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.npv { font-size: 15px; font-weight: 800; color: var(--red); font-family: var(--font-mono); }
.npv.positive { color: var(--green); }

/* ===== FAB ===== */
.fab {
  position: fixed; bottom: 24px; right: 24px;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--navy); color: #fff; font-size: 28px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg); border: none; cursor: pointer;
  transition: background 0.2s, transform 0.1s; z-index: 200;
}
.fab:hover { background: var(--blue); transform: scale(1.05); }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1a1f36; color: #fff;
  padding: 10px 20px; border-radius: 8px;
  font-size: 13px; font-weight: 500; z-index: 9999;
  opacity: 0; transition: all 0.3s; pointer-events: none;
  white-space: nowrap; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .es-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state .es-text { font-size: 14px; }
