/* ==========================================================================
   Hisaab Khata - app-style UI (mobile first)
   Idea: ledger paper. Ruled lines + a red margin line on the balance card.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f5f7fc;
  --ink: #1b2140;
  --muted: #667088;
  --line: #e3e7f0;

  --hero: #1f2c7a;
  --btn-bg: #2a3a8f;
  --btn-ink: #ffffff;
  --brand: #2a3a8f;
  --ring: rgba(42, 58, 143, .22);

  --liye: #2a3a8f;       /* paise liye  */
  --liye-bg: #e8ebfa;
  --diye: #a85a05;       /* paise diye  */
  --diye-bg: #fcefd8;

  --owe: #c93333;        /* sir ko dene baaki  */
  --owe-bg: #fdecec;
  --owe-bd: #f3c4c4;
  --get: #0f7a57;        /* sir se lene baaki  */
  --get-bg: #e2f4ec;

  --av-bg-l: 92%;
  --av-fg-l: 28%;
  --av-s: 70%;

  --shadow: 0 1px 2px rgba(27, 33, 64, .06), 0 10px 28px -14px rgba(27, 33, 64, .22);
  --tab-h: 64px;
  --side-w: 248px;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1120;
    --surface: #171b30;
    --surface-2: #1e2339;
    --ink: #e9ecf8;
    --muted: #9aa3c2;
    --line: #272c48;

    --hero: #232f85;
    --btn-bg: #93a3ff;
    --btn-ink: #0e1120;
    --brand: #93a3ff;
    --ring: rgba(147, 163, 255, .3);

    --liye: #a2b0ff;
    --liye-bg: rgba(147, 163, 255, .15);
    --diye: #f2b25c;
    --diye-bg: rgba(242, 178, 92, .14);

    --owe: #ff8f8f;
    --owe-bg: rgba(255, 143, 143, .14);
    --owe-bd: rgba(255, 143, 143, .35);
    --get: #5fd3a1;
    --get-bg: rgba(95, 211, 161, .14);

    --av-bg-l: 24%;
    --av-fg-l: 80%;
    --av-s: 40%;

    --shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
}

/* ---------- Base ---------- */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 400 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 96px);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.no-print { }
.muted { color: var(--muted); }
.owe { color: var(--owe); }
.get { color: var(--get); }
.zero { color: var(--muted); }
.t-liye { color: var(--liye); }
.t-diye { color: var(--diye); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

svg.ico { display: block; flex: none; }

/* ---------- App bar ---------- */

.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  min-height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, calc((100% - 760px) / 2 + 16px)) 0;
  background: var(--bg);
}
.appbar h1 {
  flex: 1; min-width: 0;
  font-size: 19px; font-weight: 800; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer;
}
.icon-btn.flat { border-color: transparent; background: transparent; }
.icon-btn:active { transform: scale(.96); }

/* ---------- Page ---------- */

.page {
  max-width: 760px; margin: 0 auto;
  padding: 4px 16px 24px;
}

.section-title { font-size: 15px; font-weight: 800; margin: 22px 4px 10px; }

.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; margin: 0 0 14px;
  border-radius: 14px; font-weight: 600;
  transition: opacity .3s, transform .3s;
}
.toast.ok { background: var(--get-bg); color: var(--get); }
.toast.err { background: var(--owe-bg); color: var(--owe); }
.toast.gone { opacity: 0; transform: translateY(-6px); pointer-events: none; }

/* ---------- Balance card (the ledger page) ---------- */

.hero {
  position: relative; overflow: hidden;
  margin-bottom: 18px;
  padding: 20px 20px 18px 56px;
  border-radius: 22px;
  color: #fff; background-color: var(--hero);
  background-image: repeating-linear-gradient(
    to bottom, transparent 0, transparent 31px,
    rgba(255, 255, 255, .075) 31px, rgba(255, 255, 255, .075) 32px);
}
.hero::before {                    /* ledger margin line */
  content: ""; position: absolute; top: 0; bottom: 0; left: 38px; width: 1px;
  background: rgba(255, 150, 150, .5);
}
.hero-label { font-size: 13px; font-weight: 600; opacity: .8; }
.hero-amount {
  margin: 6px 0 12px;
  font-size: 40px; font-weight: 800; line-height: 1.05; letter-spacing: -.025em;
}
.hero-amount .cur { font-size: .58em; font-weight: 700; opacity: .75; margin-right: 3px; vertical-align: .22em; }
.hero-amount .paise { font-size: .48em; font-weight: 700; opacity: .65; letter-spacing: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 99px;
  font-size: 13px; font-weight: 700;
  background: rgba(255, 255, 255, .14); color: #fff;
}
.pill.owe { background: var(--owe-bg); color: var(--owe); }
.pill.get { background: var(--get-bg); color: var(--get); }
.pill.zero { background: rgba(255, 255, 255, .14); color: #fff; }

.hero-stats {
  display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 12px;
  margin-top: 16px; padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, .16);
}
.hero-stats span { display: block; font-size: 12px; opacity: .72; }
.hero-stats b { display: block; font-size: 14px; font-weight: 700; white-space: nowrap; }

