/* Hisab — app-style UI for the sign-in screen and the client app. Mobile-first; on a wide screen it
   becomes a centered "phone-width" app. Light + dark follow the phone's setting. */
:root {
    --p: #7c3aed; --p-d: #5b21b6; --p-l: #a855f7;
    --bg: #f4f1fb; --card: #ffffff; --ink: #1a1523; --muted: #7d7690; --line: #ece7f5;
    --green: #12966f; --green-bg: #e3f6ee; --red: #e0395c; --red-bg: #fdeaef; --amber: #c27a12; --amber-bg: #fdf1dc;
    --shadow: 0 1px 2px rgba(43,25,78,.05), 0 12px 28px -14px rgba(76,29,149,.28);
    --hero: linear-gradient(155deg, #5b21b6 0%, #7c3aed 55%, #a855f7 100%);
    --r: 20px; --r-sm: 14px;
    --bar-h: 64px;
}
@media (prefers-color-scheme: dark) {
    :root { --bg: #14101f; --card: #1f1830; --ink: #f2eefc; --muted: #a79fbd; --line: #2e2542;
        --green-bg: #12332a; --red-bg: #3a1a25; --amber-bg: #3a2c12; --shadow: 0 10px 28px -14px rgba(0,0,0,.7); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; max-width: 100%; overflow-x: hidden; }
body { background: var(--bg); color: var(--ink); min-height: 100vh; min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Bengali", "Hind Siliguri", system-ui, sans-serif;
    font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--p); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }

/* ---------- Sign-in screen ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--hero); }
.auth-top { flex: 0 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 56px) 24px 34px; text-align: center; color: #fff; }
.auth-top img { width: 84px; height: 84px; border-radius: 24px; box-shadow: 0 16px 36px -10px rgba(0,0,0,.45); }
.auth-top h1 { font-size: 30px; font-weight: 800; margin-top: 16px; letter-spacing: .3px; }
.auth-top p { margin: 6px 0 0; opacity: .85; font-size: 14px; }
.auth-card { flex: 1 1 auto; background: var(--bg); border-radius: 30px 30px 0 0; padding: 28px 22px calc(env(safe-area-inset-bottom, 0px) + 28px);
    width: 100%; max-width: 520px; margin: 0 auto; box-shadow: 0 -20px 50px -20px rgba(0,0,0,.35); }
.auth-card h2 { font-size: 20px; font-weight: 800; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin: 4px 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 6px 2px; }
.input-wrap { position: relative; }
.input { width: 100%; height: 54px; border: 1.5px solid var(--line); background: var(--card); border-radius: var(--r-sm); padding: 0 16px; font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--p); box-shadow: 0 0 0 4px rgba(124,58,237,.14); }
.input-wrap .toggle { position: absolute; right: 6px; top: 6px; height: 42px; min-width: 52px; border: 0; background: transparent; color: var(--p); font-weight: 700; font-size: 13px; cursor: pointer; }
.btn-main { width: 100%; height: 54px; border: 0; border-radius: var(--r-sm); background: linear-gradient(135deg, var(--p), #6b21e8); color: #fff; font-weight: 800; font-size: 16px; cursor: pointer; box-shadow: 0 12px 24px -10px rgba(124,58,237,.6); }
.btn-main:active { transform: scale(.985); }
.alert { padding: 12px 14px; border-radius: 12px; font-size: 13px; margin-bottom: 14px; }
.alert.err { background: var(--red-bg); color: var(--red); }
.alert.ok { background: var(--green-bg); color: var(--green); }
.auth-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 22px; }

/* ---------- App shell ---------- */
.app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; position: relative; padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom, 0px) + 24px); }
.hero { background: var(--hero); color: #fff; padding: calc(env(safe-area-inset-top, 0px) + 16px) 18px 74px; border-radius: 0 0 32px 32px; position: relative; overflow: hidden; }
.hero::before { content: ""; position: absolute; width: 260px; height: 260px; right: -90px; top: -110px; border-radius: 50%; background: rgba(255,255,255,.09); }
.hero::after { content: ""; position: absolute; width: 180px; height: 180px; left: -70px; bottom: -90px; border-radius: 50%; background: rgba(255,255,255,.07); }
.topbar { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.topbar img { width: 40px; height: 40px; border-radius: 12px; }
.topbar .who { flex: 1; min-width: 0; }
.topbar .who small { display: block; opacity: .8; font-size: 12px; }
.topbar .who b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; border: 0; background: rgba(255,255,255,.16); color: #fff; display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(6px); }
.icon-btn svg { width: 22px; height: 22px; }

.balance { margin: -52px 16px 0; background: var(--card); border-radius: var(--r); padding: 20px 20px 18px; box-shadow: var(--shadow); position: relative; z-index: 2; }
.balance .lbl { font-size: 13px; color: var(--muted); font-weight: 600; }
.balance .amt { font-size: 38px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; line-height: 1.15; }
.balance .amt.due { color: var(--red); } .balance .amt.adv { color: var(--green); } .balance .amt.zero { color: var(--ink); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 6px 11px; border-radius: 999px; background: var(--p-l); background: rgba(124,58,237,.1); color: var(--p); margin-top: 12px; }
.pill.amber { background: var(--amber-bg); color: var(--amber); }

.section { padding: 0 16px; }
.sec-title { display: flex; align-items: baseline; justify-content: space-between; margin: 24px 2px 10px; }
.sec-title h3 { font-size: 16px; font-weight: 800; }
.sec-title a, .sec-title button.link { font-size: 13px; font-weight: 700; color: var(--p); background: none; border: 0; cursor: pointer; padding: 0; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.stat { background: var(--card); border-radius: 16px; padding: 14px 14px 13px; box-shadow: var(--shadow); }
.stat small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.stat b { display: block; font-size: 19px; margin-top: 3px; font-weight: 800; }
.stat b.g { color: var(--green); }
.stats .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* ---------- হিসাবের সারাংশ table ---------- */
.ledger { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.ledger td { padding: 13px 15px; border-bottom: 1px solid var(--line); font-size: 14.5px; vertical-align: middle; }
.ledger td:last-child { text-align: right; font-weight: 800; white-space: nowrap; padding-left: 8px; }
.ledger tr:last-child td { border-bottom: 0; }
.ledger small { color: var(--muted); font-weight: 600; font-size: 11.5px; }
.ledger .sub td { color: var(--muted); font-size: 13.5px; padding-top: 10px; padding-bottom: 10px; }
.ledger .sub td:last-child { font-weight: 700; color: var(--ink); }
.ledger .strong td { font-weight: 800; font-size: 15.5px; }
.ledger .op { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 7px; margin-right: 6px; font-weight: 800; font-size: 14px; line-height: 1; background: rgba(124,58,237,.12); color: var(--p); }
.ledger .plus .op { background: var(--red-bg); color: var(--red); }
.ledger .minus .op { background: var(--green-bg); color: var(--green); }
.ledger .minus td:last-child { color: var(--green); }
.ledger .total td { background: rgba(124,58,237,.06); }
.ledger .final td { background: rgba(124,58,237,.10); font-size: 17px; padding-top: 16px; padding-bottom: 16px; }
.ledger .final.due td:last-child { color: var(--red); } .ledger .final.adv td:last-child { color: var(--green); }

.cta { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; margin-top: 14px; border: 0; cursor: pointer; background: linear-gradient(135deg, var(--p), #6b21e8); color: #fff;
    border-radius: var(--r); padding: 16px 18px; box-shadow: 0 14px 26px -12px rgba(124,58,237,.7); }
.cta .ci { width: 44px; height: 44px; border-radius: 14px; background: rgba(255,255,255,.18); display: grid; place-items: center; flex: none; font-size: 22px; }
.cta b { display: block; font-size: 16px; } .cta span { display: block; font-size: 12.5px; opacity: .85; margin-top: 1px; }
.cta:active { transform: scale(.985); }

.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .ico { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; flex: none; background: rgba(124,58,237,.1); color: var(--p); font-size: 19px; }
.row .ico.g { background: var(--green-bg); color: var(--green); }
.row .ico.a { background: var(--amber-bg); color: var(--amber); }
.row .ico.r { background: var(--red-bg); color: var(--red); }
.row .mid { flex: 1; min-width: 0; }
.row .mid b { display: block; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .mid small { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; overflow-wrap: anywhere; }
.row .end { text-align: right; flex: none; }
.row .end b { display: block; font-size: 15px; font-weight: 800; }
.row .end small { display: block; color: var(--muted); font-size: 12px; }
.row .end b.g { color: var(--green); }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 4px 9px; border-radius: 999px; }
.badge.amber { background: var(--amber-bg); color: var(--amber); } .badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); } .badge.gray { background: rgba(125,118,144,.14); color: var(--muted); }
.row form { margin: 0; }
.row .mini { border: 0; background: rgba(125,118,144,.14); color: var(--muted); border-radius: 10px; font-size: 12px; font-weight: 700; padding: 6px 10px; cursor: pointer; margin-top: 6px; }
.day-head { display: flex; justify-content: space-between; padding: 9px 15px; background: rgba(124,58,237,.06); font-size: 12.5px; font-weight: 700; color: var(--muted); }
.empty { text-align: center; padding: 34px 20px; color: var(--muted); font-size: 14px; }
.empty .e { font-size: 36px; margin-bottom: 6px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 6px; margin: 14px -0px 0; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 9px 15px; border-radius: 999px; background: var(--card); color: var(--ink); font-size: 13.5px; font-weight: 700; box-shadow: var(--shadow); border: 1.5px solid transparent; white-space: nowrap; }
.chip.sel { background: linear-gradient(135deg, var(--p), #6b21e8); color: #fff; }
details.cal { margin: 10px 16px 0; background: var(--card); border-radius: var(--r-sm); box-shadow: var(--shadow); overflow: hidden; }
details.cal summary { list-style: none; cursor: pointer; padding: 12px 15px; font-size: 13.5px; font-weight: 700; color: var(--p); display: flex; align-items: center; gap: 8px; }
details.cal summary::-webkit-details-marker { display: none; }
details.cal summary::after { content: "▾"; margin-left: auto; transition: transform .2s; }
details.cal[open] summary::after { transform: rotate(180deg); }
details.cal .range-form { margin: 0; padding: 0 15px 15px; }
.range-form label { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin: 0 0 4px 2px; }
.section .chips { margin-left: -16px; margin-right: -16px; }
.section details.cal { margin-left: 0; margin-right: 0; }
.range-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin: 10px 16px 0; align-items: end; }
.range-form .input { height: 46px; font-size: 14px; padding: 0 10px; min-width: 0; }
.range-form button { grid-column: 1 / -1; height: 46px; border: 0; border-radius: var(--r-sm); background: var(--p); color: #fff; font-weight: 800; padding: 0 16px; cursor: pointer; }

/* ---------- Tabs & bottom bar ---------- */
.tab-section { display: none; }
.tab-section.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pg-head { padding: calc(env(safe-area-inset-top, 0px) + 18px) 18px 6px; }
.pg-head h2 { font-size: 24px; font-weight: 800; }
.pg-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; justify-content: center; pointer-events: none; }
.tabbar-in { pointer-events: auto; width: 100%; max-width: 560px; height: calc(var(--bar-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(3, 1fr); box-shadow: 0 -10px 30px -18px rgba(43,25,78,.35); }
.tab { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11.5px; font-weight: 700; cursor: pointer; position: relative; }
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--p); }
.tab.active::before { content: ""; position: absolute; top: 0; width: 34px; height: 3px; border-radius: 0 0 4px 4px; background: var(--p); }
.tab .dot { position: absolute; top: 9px; margin-left: 20px; min-width: 17px; height: 17px; border-radius: 9px; background: var(--amber); color: #fff; font-size: 10.5px; display: grid; place-items: center; padding: 0 4px; }

/* ---------- Bottom sheet ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(20,12,36,.5); z-index: 80; opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet-back.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; max-width: 560px; margin: 0 auto; max-height: 92dvh; overflow-y: auto; background: var(--bg);
    border-radius: 28px 28px 0 0; padding: 10px 20px calc(env(safe-area-inset-bottom, 0px) + 22px); transform: translateY(105%); transition: transform .3s cubic-bezier(.2,.8,.2,1); }
.sheet.open { transform: none; }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h3 { font-size: 19px; font-weight: 800; } .sheet .sub { color: var(--muted); font-size: 13px; margin: 3px 0 16px; }

@media (min-width: 700px) {
    body { background-image: radial-gradient(circle at 20% 0%, rgba(124,58,237,.10), transparent 45%); }
    .app { box-shadow: 0 0 60px -20px rgba(76,29,149,.3); background: var(--bg); }
}
@media (max-width: 360px) { .balance .amt { font-size: 32px; } }
