/* RatFi Billing - brand design system (shared tokens with RatFi CRM) */
:root {
  --rb-navy: #10213A;
  --rb-blue: #246BFD;
  --rb-gold: #D9A441;
  --rb-gold-soft: #FBEFD5;
  --rb-green: #16A36A;
  --rb-amber: #E9A23B;
  --rb-red: #E05252;
  --rb-bg: #F5F7FB;
  --rb-surface: #FFFFFF;
  --rb-surface-2: #F0F3F9;
  --rb-border: rgba(16, 33, 58, 0.08);
  --rb-text: #10213A;
  --rb-muted: #5B6678;
  --rb-shadow: 0 1px 2px rgba(16, 33, 58, .04), 0 8px 24px -12px rgba(16, 33, 58, .14);
  --rb-radius: 18px;
  --rb-radius-sm: 12px;
  --rb-sidebar: 256px;
  --rb-primary: var(--rb-blue);
  --rb-primary-rgb: 36, 107, 253;

  --bs-primary: var(--rb-primary);
  --bs-primary-rgb: var(--rb-primary-rgb);
  --bs-body-font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --bs-body-bg: var(--rb-bg);
  --bs-body-color: var(--rb-text);
  --bs-border-radius: 12px;
  --bs-link-color: var(--rb-primary);
  --bs-link-color-rgb: var(--rb-primary-rgb);
}
[data-bs-theme="dark"] {
  --rb-primary: #8DB2FF;
  --rb-primary-rgb: 141, 178, 255;
  --rb-gold: #F1CF85;
  --rb-gold-soft: #4A3608;
  --rb-bg: #0B1626;
  --rb-surface: #12233A;
  --rb-surface-2: #182C47;
  --rb-border: rgba(255, 255, 255, .08);
  --rb-text: #E8EEF7;
  --rb-muted: #A9B4C6;
  --rb-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
  --bs-body-bg: var(--rb-bg);
  --bs-body-color: var(--rb-text);
  --bs-secondary-color: var(--rb-muted);
  --bs-border-color: rgba(255, 255, 255, .1);
  --bs-tertiary-bg: var(--rb-surface-2);
}

body { background: var(--rb-bg); color: var(--rb-text); -webkit-font-smoothing: antialiased; }
a { text-decoration: none; }
.text-muted, .form-text { color: var(--rb-muted) !important; }
.fw-600 { font-weight: 600; }
.tabular { font-variant-numeric: tabular-nums; }

