:root {
  --paper: #f3ebdd;
  --paper-deep: #e7dccb;
  --card: #fffdf8;
  --ink: #241912;
  --muted: #74685c;
  --line: #e4d7c6;
  --accent: #c6531e;
  --accent-ink: #fff8f3;
  --leaf: #1f6b4a;
  --danger: #9d342c;
  --sidebar: #241912;
  --shadow: 0 18px 40px rgba(36, 25, 18, 0.08);
  --radius: 18px;
  --font: "Hind Siliguri", "Nirmala UI", "Segoe UI", sans-serif;
  --num: "Outfit", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 50%),
    linear-gradient(180deg, color-mix(in srgb, var(--paper) 58%, white) 0%, var(--paper) 42%, color-mix(in srgb, var(--paper) 82%, #8d7360) 100%);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; color: inherit; }
img { max-width: 100%; display: block; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 268px;
  background: var(--sidebar);
  color: #f6efe6;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 18px; }
.brand img, .monogram {
  width: 46px; height: 46px; border-radius: 14px; object-fit: cover;
  background: var(--accent); color: white; display: grid; place-items: center;
  font-family: var(--num); font-weight: 700; letter-spacing: 0.04em;
}
.brand strong { display: block; font-size: 18px; line-height: 1.2; }
.brand small { color: #d9cbbd; }
.nav { display: flex; flex-direction: column; gap: 4px; overflow: auto; flex: 1; min-height: 0; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; color: #f0e6db;
  font-size: 15.5px;
}
.nav a:hover { background: rgba(255,255,255,0.06); }
.nav a.active { background: rgba(198, 83, 30, 0.22); color: white; }
.nav a span.dot {
  width: 7px; height: 7px; border-radius: 99px; background: #c9b8a6; flex: none;
}
.nav a.active span.dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(198,83,30,.25); }
.side-foot { margin-top: auto; padding: 14px 8px 4px; }
.side-foot form { margin: 0; }
.who { font-size: 13px; color: #d9cbbd; margin-bottom: 8px; }
.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  flex-wrap: wrap;
  padding: 26px 32px 8px;
}
.kicker { margin: 0; color: var(--muted); letter-spacing: 0.08em; font-size: 12px; text-transform: uppercase; }
h1 { margin: 2px 0 0; font-size: 32px; font-weight: 700; letter-spacing: -0.03em; }
.content { padding: 12px 32px 48px; }
.topbar .menu-btn { display: none; }
.menu-btn {
  width: 42px; height: 42px; padding: 0; border-radius: 12px;
  border: 1px solid var(--line); background: white; color: var(--ink);
  display: none; flex-direction: column; justify-content: center; align-items: center; gap: 5px;
  cursor: pointer;
}
.menu-btn span { display: block; width: 16px; height: 2px; border-radius: 2px; background: currentColor; }
.back-btn { margin: 0 0 8px; }
th.serial, td.serial, th.row-id, td.row-id {
  width: 2.5rem; text-align: right; color: var(--muted);
  font-family: var(--num); font-variant-numeric: tabular-nums;
}
th.row-id, td.row-id { width: 3.2rem; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 12px 0 18px; }
.stats.cols-5 { grid-template-columns: repeat(5, 1fr); }
.stat, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat { padding: 16px 18px 14px; position: relative; overflow: hidden; }
.stat::after {
  content: ""; position: absolute; right: -20px; top: -30px; width: 90px; height: 90px;
  border-radius: 50%; background: rgba(198, 83, 30, 0.08);
}
.stat .label { color: var(--muted); font-size: 13px; }
.account-stats { gap: 10px; margin: 8px 0 10px; }
.account-stats .stat { padding: 8px 12px 7px; }
.account-stats .label { font-size: 12px; line-height: 1.25; min-height: 2.5em; }
.account-stats .stat .value { font-size: 22px; margin-top: 1px; }
.account-stats .stat .hint { font-size: 11px; margin-top: 1px; line-height: 1.25; }
.account-stats .stat::after { width: 58px; height: 58px; top: -22px; right: -14px; }
.account-groups { display: flex; flex-direction: column; gap: 10px; margin: 0 0 14px; }
.account-group {
  background: color-mix(in srgb, var(--card) 86%, var(--paper));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px 0;
}
.account-group h3 {
  margin: 0 2px; font-size: 15px;
  display: flex; align-items: center; gap: 8px;
}
.account-group h3 span {
  font-family: var(--num); font-size: 12px; font-weight: 650; color: var(--accent);
  background: #f3e4d6; border-radius: 999px; min-width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
}
.account-group .account-stats { margin-top: 6px; margin-bottom: 8px; }
.account-group .stat { background: var(--card); }
.stat .value { font-family: var(--num); font-size: 28px; font-weight: 650; margin-top: 6px; letter-spacing: -0.04em; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat.leaf .value { color: var(--leaf); }
.stat.warn .value { color: var(--danger); }
.stat.accent .value { color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1.2fr 0.8fr 0.9fr; gap: 14px; }
.card { padding: 16px 18px 18px; }
.card h2 { margin: 0 0 12px; font-size: 18px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: -8px; margin-bottom: 12px; }
.split { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.split h2 { margin: 0; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:hover td { background: rgba(243, 235, 221, 0.45); }
.num, .value, td.money, th.money { font-family: var(--num); font-variant-numeric: tabular-nums; }
td.money, th.money { text-align: right; }
.debit { color: var(--danger); font-family: var(--num); }
.credit { color: var(--leaf); font-family: var(--num); }

.khata { background: #fffaf2; }
.khata table { background-image: repeating-linear-gradient(transparent, transparent 39px, rgba(228, 215, 198, 0.45) 40px); }
.balance-pos { color: var(--danger); }
.balance-neg { color: var(--leaf); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.dash-bar { justify-content: space-between; align-items: flex-start; }
.dash-bar .filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1; }
.dash-bar .actions { margin-left: auto; }
.section-title { margin: 4px 0 12px; }
.section-title h2 { margin: 0; font-size: 18px; }
.search { display: flex; gap: 8px; flex: 1; min-width: 180px; }
.toolbar .filter { width: auto; min-width: 150px; }
.input, select.input, textarea.input {
  width: 100%; background: white; border: 1px solid #ddcfc0; border-radius: 12px;
  padding: 10px 12px; outline: none; font-size: 15px;
}
textarea.input { resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(198,83,30,.12); }
.btn {
  border: 0; border-radius: 12px; padding: 10px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { filter: brightness(1.05); }
.btn.soft { background: #f3e4d6; color: var(--ink); }
.btn.ghost { background: transparent; color: #f6efe6; border: 1px solid rgba(255,255,255,.2); }
.btn.line {
  display: inline-flex; grid-template-columns: none;
  background: white; color: var(--ink); border: 1px solid var(--line);
}
.btn.danger { background: var(--danger); color: white; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
td.row-actions { white-space: nowrap; }
td.row-actions .actions { flex-wrap: nowrap; }
.stock-adjust { display: flex; gap: 6px; align-items: center; }
.stock-adjust .input { width: 92px; padding: 6px 8px; border-radius: 10px; }
.stock-adjust .btn {
  width: 36px; height: 36px; min-width: 36px; padding: 0; flex: 0 0 36px;
  display: inline-flex; align-items: center; justify-content: center;
}
.mark { position: relative; width: 14px; height: 14px; display: block; }
.mark::before, .mark.plus::after {
  content: ""; position: absolute; background: currentColor; border-radius: 1px;
}
.mark::before { left: 0; right: 0; top: 6px; height: 2px; }
.mark.plus::after { top: 0; bottom: 0; left: 6px; width: 2px; }
.loan-box { background: #fffaf2; border: 1px dashed #e4d7c6; border-radius: 14px; padding: 12px 14px; display: grid; gap: 8px; }
.loan-box p { margin: 0; }
.settle-options { display: flex; flex-direction: column; gap: 8px; }
.settle-options label { display: flex; gap: 8px; align-items: center; }

.badge {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 8px;
  font-size: 12px; background: #f3e4d6; color: var(--ink);
}
.badge.due { background: #fde8e4; color: var(--danger); }
.badge.ok { background: #e5f4ec; color: var(--leaf); }
.badge.walk { background: #efe7fb; color: #643b86; }
.badge.off { background: #eee; color: #777; }

.messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.msg { padding: 10px 12px; border-radius: 12px; background: #e8f6ee; color: #145c38; }
.msg.error { background: #fdecea; color: #8d2b24; }
.form-error { background: #fdecea; color: #8d2b24; padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field.wide { grid-column: 1 / -1; }
.field span, .field label { color: var(--muted); }
.field .errorlist { margin: 0; padding: 0; list-style: none; color: var(--danger); overflow-wrap: anywhere; }
.visitor-grid .field { min-width: 0; }
.field:has(input[type="checkbox"]) { flex-direction: row; align-items: center; gap: 8px; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.check { display: flex; gap: 8px; align-items: center; background: white; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.perm-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: white; }
.perm-grid { width: 100%; border-collapse: collapse; }
.perm-grid th, .perm-grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: center; }
.perm-grid tr:last-child td { border-bottom: 0; }
.perm-grid th:first-child, .perm-grid td:first-child { text-align: left; font-weight: 600; }
.perm-grid thead th { font-size: 13px; color: var(--muted); font-weight: 600; background: #fff7ef; }
.perm-grid input { width: 18px; height: 18px; accent-color: var(--accent); }

.lines { display: flex; flex-direction: column; gap: 8px; }
.lines > .line {
  display: grid; grid-template-columns: 2fr 0.7fr 0.8fr 0.8fr auto; gap: 8px; align-items: center;
}
.totals { margin-top: 14px; display: grid; grid-template-columns: 1fr 220px; gap: 12px; }
.total-box { background: #fff7ef; border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.total-box div { display: flex; justify-content: space-between; }
.total-box strong { font-family: var(--num); font-size: 20px; }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.list-cards { display: flex; flex-direction: column; gap: 8px; }
.person {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.person:last-child { border-bottom: 0; }
.muted { color: var(--muted); }
.chart-box { height: 280px; }
.login-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 0.9fr;
}
.login-hero {
  padding: 36px 48px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 18px;
  min-height: 100vh; overflow: auto;
  background:
    linear-gradient(160deg, rgba(36,25,18,.2), rgba(36,25,18,.72)),
    radial-gradient(circle at 20% 20%, #e38a52, transparent 40%),
    #241912;
  color: #fff8f1;
}
.login-brand { width: min(420px, 100%); }
.login-brand h1 { margin: 0; font-size: 30px; line-height: 1.12; }
.login-brand .kicker { margin: 0; color: #f0d2c2; }
.login-brand p { margin: 4px 0 0; max-width: 380px; font-size: 14.5px; line-height: 1.45; color: #f6e7dc; }
.visitor-box {
  width: min(420px, 100%);
  background: rgba(255, 248, 241, 0.97);
  color: var(--ink);
  border-radius: 16px;
  padding: 14px 14px 12px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
}
.visitor-box.stack { gap: 8px; }
.visitor-box h2 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.visitor-box .kicker { color: var(--accent); margin: 0; }
.visitor-box .field { gap: 3px; font-size: 12.5px; }
.visitor-box .input, .visitor-box textarea.input {
  padding: 6px 10px; font-size: 14px; border-radius: 9px;
}
.visitor-box textarea.input { min-height: 52px; }
.visitor-box .btn { padding: 7px 12px; border-radius: 9px; font-size: 14px; }
.visitor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.visitor-grid .wide { grid-column: 1 / -1; }
.visitor-ok { background: #e7f6ee; color: #145c38; border-radius: 9px; padding: 7px 10px; font-size: 13px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.nav-count {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: white; font-size: 12px; font-family: var(--num);
  display: inline-flex; align-items: center; justify-content: center;
}
.person.fresh { background: #fff6ec; margin: 0 -8px; padding: 10px 8px; border-radius: 12px; }
.login-panel { display: grid; place-items: center; padding: 28px; }
.login-card { width: min(340px, 100%); }
.login-card.stack { gap: 10px; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card .input { padding: 8px 11px; }
.login-card .btn { padding: 8px 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.print-sheet { width: 720px; margin: 24px auto; background: white; padding: 28px; }
.brand { color: inherit; }
.brand:hover { opacity: 0.88; }
.global-search { display: flex; gap: 8px; flex: 1; min-width: 220px; max-width: 420px; }
.hero { display: flex; justify-content: space-between; gap: 18px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; background: linear-gradient(135deg, #fffaf4, #fff 55%, #f8efe4); }
.hero h2 { margin: 0; font-size: 28px; }
.hero-search, .global-search { display: flex; gap: 8px; }
.hero-search { flex: 1; min-width: 240px; }
.hero-search .input { background: white; }
.section-title { margin: 18px 0 10px; font-size: 20px; }
.halkhata-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.halkhata-grid.single { max-width: 420px; }
.halkhata-card {
  background: #fffaf3; border: 1px solid #c6531e; outline: 1px solid #e7cbb8; outline-offset: -8px;
  border-radius: 18px; padding: 22px 18px 16px; min-height: 460px;
  display: flex; flex-direction: column; gap: 6px; break-inside: avoid; page-break-inside: avoid;
}
.halkhata-top { display: flex; gap: 10px; align-items: center; }
.halkhata-top img, .halkhata-top .monogram { width: 42px; height: 42px; border-radius: 12px; object-fit: cover; }
.halkhata-mark { margin: 10px 0 0; font-size: 28px; letter-spacing: 0.12em; }
.halkhata-card h2 { margin: 0; }
.halkhata-card dl { margin: 8px 0; }
.halkhata-card dl div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed #eadfce; padding: 5px 0; }
.halkhata-card dt { color: var(--muted); max-width: 62%; }
.halkhata-card dd { margin: 0; font-family: var(--num); }
.halkhata-note { margin-top: auto; }
.pin { font-size: 12px; color: var(--muted); }
.settings-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.settings-layout .wide { grid-column: 1 / -1; }
.identity { display: grid; grid-template-columns: 92px 1fr; gap: 14px; align-items: start; }
.logo-preview, .monogram.big { width: 84px; height: 84px; border-radius: 20px; object-fit: cover; }
.monogram.big { display: grid; place-items: center; background: var(--accent); color: white; font-size: 28px; }
.swatches { display: flex; gap: 8px; margin-bottom: 12px; }
.swatches span { width: 42px; height: 42px; border-radius: 14px; display: block; }
.swatches span:nth-child(1) { background: var(--swatch-a, var(--accent)); }
.swatches span:nth-child(2) { background: var(--swatch-b, var(--leaf)); }
.swatches span:nth-child(3) { background: var(--swatch-c, var(--sidebar)); }
.swatches span:nth-child(4) { background: var(--swatch-d, var(--paper)); border: 1px solid var(--line); }
.search-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.card strong { font-family: var(--num); }

@media print {
  .no-print, .sidebar, .topbar, .toolbar, .pager, .side-foot { display: none !important; }
  body { background: white; }
  .app, .main { display: block; }
  .content { padding: 0; }
  .card, .stat, .halkhata-card { box-shadow: none; }
  .print-sheet { box-shadow: none; margin: 0; width: auto; }
  .halkhata-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 1100px) {
  .stats, .stats.cols-5, .grid-2, .grid-3, .form-grid, .totals, .settings-layout, .search-grid { grid-template-columns: 1fr 1fr; }
  .grid-3, .settings-layout .wide { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .topbar .menu-btn { display: inline-flex; }
  .sidebar { position: fixed; z-index: 20; transform: translateX(-105%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .stats, .stats.cols-5, .grid-2, .form-grid, .totals, .login-wrap, .line, .settings-layout, .search-grid, .identity, .halkhata-grid { grid-template-columns: 1fr; }
  h1 { font-size: 26px; }
  .login-wrap { display: flex; flex-direction: column; }
  .login-panel { order: -1; }
  .login-hero { display: flex; min-height: 0; padding: 16px 16px 24px; justify-content: flex-start; }
  .login-brand h1 { font-size: 26px; }
  .visitor-box { width: 100%; }
  .visitor-grid { grid-template-columns: 1fr; }
}
