/* ===================== Kharcha v3 design ===================== */
:root {
  --brand: #04875F;
  --in: #04875F; --in-soft: #E3F5EE;
  --out: #C93A3A; --out-soft: #FBE9E9;
  --net: #4F46E5; --net-soft: #EAE9FD;
  --warn: #B45309; --warn-soft: #FEF3C7;
  --page: #F5F7FB; --card: #FFFFFF; --line: #E5E7EB; --line2: #F1F5F9;
  --ink: #0F172A; --muted: #64748B;
  --radius: 12px;
  --side: 252px;
}
[data-bs-theme="dark"] {
  --in: #34D399; --in-soft: #0F2E25; --out: #F87171; --out-soft: #3A1717; --net: #A5B4FC; --net-soft: #23214A;
  --warn: #FBBF24; --warn-soft: #3A2A0B;
  --page: #0B1220; --card: #111A2B; --line: #22304A; --line2: #172238; --ink: #E5E7EB; --muted: #94A3B8;
}
html, body { background: var(--page); color: var(--ink); }
body { font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body.has-nav { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
a { color: var(--brand); }
.min-w-0 { min-width: 0; }
.text-in { color: var(--in) !important; } .text-out { color: var(--out) !important; } .text-net { color: var(--net) !important; }
.muted { color: var(--muted); }
.btn { border-radius: 10px; font-weight: 600; }
.btn-brand { background: var(--brand); color: #fff; border: 0; }
.btn-brand:hover, .btn-brand:focus { color: #fff; filter: brightness(.93); background: var(--brand); }
.btn-in { background: var(--in); color: #fff; border: 0; } .btn-in:hover { color: #fff; filter: brightness(.93); background: var(--in); }
.btn-out { background: var(--out); color: #fff; border: 0; } .btn-out:hover { color: #fff; filter: brightness(.93); background: var(--out); }
[data-bs-theme="dark"] .btn-in, [data-bs-theme="dark"] .btn-out { color: #0B1220; }
.btn-soft { background: var(--card); border: 1px solid var(--line); color: var(--ink); }
.btn-soft:hover { background: var(--line2); color: var(--ink); }
.form-control, .form-select { border-radius: 10px; border-color: var(--line); background-color: var(--card); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.badge-soft { background: var(--line2); color: var(--muted); font-weight: 600; }
.dropdown-item.active, .dropdown-item:active { background: var(--brand); }

/* ---------- Sidebar (desktop) ---------- */
.sidebar { display: none; }
@media (min-width: 992px) {
  .sidebar { display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--card); border-right: 1px solid var(--line); padding: 16px 12px; overflow-y: auto; z-index: 30; }
  .page { margin-left: var(--side); }
  body.has-nav { padding-bottom: 0; }
  .bottom-nav { display: none !important; }
}
.side-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; color: var(--ink); text-decoration: none; padding: 4px 8px 14px; }
.side-brand img { height: 32px; border-radius: 8px; }
.brand-dot { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; }
.side-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.side-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 500; }
.side-link i { font-size: 1.1rem; color: var(--muted); width: 20px; text-align: center; }
.side-link:hover { background: var(--line2); color: var(--ink); }
.side-link.active { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); font-weight: 600; }
.side-link.active i { color: var(--brand); }
.biz-switch { width: 100%; }
.biz-btn { width: 100%; display: flex; align-items: center; gap: 10px; background: var(--line2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; text-align: left; color: var(--ink); font-weight: 600; }
.biz-btn img, .biz-ico { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; flex: none; }
.biz-ico { background: var(--brand); color: #fff; display: grid; place-items: center; }
.biz-label { display: block; font-size: .7rem; color: var(--muted); font-weight: 500; }
.biz-btn > span.text-truncate { flex: 1; }
.biz-switch .dropdown-menu { width: 100%; max-height: 60vh; overflow: auto; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }
.top-sub { font-size: .75rem; color: var(--muted); }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; flex: none; }
.icon-btn:hover { background: var(--line2); color: var(--ink); }
.content { padding: 16px; max-width: 1180px; margin: 0 auto; }
.content.wide { max-width: none; }
@media (min-width: 992px) { .content { padding: 24px 28px; } .topbar { padding: 14px 28px; } }

.imp-bar { background: #FDE68A; color: #78350F; padding: 8px 16px; font-size: .9rem; text-align: center; position: relative; z-index: 40; }
.imp-bar a { color: #78350F; font-weight: 700; margin-left: 8px; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 10px; font-size: .7rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.bottom-nav a i { font-size: 1.25rem; }
.bottom-nav a.active { color: var(--brand); }

/* ---------- Cards & lists ---------- */
.card-k { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card-k > .card-h { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 700; }
.card-k > .card-b { padding: 16px; }
.section-t { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 22px 2px 8px; display: flex; justify-content: space-between; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: inherit; text-decoration: none; }
.row-item + .row-item { border-top: 1px solid var(--line2); }
a.row-item:hover { background: var(--line2); color: inherit; }
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--brand); }
.avatar.sq { border-radius: 11px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty i { font-size: 2.4rem; display: block; margin-bottom: 8px; opacity: .6; }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }

/* ---------- Book list cards ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.book-card { display: block; padding: 16px; text-decoration: none; color: inherit; transition: box-shadow .15s, transform .15s; position: relative; }
.book-card:hover { box-shadow: 0 6px 20px rgba(15, 23, 42, .08); transform: translateY(-1px); color: inherit; }
.book-card .bal { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.book-card .mini { display: flex; gap: 16px; font-size: .82rem; color: var(--muted); }

/* ---------- Book page (filters + summary like CashBook) ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; }
.filters .form-select { width: auto; min-width: 140px; font-size: .9rem; padding-top: 8px; padding-bottom: 8px; }
.filters .form-select.on { border-color: var(--brand); background-color: color-mix(in srgb, var(--brand) 7%, var(--card)); font-weight: 600; }
.searchbar { position: relative; flex: 1; min-width: 220px; max-width: 640px; }
.searchbar i.bi-search { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.searchbar input { padding-left: 40px; padding-right: 40px; height: 46px; }
.searchbar kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: var(--line2); color: var(--muted); border: 1px solid var(--line); font-size: .75rem; }
.cash-btn { height: 46px; padding: 0 22px; display: inline-flex; align-items: center; gap: 8px; font-size: 1rem; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); }
.summary > div { display: flex; gap: 12px; align-items: flex-start; padding: 18px 20px; }
.summary > div + div { border-left: 1px solid var(--line); }
.summary .s-ico { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 1.1rem; }
.summary .s-lbl { font-weight: 600; font-size: .9rem; }
.summary .s-val { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
@media (max-width: 640px) {
  .summary { grid-template-columns: 1fr 1fr; }
  .summary > div:last-child { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .summary > div { padding: 14px; }
  .summary .s-val { font-size: 1.2rem; }
  .filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .filters .form-select { min-width: 130px; flex: none; }
  .cash-actions { position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom, 0px)); z-index: 24; display: flex; gap: 10px; padding: 10px 16px; background: color-mix(in srgb, var(--page) 92%, transparent); backdrop-filter: blur(8px); }
  .cash-actions .cash-btn { flex: 1; justify-content: center; }
  body.book-page { padding-bottom: 150px; }
}
.ico-in { background: var(--in-soft); color: var(--in); }
.ico-out { background: var(--out-soft); color: var(--out); }
.ico-net { background: var(--net-soft); color: var(--net); }

/* Entries table */
.etable { width: 100%; border-collapse: separate; border-spacing: 0; }
.etable th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 12px 14px; background: var(--line2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.etable td { padding: 12px 14px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.etable tr.click { cursor: pointer; }
.etable tr.click:hover td { background: var(--line2); }
.etable .amt { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.etable .remark { font-weight: 600; }
.chip-s { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--line2); color: var(--muted); font-weight: 600; white-space: nowrap; }
.chip-s .sw { width: 8px; height: 8px; border-radius: 50%; }
.day-row td { background: var(--page) !important; font-size: .8rem; font-weight: 700; color: var(--muted); padding: 8px 14px; }
@media (max-width: 767px) { .etable .hide-sm { display: none; } }

/* Entry form */
.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-switch label { border: 2px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; font-weight: 700; cursor: pointer; }
#t_in:checked + label { border-color: var(--in); background: var(--in-soft); color: var(--in); }
#t_out:checked + label { border-color: var(--out); background: var(--out-soft); color: var(--out); }
.amount-in { font-size: 2rem; font-weight: 700; height: 64px; font-variant-numeric: tabular-nums; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; }
.stat .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .8rem; color: var(--muted); font-weight: 600; }

/* Bars & charts */
.bar-row { padding: 12px 16px; }
.bar-row + .bar-row { border-top: 1px solid var(--line2); }
.bar { height: 8px; background: var(--line2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; border-radius: 4px; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding: 10px 4px 24px; }
.chart .col { flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; position: relative; min-width: 0; }
.chart .col > i { display: block; width: 45%; max-width: 18px; border-radius: 4px 4px 0 0; }
.chart .col > small { position: absolute; bottom: -20px; font-size: .65rem; color: var(--muted); white-space: nowrap; }

/* Reminders */
.rem-due { font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.rem-over { background: var(--out-soft); color: var(--out); }
.rem-soon { background: var(--warn-soft); color: var(--warn); }
.rem-later { background: var(--line2); color: var(--muted); }

/* Permissions grid */
.perm-grid { width: 100%; font-size: .9rem; }
.perm-grid th { font-size: .75rem; color: var(--muted); text-transform: uppercase; font-weight: 700; text-align: center; padding: 6px; }
.perm-grid td { padding: 8px 6px; border-top: 1px solid var(--line2); text-align: center; }
.perm-grid td:first-child, .perm-grid th:first-child { text-align: left; }

/* Settings tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 14px; }
.tabs a { white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 600; font-size: .9rem; }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; }
.switch-row + .switch-row { border-top: 1px solid var(--line2); }
.switch-row .form-switch .form-check-input { width: 2.8em; height: 1.5em; }

/* Plans */
.plan-card { padding: 20px; position: relative; }
.plan-card .price { font-size: 2rem; font-weight: 700; }
.plan-card.current { border: 2px solid var(--brand); }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: calc(24px + env(safe-area-inset-top, 0px)) 16px 24px;
  background: radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--brand) 18%, transparent), transparent), var(--page); }
.auth-card { width: 100%; max-width: 420px; }
.brand-mark { width: 60px; height: 60px; border-radius: 18px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 1.7rem; margin: 0 auto 12px; box-shadow: 0 10px 30px color-mix(in srgb, var(--brand) 35%, transparent); }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; border-radius: 18px; }
.legal-links a { color: var(--muted); text-decoration: none; }

/* Docs */
.doc { line-height: 1.65; }
.doc h2 { font-size: 1.05rem; font-weight: 700; margin: 22px 0 6px; }
.logo-prev { width: 72px; height: 72px; border-radius: 16px; object-fit: cover; border: 1px solid var(--line); background: var(--line2); display: grid; place-items: center; font-size: 1.6rem; color: var(--muted); }

@media print {
  .sidebar, .bottom-nav, .topbar, .filters, .cash-actions, .no-print { display: none !important; }
  .page { margin: 0 !important; }
  body { background: #fff; }
}
.book-grid > .card-k { position: relative; }
.flex-none { flex: none; }
