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

/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body { font-family: 'Nunito', system-ui, sans-serif; background: #F9F4EE; color: #2C1810; max-width: 430px; margin: 0 auto; min-height: 100vh; overflow-x: hidden; }

/* ── CSS VARIABLES ── */
:root {
  --brown:       #3B1F0E;
  --brown2:      #5C2E0F;
  --orange:      #E8891A;
  --orange2:     #F5B04A;
  --orange-pale: #FEF3E2;
  --cream:       #FFFBF5;
  --bg:          #F9F4EE;
  --card:        #FFFFFF;
  --border:      #EDE0D0;
  --border2:     #D4C0A8;
  --sage:        #2E7D5E;
  --sage2:       #5BAD8A;
  --sage-pale:   #E8F5EF;
  --red:         #C0392B;
  --red-pale:    #FDECEA;
  --muted:       #9C7B6A;
  --text2:       #5C3D2E;
  --r:           14px;
  --r2:          9px;
  --shadow:      0 2px 16px rgba(59,31,14,.08);
  --shadow2:     0 8px 32px rgba(59,31,14,.15);
}

/* ── HIDDEN UTILITY ── */
.hidden { display: none !important; }

/* ── LOGIN SCREEN ── */
#login-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--cream); padding: 20px;
}
#login-screen.hidden { display: none !important; }

.login-wrap { width: 100%; max-width: 340px; }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo .icon { width: 70px; height: 70px; border-radius: 18px; margin: 0 auto 12px; background: linear-gradient(135deg, var(--brown), var(--brown2)); display: flex; align-items: center; justify-content: center; font-size: 34px; box-shadow: 0 8px 24px rgba(59,31,14,.25); }
.login-logo h1 { font-size: 20px; font-weight: 900; color: var(--brown); }
.login-logo p  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.login-card { background: var(--card); border-radius: var(--r); padding: 24px; box-shadow: var(--shadow2); border: 1.5px solid var(--border); }
.login-card h2 { font-size: 15px; font-weight: 800; text-align: center; margin-bottom: 18px; }
.l-error { display: none; background: var(--red-pale); color: var(--red); border-radius: var(--r2); padding: 9px 12px; font-size: 12px; font-weight: 700; margin-bottom: 12px; }
.l-error.show { display: block; }

/* ── MAIN APP ── */
#app { display: none; padding-bottom: 80px; }
#app.visible { display: block; }

