:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #f0ede4;
  --ink: #1c1f1a;
  --muted: #6b6f66;
  --line: #e4e0d5;
  --brand: #14532d;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe6;
  --cash: #15803d; --cash-bg: #e8f5ec;
  --pos: #1d4ed8;  --pos-bg: #e8eefc;
  --exp: #b91c1c;  --exp-bg: #fbeaea;
  --warn: #a16207; --warn-bg: #fdf4d8;
  --side-w: 256px;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.04);
}
:root:not([data-theme="light"]) { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121411; --surface: #1b1e1a; --surface-2: #232722; --ink: #ecebe5; --muted: #9da196; --line: #2c302a;
    --brand: #22c55e; --brand-ink: #062b12; --brand-soft: #16301f;
    --cash: #4ade80; --cash-bg: #15291c; --pos: #93b4ff; --pos-bg: #18213a; --exp: #f87171; --exp-bg: #331a1a;
    --warn: #facc15; --warn-bg: #2f2a12;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Hind Siliguri", "Noto Sans Bengali", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.invisible { visibility: hidden; }
.muted { color: var(--muted); }
.d-block { display: block; }
.hint { color: var(--muted); font-size: .86rem; margin: 0 0 12px; }
h1, h2, h3, h4 { margin: 0 0 10px; line-height: 1.25; }
h3 { font-size: 1.05rem; font-weight: 600; }
h4 { font-size: .95rem; font-weight: 600; margin-top: 18px; color: var(--muted); }
input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select { margin-top: 4px; color: var(--ink); }
.num { font-variant-numeric: tabular-nums; }
.pos-n { color: var(--cash); } .neg-n { color: var(--exp); } .cash-n { color: var(--cash); }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 10px;
  cursor: pointer; min-height: 44px; font-weight: 500; white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--exp); border-color: var(--exp); background: transparent; }
