/* ═══════════════════════════════════════════════════════
   Tindahan – Sari-Sari Ledger  |  app.css  (Enhanced)
   Preserves original design & color theme.
   Added: popup notifications, cart-count bar, inventory
   summary, out-of-stock label, home screen, responsive.
═══════════════════════════════════════════════════════ */

:root {
  --red:      #E63946;
  --red-dark: #c42f3b;
  --bg:       #f6f4f1;
  --card:     #ffffff;
  --ink:      #1d1d1f;
  --muted:    #6b6b72;
  --ok:       #2a9d5c;
  --warn:     #e9a100;
  --line:     #e8e4de;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}
.hidden { display: none !important; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

/* ── Header ── */
#header {
  background: var(--red);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  flex-shrink: 0;
}
#header h1 { font-size: 18px; margin: 0; flex: 1; }
.kita-bar {
  background: rgba(255,255,255,0.2);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
}
#btn-summary {
  border: 0;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 18px;
  width: 38px; height: 38px;
  border-radius: 50%;
}

/* ── Main ── */
#screen {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 12px;
  -webkit-overflow-scrolling: touch;
}

/* ── Bottom Nav ── */
#nav {
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  border: 0;
  background: none;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.nav-btn .icon { font-size: 22px; }
.nav-btn.active { color: var(--red); font-weight: 700; }

/* ── Search ── */
.search { margin-bottom: 8px; }
.search input,
input[type="text"],
input[type="number"],
input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus { border-color: var(--red); }