/* ── TOPBAR ── */
.topbar { background: linear-gradient(135deg, var(--brown), var(--brown2)); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 16px rgba(59,31,14,.3); }
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-icon { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--orange), var(--orange2)); display: flex; align-items: center; justify-content: center; font-size: 18px; box-shadow: 0 2px 8px rgba(232,137,26,.4); }
.topbar-name { color: #fff; font-size: 14px; font-weight: 800; }
.topbar-sub  { color: rgba(255,255,255,.5); font-size: 10px; font-weight: 600; margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-date { color: rgba(255,255,255,.55); font-size: 10px; text-align: right; line-height: 1.5; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sage2); }
.btn-logout { background: rgba(255,255,255,.12); border: none; color: rgba(255,255,255,.8); font-size: 11px; font-weight: 700; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-family: inherit; }
.btn-gear { background: rgba(255,255,255,.12); border: none; color: #fff; font-size: 14px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }

/* ── SCREENS ── */
.screen { display: none; }
.screen.active { display: block; }
.screen-hd { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.screen-hd h2 { font-size: 16px; font-weight: 800; }

/* ── BOTTOM NAV ── */
.bnav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 430px; max-width: 100%; background: var(--brown); display: flex; padding: 7px 0 12px; z-index: 100; box-shadow: 0 -4px 20px rgba(59,31,14,.25); }
.bni { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; opacity: .4; transition: opacity .15s; position: relative; }
.bni.on { opacity: 1; }
.bni-ico { font-size: 19px; }
.bni-lbl { font-size: 8px; color: #fff; font-weight: 700; }
.bni-dot { position: absolute; top: 0; right: calc(50% - 18px); background: var(--orange); color: #fff; font-size: 8px; font-weight: 800; min-width: 14px; height: 14px; border-radius: 7px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }
.bni-dot:empty { display: none; }

/* ── FAB ── */
.fab { position: fixed; bottom: 88px; right: calc(50% - 200px); width: 52px; height: 52px; border-radius: 50%; border: none; background: linear-gradient(135deg, var(--orange), var(--orange2)); color: #fff; font-size: 26px; cursor: pointer; z-index: 99; box-shadow: 0 4px 20px rgba(232,137,26,.45); transition: transform .15s; font-family: inherit; display: flex; align-items: center; justify-content: center; }
.fab:hover { transform: scale(1.08); }

/* ── STAT GRID ── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 14px 4px; }
.stat-card { background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r); padding: 14px; cursor: pointer; transition: transform .15s, box-shadow .15s; position: relative; overflow: hidden; }
.stat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; border-radius: 3px 3px 0 0; }
.sc-or::before { background: linear-gradient(90deg, var(--orange), var(--orange2)); }
.sc-rd::before { background: var(--red); }
.sc-br::before { background: var(--brown); }
.sc-gr::before { background: var(--sage); }
.stat-ico { font-size: 20px; margin-bottom: 6px; }
.stat-val { font-size: 22px; font-weight: 900; line-height: 1; }
.stat-lbl { font-size: 10px; color: var(--muted); margin-top: 4px; font-weight: 600; }

/* ── SECTION HEADER ── */
.sh { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 5px; }
.sh-t { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.sh-a { font-size: 11px; color: var(--orange); font-weight: 700; cursor: pointer; }

/* ── CARD ── */
.card { background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r); padding: 13px 15px; margin: 0 14px 9px; transition: box-shadow .15s; }
.card.tap { cursor: pointer; }
.card.tap:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-row { display: flex; align-items: center; gap: 11px; }
.av { width: 42px; height: 42px; border-radius: 11px; background: var(--orange-pale); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.av.txt { font-size: 15px; font-weight: 900; color: var(--orange); }
.av.gr  { background: var(--sage-pale); }
.ci { flex: 1; min-width: 0; }
.ci .cn { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci .cs { font-size: 11px; color: var(--muted); margin-top: 2px; }
.cr { text-align: right; flex-shrink: 0; }
.cr .ca { font-size: 14px; font-weight: 800; color: var(--orange); }

/* ── BADGE ── */
.badge { display: inline-block; font-size: 9px; font-weight: 700; padding: 3px 8px; border-radius: 20px; margin-top: 3px; }
.bd { background: var(--sage-pale); color: #1A5C3A; }
.bq { background: #EEF0FF; color: #2D3A9A; }
.bp { background: var(--orange-pale); color: #7A4A10; }
.br { background: var(--red-pale); color: #7A1A1A; }
.bpd { background: var(--sage-pale); color: var(--sage); }

/* ── CARD ACTIONS ── */
.card-acts { display: flex; gap: 6px; margin-top: 10px; }
.btn-a { flex: 1; padding: 7px; border-radius: 8px; border: 1.5px solid; font-size: 11px; font-weight: 700; cursor: pointer; font-family: inherit; }
.btn-done { background: var(--sage-pale); color: var(--sage); border-color: var(--sage2); }
.btn-pay  { background: var(--orange-pale); color: var(--brown2); border-color: var(--orange2); }
.btn-edit { background: #EEF2FF; color: #3D52B0; border-color: #B0BCEF; }
.btn-del  { background: var(--red-pale); color: var(--red); border-color: #EBA8A0; }

/* ── FILTER TABS ── */
.ftabs { display: flex; gap: 6px; padding: 4px 14px 10px; overflow-x: auto; scrollbar-width: none; }
.ftabs::-webkit-scrollbar { display: none; }
.ftab { flex-shrink: 0; padding: 6px 14px; border-radius: 20px; border: 1.5px solid var(--border2); background: var(--card); font-size: 12px; font-weight: 700; color: var(--muted); cursor: pointer; font-family: inherit; transition: all .15s; }
.ftab.on { background: var(--brown); border-color: var(--brown); color: #fff; }

/* ── LEDGER ── */
.ledger-sum { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 0 14px 10px; }
.ls-box { background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r2); padding: 10px; text-align: center; }
.ls-val { font-size: 15px; font-weight: 800; color: var(--red); }
.ls-val.g { color: var(--sage); }
.ls-lbl { font-size: 9px; color: var(--muted); font-weight: 600; margin-top: 3px; }
.lb { background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r); margin: 0 14px 10px; overflow: hidden; }
.lb-hd { padding: 12px 14px; background: linear-gradient(135deg, var(--brown), var(--brown2)); display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.lb-name { font-size: 13px; font-weight: 700; color: #fff; }
.lb-due  { font-size: 13px; font-weight: 800; color: var(--orange2); }
.lb-ok   { font-size: 13px; font-weight: 800; color: var(--sage2); }
.lb-body { display: none; }
.lb-body.open { display: block; }
.lb-row { padding: 10px 14px; display: flex; justify-content: space-between; align-items: flex-start; border-top: 1px solid var(--border); }
.le-date { font-size: 10px; color: var(--muted); font-weight: 600; }
.le-item { font-size: 12px; color: var(--brown); margin-top: 2px; }
.le-r { text-align: right; }
.le-amt  { font-size: 12px; font-weight: 700; }
.le-paid { font-size: 10px; color: var(--sage); }
.le-due  { font-size: 10px; color: var(--red); }
.lb-pay-btn { display: block; margin: 10px 14px 4px; width: calc(100% - 28px); padding: 9px; background: linear-gradient(135deg, var(--sage), var(--sage2)); color: #fff; border: none; border-radius: var(--r2); font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit; }
.lb-wa  { display: block; margin: 6px 14px 12px; width: calc(100% - 28px); padding: 9px; background: #25D366; color: #fff; border: none; border-radius: var(--r2); font-size: 12px; font-weight: 700; text-align: center; text-decoration: none; font-family: inherit; }

/* ── STOCK ── */
.stock-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding: 0 14px 10px; }
.stk { background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r); padding: 13px; }
.stk-emo   { font-size: 26px; margin-bottom: 5px; }
.stk-name  { font-size: 12px; font-weight: 700; }
.stk-price { font-size: 14px; font-weight: 800; color: var(--orange); margin-top: 2px; }
.stk-bar-wrap { background: var(--border); border-radius: 6px; height: 7px; margin-top: 8px; overflow: hidden; }
.stk-bar { height: 100%; border-radius: 6px; background: var(--sage); transition: width .5s; }
.stk-bar.w { background: var(--orange); }
.stk-bar.l { background: var(--red); }
.stk-qty { font-size: 10px; color: var(--muted); margin-top: 4px; font-weight: 600; }
.stk-low { display: inline-block; background: var(--red-pale); color: var(--red); font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 10px; margin-top: 4px; }

/* ── REPORT ── */
.rep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding: 0 14px 6px; }
.rep-card { background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r); padding: 14px; }
.rv { font-size: 20px; font-weight: 900; margin-top: 4px; }
.rv.g { color: var(--sage); } .rv.r { color: var(--red); } .rv.o { color: var(--orange); }
.rl { font-size: 10px; color: var(--muted); font-weight: 600; margin-top: 3px; }
.chart-card { background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r); margin: 0 14px 10px; padding: 14px; }
.wc-wrap { display: flex; align-items: flex-end; gap: 5px; height: 80px; }
.wc-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.wc-bar { width: 100%; border-radius: 5px 5px 0 0; min-height: 4px; background: linear-gradient(180deg, var(--orange2), var(--orange)); }
.wc-bar.today { background: linear-gradient(180deg, var(--brown2), var(--brown)); }
.wc-val { font-size: 8px; font-weight: 700; color: var(--muted); }
.wc-lbl { font-size: 9px; color: var(--muted); font-weight: 600; }
.top-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.top-row:last-child { border-bottom: none; }
.tp-rank { font-size: 14px; font-weight: 800; color: var(--orange2); width: 22px; }
.tp-emo  { font-size: 18px; }
.tp-info { flex: 1; }
.tp-name { font-size: 12px; font-weight: 700; }
.tp-sold { font-size: 10px; color: var(--muted); }
.tp-bar-wrap { background: var(--border); border-radius: 4px; height: 5px; margin-top: 4px; }
.tp-bar { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--orange), var(--orange2)); }
.cat-rows { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: flex; align-items: center; gap: 10px; }
.cat-lbl { font-size: 11px; font-weight: 600; width: 70px; flex-shrink: 0; }
.cat-bar-wrap { flex: 1; background: var(--border); border-radius: 6px; height: 10px; overflow: hidden; }
.cat-bar { height: 100%; border-radius: 6px; }
.cat-pct { font-size: 11px; font-weight: 700; color: var(--muted); width: 36px; text-align: right; }

/* ── SETTINGS ── */
.set-sec { background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r); margin: 0 14px 12px; overflow: hidden; }
.set-sec h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--border); }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.sr-lbl { font-size: 13px; font-weight: 600; }
.sr-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── MODAL ── */
.overlay { position: fixed; inset: 0; background: rgba(59,31,14,.55); z-index: 500; display: none; backdrop-filter: blur(2px); }
.overlay.show { display: block; }
.modal { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%) translateY(100%); width: 430px; max-width: 100%; background: var(--card); border-radius: 20px 20px 0 0; z-index: 600; transition: transform .3s cubic-bezier(.4,0,.2,1); max-height: 92vh; overflow-y: auto; }
.modal.show { transform: translateX(-50%) translateY(0); }
.modal-hd { padding: 16px 16px 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); z-index: 1; }
.modal-hd h3 { font-size: 15px; font-weight: 800; }
.modal-x { width: 28px; height: 28px; border-radius: 50%; border: none; background: var(--border); color: var(--muted); font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-family: inherit; }
.modal-body { padding: 14px 16px; }
.modal-foot { padding: 12px 16px 20px; display: flex; gap: 8px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--card); }

/* ── CONFIRM ── */
.confirm-wrap { position: fixed; inset: 0; background: rgba(59,31,14,.6); z-index: 700; display: none; align-items: center; justify-content: center; padding: 20px; }
.confirm-wrap.show { display: flex; }
.confirm-box { background: var(--card); border-radius: var(--r); padding: 20px; max-width: 300px; width: 100%; box-shadow: var(--shadow2); }
.cf-title { font-size: 15px; font-weight: 800; margin-bottom: 8px; }
.cf-msg   { font-size: 13px; color: var(--muted); line-height: 1.5; }
.cf-btns  { display: flex; gap: 8px; margin-top: 16px; }

/* ── FORM ── */
.fl { display: block; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; margin-top: 13px; }
.fl:first-child { margin-top: 0; }
.fi { width: 100%; padding: 11px 13px; border: 1.5px solid var(--border2); border-radius: var(--r2); font-size: 14px; font-weight: 600; color: var(--brown); background: var(--bg); font-family: inherit; outline: none; transition: border-color .15s; }
.fi:focus { border-color: var(--orange); background: #fff; }
.due-box { border-radius: var(--r2); padding: 10px 13px; font-size: 12px; font-weight: 700; margin-top: 10px; display: none; }
.due-box.show { display: block; }
.due-box.due  { background: var(--red-pale); border: 1.5px solid #EBA8A0; color: var(--red); }
.due-box.ok   { background: var(--sage-pale); border: 1.5px solid var(--sage2); color: var(--sage); }
.pay-info { background: var(--bg); border-radius: var(--r2); padding: 12px; margin-bottom: 4px; }
.pi-name { font-size: 14px; font-weight: 800; }
.pi-due  { font-size: 22px; font-weight: 800; color: var(--red); margin-top: 4px; }
.pi-lbl  { font-size: 10px; color: var(--muted); }

/* ── BUTTONS ── */
.btn-p { flex: 1; padding: 12px; background: linear-gradient(135deg, var(--brown), var(--brown2)); color: #fff; border: none; border-radius: var(--r2); font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit; transition: opacity .15s; }
.btn-p:hover { opacity: .9; }
.btn-p.sm  { padding: 7px 14px; font-size: 12px; flex: none; }
.btn-p.or  { background: linear-gradient(135deg, var(--orange), var(--orange2)); }
.btn-p.rd  { background: var(--red); }
.btn-g { flex: 0 0 80px; padding: 12px; background: var(--border); color: var(--muted); border: none; border-radius: var(--r2); font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit; }

/* ── CART ── */
.cart-item { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1.5px solid var(--border); border-radius: var(--r2); padding: 9px 11px; margin-bottom: 6px; }
.ci-info { flex: 1; min-width: 0; }
.ci-name { font-size: 13px; font-weight: 700; }
.ci-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.ci-amt  { font-size: 13px; font-weight: 800; color: var(--orange); }
.ci-del  { width: 26px; height: 26px; border-radius: 50%; border: none; background: var(--red-pale); color: var(--red); font-size: 13px; cursor: pointer; flex-shrink: 0; font-family: inherit; }
.cart-empty { text-align: center; padding: 16px; font-size: 12px; color: var(--muted); background: var(--bg); border-radius: var(--r2); border: 1.5px dashed var(--border2); }
.total-line { background: var(--orange-pale); border: 1.5px solid var(--orange2); border-radius: var(--r2); padding: 10px 13px; font-size: 14px; font-weight: 800; color: var(--brown); margin-top: 10px; }

/* ── RECEIPT ── */
.r-shop { text-align: center; border-bottom: 2px dashed var(--border2); padding-bottom: 12px; margin-bottom: 12px; }
.r-shop .r-ico { font-size: 32px; }
.r-shop h2 { font-size: 16px; font-weight: 900; color: var(--brown); margin-top: 4px; }
.r-shop p  { font-size: 10px; color: var(--muted); }
.r-meta { font-size: 11px; color: var(--text2); margin-bottom: 8px; display: flex; justify-content: space-between; }
.r-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: 12px; }
.r-table th { font-size: 10px; text-transform: uppercase; color: var(--muted); text-align: left; border-bottom: 1.5px solid var(--border2); padding: 4px 2px; }
.r-table th:last-child, .r-table td:last-child { text-align: right; }
.r-table td { padding: 5px 2px; border-bottom: 1px solid var(--border); }
.r-totals { border-top: 2px dashed var(--border2); padding-top: 10px; }
.r-row { display: flex; justify-content: space-between; font-size: 12px; padding: 3px 0; }
.r-row.grand { font-size: 15px; font-weight: 900; color: var(--brown); }
.r-row.due   { color: var(--red); font-weight: 800; }
.r-row.paid  { color: var(--sage); font-weight: 800; }
.r-foot { text-align: center; margin-top: 14px; font-size: 10px; color: var(--muted); border-top: 1px dashed var(--border2); padding-top: 10px; }

/* ── TOAST ── */
.toast { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--brown); color: #fff; padding: 10px 18px; border-radius: 14px; font-size: 13px; font-weight: 700; z-index: 800; opacity: 0; transition: all .3s; pointer-events: none; max-width: 85%; text-align: center; line-height: 1.4; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── EMPTY STATE ── */
.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty .e-ico { font-size: 40px; margin-bottom: 10px; }
.empty .e-txt { font-size: 13px; font-weight: 600; }
