:root {
  --brand: #5b2be0;
  --ink: #1b1d29;
  --ink-2: #4a4f63;
  --muted: #7d8296;
  --line: #e4e6ee;
  --bg: #f5f6fa;
  --card: #ffffff;
  --ok: #157a4a;
  --ok-bg: #e5f6ec;
  --warn: #b25b00;
  --warn-bg: #fff2e0;
  --err: #b3261e;
  --err-bg: #fdeceb;
  --radius: 10px;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; font-weight: 400; }
code { background: #eef0f6; padding: 1px 5px; border-radius: 4px; }

/* Top bar */
.topbar { background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; min-height: 58px; gap: 16px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; font-size: 17px; }
.brand span { color: var(--brand); filter: brightness(1.6); font-weight: 500; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: #c9ccda; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.topbar nav a.active { background: var(--brand); color: #fff; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 80px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Cards & stats */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.warn { color: var(--warn); }
.stat-sub { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--brand); color: #fff; border: 1px solid var(--brand); padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); filter: none; }
.btn-danger { background: #fff; color: var(--err); border-color: #f1c4c1; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 6px; width: 30px; height: 30px; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; }
.icon-btn:hover { color: var(--err); border-color: var(--err); }
.link-btn { background: none; border: 0; color: var(--err); cursor: pointer; padding: 0; font: inherit; font-size: 13px; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
.danger-zone { margin-top: 8px; text-align: right; }

/* Forms */
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
input, select, textarea { font: inherit; font-size: 14px; font-weight: 400; color: var(--ink); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 30%, transparent); border-color: var(--brand); }
input[type=color] { height: 40px; padding: 3px; width: 80px; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 10px; }
.inline { display: flex; gap: 8px; align-items: center; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.check { flex-direction: row; display: flex; gap: 6px; align-items: center; font-weight: 400; }
.preview-img { max-height: 60px; max-width: 200px; object-fit: contain; background: #fafafa; border: 1px dashed var(--line); padding: 4px; border-radius: 6px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px; }
.filters input { flex: 1; min-width: 200px; }
.filters select { width: auto; }
.search input { min-width: 240px; }
.pay-form { display: grid; grid-template-columns: repeat(5, 1fr) auto; gap: 10px; align-items: end; margin-top: 14px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.table tfoot th { color: var(--ink); font-size: 14px; text-transform: none; letter-spacing: 0; border-bottom: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions a { margin-left: 12px; font-size: 13px; }
.items-table td { padding: 6px 4px; border-bottom: 0; }
.items-table textarea { min-height: 38px; }
.w-sac { width: 90px; } .w-num { width: 80px; } .w-rate { width: 120px; }
.line-amt { padding-top: 14px !important; font-weight: 600; }

.totals { margin: 16px 0 0 auto; max-width: 320px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-size: 18px; }

/* Badges & flash */
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef0f6; color: var(--ink-2); vertical-align: middle; }
.badge-paid, .badge-accepted, .badge-converted { background: var(--ok-bg); color: var(--ok); }
.badge-partial, .badge-sent { background: #e8efff; color: #2453c7; }
.badge-overdue, .badge-rejected { background: var(--err-bg); color: var(--err); }
.badge-unpaid { background: var(--warn-bg); color: var(--warn); }
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); }

/* Auth pages */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 20px; margin-bottom: 16px; }
.auth-card form { display: grid; gap: 14px; }
.auth-logo { max-height: 56px; margin-bottom: 12px; }

/* ===== Invoice document ===== */
.invoice { --c-green: #12a26b; --c-red: #e0284f; --tint: #f5f8fc; --tint-line: #dfe6f0;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; color: #1d2433; font-size: 12.5px; overflow: hidden;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; display: flex; flex-direction: column; }
.invoice { --tint: color-mix(in srgb, var(--brand) 4%, #fff); --tint-line: color-mix(in srgb, var(--brand) 14%, #fff); }
.iv-body { padding: 36px 40px 20px; flex: 1; }
.c-brand { color: var(--brand); } .c-green { color: var(--c-green); } .c-red { color: var(--c-red); }
.iv-strong { font-weight: 700; }
.iv-muted { color: #5d6678; font-size: 12px; line-height: 1.7; }
.iv-note { color: #7a8292; font-size: 11px; margin-top: 6px; }
.iv-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); font-weight: 700; margin-bottom: 4px; }

.iv-head { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 16px; border-bottom: 3px solid var(--brand); }
.iv-brand { display: flex; gap: 16px; align-items: flex-start; }
.iv-logo-box { width: 88px; height: 88px; flex: none; background: var(--brand); display: grid; place-items: center; overflow: hidden; }
.iv-logo-box span { color: #fff; font-size: 30px; font-weight: 800; letter-spacing: .02em; }
.iv-logo-box.has-img { background: transparent; }
.iv-logo-box img { width: 100%; height: 100%; object-fit: contain; }
.iv-name { font-size: 24px; font-weight: 800; color: var(--brand); line-height: 1.15; }
.iv-tag { font-size: 11.5px; font-weight: 700; color: #6b7385; text-transform: uppercase; letter-spacing: .05em; margin: 4px 0 4px; }
.iv-ids strong { color: #1d2433; }
.iv-titlebox { text-align: right; min-width: 250px; flex: none; }
.iv-title { font-size: 26px; font-weight: 800; color: var(--brand); letter-spacing: .01em; line-height: 1.1; }
.iv-number { font-size: 15px; font-weight: 800; margin: 8px 0 4px; }
.iv-status { font-weight: 800; font-size: 12.5px; margin-top: 4px; white-space: nowrap; }
.iv-status-due { color: var(--c-red); } .iv-status-paid { color: var(--c-green); } .iv-status-info { color: var(--brand); }

.iv-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 20px 0; }
.iv-card { background: var(--tint); border: 1px solid var(--tint-line); border-radius: 8px; padding: 16px 18px; }
.iv-card-h { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; color: var(--brand); margin-bottom: 10px; }
.iv-card-h.center { text-align: center; }
.iv-client { font-size: 15px; font-weight: 800; margin-bottom: 4px; }
.iv-kv { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 12.5px; }
.iv-kv strong { font-variant-numeric: tabular-nums; }

.iv-items { width: 100%; border-collapse: collapse; }
.iv-items th { background: var(--brand); color: #fff; font-size: 11.5px; font-weight: 800; text-transform: uppercase; padding: 10px 14px; text-align: left; }
.iv-items td { padding: 10px 14px; border-bottom: 1px solid #e6e9ef; vertical-align: top; }
.iv-items tbody tr:nth-child(even) td { background: var(--tint); }
.iv-items .c-desc { width: 42%; }

.iv-after { display: flex; justify-content: space-between; gap: 24px; margin-top: 4px; }
.iv-left { flex: 1; padding-top: 14px; }
.iv-words { font-weight: 700; margin-bottom: 10px; }
.iv-taxsum { border-collapse: collapse; font-size: 11px; }
.iv-taxsum th, .iv-taxsum td { border: 1px solid var(--tint-line); padding: 4px 9px; }
.iv-taxsum th { background: var(--tint); color: var(--brand); font-weight: 700; }
.iv-totals { border-collapse: collapse; min-width: 300px; font-variant-numeric: tabular-nums; }
.iv-totals th { text-align: left; font-weight: 400; color: #6b7385; padding: 5px 14px; }
.iv-totals td { text-align: right; padding: 5px 14px; }
.iv-totals .t-grand th, .iv-totals .t-grand td { border-top: 2px solid var(--brand); color: var(--brand); font-size: 16px; font-weight: 800; padding-top: 10px; }
.iv-totals .t-paid th, .iv-totals .t-paid td { color: var(--c-green); font-weight: 800; font-size: 13.5px; }
.iv-totals .t-due th, .iv-totals .t-due td { color: var(--c-red); font-weight: 800; font-size: 13.5px; }

.iv-notes { font-weight: 700; color: var(--brand); margin: 12px 0 8px; }
.iv-terms { color: #5d6678; font-size: 11px; line-height: 1.55; }

.iv-bottom { display: grid; grid-template-columns: 1.65fr 1fr; gap: 18px; margin-top: 22px; }
.iv-bottom > .iv-signcard:only-child { grid-column: 2; }
.iv-pay-row { display: flex; gap: 16px; align-items: flex-start; }
.iv-qr { text-align: center; flex: none; }
.iv-qr-box { width: 128px; height: 128px; border: 2px solid var(--tint-line); border-radius: 6px; background: #fff; padding: 5px; display: grid; place-items: center; }
.iv-qr-box img, .iv-qr-box canvas { width: 100%; height: 100%; object-fit: contain; }
.iv-qr-box #upiQr { width: 100%; height: 100%; } .iv-qr-box #upiQr img { width: 100%; height: 100%; }
.iv-qr-cap { font-size: 10px; font-weight: 700; color: var(--brand); margin-top: 6px; line-height: 1.5; }
.iv-bank { font-size: 12px; line-height: 1.85; }
.iv-signcard { text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; }
.iv-signature { max-height: 64px; max-width: 170px; margin: 6px auto; display: block; }
.iv-sign-space { height: 52px; }
.iv-sign-name { font-size: 14px; font-weight: 800; margin-top: 2px; }
.iv-generated { text-align: center; color: #9aa1ae; font-size: 10px; margin-top: 18px; }
.iv-footbar { background: var(--brand); color: #fff; text-align: center; font-size: 11px; padding: 14px 20px; }
.preview-qr { max-height: 120px; }

@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .pay-form { grid-template-columns: 1fr 1fr; }
  .iv-body { padding: 20px; }
  .iv-head, .iv-after, .iv-pay-row { flex-direction: column; }
  .iv-cards, .iv-bottom { grid-template-columns: 1fr; }
  .iv-bottom > .iv-signcard:only-child { grid-column: 1; }
  .iv-titlebox { text-align: left; }
  .iv-totals { min-width: 0; width: 100%; }
  .topbar { padding: 10px 16px; }
}

@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-print, .topbar, .flash, .danger-zone { display: none !important; }
  .container { padding: 0; max-width: none; margin: 0; }
  .invoice { border: 0; border-radius: 0; margin: 0; min-height: 296mm; font-size: 11px; }
  .iv-body { padding: 11mm 12mm 6mm; }
  .iv-logo-box { width: 78px; height: 78px; }
  .iv-muted { line-height: 1.6; font-size: 11px; }
  .iv-cards { margin: 14px 0; }
  .iv-card { padding: 12px 15px; }
  .iv-items td { padding: 8px 12px; } .iv-items th { padding: 9px 12px; }
  .iv-totals th, .iv-totals td { padding: 4px 12px; }
  .iv-bottom { margin-top: 16px; }
  .iv-generated { margin-top: 10px; }
  .iv-items tr, .iv-bottom, .iv-cards { page-break-inside: avoid; break-inside: avoid; }
  .iv-footbar { padding: 5mm 10mm; }
}