/* ── Product Rows ── */
.prod {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.prod.out           { cursor: default; opacity: 0.65; }
.prod.picked        { border-color: var(--red); background: #fff1f2; box-shadow: 0 0 0 1px var(--red) inset; }
.prod.in-cart:not(.picked) { background: #f3faf5; border-color: #bfe3cb; }

.chk {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border: 2px solid #c9c4bc;
  border-radius: 8px;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 16px; line-height: 1;
}
.chk.on  { background: var(--red); border-color: var(--red); }
.chk.off { background: #eeebe6;   border-color: #e0dcd5; }

.tag {
  flex-shrink: 0;
  font-size: 12px; font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.tag.incart { background: #dff3e6; color: #1f7a45; }
.tag.out    { background: #fde2e4; color: var(--red); }

.prod.low .prod-meta { color: var(--warn); font-weight: 600; }
.prod.out .prod-meta { color: var(--red);  font-weight: 600; }
.prod-info   { flex: 1; min-width: 0; }
.prod-name   { font-weight: 600; font-size: 15px; }
.prod-meta   { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Per-product "Add to Cart" button */
.btn-add {
  flex-shrink: 0;
  border: 0;
  background: var(--red);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 10px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s;
}
.btn-add:active   { background: var(--red-dark); }
.btn-add:disabled { background: #cfcac3; color: #fff; cursor: not-allowed; }

/* ── Stepper ── */
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 36px; height: 36px;
  border: 0; border-radius: 10px;
  background: var(--red); color: #fff;
  font-size: 20px; font-weight: 700; line-height: 1;
  cursor: pointer;
}
.stepper button:disabled { background: #cfcac3; cursor: not-allowed; }
.stepper span  { min-width: 28px; text-align: center; font-weight: 700; font-size: 16px; }

/* ── Cart bar slot ── */
#cartbar-slot {
  position: sticky;
  bottom: 0;
  padding-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Add-selected bar */
.add-bar { display: flex; gap: 8px; }
.add-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  padding: 15px 16px;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(230,57,70,.4);
  cursor: pointer;
}
.add-btn:active { background: var(--red-dark); }
.add-ico  { font-size: 20px; }
.add-cancel {
  width: 52px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 18px;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12);
  cursor: pointer;
}
.cart-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--ink);
  color: #fff;
  padding: 14px 16px;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
  font-size: 15px;
  cursor: pointer;
}
.cart-bar strong { font-size: 17px; }
.cart-bar .go   { color: #ffb3b9; font-weight: 700; font-size: 13px; }

/* ── Cart sheet ── */
.cart-count-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0 10px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 4px;
}
.cart-count-label { font-weight: 700; font-size: 15px; color: var(--muted); }
.cart-count-num   { font-weight: 800; font-size: 15px; color: var(--ink); background: var(--bg); border-radius: 999px; padding: 3px 10px; }

.cart-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.cl-info   { flex: 1; min-width: 0; }
.cl-name   { font-weight: 600; }
.cl-meta   { font-size: 13px; color: var(--muted); margin-top: 2px; }
.cl-stock  { font-size: 11px; color: var(--muted); margin-top: 2px; }
.cl-max-tag {
  font-size: 10px;
  font-weight: 700;
  background: var(--red);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 4px;
}
.rm { border: 0; background: none; font-size: 18px; padding: 6px; cursor: pointer; }
.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0 6px;
  font-size: 16px;
}
.cart-total strong { font-size: 24px; color: var(--red); }
.sukli { min-height: 22px; margin-top: 6px; font-weight: 700; }
.sukli.ok  { color: var(--ok); }
.sukli.bad { color: var(--red); }

/* ── Generic rows / cards ── */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.row-main  { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub   { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row-amt   { font-weight: 800; font-size: 17px; }
.row-amt.bad       { color: var(--red); }
.row.low .stock-num { color: var(--warn); }
.row.out .stock-num { color: var(--red); }
.stock-num { font-size: 22px; min-width: 40px; text-align: right; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.total-card { display: flex; justify-content: space-between; align-items: center; }
.total-card strong { font-size: 22px; color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; line-height: 1.6; }
.empty.small { padding: 8px 0; }

/* ── Buttons ── */
.btn {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  padding: 13px 10px;
  border-radius: 12px;
  cursor: pointer;
}
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger  { background: #fff; border-color: var(--red); color: var(--red); }
.btn.ghost   { color: var(--muted); }
.btn.wide    { width: 100%; margin-bottom: 10px; display: block; }
.btn-row     { display: flex; gap: 8px; margin-top: 14px; }

/* ── Bottom sheet ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.sheet {
  background: #fff;
  width: 100%; max-width: 560px;
  max-height: 88vh; max-height: 88dvh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: sheet-up .2s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.x { border: 0; background: var(--bg); width: 34px; height: 34px; border-radius: 50%; font-size: 15px; cursor: pointer; }

/* ── Form helpers ── */
.lbl  { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }
.two  { display: flex; gap: 10px; }
.two > div { flex: 1; }
.chips { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.chip  { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: 14px; cursor: pointer; }

/* ── Debt entries ── */
.debt-entry { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }

/* ── Summary ── */
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sum { background: var(--bg); border-radius: 12px; padding: 12px; }
.sum span   { display: block; font-size: 12px; color: var(--muted); }
.sum strong { font-size: 18px; }
.sum-sec    { margin: 16px 0 4px; font-weight: 700; }
.sum em     { display: block; font-style: normal; font-size: 12px; color: var(--muted); margin-top: 2px; }
.sum.link   { cursor: pointer; }
.sum.warn strong { color: var(--red); }
.sum.warn em     { color: var(--red); font-weight: 700; }
.sum-actions { display: flex; gap: 8px; margin-top: 14px; align-items: stretch; }
.sum-actions .btn { white-space: nowrap; padding: 13px 8px; font-size: 14px; }
.sum-actions .btn.cart-ico {
  flex: 0 0 54px;
  position: relative;
  font-size: 22px; padding: 10px 0;
  background: var(--ink); border-color: var(--ink); color: #fff;
}
.badge {
  position: absolute; top: -7px; right: -5px;
  min-width: 20px; height: 20px;
  padding: 0 5px; border-radius: 999px;
  background: var(--red); color: #fff;
  font-size: 12px; font-weight: 800; line-height: 20px; text-align: center;
}

/* ── Toast (kept as-is) ── */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 999px;
  font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100; max-width: 90%; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════
   POP-UP NOTIFICATION (new)
═══════════════════════════════════ */
.popup-notif {
  position: fixed;
  top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-120%);
  min-width: 280px; max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  z-index: 200;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s;
  opacity: 0;
  pointer-events: none;
}
.popup-notif.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.popup-notif.hidden { display: none; }
.popup-icon { font-size: 24px; flex-shrink: 0; line-height: 1.3; }
.popup-body { flex: 1; min-width: 0; }
.popup-title { font-weight: 800; font-size: 14px; margin-bottom: 2px; }
.popup-msg   { font-size: 13px; color: var(--muted); line-height: 1.4; }
.popup-close {
  flex-shrink: 0;
  border: 0;
  background: var(--bg);
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  align-self: flex-start;
}

/* Popup colour bands (left border accent) */
.popup-notif.success { border-left: 4px solid var(--ok); }
.popup-notif.success .popup-title { color: var(--ok); }
.popup-notif.error   { border-left: 4px solid var(--red); }
.popup-notif.error   .popup-title { color: var(--red); }
.popup-notif.warning { border-left: 4px solid var(--warn); }
.popup-notif.warning .popup-title { color: var(--warn); }
.popup-notif.info    { border-left: 4px solid #4a90e2; }
.popup-notif.info    .popup-title { color: #4a90e2; }

/* ═══════════════════════════════════
   INVENTORY ADMIN SUMMARY (new)
═══════════════════════════════════ */
.inv-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.inv-stat {
  border-radius: 12px;
  padding: 12px 10px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
}
.inv-num  { display: block; font-size: 26px; font-weight: 900; }
.inv-stat span:last-child { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
.inv-stat.out-s .inv-num { color: var(--red); }
.inv-stat.low-s .inv-num { color: var(--warn); }
.inv-stat.ok-s  .inv-num { color: var(--ok); }

.inv-tag {
  display: inline-block;
  font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
  margin-left: 4px;
}
.inv-tag.out-tag { background: #fde2e4; color: var(--red); }
.inv-tag.low-tag { background: #fff3cd; color: var(--warn); }

/* ═══════════════════════════════════
   HOME SCREEN (new)
═══════════════════════════════════ */
.home-hero {
  text-align: center;
  padding: 16px 0 10px;
}
.home-title { font-size: 18px; font-weight: 800; }
.home-sub   { font-size: 13px; color: var(--muted); margin-top: 4px; }

.home-alert {
  background: #fff9f0;
  border: 1px solid #f5d799;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.6;
}
.ha-row { margin-bottom: 4px; }
.ha-row.out-h { color: var(--red); }
.ha-row.low-h { color: var(--warn); }

.home-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.home-actions .btn { padding: 14px 12px; }

/* ═══════════════════════════════════
   RESPONSIVE  (tablet / desktop)
═══════════════════════════════════ */
@media (min-width: 560px) {
  /* On wider screens the app is centred at 560 px already;
     just add a little breathing room. */
  #screen { padding: 14px 18px 16px; }
  .prod { padding: 12px 14px; }
  .btn-add { font-size: 14px; padding: 9px 14px; }
}

@media (max-width: 360px) {
  .prod-name { font-size: 14px; }
  .btn-add   { font-size: 11px; padding: 7px 9px; }
  .stepper button { width: 32px; height: 32px; font-size: 18px; }
  .inv-num   { font-size: 20px; }
}


/* ═══════════════════════════════════════════
   LOGIN SCREEN
═══════════════════════════════════════════ */
#login-screen {
  position: fixed;
  inset: 0;
  background: rgba(230, 57, 70, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.login-card {
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  padding: 36px 28px 28px;
  width: 100%;
  max-width: 360px;
  animation: sheet-up .3s ease-out;
}

.login-logo {
  font-size: 56px;
  text-align: center;
  margin-bottom: 8px;
}

.login-title {
  font-size: 24px;
  font-weight: 900;
  text-align: center;
  color: var(--red);
  margin-bottom: 4px;
}

.login-sub {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 20px;
}

.login-err {
  background: #fde2e4;
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  text-align: center;
}

.login-btn {
  margin-top: 18px;
  font-size: 16px;
  padding: 15px;
  border-radius: 14px;
}

.login-hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 14px;
}

/* PIN / password input with toggle */
.pin-wrap {
  position: relative;
}
.pin-wrap input {
  padding-right: 44px;
}
.pin-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  color: var(--muted);
}

/* ═══════════════════════════════════════════
   LOGOUT BUTTON (in header)
═══════════════════════════════════════════ */
.logout-btn {
  border: 0;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}
.logout-btn:hover { background: rgba(255,255,255,0.35); }

/* ═══════════════════════════════════════════
   ACCOUNT / USER MENU SHEET
═══════════════════════════════════════════ */
.account-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.acc-avatar {
  font-size: 48px;
  width: 72px; height: 72px;
  background: var(--bg);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.acc-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
}
.acc-role {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

/* ═══════════════════════════════════════════
   CREDIT HISTORY — with dates
═══════════════════════════════════════════ */
.debt-balance-card {
  background: var(--bg);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.dbc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 14px;
}
.dbc-row.muted { color: var(--muted); font-size: 13px; }
.dbc-amount {
  font-size: 26px;
  font-weight: 900;
  color: var(--red);
}

.credit-entry {
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 13px;
}
.credit-entry.paid-entry   { background: #f3faf5; border-color: #bfe3cb; }
.credit-entry.unpaid-entry { background: #fff9f0; border-color: #f5d799; }

.ce-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.ce-date {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.ce-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.ce-badge-paid   { background: #dff3e6; color: #1f7a45; }
.ce-badge-owing  { background: #fff3cd; color: #7a4f00; }

.ce-items {
  font-weight: 600;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line);
}

.ce-amounts {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  font-size: 13px;
}

.ok-text  { color: var(--ok); }
.bad-text { color: var(--red); }

.ce-payments {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.ce-pay-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.ce-pay-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 12px;
}
.ce-pay-date { color: var(--muted); }
.ce-pay-amt  { font-weight: 700; }
