/* Nikat Billing Solutions — design tokens + components. Mobile-first. */
:root {
  --brand: #0F766E; --brand-ink: #ffffff; --brand-soft: #E6F4F2; --dark: #0B1F2A; --accent: #F59E0B;
  --bg: #F6F8F9; --surface: #FFFFFF; --surface-2: #F1F4F5; --line: #DDE3E6; --text: #13232C; --muted: #5B6B73;
  --ok: #15803D; --ok-soft: #E7F6EC; --warn: #B45309; --warn-soft: #FEF3C7; --bad: #B91C1C; --bad-soft: #FDECEC; --info: #1D4ED8; --info-soft: #E8EFFD;
  --radius: 10px; --shadow: 0 1px 2px rgba(11,31,42,.06), 0 4px 16px rgba(11,31,42,.06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', 'Noto Sans Devanagari', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --brand: #2DD4BF; --brand-ink: #062A27; --brand-soft: #0F2E2C; --bg: #0B1419; --surface: #111D24; --surface-2: #16252D; --line: #24363F; --text: #E3ECEF; --muted: #93A6AE;
  --ok: #4ADE80; --ok-soft: #12301F; --warn: #FBBF24; --warn-soft: #33270C; --bad: #F87171; --bad-soft: #3A1717; --info: #93C5FD; --info-soft: #14243F;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .tiny { font-size: .75rem; }
.hide { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .6rem; padding: .55rem .9rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); }
.logo-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; font-size: .9rem; }
.topbar .spacer { flex: 1; }
.iconbtn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; height: 36px; min-width: 36px; padding: 0 .55rem; cursor: pointer; font: inherit; }
.iconbtn:hover { background: var(--surface-2); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 272px; transform: translateX(-100%); transition: transform .2s; z-index: 50; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; padding: .75rem .5rem 5rem; }
.sidebar.open { transform: none; box-shadow: var(--shadow); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.nav-group { margin: .75rem .5rem .25rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .75rem; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .lock { font-size: .7rem; color: var(--muted); }
.main { padding: 1rem .9rem 6rem; max-width: 1240px; width: 100%; margin: 0 auto; }
.bottombar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding: .35rem .4rem calc(.35rem + env(safe-area-inset-bottom)); }
.bottombar a { display: flex; flex-direction: column; align-items: center; font-size: .72rem; color: var(--muted); padding: .25rem; border-radius: 8px; }
.bottombar a b { font-size: 1.1rem; color: var(--text); }
.bottombar a.primary b { background: var(--brand); color: var(--brand-ink); border-radius: 50%; width: 32px; height: 32px; display: grid; place-items: center; }
@media (min-width: 960px) {
  .shell { grid-template-columns: 248px 1fr; }
  .sidebar { position: sticky; top: 53px; height: calc(100vh - 53px); transform: none; width: auto; padding-bottom: 1rem; z-index: 20; }
  .scrim, .bottombar, .menu-btn { display: none !important; }
  .main { padding: 1.25rem 1.75rem 3rem; }
  .shell > .topbar { grid-column: 1 / -1; }
}

@media (max-width: 719px) { .hide-sm, .topbar .tenant-name { display: none !important; } .topbar select { max-width: 140px !important; } }

/* ---------- banners ---------- */
.banner { padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: .9rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.banner.info { background: var(--info-soft); color: var(--info); } .banner.warn { background: var(--warn-soft); color: var(--warn); } .banner.bad { background: var(--bad-soft); color: var(--bad); } .banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner .spacer { flex: 1; }

/* ---------- layout pieces ---------- */
.page-head { display: flex; align-items: flex-start; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .spacer { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: .9rem; }
.grid.k { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .grid.k { grid-template-columns: repeat(4, minmax(0, 1fr)); } .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; }
.kpi .label { font-size: .78rem; color: var(--muted); } .kpi .value { font-family: var(--mono); font-size: 1.25rem; font-weight: 600; margin-top: .15rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row .spacer { flex: 1; }
.stack > * + * { margin-top: .6rem; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; margin: 0; } dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .5rem .9rem; font: inherit; font-weight: 600; cursor: pointer; min-height: 38px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; } .btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .25rem .6rem; min-height: 30px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
label.field { display: block; } label.field > span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; min-height: 38px; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.form-grid { display: grid; gap: .7rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .form-grid { grid-template-columns: repeat(2, 1fr); } .form-grid .full { grid-column: 1 / -1; } .form-grid.three { grid-template-columns: repeat(3, 1fr); } }
.help { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.err { color: var(--bad); font-size: .85rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: var(--surface-2); }
.lines-table input, .lines-table select { min-height: 34px; padding: .3rem .4rem; }
@media (max-width: 719px) {
  table.cards thead { display: none; }
  table.cards tr { display: block; border-bottom: 1px solid var(--line); padding: .4rem 0; }
  table.cards td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .25rem .7rem; }
  table.cards td::before { content: attr(data-l); color: var(--muted); font-size: .8rem; }
  table.cards td.num { text-align: right; }
}

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.draft { background: var(--surface-2); color: var(--muted); } .badge.issued, .badge.claimed, .badge.open, .badge.trial { background: var(--info-soft); color: var(--info); }
.badge.sent, .badge.part_paid, .badge.proposed, .badge.grace, .badge.readonly { background: var(--warn-soft); color: var(--warn); }
.badge.paid, .badge.verified, .badge.matched, .badge.approved, .badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.cancelled, .badge.written_off, .badge.rejected, .badge.reversed, .badge.suspended, .badge.archived { background: var(--bad-soft); color: var(--bad); }

/* ---------- modal / toast / skeleton / empty ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(4,12,16,.5); z-index: 80; display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: 14px; width: min(640px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal header { display: flex; align-items: center; padding: .9rem 1rem; border-bottom: 1px solid var(--line); gap: .5rem; } .modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 1rem; } .modal footer { padding: .8rem 1rem; border-top: 1px solid var(--line); display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.confirm-amount { font-family: var(--mono); font-size: 1.4rem; font-weight: 700; }
.toasts { position: fixed; z-index: 90; bottom: 5rem; left: 50%; transform: translateX(-50%); display: grid; gap: .4rem; width: min(480px, 92vw); }
@media (min-width: 960px) { .toasts { bottom: 1.5rem; } }
.toast { padding: .65rem .9rem; border-radius: 10px; background: var(--dark); color: #fff; box-shadow: var(--shadow); font-size: .9rem; }
.toast.bad { background: var(--bad); color: var(--bg); } .toast.ok { background: var(--ok); color: var(--bg); }
.skel { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; height: 14px; margin: .5rem 0; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } .sidebar { transition: none; } }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: .3rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .8rem; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs a.active { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; } .timeline li { padding: .4rem 0 .4rem .9rem; border-left: 2px solid var(--line); position: relative; font-size: .88rem; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: .75rem; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.stage-bar { display: flex; gap: .25rem; margin: .5rem 0 1rem; flex-wrap: wrap; } .stage-bar span { flex: 1; min-width: 80px; text-align: center; font-size: .72rem; padding: .3rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.stage-bar span.done { background: var(--brand-soft); color: var(--brand); font-weight: 600; } .stage-bar span.now { background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: min(520px, 100%); }
.bar { height: 8px; border-radius: 4px; background: var(--brand); }
.plan-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: var(--surface); }
.plan-card.rec { border: 2px solid var(--brand); }
.plan-card .price { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; }
.plan-card ul { padding-left: 1.1rem; margin: .5rem 0; font-size: .88rem; }
@media print { .topbar, .sidebar, .bottombar, .no-print { display: none !important; } .main { padding: 0; } .card { box-shadow: none; } }

/* Logos & branding (v1.3.1) */
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .9rem; }
.logo-slot { border: 1px solid var(--line); border-radius: 10px; padding: .8rem; display: grid; gap: .5rem; align-content: start; }
.logo-slot-h { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.logo-well { height: 96px; border-radius: 8px; display: grid; place-items: center; padding: 10px; background-color: #fff; background-image: linear-gradient(45deg, #eef1f3 25%, transparent 25%), linear-gradient(-45deg, #eef1f3 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eef1f3 75%), linear-gradient(-45deg, transparent 75%, #eef1f3 75%); background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; border: 1px solid var(--line); }
.logo-well img { max-width: 100%; max-height: 76px; object-fit: contain; }
.logo-well.sq img { max-height: 76px; aspect-ratio: 1; }
.logo-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .9rem; }
.pv { display: grid; gap: .4rem; align-content: start; }
.pv-cap { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pv-doc { background: #fff; color: #13232c; border: 1px solid var(--line); border-radius: 6px; padding: 12px; display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; min-height: 72px; }
.pv-doc-l { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; min-width: 0; }
.pv-doc-l b { font-size: .78rem; }
.pv-doc-r { text-align: right; color: #0f766e; white-space: nowrap; font-size: .72rem; }
.pv-line { height: 6px; background: #dde3e6; border-radius: 3px; margin-top: 6px; width: 120px; } .pv-line.short { width: 70px; margin-left: auto; }
.pv-doc-l .pv-line.short { margin-left: 0; }
.pv-bar { display: flex; align-items: center; gap: .6rem; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-height: 46px; font-weight: 600; font-size: .9rem; }
.pv-tab { display: inline-flex; align-items: center; gap: .45rem; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 8px 8px 0 0; background: var(--surface-2); font-size: .8rem; max-width: 220px; }
.pv-app { width: 56px; height: 56px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); }
.tenant-logo { object-fit: contain; display: block; }
.pv-bar img, .pv-tab img, .pv-doc-l img { flex-shrink: 0; }
.pv-bar span, .pv-tab span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv { min-width: 0; }

.badge.brand { background: var(--brand-soft, #e6f4ef); color: var(--brand, #0f766e); border: 1px solid currentColor; font-weight: 600; }
