/* ============================================================
   Modern Ledger — design system
   Paper canvas · ink text · mono tabular figures · one accent
   Mobile-first, responsive to desktop.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,400;0,500;0,600;0,700;0,800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Surfaces */
  --paper:      #FBFAF6;
  --paper-2:    #F3F0E7;
  --panel:      #FFFFFF;
  --ink:        #16150F;
  --ink-2:      #6B6656;
  --ink-3:      #9A9482;
  --line:       #E7E2D5;
  --line-2:     #D8D2C2;

  /* Composition (donut) — clear red / green / blue */
  --c-green:    #1FA85A;
  --c-blue:     #2F6BFF;
  --c-red:      #E5342A;

  /* Page background (no more ruled lines) */
  --bg:         #FBFAF6;
  --bg-glow:    radial-gradient(52% 44% at 100% 0%, rgba(14,92,67,.06), transparent 62%),
                radial-gradient(46% 40% at 0% 6%, rgba(14,92,67,.045), transparent 60%);

  /* Brand + semantics */
  --accent:     #0E5C43;   /* currency green */
  --accent-2:   #0A4632;
  --primary:    #0891B2;   /* cyan — primary actions */
  --primary-2:  #0E7490;   /* cyan hover */
  --pop:        #D8F24B;   /* acid lime, used sparingly */
  --paid:       #0E7A4E;
  --due:        #B0791C;
  --over:       #C0362C;
  --info:       #2F5BEA;

  /* Radius + shadow */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(22,21,15,.05);
  --shadow-md: 0 6px 20px -8px rgba(22,21,15,.18);
  --shadow-lg: 0 24px 60px -24px rgba(22,21,15,.30);

  /* Type */
  /* One consistent typeface across the UI; mono is reserved only for tabular figures. */
  --ui: 'Source Sans 3', ui-sans-serif, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --display: 'Source Sans 3', ui-sans-serif, system-ui, sans-serif;

  --nav-h: 64px;
}