/* buttons */
.btn { border-radius: 12px; font-weight: 600; padding: .55rem 1rem; }
.btn-primary { --bs-btn-bg: var(--rb-primary); --bs-btn-border-color: var(--rb-primary); --bs-btn-hover-bg: #1c5ae0; --bs-btn-hover-border-color: #1c5ae0; --bs-btn-active-bg: #164bbd; --bs-btn-disabled-bg: var(--rb-primary); --bs-btn-disabled-border-color: var(--rb-primary); }
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0B1626; --bs-btn-hover-color: #0B1626; --bs-btn-hover-bg: #a9c5ff; --bs-btn-hover-border-color: #a9c5ff; }
.btn-gold { background: var(--rb-gold); color: var(--rb-navy); border: 0; }
.btn-gold:hover { background: #c99232; color: var(--rb-navy); }
.btn-soft { background: var(--rb-surface-2); color: var(--rb-text); border: 1px solid var(--rb-border); }
.btn-soft:hover { background: var(--rb-surface); color: var(--rb-text); border-color: rgba(var(--rb-primary-rgb), .35); }
.btn-lg-touch { min-height: 52px; font-size: 1.05rem; }

/* forms */
.form-control, .form-select { border-radius: 12px; border-color: var(--rb-border); background-color: var(--rb-surface); padding: .6rem .85rem; }
.form-control:focus, .form-select:focus { border-color: rgba(var(--rb-primary-rgb), .55); box-shadow: 0 0 0 .2rem rgba(var(--rb-primary-rgb), .15); }
.form-label { font-weight: 600; font-size: .875rem; margin-bottom: .35rem; }
.invalid-feedback { display: block; }

/* cards */
.rb-card { background: var(--rb-surface); border: 1px solid var(--rb-border); border-radius: var(--rb-radius); box-shadow: var(--rb-shadow); }
.rb-card-body { padding: 1.25rem; }
.rb-card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--rb-border); display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.rb-card-header h2, .rb-card-header h3 { font-size: 1rem; font-weight: 700; margin: 0; }

.stat { padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .35rem; height: 100%; }
.stat-label { font-size: .8rem; color: var(--rb-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: .4rem; }
.stat-value { font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .8rem; color: var(--rb-muted); }
.stat-icon { width: 30px; height: 30px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; background: rgba(var(--rb-primary-rgb), .1); color: var(--rb-primary); }
.stat-icon.gold { background: var(--rb-gold-soft); color: #8a5c0c; }
[data-bs-theme="dark"] .stat-icon.gold { color: var(--rb-gold); }
.stat-icon.green { background: rgba(22, 163, 106, .12); color: var(--rb-green); }
.stat-icon.red { background: rgba(224, 82, 82, .12); color: var(--rb-red); }

/* badges */
.badge-soft { padding: .35em .65em; border-radius: 999px; font-weight: 600; font-size: .75rem; }
.bs-paid, .bs-active, .bs-finalized { background: rgba(22, 163, 106, .12); color: #0f7a4f; }
.bs-partial, .bs-pending, .bs-trial { background: rgba(233, 162, 59, .16); color: #8a5a0c; }
.bs-unpaid, .bs-suspended, .bs-cancelled, .bs-void, .bs-rejected, .bs-disabled { background: rgba(224, 82, 82, .12); color: #b23535; }
.bs-draft, .bs-not_applicable, .bs-manual { background: var(--rb-surface-2); color: var(--rb-muted); }
[data-bs-theme="dark"] .bs-paid, [data-bs-theme="dark"] .bs-active, [data-bs-theme="dark"] .bs-finalized { color: #5be0a6; }
[data-bs-theme="dark"] .bs-partial, [data-bs-theme="dark"] .bs-pending, [data-bs-theme="dark"] .bs-trial { color: #f3c477; }
[data-bs-theme="dark"] .bs-unpaid, [data-bs-theme="dark"] .bs-suspended, [data-bs-theme="dark"] .bs-cancelled, [data-bs-theme="dark"] .bs-void { color: #ff9b9b; }

/* tables */
.rb-table { margin: 0; --bs-table-bg: transparent; --bs-table-color: var(--rb-text); }
.rb-table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--rb-muted); font-weight: 700; border-bottom-color: var(--rb-border); white-space: nowrap; }
.rb-table td { border-bottom-color: var(--rb-border); vertical-align: middle; }
.rb-table tbody tr.clickable { cursor: pointer; }
.rb-table tbody tr.clickable:hover { background: rgba(var(--rb-primary-rgb), .04); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------------- app shell */
.rb-shell { min-height: 100vh; }
.rb-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--rb-sidebar); z-index: 1030;
  background: var(--rb-navy); color: #d6deec; display: flex; flex-direction: column;
  padding: 1rem .75rem; overflow-y: auto;
}
[data-bs-theme="dark"] .rb-sidebar { background: #08111e; border-right: 1px solid var(--rb-border); }
.rb-brand { display: flex; align-items: center; gap: .65rem; padding: .35rem .5rem 1.1rem; color: #fff; }
.rb-brand-mark { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(135deg, var(--rb-blue), #0D3FB8); color: #fff; box-shadow: inset 0 -2px 0 var(--rb-gold); overflow: hidden; }
.rb-brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.rb-brand-mark.is-logo { background: #fff; padding: 3px; box-shadow: inset 0 -2px 0 var(--rb-gold); }
.logo-chip { display: inline-flex; align-items: center; }
.logo-chip img { width: auto; display: block; }
[data-bs-theme="dark"] .logo-chip { background: #fff; border-radius: 10px; padding: 3px 8px; }
.brand-product { font-weight: 800; font-size: .95rem; color: var(--rb-primary); border-left: 2px solid var(--rb-gold); padding-left: .55rem; margin-left: .15rem; }
.rb-brand-name { font-weight: 800; line-height: 1.1; }
.rb-brand-sub { font-size: .72rem; color: #9fb0cc; }
.rb-nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7d8eab; padding: .9rem .75rem .35rem; }
.rb-nav a { display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: 12px; color: #c9d4e6; font-weight: 500; margin-bottom: 2px; }
.rb-nav a i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.rb-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.rb-nav a.active { background: rgba(255, 255, 255, .1); color: #fff; box-shadow: inset 3px 0 0 var(--rb-gold); }
.rb-main { margin-left: var(--rb-sidebar); min-height: 100vh; display: flex; flex-direction: column; }
.rb-topbar {
  position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1.5rem; background: color-mix(in srgb, var(--rb-bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--rb-border);
}
.rb-topbar h1 { font-size: 1.15rem; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.rb-content { padding: 1.5rem; flex: 1; width: 100%; max-width: 1320px; }
.rb-banner { padding: .65rem 1.5rem; font-size: .9rem; font-weight: 500; }
.rb-banner.warn { background: var(--rb-gold-soft); color: #6b4708; }
[data-bs-theme="dark"] .rb-banner.warn { color: var(--rb-gold); }
.rb-bottomnav { display: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--rb-gold-soft); color: #7a5208; display: grid; place-items: center; font-weight: 700; font-size: .85rem; }

@media (max-width: 991.98px) {
  .rb-sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .rb-sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .rb-main { margin-left: 0; padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .rb-topbar { padding: .65rem 1rem; }
  .rb-content { padding: 1rem; }
  .rb-bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1025; height: calc(64px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--rb-surface); border-top: 1px solid var(--rb-border);
  }
  .rb-bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .7rem; font-weight: 600; color: var(--rb-muted); }
  .rb-bottomnav a i { font-size: 1.25rem; }
  .rb-bottomnav a.active { color: var(--rb-primary); }
  .rb-bottomnav a.fab i { width: 46px; height: 46px; border-radius: 16px; background: var(--rb-primary); color: #fff; display: grid; place-items: center; margin-top: -18px; box-shadow: 0 8px 20px -6px rgba(var(--rb-primary-rgb), .6); }
}

/* charts (SVG, no library) */
.chart-wrap { width: 100%; }
.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-bar { fill: var(--rb-primary); opacity: .85; transition: opacity .15s; }
.chart-bar:hover { opacity: 1; }
.chart-axis { stroke: var(--rb-border); }
.chart-label { fill: var(--rb-muted); font-size: 10px; }
.hbar { height: 8px; border-radius: 99px; background: var(--rb-surface-2); overflow: hidden; }
.hbar > span { display: block; height: 100%; background: var(--rb-primary); border-radius: 99px; }
.hbar.gold > span { background: var(--rb-gold); }

/* billing screen */
.bill-items .item-row { display: grid; grid-template-columns: minmax(150px, 1fr) 72px 100px 64px 88px 100px 38px; gap: .5rem; align-items: start; padding: .6rem 0; border-bottom: 1px dashed var(--rb-border); }
.bill-items .item-head { font-size: .72rem; font-weight: 700; color: var(--rb-muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--rb-border); }
.bill-items .item-total { text-align: right; padding-top: .4rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--rb-text); }
@media (max-width: 767.98px) {
  .bill-items .item-head { display: none; }
  .bill-items .item-row { grid-template-columns: 1fr 1fr 1fr; }
  .bill-items .item-row > :first-child { grid-column: 1 / -1; }
  .bill-items .item-total { text-align: left; }
}
@media (max-width: 575.98px) { .stat-value { font-size: 1.25rem; } .stat-label { font-size: .7rem; } }
.totals-box { position: sticky; top: 84px; }
.totals-row { display: flex; justify-content: space-between; padding: .3rem 0; font-variant-numeric: tabular-nums; }
.totals-row.grand { font-size: 1.35rem; font-weight: 800; border-top: 1px solid var(--rb-border); margin-top: .4rem; padding-top: .7rem; }
.suggest { position: absolute; z-index: 1050; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--rb-surface); border: 1px solid var(--rb-border); border-radius: 12px; box-shadow: var(--rb-shadow); max-height: 280px; overflow-y: auto; }
.suggest button { display: block; width: 100%; text-align: left; padding: .55rem .8rem; border: 0; background: none; color: var(--rb-text); }
.suggest button:hover, .suggest button.active { background: rgba(var(--rb-primary-rgb), .08); }

/* empty / loading */
.empty { text-align: center; padding: 3rem 1rem; color: var(--rb-muted); }
.empty i { font-size: 2.4rem; display: block; margin-bottom: .5rem; opacity: .5; }
.skeleton { background: linear-gradient(90deg, var(--rb-surface-2) 25%, var(--rb-surface) 50%, var(--rb-surface-2) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 10px; min-height: 18px; }
@keyframes sk { to { background-position: -200% 0; } }
.fade-in { animation: fi .25s ease both; }
@keyframes fi { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .fade-in, .skeleton { animation: none; } }

.rb-toast-wrap { position: fixed; right: 1rem; bottom: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; max-width: 360px; }
@media (max-width: 991.98px) { .rb-toast-wrap { bottom: 84px; left: 1rem; right: 1rem; max-width: none; } }
.rb-toast { background: var(--rb-navy); color: #fff; padding: .75rem 1rem; border-radius: 12px; box-shadow: var(--rb-shadow); display: flex; gap: .6rem; align-items: flex-start; }
.rb-toast.error { background: #8f2424; }
.rb-toast.success { background: #0f6b45; }

/* ---------------------------------------------------------- public site */
.pub-nav { position: sticky; top: 0; z-index: 1020; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); background: color-mix(in srgb, var(--rb-bg) 80%, transparent); border-bottom: 1px solid var(--rb-border); }
.pub-nav .brand { font-weight: 800; color: var(--rb-text); display: flex; align-items: center; gap: .55rem; }
.hero { padding: 5rem 0 4rem; position: relative; overflow: hidden; }
.hero::before { content: ""; position: absolute; inset: -40% -10% auto auto; width: 640px; height: 640px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(36, 107, 253, .18), transparent); pointer-events: none; }
.hero h1 { font-size: clamp(2.1rem, 4.5vw, 3.4rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.08; }
.hero .lead { color: var(--rb-muted); font-size: 1.15rem; max-width: 560px; }
.eyebrow { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 700; color: #8a5c0c; background: var(--rb-gold-soft); padding: .35rem .75rem; border-radius: 999px; }
[data-bs-theme="dark"] .eyebrow { color: var(--rb-gold); }
.hero-preview { border-radius: 22px; padding: 1.25rem; background: var(--rb-surface); border: 1px solid var(--rb-border); box-shadow: 0 30px 60px -30px rgba(16, 33, 58, .35); }
.section { padding: 4.5rem 0; }
.section h2 { font-weight: 800; letter-spacing: -.02em; }
.feature { padding: 1.4rem; height: 100%; }
.feature i { font-size: 1.4rem; width: 44px; height: 44px; border-radius: 14px; display: inline-grid; place-items: center; background: rgba(var(--rb-primary-rgb), .1); color: var(--rb-primary); margin-bottom: .8rem; }
.price-card { padding: 1.6rem; height: 100%; display: flex; flex-direction: column; }
.price-card.featured { border: 2px solid var(--rb-gold); }
.price-card .price { font-size: 1.9rem; font-weight: 800; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card { width: 100%; max-width: 440px; padding: 2rem; }
.legal { max-width: 820px; }
.legal h2 { font-size: 1.15rem; font-weight: 700; margin-top: 1.8rem; }
footer.pub-footer { border-top: 1px solid var(--rb-border); padding: 2rem 0; color: var(--rb-muted); font-size: .9rem; }

@media print {
  .rb-sidebar, .rb-topbar, .rb-bottomnav, .no-print, .rb-banner { display: none !important; }
  .rb-main { margin: 0; }
  .rb-card { box-shadow: none; border: 0; }
}

/* ---------------------------------------------------------------- printable invoice (/print, /i/<token>) */
.invoice-page { background: var(--rb-bg, #F5F7FB); }
.inv-toolbar { position: sticky; top: 0; z-index: 5; background: var(--rb-surface, #fff); border-bottom: 1px solid rgba(16,33,58,.08); }
.inv-sheet-wrap { padding: 16px 8px 48px; overflow-x: auto; }
.inv-sheet { --inv-accent: #246BFD; position: relative; width: 210mm; min-height: 280mm; margin: 0 auto; padding: 12mm; background: #fff; color: #10213A;
  font-size: 12px; line-height: 1.45; box-shadow: 0 6px 30px rgba(16,33,58,.10); border-radius: 6px; overflow: hidden; }
.inv-sheet .small { font-size: 11px; }
.inv-head { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 10px; }
.inv-seller { display: flex; gap: 12px; align-items: flex-start; max-width: 60%; }
.inv-logo { max-height: 64px; max-width: 140px; object-fit: contain; }
.inv-seller-name { font-size: 18px; font-weight: 800; }
.inv-title { text-align: right; }
.inv-doc { font-size: 20px; font-weight: 800; letter-spacing: .04em; color: var(--inv-accent); }
.inv-meta { margin-left: auto; margin-top: 4px; }
.inv-meta td { padding: 1px 0 1px 10px; }
.inv-meta td:first-child { color: #5b6b80; }
.inv-parties { display: flex; gap: 24px; justify-content: space-between; padding: 10px 0; border-top: 1px solid #e3e8ef; border-bottom: 1px solid #e3e8ef; margin-bottom: 10px; }
.inv-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: #5b6b80; font-weight: 700; }
.inv-items, .inv-tax, .inv-totals { width: 100%; border-collapse: collapse; }
.inv-items th { background: var(--inv-accent); color: #fff; font-weight: 700; padding: 6px; text-align: left; font-size: 11px; }
.inv-items td { padding: 6px; border-bottom: 1px solid #eef1f6; vertical-align: top; }
.inv-items tbody tr:nth-child(even) td { background: #f8fafd; }
.inv-items tr { page-break-inside: avoid; }
.inv-sheet .r { text-align: right; white-space: nowrap; }
.inv-bottom { display: flex; gap: 20px; justify-content: space-between; margin-top: 12px; page-break-inside: avoid; }
.inv-left { flex: 1; }
.inv-tax { width: auto; min-width: 60%; margin-bottom: 8px; }
.inv-tax th, .inv-tax td { padding: 3px 6px; border: 1px solid #e3e8ef; font-size: 11px; }
.inv-words, .inv-pay { margin-bottom: 8px; }
.inv-totals { width: 45%; align-self: flex-start; }
.inv-totals td { padding: 4px 6px; }
.inv-totals .grand td { font-size: 15px; font-weight: 800; border-top: 2px solid var(--inv-accent); color: var(--inv-accent); }
.inv-totals .due td { font-weight: 700; }
.inv-notes { margin-top: 10px; }
.inv-foot { display: flex; justify-content: space-between; gap: 20px; margin-top: 18px; page-break-inside: avoid; }
.inv-terms { flex: 1; font-size: 11px; }
.inv-sign { text-align: center; min-width: 160px; }
.inv-sign img { max-height: 56px; max-width: 160px; display: block; margin: 0 auto 4px; }
.inv-footer-line { margin-top: 12px; text-align: center; font-size: 11px; color: #5b6b80; }
.inv-computer { margin-top: 8px; text-align: center; font-size: 10px; color: #8a97a8; }
.inv-watermark { position: absolute; top: 40%; left: 0; right: 0; text-align: center; font-size: 90px; font-weight: 900; color: rgba(224,82,82,.12); transform: rotate(-24deg); pointer-events: none; }
/* Classic GST: bordered, formal */
.tpl-classic .inv-items th { background: #fff; color: #10213A; border: 1px solid #10213A; }
.tpl-classic .inv-items td { border: 1px solid #c9d1dc; }
.tpl-classic .inv-items tbody tr:nth-child(even) td { background: none; }
.tpl-classic .inv-head { border: 1px solid #10213A; padding: 8px; }
.tpl-classic .inv-doc { color: #10213A; }
/* Minimal Retail: black & white */
.tpl-minimal { --inv-accent: #10213A; }
.tpl-minimal .inv-items th { background: none; color: #10213A; border-bottom: 2px solid #10213A; }
.tpl-minimal .inv-items tbody tr:nth-child(even) td { background: none; }
@media (max-width: 860px) { .inv-sheet { transform-origin: top left; } }
@media print {
  @page { size: A4; margin: 8mm; }
  .no-print { display: none !important; }
  .invoice-page { background: #fff; }
  .inv-sheet-wrap { padding: 0; }
  .inv-sheet { width: auto; min-height: 0; box-shadow: none; border-radius: 0; padding: 0; }
  .inv-items th, .inv-totals .grand td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
