/* Raghav Traders — Supplier Ledger. Restrained corporate UI on Bootstrap 5. */
:root {
  --ink: #101828;
  --ink-2: #344054;
  --muted: #667085;
  --line: #e4e7ec;
  --line-2: #eef0f3;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --primary: #1f4e8c;
  --primary-ink: #163a69;
  --primary-soft: #eaf1fb;
  --side: #0f2440;
  --side-2: #142e52;
  --side-text: #b9c6da;
  --payable: #b54708;
  --payable-soft: #fff4e5;
  --advance: #067647;
  --advance-soft: #e8f7ef;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff6db;
  --info: #175cd3;
  --info-soft: #eaf2ff;
  --ok: #067647;
  --ok-soft: #e8f7ef;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-body-color: var(--ink);
  --bs-primary: var(--primary);
  --bs-primary-rgb: 31, 78, 140;
  --bs-link-color: var(--primary);
  --bs-link-color-rgb: 31, 78, 140;
  --bs-border-color: var(--line);
}
html, body { background: var(--bg); }
body { font-size: 14px; color: var(--ink); -webkit-font-smoothing: antialiased; }
.num, .data-table td.num, .kpi-value { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
a { text-decoration: none; }
code { color: var(--primary-ink); }

/* Buttons */
.btn { border-radius: 8px; font-weight: 500; }
.btn-primary { --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary); --bs-btn-hover-bg: var(--primary-ink); --bs-btn-hover-border-color: var(--primary-ink); --bs-btn-active-bg: var(--primary-ink); --bs-btn-disabled-bg: var(--primary); }
.btn-outline-primary { --bs-btn-color: var(--primary); --bs-btn-border-color: #b7c9e4; --bs-btn-hover-bg: var(--primary); --bs-btn-hover-border-color: var(--primary); }
.btn-icon { border: 1px solid var(--line); background: var(--surface); width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 0; font-size: 20px; }
.form-control, .form-select { border-radius: 8px; border-color: #d0d5dd; }
.form-control:focus, .form-select:focus { border-color: #84a9dc; box-shadow: 0 0 0 3px rgba(31, 78, 140, .12); }
.form-label { font-weight: 500; color: var(--ink-2); margin-bottom: .3rem; font-size: 13px; }
.form-text { color: var(--muted); font-size: 12px; }
.req::after { content: " *"; color: var(--bad); }

/* Shell */
.sidebar { position: fixed; inset: 0 auto 0 0; width: 252px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; z-index: 1040; transition: transform .2s ease; }
.brand { display: flex; align-items: center; gap: 12px; padding: 18px 18px 16px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, #3b7bd4, #1f4e8c); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; letter-spacing: .5px; flex: none; }
.brand-mark.lg { width: 48px; height: 48px; font-size: 18px; border-radius: 12px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { color: var(--side-text); font-size: 12px; }
.side-nav { flex: 1; overflow-y: auto; padding: 8px 10px 16px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7f93b2; padding: 14px 10px 6px; font-weight: 600; }
.side-nav a { display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 7px 10px; border-radius: 7px; font-size: 13.5px; position: relative; }
.side-nav a i { font-size: 16px; width: 18px; text-align: center; opacity: .9; }
.side-nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.side-nav a.active { background: rgba(78,161,255,.14); color: #fff; }
.side-nav a.active::before { content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: #4ea1ff; }
.nav-count { margin-left: auto; background: #f79009; color: #1b1300; font-size: 11px; border-radius: 10px; padding: 1px 7px; font-weight: 700; }
.side-foot { font-size: 11px; color: #7f93b2; padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.06); }
.main { margin-left: 252px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 1020; background: rgba(255,255,255,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 12px 28px; min-height: 64px; }
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { font-size: 19px; font-weight: 600; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb { font-size: 12px; color: var(--muted); }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--primary); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btn-user { border: 1px solid var(--line); background: var(--surface); display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; }
.content { padding: 24px 28px 48px; flex: 1; }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1030; }
  .main { margin-left: 0; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .topbar h1 { font-size: 17px; }
}

/* Panels & cards */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel > .card-header, .panel-head { background: transparent; border-bottom: 1px solid var(--line); padding: 14px 18px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel-head h2, .panel > .card-header h2 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; min-width: 0; }
.panel-head .sub { color: var(--muted); font-size: 12px; font-weight: 400; }
.panel .card-body { padding: 18px; }
.mb-section { margin-bottom: 20px; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
@media (max-width: 991.98px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 575.98px) { .kpi-grid { grid-template-columns: 1fr; } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); position: relative; min-width: 0; }
.kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi-label i { font-size: 14px; }
.kpi-value { font-size: 23px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent-payable { border-top: 3px solid var(--payable); }
.kpi.accent-advance { border-top: 3px solid var(--advance); }
.kpi.accent-primary { border-top: 3px solid var(--primary); }
.kpi.accent-muted { border-top: 3px solid #98a2b3; }
.kpi a.stretched-link { color: inherit; }

/* Balance + badges */
.bal { font-weight: 600; white-space: nowrap; }
.bal small { font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; margin-left: 4px; vertical-align: 1px; }
.bal-payable { color: var(--payable); }
.bal-payable small { background: var(--payable-soft); }
.bal-advance { color: var(--advance); }
.bal-advance small { background: var(--advance-soft); }
.bal-zero { color: var(--muted); }
.bal-zero small { background: var(--line-2); }
.badge-s { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; line-height: 1.5; }
.s-ok { background: var(--ok-soft); color: var(--ok); }
.s-warn { background: var(--warn-soft); color: var(--warn); }
.s-bad { background: var(--bad-soft); color: var(--bad); }
.s-info { background: var(--info-soft); color: var(--info); }
.s-muted { background: #f2f4f7; color: #475467; }
.eff-plus { color: var(--payable); font-weight: 600; }
.eff-minus { color: var(--advance); font-weight: 600; }
.sign-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--muted); }
.sign-legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }
.sign-legend .lg-p::before { background: var(--payable); }
.sign-legend .lg-a::before { background: var(--advance); }

/* Tables */
.data-table { margin: 0; --bs-table-bg: transparent; }
.data-table thead th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #f9fafb; border-bottom: 1px solid var(--line); padding: 9px 12px; white-space: nowrap; }
.data-table td { padding: 9px 12px; border-color: var(--line-2); vertical-align: middle; }
.data-table tbody tr:hover { background: #fafbfd; }
.data-table tfoot td { font-weight: 650; background: #f6f8fb; border-top: 2px solid var(--line); }
.data-table td.empty { text-align: center; color: var(--muted); padding: 28px; }
.data-table .row-opening td { background: #f8fafc; font-weight: 600; }
.data-table .row-reversed td { color: #98a2b3; text-decoration: line-through; text-decoration-color: rgba(152,162,179,.6); }
.data-table .row-reversed td .badge-s { text-decoration: none; }
.data-table .row-pending td { background: #fffcf0; }
.cell-sub { display: block; font-size: 12px; color: var(--muted); }
.t-link { font-weight: 600; color: var(--primary); white-space: nowrap; }
.table-responsive { border-radius: 0 0 var(--radius) var(--radius); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 18px; border-bottom: 1px solid var(--line); background: #fbfcfd; border-radius: var(--radius) var(--radius) 0 0; }
.filters .f { display: flex; flex-direction: column; gap: 4px; min-width: 140px; flex: 1 1 160px; max-width: 260px; }
.filters .f label { font-size: 12px; color: var(--muted); font-weight: 500; }
.filters .f-actions { display: flex; gap: 6px; align-items: flex-end; flex: 0 0 auto; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; color: var(--muted); font-size: 13px; gap: 10px; flex-wrap: wrap; }
.pagination { --bs-pagination-active-bg: var(--primary); --bs-pagination-active-border-color: var(--primary); --bs-pagination-color: var(--primary); }

/* Detail lists */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 500; font-size: 13px; }
.kv dd { margin: 0; word-break: break-word; }
@media (max-width: 575.98px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 8px; } }

.summary-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.summary-strip > div { padding: 12px 16px; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); }
.summary-strip .lbl { font-size: 12px; color: var(--muted); }
.summary-strip .val { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.summary-strip .closing { background: var(--primary-soft); }

/* Transaction entry */
.effect-box { border: 1px dashed #b7c9e4; background: var(--primary-soft); border-radius: 10px; padding: 12px 14px; font-size: 13px; }
.effect-box strong { font-size: 15px; }
.line-table td { padding: 6px; vertical-align: top; }
.line-table .form-control, .line-table .form-select { font-size: 13px; padding: 6px 8px; }
.line-table .rate-hint { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.line-table .rate-hint.undisclosed { color: var(--warn); font-weight: 500; }
.line-total { font-weight: 600; text-align: right; padding-top: 12px !important; white-space: nowrap; }
.totals-box { margin-left: auto; max-width: 340px; }
.totals-box div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-box .grand { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; font-size: 16px; font-weight: 700; }
.hidden { display: none !important; }

/* Charts */
.chart-box { position: relative; height: 300px; }
.chart-box.sm { height: 240px; }

/* Lists */
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line-2); }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .grow { flex: 1; min-width: 0; }
.mini-list .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.mini-list .meta { color: var(--muted); font-size: 12px; }
.empty-mini { padding: 22px 18px; color: var(--muted); text-align: center; font-size: 13px; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state i { font-size: 40px; color: #98a2b3; }
.empty-state h2 { font-size: 18px; color: var(--ink); margin: 12px 0 6px; }

.callout { border-left: 3px solid var(--primary); background: var(--primary-soft); padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 13px; }
.callout.warn { border-color: #f79009; background: var(--warn-soft); }
.callout.bad { border-color: var(--bad); background: var(--bad-soft); }
.callout.ok { border-color: var(--ok); background: var(--ok-soft); }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.checklist li:last-child { border-bottom: 0; }
.checklist i { font-size: 16px; }
.checklist .ok { color: var(--ok); }
.checklist .no { color: #98a2b3; }
.secret-mask { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--ink-2); }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }
.json-cell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; max-width: 360px; white-space: pre-wrap; word-break: break-all; color: var(--ink-2); }
.alert { border-radius: 10px; }

/* Auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, #dfe9f7 0%, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: 0 12px 40px rgba(16, 24, 40, .08); }
.auth-card.wide { max-width: 640px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-brand h1 { font-size: 20px; margin: 0; font-weight: 700; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-foot { margin: 18px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

@media print {
  .sidebar, .topbar, .filters, .export-group, .btn, .no-print { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  .panel { border: 0; box-shadow: none; }
  body { background: #fff; }
}
.summary-strip .val .bal { white-space: normal; }