.btn.icon { width: 44px; padding: 0; font-size: 1.4rem; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 4px 10px; font-size: .85rem; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; }
.linkbtn {
  display: block; margin: 14px auto 0; background: none; border: 0; color: var(--brand);
  cursor: pointer; font-weight: 500; padding: 6px; text-decoration: underline; text-underline-offset: 3px;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg .dot { fill: currentColor; stroke: none; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); padding: 28px 24px; border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { font-size: 1.6rem; margin-top: 12px; }
.login-top { display: flex; justify-content: space-between; align-items: center; }
.logo { width: 52px; height: 52px; border-radius: 12px; display: block; }
.logo.sm { width: 34px; height: 34px; border-radius: 9px; }
.lang-btn { min-width: 72px; font-weight: 600; }
.msg { min-height: 1.5em; margin: 12px 0 0; color: var(--exp); font-size: .92rem; }
.msg.ok { color: var(--cash); }

/* ---------- layout + sidebar ---------- */
.layout { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 40;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 12px;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.side-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.12rem; padding: 2px 6px 14px; }
.side-brand .side-close { margin-left: auto; display: none; }
.side-nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: .74rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 14px 12px 6px; }
.nav-group:first-child { padding-top: 4px; }
.side-nav button {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 0; background: none; padding: 11px 12px; border-radius: 10px; cursor: pointer;
  color: var(--ink); font-weight: 500; min-height: 44px;
}
.side-nav button:hover { background: var(--surface-2); }
.side-nav button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side-nav button.active svg { stroke-width: 2.2; }
.side-foot { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.side-user { padding: 0 6px 10px; display: flex; gap: 8px; align-items: center; overflow: hidden; }
.side-user b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scrim { display: none; }

.content { margin-left: var(--side-w); min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 10px 24px; min-height: 64px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.menu-btn { display: none; }
.page-title { margin: 0; font-size: 1.2rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
#bizSelect { width: auto; max-width: 240px; font-weight: 600; }
main { max-width: 1120px; margin: 0 auto; padding: 20px 24px 60px; }

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.25);
    width: min(84vw, 300px);
  }
  .side-open .sidebar { transform: none; }
  .side-brand .side-close { display: inline-flex; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .side-open .scrim { opacity: 1; pointer-events: auto; }
  .side-open { overflow: hidden; }
  .content { margin-left: 0; }
  .menu-btn { display: inline-flex; margin-left: -6px; }
  .topbar { padding: 8px 12px; gap: 6px; min-height: 58px; }
  .page-title { font-size: 1.05rem; }
  #bizSelect { max-width: 46vw; min-height: 40px; padding: 6px 10px; }
  main { padding: 14px 16px 60px; }
}

.install-bar {
  display: flex; align-items: center; gap: 10px; max-width: 1072px; margin: 12px auto 0; padding: 10px 14px;
  background: var(--cash-bg); border-radius: 12px; width: calc(100% - 32px);
}
.install-bar span { flex: 1; font-weight: 500; }

/* ---------- shared blocks ---------- */
.datebar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.datebar input { width: auto; flex: 1; min-width: 140px; max-width: 220px; }
.spacer { flex: 1; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.card .k { font-size: .85rem; color: var(--muted); }
.card .v { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card.cash .v { color: var(--cash); } .card.pos .v { color: var(--pos); } .card.exp .v { color: var(--exp); }
.card.net { background: var(--brand); border-color: var(--brand); }
.card.net .k, .card.net .v { color: var(--brand-ink); }
.card.net.neg { background: var(--exp); border-color: var(--exp); }
.card.net.neg .k, .card.net.neg .v { color: #fff; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.panel-head h3 { margin: 0; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > label { margin-bottom: 10px; }
.grow { flex: 1; min-width: 0; }
.two-col { display: grid; grid-template-columns: 1fr; gap: 0 14px; align-items: start; }
@media (min-width: 1000px) {
  .two-col { grid-template-columns: 1fr 1fr; }
  .two-col.wide-left { grid-template-columns: 1.6fr 1fr; }
}

/* segmented */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.seg.two { grid-template-columns: 1fr 1fr; }
.seg.four { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 520px) { .seg.four { grid-template-columns: repeat(4, 1fr); } }
.seg button { border: 1px solid var(--line); background: var(--surface); padding: 10px 6px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--muted); min-height: 44px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.seg button.on.cash { background: var(--cash-bg); color: var(--cash); border-color: var(--cash); }
.seg button.on.pos { background: var(--pos-bg); color: var(--pos); border-color: var(--pos); }
.seg button.on.expense { background: var(--exp-bg); color: var(--exp); border-color: var(--exp); }

/* entries */
.entry { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.entry:first-child { border-top: 0; }
.tag { font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.tag:empty { display: none; }
.tag.cash { background: var(--cash-bg); color: var(--cash); }
.tag.pos { background: var(--pos-bg); color: var(--pos); }
.tag.expense { background: var(--exp-bg); color: var(--exp); }
.tag.link { cursor: help; }
.mini { font-size: .72rem; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--pos-bg); color: var(--pos); vertical-align: 1px; }
.entry .info { flex: 1; min-width: 0; }
.entry .info small, .tx small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry .amt.expense { color: var(--exp); }
.entry .acts { display: flex; gap: 4px; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }

/* table */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { font-weight: 600; color: var(--muted); font-size: .82rem; }
.tbl .n { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--bg); }
.tbl tr.empty-day td { color: var(--muted); }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
.check { display: flex; gap: 8px; align-items: center; margin: 10px 0 0; color: var(--ink); }
.check input { width: auto; min-height: 0; margin: 0; }

.catrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin-bottom: 10px; }
.catrow .bar { grid-column: 1 / -1; height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.catrow .bar i { display: block; height: 100%; background: var(--exp); border-radius: 99px; }

/* list rows (staff, dues) */
.row-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  background: none; border: 0; border-top: 1px solid var(--line); padding: 12px 4px; min-height: 60px;
}
.row-item:first-child { border-top: 0; }
.row-item:hover { background: var(--bg); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
}
.avatar.supplier { background: var(--pos-bg); color: var(--pos); }
.ri-main { flex: 1; min-width: 0; }
.ri-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-amt { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ri-amt small { font-weight: 400; font-size: .76rem; }
.progress { display: block; height: 5px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; max-width: 220px; }
.progress i { display: block; height: 100%; background: var(--cash); border-radius: 99px; }
#duSearch { margin-bottom: 6px; }

/* sheet */
dialog#sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--ink);
  width: min(560px, 100%); max-height: min(88vh, 900px); border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog#sheet::backdrop { background: rgba(0,0,0,.45); }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sheetBody { padding: 16px 20px 24px; }
@media (max-width: 600px) {
  dialog#sheet { margin: auto 0 0; max-width: 100%; width: 100%; border-radius: 18px 18px 0 0; max-height: 92vh; }
  #sheetBody { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.mini-grid > div { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.mini-grid small { display: block; color: var(--muted); font-size: .8rem; }
.mini-grid b { font-variant-numeric: tabular-nums; }
.mini-grid .span2 { grid-column: 1 / -1; }
.mini-grid .hl { background: var(--cash-bg); }
.mini-grid .hl b { font-size: 1.25rem; color: var(--cash); }
.mini-grid .hl.neg { background: var(--exp-bg); }
.mini-grid .hl.neg b { color: var(--exp); }
.sub-form { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 4px; }
.bal-box { text-align: center; padding: 14px; border-radius: 12px; background: var(--surface-2); margin-bottom: 12px; }
.bal-box > div { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.bal-box small { color: var(--muted); }
.bal-box.recv { background: var(--cash-bg); }
.bal-box.pay { background: var(--exp-bg); }
.contact { margin-bottom: 12px; }
.contact .wa { color: #128c4a; border-color: #25d366; }
.txlist .tx, #caMoves .tx { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.txlist .tx:first-child, #caMoves .tx:first-child { border-top: 0; }
.tx-d { font-size: .82rem; color: var(--muted); width: 82px; flex-shrink: 0; }
.tx-k { flex: 1; min-width: 0; }
.tx-a { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.edit-box { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 4px; }

/* cash */
.calc-line { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.calc-line b { font-weight: 600; }
.calc-line.muted-line { color: var(--muted); }
.calc-line.total-line { border-bottom: 0; border-top: 2px solid var(--ink); font-size: 1.05rem; }
.calc-line.total-line b { font-weight: 700; }
.calc-line.total-line + .calc-line.total-line { border-top: 0; }
.calc-status { margin: 8px 0 12px; padding: 8px 12px; border-radius: 10px; font-weight: 600; text-align: center; }
.calc-status.ok { background: var(--cash-bg); color: var(--cash); }
.calc-status.bad { background: var(--exp-bg); color: var(--exp); }
.calc-status.warn { background: var(--warn-bg); color: var(--warn); }
.count-box { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

/* settings */
.list { list-style: none; padding: 0; margin: 12px 0 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list li > span:first-child { flex: 1 1 180px; font-weight: 500; min-width: 0; }
.li-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 99px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1.1rem; line-height: 1; padding: 2px 4px; margin-right: -6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 .span2 { grid-column: 1 / -1; }
details summary { cursor: pointer; color: var(--brand); font-weight: 500; padding: 8px 0; }
details form { margin-top: 8px; }
#emailForm { margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(80px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  z-index: 100; max-width: calc(100% - 32px); opacity: 0; visibility: hidden;
  transition: transform .2s, opacity .2s, visibility .2s;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
.print-title { display: none; }

@media (max-width: 520px) {
  .card .v { font-size: 1.12rem; }
  .tbl { font-size: .85rem; }
  .grid2 { grid-template-columns: 1fr; }
  .datebar input { min-width: 0; }
}

@media print {
  body { background: #fff; color: #000; }
  .sidebar, .topbar, .scrim, .noprint, .datebar, #entryForm, .check, .install-bar { display: none !important; }
  .content { margin: 0; }
  .print-title { display: block; }
  .panel, .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .card.net, .card.net.neg { background: #fff; } .card.net .k, .card.net .v { color: #000; }
  .two-col { grid-template-columns: 1fr !important; }
  main { padding: 0; }
}