/* ---------- Cards and lists ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.pad { padding: 18px; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.row:first-child { border-top: 0; }
a.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; font-size: 13px; color: var(--muted); }
.row-sub .gap { margin-right: 10px; }
.row-end { text-align: right; flex: none; }
.amt { display: block; font-weight: 800; font-size: 16px; white-space: nowrap; }

.avatar {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 14px; font-weight: 800; font-size: 17px;
  background: hsl(var(--h) var(--av-s) var(--av-bg-l));
  color: hsl(var(--h) 50% var(--av-fg-l));
}

.chip-ico {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center; border-radius: 50%;
}
.chip-ico.t-liye { background: var(--liye-bg); }
.chip-ico.t-diye { background: var(--diye-bg); }

.day {
  padding: 9px 16px 7px;
  font-size: 13px; font-weight: 700; color: var(--muted);
  background: var(--surface-2);
  border-top: 1px solid var(--line);
}
.day:first-child { border-top: 0; }

.open-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 16px; font-size: 14px; color: var(--muted);
  background: var(--surface-2);
}
.open-row b { color: var(--ink); }

.empty { text-align: center; padding: 38px 24px 34px; color: var(--muted); }
.empty .empty-ico {
  width: 56px; height: 56px; margin: 0 auto 14px;
  display: grid; place-items: center; border-radius: 18px;
  background: var(--liye-bg); color: var(--liye);
}
.empty strong { display: block; margin-bottom: 4px; font-size: 16px; color: var(--ink); }

/* report rows */
.rep { display: block; padding: 14px 16px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.rep:first-child { border-top: 0; }
.rep:active { background: var(--surface-2); }
.rep-head { display: flex; align-items: center; gap: 12px; }
.rep-minis { display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 12px; margin: 12px 0 0 56px; }
.rep-minis span { display: block; font-size: 12px; color: var(--muted); }
.rep-minis b { display: block; font-size: 14px; font-weight: 700; white-space: nowrap; }

/* ---------- Month bar and chips ---------- */

.monthbar { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; }
.monthpick {
  position: relative; flex: 1; min-width: 0; height: 40px;
  display: block;
}
.monthpick input {
  width: 100%; height: 100%;
  padding: 0 12px; text-align: center;
  font-weight: 700; font-size: 15px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  appearance: none; -webkit-appearance: none;
}
.chips { display: flex; gap: 8px; margin: -4px 0 14px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 99px;
  font-size: 13.5px; font-weight: 700; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
}
.chip.on { background: var(--liye-bg); border-color: transparent; color: var(--liye); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 22px; border: 0; border-radius: 14px;
  font-weight: 700; font-size: 15px; text-decoration: none; cursor: pointer;
  background: var(--btn-bg); color: var(--btn-ink);
}
.btn:active { transform: scale(.985); }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--owe); border: 1.5px solid var(--owe-bd); }
.btn.small { height: 40px; font-size: 14px; padding: 0 16px; }

.fab {
  position: fixed; z-index: 30;
  right: 16px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  height: 54px; padding: 0 22px 0 18px; border: 0; border-radius: 99px;
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 15px; cursor: pointer;
  background: var(--btn-bg); color: var(--btn-ink);
  box-shadow: 0 12px 26px -8px rgba(31, 44, 122, .6);
}
.fab:active { transform: scale(.97); }

.danger-zone { margin-top: 26px; text-align: center; }
.danger-zone.left { text-align: left; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px; }
.section-head .section-title { margin: 0 4px; }
.section-head .btn { display: none; }

/* ---------- Forms ---------- */

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field input[type=text], .field input[type=date], .field input[type=password] {
  width: 100%; height: 50px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--surface-2); color: var(--ink);
}
.field input:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring); background: var(--surface); }

.amount, .pass { display: block; }
.amount { position: relative; }
.amount b { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 22px; font-weight: 700; color: var(--muted); }
.amount input { height: 60px !important; padding-left: 40px !important; font-size: 26px; font-weight: 800; letter-spacing: -.01em; }

.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1.5px solid var(--line); border-radius: 16px;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; border-radius: 12px;
  font-weight: 700; color: var(--muted); cursor: pointer;
}
.seg input:checked + label { background: var(--surface); box-shadow: 0 1px 4px rgba(27, 33, 64, .14); }
.seg input#t-liye:checked + label { color: var(--liye); }
.seg input#t-diye:checked + label { color: var(--diye); }
.seg input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 1px; }

