:root {
  --brand: #1e3a8a;
  --brand-600: #1d4ed8;
  --brand-50: #eef2ff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f6f7fb;
  --card: #ffffff;
  --sidebar: #0f1b3d;
  --sidebar-ink: #c7d2fe;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --bs-primary: #1e3a8a;
  --bs-primary-rgb: 30, 58, 138;
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --bs-body-color: #0f172a;
  --bs-border-color: #e2e8f0;
}

[data-bs-theme="dark"] {
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --line: #273449;
  --bg: #0b1220;
  --card: #111a2e;
  --brand-50: #172554;
  --bs-body-bg: #0b1220;
  --bs-body-color: #e2e8f0;
  --bs-border-color: #273449;
  --bs-secondary-bg: #111a2e;
  --bs-tertiary-bg: #0f172a;
}

body { background: var(--bg); color: var(--ink); font-size: .925rem; }
a { color: var(--brand-600); }
[data-bs-theme="dark"] a { color: #93c5fd; }

.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: #172f72; --bs-btn-hover-border-color: #172f72; --bs-btn-active-bg: #142862; }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); }
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: #93c5fd; --bs-btn-border-color: #3b5bb5; }
.text-primary { color: var(--brand) !important; }
[data-bs-theme="dark"] .text-primary { color: #93c5fd !important; }
.bg-primary { background-color: var(--brand) !important; }
.form-control:focus, .form-select:focus { border-color: #6b83d6; box-shadow: 0 0 0 .2rem rgba(30,58,138,.15); }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-ink);
  position: fixed; inset: 0 auto 0 0; z-index: 1040; display: flex; flex-direction: column;
  transition: transform .2s ease;
}
.sidebar .brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.25rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar .brand-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg,#f59e0b,#ea580c); display: grid; place-items: center; font-weight: 800; color: #fff; font-size: .95rem; }
.sidebar .brand-name { font-weight: 700; line-height: 1.1; font-size: .98rem; }
.sidebar .brand-sub { font-size: .7rem; color: #94a3b8; }
.sidebar nav { padding: .75rem .65rem; overflow-y: auto; flex: 1; }
.sidebar .nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: .9rem .7rem .35rem; }
.sidebar .nav-link { color: var(--sidebar-ink); border-radius: 8px; padding: .5rem .7rem; display: flex; align-items: center; gap: .65rem; font-weight: 500; }
.sidebar .nav-link i { font-size: 1.05rem; opacity: .85; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-link.active { background: rgba(99,131,255,.18); color: #fff; }
.sidebar .nav-link.active i { color: #fbbf24; opacity: 1; }
.sidebar .sidebar-foot { padding: .8rem 1rem; border-top: 1px solid rgba(255,255,255,.06); font-size: .78rem; color: #94a3b8; }

.main { margin-left: 248px; flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .75rem; padding: 0 1.5rem; position: sticky; top: 0; z-index: 1030; }
.topbar .page-title { font-weight: 600; font-size: 1.05rem; margin: 0; }
.content { padding: 1.5rem; flex: 1; }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }
  .main { margin-left: 0; }
  .content { padding: 1rem; }
  .topbar { padding: 0 1rem; }
}

/* ---------- Cards & tables ---------- */
.card { border: 1px solid var(--line); border-radius: 12px; background: var(--card); box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); font-weight: 600; padding: .85rem 1.1rem; }
.card-body { padding: 1.1rem; }
.stat { display: flex; gap: .9rem; align-items: flex-start; }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 1.2rem; flex-shrink: 0; }
.stat-label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.stat-value { font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .78rem; color: var(--muted); }
.tone-blue { background: #e0e7ff; color: #3730a3; }
.tone-green { background: #dcfce7; color: #166534; }
.tone-amber { background: #fef3c7; color: #92400e; }
.tone-red { background: #fee2e2; color: #991b1b; }
[data-bs-theme="dark"] .tone-blue { background: #1e2a5a; color: #a5b4fc; }
[data-bs-theme="dark"] .tone-green { background: #10321f; color: #86efac; }
[data-bs-theme="dark"] .tone-amber { background: #3a2a0c; color: #fcd34d; }
[data-bs-theme="dark"] .tone-red { background: #3b1414; color: #fca5a5; }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--bg); border-bottom-width: 1px; white-space: nowrap; }
.table td, .table th { padding: .65rem .9rem; vertical-align: middle; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: var(--brand-50); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.text-muted, .form-text { color: var(--muted) !important; }

.badge-status { font-weight: 600; font-size: .72rem; padding: .35em .65em; border-radius: 999px; }
.badge-status.bg-light { background: #f1f5f9 !important; color: #475569; border: 1px solid #e2e8f0; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.1rem; }
.page-head h1 { font-size: 1.35rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: .85rem; }

.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 140px; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty i { font-size: 2.2rem; display: block; margin-bottom: .5rem; color: #cbd5e1; }

/* ---------- Invoice builder ---------- */
.items-table td { padding: .4rem .35rem; }
.items-table .form-control, .items-table .form-select { padding: .35rem .5rem; font-size: .88rem; }
.items-table .col-desc { min-width: 220px; }
.items-table .col-hsn { width: 100px; }
.items-table .col-qty { width: 90px; }
.items-table .col-unit { width: 90px; }
.items-table .col-rate { width: 120px; }
.items-table .col-disc { width: 80px; }
.items-table .col-tax { width: 95px; }
.items-table .col-amt { width: 130px; }
.items-table .line-amount { font-weight: 600; padding-top: .45rem; }
.totals-box dl { display: grid; grid-template-columns: 1fr auto; gap: .35rem 1rem; margin: 0; }
.totals-box dt { font-weight: 500; color: var(--muted); }
.totals-box dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals-box .grand { font-size: 1.25rem; font-weight: 700; color: var(--ink); border-top: 1px solid var(--line); padding-top: .5rem; }
.supply-pill { display: inline-flex; gap: .35rem; align-items: center; font-size: .78rem; font-weight: 600; padding: .25rem .6rem; border-radius: 999px; }
.supply-intra { background: #dcfce7; color: #166534; }
.supply-inter { background: #e0e7ff; color: #3730a3; }

/* ---------- Auth / installer ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0, transparent 60%), radial-gradient(900px 500px at 110% 110%, #fde68a55 0, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card.wide { max-width: 680px; }
.auth-brand { display: flex; align-items: center; gap: .6rem; justify-content: center; margin-bottom: 1.25rem; font-weight: 700; font-size: 1.15rem; }
.check-row { display: flex; justify-content: space-between; padding: .45rem 0; border-bottom: 1px dashed var(--line); }

/* ---------- Document preview (show page) ---------- */
.doc-preview { background: #fff; color: #0f172a; border-radius: 12px; border: 1px solid var(--line); overflow: hidden; }
.doc-frame { width: 100%; height: 1100px; border: 0; display: block; background: #fff; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin: 0; }
}