/* ---------- Dark mode (Nocturne) ---------- */
[data-theme="dark"] { color-scheme: dark; }
[data-theme="dark"] {
  --paper:   #0B0E14;
  --paper-2: #1C2330;
  --panel:   #151A23;
  --ink:     #EAF0FA;
  --ink-2:   #8B97AD;
  --ink-3:   #5C6577;
  --line:    #242C3A;
  --line-2:  #2E3746;

  --accent:  #57F2C4;
  --accent-2:#31C39B;
  --primary: #22D3EE;
  --primary-2:#67E8F9;
  --pop:     #9B8CFF;
  --paid:    #34D399;
  --due:     #F5B851;
  --over:    #FF6B6B;
  --info:    #6E9BFF;

  --c-green: #34D77B;
  --c-blue:  #5B8DFF;
  --c-red:   #FF6B6B;

  --bg:      #0B0E14;
  --bg-glow: radial-gradient(60% 40% at 82% -5%, rgba(87,242,196,.12), transparent 60%),
             radial-gradient(52% 42% at 0% 8%, rgba(155,140,255,.12), transparent 60%);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
  --shadow-md: 0 10px 28px -12px rgba(0,0,0,.7);
  --shadow-lg: 0 24px 60px -24px rgba(0,0,0,.8);
}
[data-theme="dark"] .kpi.feature { background: linear-gradient(140deg, #141A26, #10202A); border-color: rgba(87,242,196,.28); color: var(--ink); }
[data-theme="dark"] .kpi.feature .label { color: var(--ink-2); }
[data-theme="dark"] .kpi.feature .value { color: var(--accent); }
[data-theme="dark"] .chart .bar .col span { box-shadow: 0 0 18px rgba(87,242,196,.30); }
[data-theme="dark"] .chart .bar.now .col span { background: var(--ink); box-shadow: none; }
[data-theme="dark"] .wordmark .mark { background: linear-gradient(135deg, var(--accent), var(--pop)); color: #0B0E14; }
[data-theme="dark"] .fab { color: #06232B; background: var(--primary); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background-color: var(--bg);
  background-image: var(--bg-glow);
  background-attachment: fixed;
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: -0.006em;
  transition: background-color .3s ease, color .3s ease;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* Numbers everywhere money/data appears */
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.rupee { font-family: var(--mono); opacity: .55; margin-right: .12em; font-weight: 500; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.wordmark {
  font-family: var(--display); font-weight: 600; font-size: 22px;
  letter-spacing: -0.02em; display: flex; align-items: center; gap: 9px;
}
.wordmark .mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--ink);
  color: var(--pop); display: grid; place-items: center;
  font-family: var(--mono); font-size: 15px; font-weight: 600;
  transform: rotate(-4deg);
}
.topbar .spacer { flex: 1; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--line-2);
  background: var(--panel); display: grid; place-items: center; color: var(--ink-2);
  transition: .18s;
}
.iconbtn:hover { border-color: var(--ink); color: var(--ink); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px;
}

/* Sidebar (desktop) */
.sidebar { display: none; }

/* Main */
.main { padding: 18px 18px calc(var(--nav-h) + 28px); max-width: 1200px; margin: 0 auto; }

/* Bottom nav (mobile) */
.botnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
.botnav a {
  display: grid; justify-items: center; gap: 3px; padding: 6px 0;
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em; color: var(--ink-3);
  position: relative; transition: .18s;
}
.botnav a svg { width: 21px; height: 21px; }
.botnav a.active { color: var(--ink); }
.botnav a.active::before {
  content: ''; position: absolute; top: -8px; width: 26px; height: 3px;
  border-radius: 3px; background: var(--accent);
}
.botnav .fab-slot { position: relative; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin: 6px 0 20px; }
.page-head .eyebrow { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-3); }
.page-head h1 { font-size: clamp(26px, 7vw, 36px); margin: 4px 0 0; letter-spacing: -0.03em; font-weight: 800; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 18px;
  border-radius: 12px; border: 1px solid transparent; font-weight: 700; font-size: 14px;
  transition: .18s; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: var(--paper); }
.btn-primary:hover { background: var(--primary-2); }
.btn-ghost { background: var(--panel); border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
.btn:disabled { opacity: .45; pointer-events: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px; }

/* KPI grid */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi { position: relative; overflow: hidden; padding: 16px 16px 18px; }
.kpi .label { font-size: 12px; color: var(--ink-2); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi .dot { width: 7px; height: 7px; border-radius: 50%; }
.kpi .value { font-size: clamp(22px, 6.4vw, 30px); font-weight: 500; margin-top: 12px; }
.kpi .delta { font-size: 11.5px; font-weight: 600; margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; }
.kpi.feature { grid-column: span 2; background: var(--ink); color: var(--paper); border-color: var(--ink); }
.kpi.feature .label { color: color-mix(in srgb, var(--paper) 70%, transparent); }
.kpi.feature .value { color: var(--paper); font-weight: 500; }
.kpi.feature .value .rupee { opacity: .5; }
.kpi.feature::after {
  content: ''; position: absolute; right: -30px; bottom: -40px; width: 150px; height: 150px;
  background: radial-gradient(circle, color-mix(in srgb, var(--pop) 26%, transparent), transparent 70%);
}

.up { color: var(--paid); }
.down { color: var(--over); }

/* Compact KPI row */
.kpis.compact { gap: 10px; margin-bottom: 10px; }
.kpis.compact .kpi { padding: 12px 14px; }
.kpis.compact .kpi .label { font-size: 11.5px; }
.kpis.compact .kpi .value { font-size: clamp(19px, 5vw, 22px); margin-top: 6px; }
.kpis.compact .kpi .delta { margin-top: 3px; }
.kpis.compact .kpi.feature::after { width: 110px; height: 110px; }

/* ---------- Section ---------- */
.section { margin-top: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.section-head a { font-size: 13px; font-weight: 600; color: var(--accent); }

/* ---------- Ledger rows (invoice list) ---------- */
.ledger { list-style: none; margin: 0; padding: 0; }
.ledger li {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.ledger li:last-child { border-bottom: 0; }
.ledger .who { font-weight: 700; font-size: 14.5px; }
.ledger .meta { font-size: 12px; color: var(--ink-3); font-family: var(--mono); letter-spacing: -0.01em; }
.ledger .amt { text-align: right; font-size: 15px; font-weight: 500; }
.ledger .chip-wrap { grid-column: 2; }

/* Status chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 25px; padding: 0 10px 0 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .01em;
  border: 1px solid transparent; text-transform: capitalize; white-space: nowrap;
}
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 16%, transparent); }
.chip.paid    { color: var(--paid); background: color-mix(in srgb, var(--paid) 13%, transparent); }
.chip.partial { color: var(--info); background: color-mix(in srgb, var(--info) 13%, transparent); }
.chip.due     { color: var(--due);  background: color-mix(in srgb, var(--due) 14%, transparent); }
.chip.over    { color: var(--over); background: color-mix(in srgb, var(--over) 13%, transparent); }
.chip.draft   { color: var(--ink-2); background: var(--paper-2); border-color: var(--line-2); }

/* ---------- Segmented control (period toggle) ---------- */
.segment {
  display: inline-flex; padding: 3px; border-radius: 11px; background: var(--paper-2);
  border: 1px solid var(--line); gap: 2px;
}
.segment button {
  border: none; background: transparent; color: var(--ink-2); font-weight: 700; font-size: 13px;
  padding: 7px 15px; border-radius: 8px; transition: .16s; letter-spacing: .01em;
}
.segment button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- Summary period label ---------- */
.period-note { font-family: var(--mono); font-size: 11px; color: var(--ink-3); letter-spacing: .02em; }

/* ---------- Donut composition ---------- */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 150px; height: 150px; flex-shrink: 0; transform: rotate(-90deg); }
.donut circle { fill: none; stroke-width: 18; stroke-linecap: butt; }
.donut .track { stroke: var(--paper-2); }
.donut-seg { transition: stroke-dasharray .9s cubic-bezier(.2,.8,.2,1); }
.donut-center { position: relative; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 11px; flex: 1; }
.legend li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .lb { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.legend .vl { font-size: 13px; font-weight: 500; }

/* ---------- Mini bar chart ---------- */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 120px; padding: 4px 2px 0; }
.chart .bar { flex: 1; display: grid; align-items: end; gap: 8px; text-align: center; }
.chart .bar .col { width: 100%; border-radius: 6px 6px 3px 3px; background: var(--paper-2); position: relative; overflow: hidden; }
.chart .bar .col span { position: absolute; inset: auto 0 0 0; background: var(--accent); border-radius: 6px 6px 3px 3px; animation: grow 1s cubic-bezier(.2,.8,.2,1) both; }
.chart .bar.now .col span { background: var(--ink); }
.chart .bar .m { font-size: 10.5px; color: var(--ink-3); font-family: var(--mono); }
.chart.year { gap: 5px; }
.chart.year .bar .m { font-size: 8.5px; }
.chart .bar .col span.empty { background: var(--line); }
@keyframes grow { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ---------- Outstanding clients ---------- */
.clients { list-style: none; margin: 0; padding: 0; }
.clients li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.clients li:last-child { border-bottom: 0; }
.clients .ini { width: 38px; height: 38px; border-radius: 11px; background: var(--paper-2); display: grid; place-items: center; font-weight: 700; font-size: 14px; color: var(--accent); }
.clients .grow { flex: 1; min-width: 0; }
.clients .nm { display: block; font-weight: 700; font-size: 14px; }
.clients .sub { display: block; font-size: 11.5px; color: var(--ink-3); font-family: var(--mono); }
.clients .bal { font-weight: 500; font-size: 14.5px; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.search { flex: 1; min-width: 180px; display: flex; align-items: center; gap: 9px; padding: 0 14px; height: 44px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; }
.search:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
.search svg { width: 18px; height: 18px; color: var(--ink-3); flex-shrink: 0; }
.search input { border: none; outline: none; background: transparent; font: inherit; width: 100%; color: var(--ink); }
.select { height: 44px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel); font: inherit; font-weight: 600; color: var(--ink); }

/* Selects — remove native chrome, add a themed chevron */
select.input, .select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  cursor: pointer; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B6656' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; background-size: 16px;
}
select.input:hover, .select:hover { border-color: var(--ink-3); }
select.input:focus, .select:focus { outline: none; border-color: var(--ink); }
.select:focus, select.input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
[data-theme="dark"] select.input, [data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238B97AD' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
select.input option, .select option { background: var(--panel); color: var(--ink); }

.filter-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; -ms-overflow-style: none; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.fchip { flex-shrink: 0; height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); font-size: 13px; font-weight: 600; color: var(--ink-2); display: inline-flex; align-items: center; gap: 7px; transition: .15s; }
.fchip .ct { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.fchip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.fchip.on .ct { color: color-mix(in srgb, var(--paper) 65%, transparent); }

/* Table lists: card-style on mobile, ruled table on desktop */
.lhead { display: none; }
.ledger.table .col-date, .ledger.table .col-bal { display: none; }
@media (min-width: 700px) {
  .lhead { display: grid; grid-template-columns: 1.6fr 1fr .9fr .9fr auto; gap: 12px; padding: 10px 16px; font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); border-bottom: 1px solid var(--line-2); }
  .lhead .r { text-align: right; }
  .ledger.table li { grid-template-columns: 1.6fr 1fr .9fr .9fr auto; align-items: center; }
  .ledger.table .col-date, .ledger.table .col-bal { display: block; }
  .ledger.table .chip-wrap { grid-column: auto; justify-self: start; }
  .ledger.table .amt { grid-column: auto; }
}

/* Filter count badge on the Filters button */
.fbadge { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin-left: 3px; border-radius: 10px; background: var(--accent); color: #fff; font-family: var(--mono); font-size: 11px; font-weight: 600; }

/* Group header row (grouped lists) */
.ledger .group-head, .clients .group-head { display: flex; align-items: center; justify-content: space-between; padding: 9px 16px; background: var(--paper-2); border-bottom: 1px solid var(--line-2); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2); font-weight: 600; }
.ledger .group-head .gcount, .clients .group-head .gcount { color: var(--ink-3); }

/* Clients list: initials as a full-height left band + right status stripe (mirrors invoices) */
.clients.striped li { position: relative; padding-left: 62px; padding-right: 34px; }
.clients.striped.nostripe li { padding-right: 16px; }
.clients li.group-head { padding-left: 16px; padding-right: 16px; }
.clients.striped .ini { position: absolute; left: 0; top: 0; bottom: 0; width: 52px; height: auto; border-radius: 0; border-right: 1px solid var(--line); font-size: 14px; font-weight: 700; }
.clients .ini.s-paid    { background: color-mix(in srgb, var(--paid) 14%, transparent); color: var(--paid); }
.clients .ini.s-due     { background: color-mix(in srgb, var(--due) 16%, transparent);  color: var(--due); }
.clients .ini.s-over    { background: color-mix(in srgb, var(--over) 14%, transparent); color: var(--over); }

/* Invoices row: [date band] · Client·Invoice · Amount · [status stripe] — both edges flush */
.lhead.inv, .ledger.inv li { grid-template-columns: 1.6fr 1fr; }
.ledger.inv li { position: relative; padding-left: 62px; padding-right: 34px; }
.ledger.inv li:not(.group-head) { cursor: pointer; transition: background .14s; }
.ledger.inv li:not(.group-head):hover { background: var(--paper-2); }
.ledger.inv.nostripe li { padding-right: 16px; }
.ledger.inv li.group-head { padding-left: 16px; padding-right: 16px; }
.lhead.inv { padding-left: 62px; padding-right: 34px; }

/* Full-height date band, flush to the left edge, filled with the status color */
.dateblock { position: absolute; left: 0; top: 0; bottom: 0; width: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--line); line-height: 1; }
.dateblock b { font-family: var(--mono); font-size: 16px; font-weight: 600; letter-spacing: -.02em; }
.dateblock span { font-family: var(--mono); font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; margin-top: 2px; }
.dateblock.s-paid    { background: color-mix(in srgb, var(--paid) 14%, transparent); color: var(--paid); }
.dateblock.s-partial { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); }
.dateblock.s-due     { background: color-mix(in srgb, var(--due) 16%, transparent);  color: var(--due); }
.dateblock.s-over    { background: color-mix(in srgb, var(--over) 14%, transparent); color: var(--over); }
.dateblock.s-draft   { background: var(--paper-2); color: var(--ink-2); }
.statusbar { position: absolute; top: 0; right: 0; bottom: 0; width: 24px; display: flex; align-items: center; justify-content: center; border-left: 1px solid var(--line); }
.statusbar b { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 8.5px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; line-height: 1; }
.statusbar.s-paid    { background: color-mix(in srgb, var(--paid) 14%, transparent); color: var(--paid); }
.statusbar.s-partial { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); }
.statusbar.s-due     { background: color-mix(in srgb, var(--due) 16%, transparent);  color: var(--due); }
.statusbar.s-over    { background: color-mix(in srgb, var(--over) 14%, transparent); color: var(--over); }
.statusbar.s-draft   { background: var(--paper-2); color: var(--ink-2); }
.statusbar.s-service { background: color-mix(in srgb, var(--info) 14%, transparent);   color: var(--info); }
.statusbar.s-product { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

/* Items list: type as a right stripe, GST under the rate */
.ledger.items li { position: relative; padding-right: 34px; cursor: pointer; transition: background .14s; }
.ledger.items li:hover { background: var(--paper-2); }
.lhead.items { grid-template-columns: 1fr auto; padding-right: 34px; }

/* Pagination */
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.pager .info { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.pager .nav { display: flex; gap: 6px; }
.pager button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel); color: var(--ink); font-weight: 700; }
.pager button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.pager button:disabled { opacity: .4; }

/* ---------- Forms (editor) ---------- */
.field { display: block; margin-bottom: 14px; }
.field > .lab { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; letter-spacing: .01em; }
.input { width: 100%; height: 46px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel); font: inherit; color: var(--ink); }
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
textarea.input { height: auto; padding: 12px 14px; resize: vertical; min-height: 84px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Line items */
.lines { list-style: none; margin: 0; padding: 0; }
.line { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; padding: 14px 0; border-bottom: 1px dashed var(--line-2); }
.line .lname { grid-column: 1 / -1; }
.line .mini { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 8px; align-items: center; grid-column: 1 / -1; }
.line .mini .input { height: 40px; text-align: right; }
.line .mini .amt { font-weight: 500; text-align: right; padding-right: 4px; }
.line .rm { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-3); font-size: 18px; }
.line .rm:hover { border-color: var(--over); color: var(--over); }