.form-stack { display: grid; gap: 16px; }
.pass { position: relative; }
.pass .icon-btn { position: absolute; right: 5px; top: 5px; width: 40px; height: 40px; border: 0; background: transparent; color: var(--muted); }
.pass input { padding-right: 52px !important; }

/* ---------- Bottom sheet ---------- */

dialog.sheet {
  width: 100%; max-width: 520px; max-height: 92dvh; overflow: auto;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 26px 26px 0 0;
  background: var(--surface); color: var(--ink);
}
dialog.sheet[open] { animation: sheet-up .24s cubic-bezier(.2, .8, .2, 1); }
dialog.sheet::backdrop { background: rgba(14, 17, 40, .55); }
@keyframes sheet-up { from { transform: translateY(32px); opacity: 0; } to { transform: none; opacity: 1; } }

.grab { width: 40px; height: 4px; margin: 10px auto 0; border-radius: 99px; background: var(--line); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 0 22px; }
.sheet-head h2 { font-size: 19px; font-weight: 800; }
.sheet-body { display: grid; gap: 16px; padding: 14px 22px calc(22px + env(safe-area-inset-bottom)); }

/* ---------- Bottom tab bar (phone) / sidebar (desktop) ---------- */

.tabbar {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 700; color: var(--muted); text-decoration: none;
}
.tab-ico { width: 58px; height: 30px; display: grid; place-items: center; border-radius: 99px; }
.tabbar a.on { color: var(--liye); }
.tabbar a.on .tab-ico { background: var(--liye-bg); }
.side-brand { display: none; }

/* ---------- Login ---------- */

body.login {
  min-height: 100dvh; padding: 20px;
  display: grid; place-items: center;
  background-color: var(--hero);
  background-image: repeating-linear-gradient(
    to bottom, transparent 0, transparent 31px,
    rgba(255, 255, 255, .075) 31px, rgba(255, 255, 255, .075) 32px);
  position: relative;
}
body.login::before {
  content: ""; position: fixed; top: 0; bottom: 0; left: 34px; width: 1px;
  background: rgba(255, 150, 150, .5);
}
.login-card {
  position: relative; width: min(400px, 100%);
  padding: 30px 24px 26px; border-radius: 26px;
  background: var(--surface); box-shadow: 0 30px 60px -24px rgba(8, 12, 50, .6);
}
.login-card .brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; text-align: center; }
.login-card h1 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.login-card p { color: var(--muted); font-size: 14px; }

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  body { padding-left: var(--side-w); padding-bottom: 96px; }
  body.login { padding-left: 20px; padding-bottom: 20px; }

  .tabbar {
    top: 0; right: auto; bottom: 0; width: var(--side-w); height: auto;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 22px 14px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
  .tabbar a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 14px; border-radius: 14px; font-size: 15px; }
  .tab-ico { width: auto; height: auto; background: none !important; }
  .tabbar a.on { background: var(--liye-bg); }
  .tabbar a.logout { margin-top: auto; }

  .appbar.is-home { display: none; }
  .appbar { min-height: 72px; }
  .page { padding-top: 32px; }
  .appbar:not(.is-home) + .page { padding-top: 6px; }
  .fab { display: none; }
  .section-head .btn { display: inline-flex; }
  dialog.sheet { margin: auto; border-radius: 26px; }
  .hero-amount { font-size: 46px; }
}

@media (min-width: 600px) and (max-width: 899px) {
  dialog.sheet { margin: auto; border-radius: 26px; }
}

@media (max-width: 360px) {
  .hero-amount { font-size: 34px; }
  .hero { padding-left: 50px; }
  .hero::before { left: 34px; }
  .hero-stats b { font-size: 13px; }
  .hero-stats { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  dialog.sheet[open] { animation: none; }
  .toast { transition: none; }
}

/* ---------- Print ---------- */

@media print {
  body { background: #fff; color: #000; padding: 0 !important; }
  .no-print, .tabbar, .fab, .appbar-actions, .monthbar, .chips, dialog, .toast { display: none !important; }
  .appbar { position: static; padding: 0 0 8px; background: #fff; }
  .hero { background: #fff !important; color: #000; border: 1px solid #888; }
  .hero::before { display: none; }
  .hero-stats { border-color: #bbb; }
  .pill, .pill.owe, .pill.get { background: none; border: 1px solid #888; color: #000; }
  .card { box-shadow: none; border-color: #888; break-inside: avoid; }
  .page { max-width: none; padding: 0; }
}
