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

:root {
  --blue:   #1565c0;
  --blue2:  #1976d2;
  --green:  #2e7d32;
  --red:    #c62828;
  --orange: #c05000;
  --purple: #9333ea;
  --bg:     #f5f8fc;
  --card:   #ffffff;
  --border: #e2e8f0;
  --tx1:    #1a2035;
  --tx2:    #5a6378;
  --tx3:    #94a3b8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--tx1); font-size: 15px; -webkit-text-size-adjust: 100%; }

#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }

/* ── Screens ── */
.screen { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; }

/* ── Login ── */
#login-screen { background: var(--blue); justify-content: center; align-items: center;
  padding: 24px; padding-top: calc(var(--safe-top) + 24px); }
.login-card { background: #fff; border-radius: 20px; padding: 36px 28px; width: 100%;
  max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25); text-align: center; }
.login-logo { width: 72px; height: 72px; border-radius: 20px; background: var(--blue);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
  font-size: 36px; color: #fff; font-weight: 900; }
.login-title { font-size: 26px; font-weight: 900; color: var(--tx1); margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--tx3); margin-bottom: 28px; }
.login-input { width: 100%; padding: 14px 16px; border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 16px; margin-bottom: 12px; background: var(--bg); color: var(--tx1);
  -webkit-appearance: none; outline: none; }
.login-input:focus { border-color: var(--blue); }
.login-btn { width: 100%; padding: 15px; background: var(--blue); color: #fff; border: none;
  border-radius: 12px; font-size: 16px; font-weight: 700; cursor: pointer; margin-bottom: 12px; }
.login-btn:active { opacity: .85; }
.login-err { color: var(--red); font-size: 13px; font-weight: 600; min-height: 20px; }
.login-hint { font-size: 12px; color: var(--tx3); margin-top: 12px; }

/* ── Header ── */
.app-header { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(var(--safe-top) + 12px);
  background: var(--blue); color: #fff; flex-shrink: 0; }
.hdr-title { font-size: 18px; font-weight: 800; }
.hdr-sub   { font-size: 11px; color: #bfdbfe; margin-top: 1px; }
.hdr-right { display: flex; align-items: center; gap: 10px; }
.hdr-refresh { background: rgba(255,255,255,.15); border: none; color: #fff; width: 34px; height: 34px;
  border-radius: 10px; font-size: 16px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.hdr-user { background: rgba(255,255,255,.2); border: none; color: #fff; border-radius: 8px;
  padding: 4px 10px; font-size: 12px; font-weight: 700; cursor: pointer; }

/* ── Tab bar ── */
.tab-bar { display: flex; background: #fff; border-top: 1px solid var(--border); flex-shrink: 0;
  padding-bottom: var(--safe-bot); }
.tab-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 8px 4px; border: none; background: none; color: var(--tx3); cursor: pointer;
  font-family: inherit; transition: color .15s; min-height: 56px; }
.tab-btn.active { color: var(--blue); }
.tab-icon { font-size: 22px; line-height: 1; margin-bottom: 3px; }
.tab-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }

/* ── Scroll container ── */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ── KPI cards ── */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 12px 0; }
.kpi-card { background: var(--card); border-radius: 12px; padding: 14px 16px;
  border-left: 4px solid currentColor; }
.kpi-label { font-size: 10px; font-weight: 700; color: var(--tx3); text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 6px; }
.kpi-val   { font-size: 20px; font-weight: 900; line-height: 1.2; }
.kpi-sub   { font-size: 11px; color: var(--tx3); margin-top: 3px; }

/* ── Section title ── */
.section-title { font-size: 11px; font-weight: 800; color: var(--tx3); text-transform: uppercase;
  letter-spacing: .6px; padding: 16px 16px 8px; }

/* ── Cards / rows ── */
.card { background: var(--card); border-radius: 12px; border: 1px solid var(--border); }
.row-list { display: flex; flex-direction: column; gap: 6px; padding: 0 12px; }
.row-item { background: var(--card); border-radius: 10px; border: 1px solid var(--border);
  padding: 12px 14px; }