/* Unit toggle (₹ / %) + mini numeric input, used in totals */
.unit-toggle { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.unit-toggle button { border: 0; background: var(--panel); color: var(--ink-3); font-family: var(--mono); font-weight: 700; font-size: 12px; width: 26px; height: 30px; cursor: pointer; }
.unit-toggle button.on { background: var(--ink); color: var(--paper); }
.miniinput { width: 58px; height: 30px; text-align: right; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 8px; background: var(--panel); color: var(--ink); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.miniinput:focus { outline: none; border-color: var(--ink); }

/* Totals summary card */
.totals { display: grid; gap: 10px; }
.totals .row { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
.totals .row .k { color: var(--ink-2); font-weight: 600; }
.totals .grand { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 2px; }
.totals .grand .k { font-size: 15px; font-weight: 800; color: var(--ink); }
.totals .grand .v { font-size: 24px; font-weight: 500; }

@media (min-width: 900px) {
  .editor-grid { display: grid; grid-template-columns: 1fr 340px; gap: 22px; align-items: start; }
  .editor-grid .aside { position: sticky; top: 30px; }
}

/* ---------- Invoice document (preview / print) ---------- */
.doc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 26px; box-shadow: var(--shadow-sm); }
.doc-top { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.doc-top .biz { font-weight: 800; font-size: 18px; }
.doc-top .muted { color: var(--ink-2); font-size: 13px; line-height: 1.6; }
.doc-title { text-align: right; }
.doc-title .big { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.doc-parties { display: grid; gap: 18px; grid-template-columns: 1fr; margin: 22px 0; }
@media (min-width: 560px) { .doc-parties { grid-template-columns: 1fr 1fr; } }
.doc-parties .lbl { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); margin-bottom: 6px; }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th { text-align: left; font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); padding: 10px 8px; border-bottom: 1px solid var(--line-2); }
.doc-table th.r, .doc-table td.r { text-align: right; }
.doc-table td { padding: 13px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.doc-sum { margin-top: 18px; margin-left: auto; max-width: 280px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 20px 26px; }
.timeline li::before { content: ''; position: absolute; left: 5px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.timeline li::after { content: ''; position: absolute; left: 9px; top: 16px; bottom: 0; width: 2px; background: var(--line-2); }
.timeline li:last-child { padding-bottom: 0; }
.timeline li:last-child::after { display: none; }
.timeline .t { font-weight: 700; font-size: 14px; }
.timeline .d { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.timeline li.pending::before { background: var(--panel); border: 2px solid var(--line-2); box-shadow: none; }

/* Aging bars */
.aging { display: grid; gap: 12px; }
.aging .r { display: grid; gap: 6px; }
.aging .rt { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.aging .track { height: 10px; border-radius: 6px; background: var(--paper-2); overflow: hidden; }
.aging .fill { height: 100%; border-radius: 6px; }

/* Settings tabs (reuse filter-row look) + rows */
.set-list { list-style: none; margin: 0; padding: 0; }
.set-row { display: flex; align-items: center; gap: 14px; padding: 16px; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row .ic { width: 40px; height: 40px; border-radius: 11px; background: var(--paper-2); display: grid; place-items: center; color: var(--accent); flex-shrink: 0; }
.set-row .grow { flex: 1; min-width: 0; }
.set-row .t { display: block; font-weight: 700; font-size: 14.5px; }
.set-row .s { display: block; font-size: 12.5px; color: var(--ink-3); }
.set-row .chev { color: var(--ink-3); }

/* Settings section label */
.setgroup { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); margin: 24px 4px 9px; }
.setgroup::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.set-row.tap { cursor: pointer; transition: background .14s; }
.set-row.tap:hover { background: var(--paper-2); }
.set-row .val { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); font-weight: 600; }

/* Toggle switch */
.switch { width: 44px; height: 26px; border-radius: 999px; background: var(--line-2); position: relative; transition: .2s; border: none; flex-shrink: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: var(--shadow-sm); }
.switch.on { background: var(--accent); }
.switch.on::after { left: 21px; }

/* Empty state */
.empty { text-align: center; padding: 48px 20px; }
.empty .em { width: 64px; height: 64px; border-radius: 18px; background: var(--paper-2); display: grid; place-items: center; margin: 0 auto 16px; color: var(--ink-3); }
.empty h3 { font-size: 17px; font-weight: 700; }
.empty p { color: var(--ink-2); font-size: 14px; margin: 6px auto 18px; max-width: 40ch; }

/* ---------- FAB (mobile) ---------- */
/* Extended, labelled action button — reads as part of the UI, not a generic + blob */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px); z-index: 45;
  display: inline-flex; align-items: center; gap: 8px; height: 50px; padding: 0 20px 0 17px;
  border-radius: 15px; background: var(--primary); color: #fff; border: none;
  font-family: var(--ui); font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  box-shadow: var(--shadow-lg); cursor: pointer; transition: transform .18s ease, background .18s ease;
}
.fab svg { width: 19px; height: 19px; }
.fab:hover { transform: translateY(-2px); background: var(--primary-2); }
.fab:active { transform: translateY(0); }

/* ---------- Left drawer (add / create flows) ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(10,12,16,.42); backdrop-filter: blur(2px); opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility .25s ease; z-index: 60; }
.drawer-scrim.open { opacity: 1; visibility: visible; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 92vw); z-index: 61;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transform: translateX(102%);
  transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.drawer.open { transform: none; }
.drawer.drawer-wide { width: min(720px, 96vw); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.drawer-head .sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.drawer-x { width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-2); font-size: 20px; flex-shrink: 0; }
.drawer-x:hover { border-color: var(--ink); color: var(--ink); }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 16px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.drawer-foot .btn { flex: 1; justify-content: center; }
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }

/* ---------- Entrance animation ---------- */
.stagger > * { opacity: 0; transform: translateY(10px); animation: rise .6s cubic-bezier(.2,.8,.2,1) forwards; }
.stagger > *:nth-child(1) { animation-delay: .04s; }
.stagger > *:nth-child(2) { animation-delay: .10s; }
.stagger > *:nth-child(3) { animation-delay: .16s; }
.stagger > *:nth-child(4) { animation-delay: .22s; }
.stagger > *:nth-child(5) { animation-delay: .28s; }
.stagger > *:nth-child(6) { animation-delay: .34s; }
@keyframes rise { to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* ============================================================
   Desktop
   ============================================================ */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 250px 1fr; }
  .botnav, .fab { display: none; }
  .topbar { display: none; }

  .sidebar {
    display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
    padding: 22px 16px; border-right: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 70%, var(--panel));
  }
  .sidebar .wordmark { padding: 4px 8px 22px; }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 11px;
    font-weight: 600; font-size: 14px; color: var(--ink-2); transition: .16s;
  }
  .sidebar nav a svg { width: 19px; height: 19px; }
  .sidebar nav a:hover { background: var(--paper-2); color: var(--ink); }
  .sidebar nav a.active { background: var(--ink); color: var(--paper); }
  .sidebar nav a.active svg { color: var(--pop); }
  .sidebar .side-foot { margin-top: auto; }
  .sidebar .newbtn { width: 100%; justify-content: center; margin-bottom: 16px; }
  .sidebar .userchip { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-family: inherit; }
  .sidebar .userchip .nm { font-size: 13px; font-weight: 700; }
  .sidebar .userchip .rl { font-size: 11px; color: var(--ink-3); }

  .main { padding: 30px 40px 60px; }
  .kpis { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .kpi.feature { grid-column: span 1; }
  .split { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
  .page-head h1 { font-size: 34px; }
}

.desktop-actions { display: none; gap: 10px; }
@media (min-width: 900px) {
  .desktop-actions { display: flex; }
  .mobile-only { display: none !important; }
}

/* ---------- Onboarding (no app chrome) ---------- */
body.onboarding .sidebar,
body.onboarding .topbar,
body.onboarding .botnav,
body.onboarding .fab { display: none !important; }
body.onboarding .app { display: block; }
body.onboarding .main { max-width: none; margin: 0; padding: 0; min-height: 100vh; }

/* ---------- Settings: app icon picker + image upload ---------- */
.iconpick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.iconpick .tile { position: relative; aspect-ratio: 1/1; border-radius: 16px; border: 2px solid transparent; cursor: pointer; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 24px; overflow: hidden; background-size: cover; background-position: center; }
.iconpick .tile svg { width: 28px; height: 28px; }
.iconpick .tile.sel { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.iconpick .tile.sel::after { content: '✓'; position: absolute; top: 5px; right: 6px; font-size: 12px; background: var(--primary); color: #fff; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; }
.iconpick .upload { background: var(--paper-2); border: 2px dashed var(--line-2); color: var(--ink-3); font-size: 11px; font-weight: 700; }
.iconpick .upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.imgdrop { display: grid; place-items: center; min-height: 150px; border: 2px dashed var(--line-2); border-radius: 14px; background: var(--paper-2); padding: 20px; text-align: center; position: relative; cursor: pointer; color: var(--ink-2); font-size: 13px; font-weight: 600; line-height: 1.8; }
.imgdrop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.imgdrop img { max-height: 120px; max-width: 100%; border-radius: 8px; }
#appicon-thumb svg { width: 19px; height: 19px; }