.row-item:active { background: #f0f7ff; }

/* ── Search + filter bar ── */
.search-bar { padding: 10px 12px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center; }
.search-input { flex: 1; background: var(--bg); border: 1.5px solid var(--border); border-radius: 10px;
  padding: 8px 12px; font-size: 14px; font-family: inherit; color: var(--tx1); outline: none; }
.search-input:focus { border-color: var(--blue); }
.filter-row { display: flex; gap: 6px; padding: 8px 12px; background: #fff;
  border-bottom: 1px solid var(--border); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.filter-row::-webkit-scrollbar { display: none; }
.pill { padding: 5px 14px; border-radius: 14px; border: 1.5px solid var(--border);
  background: #fff; font-size: 12px; font-weight: 600; color: var(--tx2); white-space: nowrap;
  cursor: pointer; -webkit-tap-highlight-color: transparent; }
.pill.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.filter-total { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--blue);
  white-space: nowrap; display: flex; align-items: center; }

/* ── Sale row ── */
.sale-row { padding: 12px 14px; }
.sale-top  { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sale-inv  { font-family: 'Courier New', monospace; font-size: 13px; font-weight: 700;
  color: var(--blue); flex: 1; }
.sale-time { font-size: 11.5px; color: var(--tx3); }
.sale-amt  { font-size: 16px; font-weight: 900; }
.sale-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 700; display: inline-block; }
.badge-plat  { background: #eff6ff; color: var(--blue); }
.badge-walk  { background: #f0fdf4; color: var(--green); }
.badge-paid  { background: #dcfce7; color: #15803d; }
.badge-credit { background: #fff7ed; color: var(--orange); }
.sale-cust { font-size: 11.5px; color: var(--tx3); flex: 1; }

/* ── Alert banner ── */
.alert-banner { margin: 10px 12px 0; padding: 10px 14px; border-radius: 10px;
  border: 1.5px solid #fcd34d; background: #fff3e0; }
.alert-text { font-size: 13px; font-weight: 700; color: var(--orange); }

/* ── Platform breakdown row ── */
.plat-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--card); border-radius: 10px; border: 1px solid var(--border); }
.plat-dot  { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.plat-name { flex: 1; font-size: 13px; font-weight: 600; }
.plat-count { font-size: 11.5px; color: var(--tx3); }
.plat-rev  { font-size: 14px; font-weight: 900; color: var(--blue); }

/* ── Stock item ── */
.stock-item { padding: 12px 14px; }
.stock-top  { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.stock-name { flex: 1; font-size: 13.5px; font-weight: 700; }
.stock-qty  { font-size: 16px; font-weight: 900; white-space: nowrap; }
.stock-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.stock-cat  { background: var(--bg); color: var(--tx3); padding: 2px 8px; border-radius: 8px; font-size: 11px; }
.stock-bc   { font-size: 11px; color: var(--blue); font-family: 'Courier New', monospace; }
.stock-price { font-size: 12px; font-weight: 700; color: var(--green); }
.stock-cost  { font-size: 11.5px; color: var(--tx2); }
.out-badge   { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 10px;
  font-weight: 800; letter-spacing: .5px; margin-top: 5px; }

/* ── Scanner overlay ── */
#scanner-overlay { display: none; position: fixed; inset: 0; background: #000; z-index: 100;
  flex-direction: column; }
#scanner-overlay.active { display: flex; }
#scanner-video { width: 100%; flex: 1; object-fit: cover; }
.scanner-frame { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 240px; height: 160px; border: 3px solid #fff; border-radius: 14px; }
.scanner-hint { position: absolute; bottom: 120px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 14px; font-weight: 600; text-align: center;
  background: rgba(0,0,0,.5); padding: 8px 20px; border-radius: 20px; white-space: nowrap; }
.scanner-close { position: absolute; bottom: 50px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.15); color: #fff; border: 2px solid rgba(255,255,255,.4);
  padding: 12px 32px; border-radius: 30px; font-size: 16px; font-weight: 700; cursor: pointer; }

/* ── Stocktake ── */
.stocktake-banner { background: var(--blue); color: #fff; padding: 8px 14px;
  display: flex; align-items: center; gap: 10px; }
.stocktake-txt { flex: 1; font-size: 12px; font-weight: 600; }
.stocktake-save { background: #fff; color: var(--blue); border: none; padding: 6px 14px;
  border-radius: 8px; font-size: 12px; font-weight: 700; cursor: pointer; }
.stocktake-list { max-height: 200px; overflow-y: auto; background: #fff;
  border-bottom: 1px solid var(--border); }
.stocktake-row  { display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  border-bottom: 1px solid var(--border); }
.stocktake-row-name { flex: 1; font-size: 13px; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.stocktake-sys { font-size: 11.5px; color: var(--tx3); white-space: nowrap; }
.stocktake-input { width: 72px; border: 1.5px solid var(--blue); border-radius: 8px;
  padding: 5px 8px; text-align: center; font-size: 15px; font-weight: 700; font-family: inherit; }

/* ── Loading ── */
.spinner { display: flex; align-items: center; justify-content: center; padding: 48px;
  flex-direction: column; gap: 12px; }
.spin { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--blue);
  border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px 24px; color: var(--tx3); font-size: 14px; }

/* ── Updated label ── */
.updated-lbl { font-size: 11px; color: #93c5fd; text-align: right; padding: 4px 16px 0; }

/* ── Toolbar icon button ── */
.icon-btn { width: 40px; height: 40px; border-radius: 10px; background: var(--bg);
  border: 1.5px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; flex-shrink: 0; }
.icon-btn.on { background: var(--blue); border-color: var(--blue); }

/* ── Utility ── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; }
.mt-8 { margin-top: 8px; }
.green { color: var(--green); }
.red   { color: var(--red); }
.orange { color: var(--orange); }
.blue  { color: var(--blue); }
.mono  { font-family: 'Courier New', monospace; }
.bold  { font-weight: 700; }
.pb-safe { padding-bottom: calc(var(--safe-bot) + 8px); }
