/* ERP design system — layered on Bootstrap 5.3. One file restyles every page. */
:root {
  --app-primary: #1f5eff;
  --app-primary-rgb: 31, 94, 255;
  --app-primary-hover: #1a4fd6;
  --app-sidebar-w: 248px;
  --app-radius: 8px;
  --app-bg: #f5f6f8;
  --app-surface: #ffffff;
  --app-border: #e6e9f2;
  --app-muted: #6b7280;
  --app-text: #111827;
  --app-sidebar-bg: #17202e;
  --app-sidebar-text: #cbd5e1;
  --app-sidebar-active: rgba(255, 255, 255, .08);
  --app-shadow: none;
  --bs-primary: var(--app-primary);
  --bs-primary-rgb: var(--app-primary-rgb);
  --bs-link-color: var(--app-primary);
  --bs-link-color-rgb: var(--app-primary-rgb);
  --bs-link-hover-color: var(--app-primary-hover);
  --bs-body-font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-font-size: .925rem;
  --bs-border-radius: 6px;
}
[data-bs-theme="dark"] {
  --app-bg: #0b1020;
  --app-surface: #121a2e;
  --app-border: #1f2a44;
  --app-muted: #94a3b8;
  --app-text: #e5e7eb;
  --app-sidebar-bg: #070b16;
  --bs-body-bg: var(--app-bg);
  --bs-body-color: var(--app-text);
  --bs-border-color: var(--app-border);
}

body.app { background: var(--app-bg); color: var(--app-text); }

/* ---------- Shell ---------- */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--app-sidebar-w); z-index: 1040;
  background: var(--app-sidebar-bg); color: var(--app-sidebar-text);
  display: flex; flex-direction: column; transition: transform .2s ease;
}
.app-brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.1rem .9rem; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .2px; }
.app-brand .logo { width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center; background: var(--app-primary); color: #fff; font-size: .85rem; font-weight: 700; flex: none; letter-spacing: .02em; }
.app-brand .name { line-height: 1.15; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-brand .name small { display: block; color: #94a3b8; font-weight: 500; font-size: .72rem; }
.app-nav { overflow-y: auto; padding: .25rem .6rem 1rem; flex: 1; scrollbar-width: thin; }
.app-nav .section { color: #64748b; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: .9rem .6rem .35rem; }
.app-nav a { display: flex; align-items: center; gap: .65rem; padding: .48rem .65rem; border-radius: 8px; color: var(--app-sidebar-text); text-decoration: none; font-size: .875rem; }
.app-nav a i { font-size: 1.02rem; width: 1.2rem; text-align: center; opacity: .85; }
.app-nav a:hover { background: var(--app-sidebar-active); color: #fff; }
.app-nav a.active { background: rgba(255, 255, 255, .09); color: #fff; box-shadow: inset 2px 0 0 #5b8cff; }
.app-sidebar-foot { padding: .8rem 1rem; border-top: 1px solid rgba(255, 255, 255, .06); font-size: .75rem; color: #64748b; }

.app-main { margin-left: var(--app-sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.app-topbar {
  position: sticky; top: 0; z-index: 1030; height: 60px; display: flex; align-items: center; gap: .75rem;
  padding: 0 1.25rem; background: var(--app-surface);
  border-bottom: 1px solid var(--app-border);
}
.app-search { flex: 1; max-width: 520px; position: relative; }
.app-search i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--app-muted); }
.app-search input { padding-left: 2.2rem; border-radius: 10px; background: var(--app-bg); border-color: var(--app-border); }
.app-search kbd { position: absolute; right: .6rem; top: 50%; transform: translateY(-50%); font-size: .7rem; background: var(--app-surface); color: var(--app-muted); border: 1px solid var(--app-border); }
.app-topbar .icon-btn { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; border: 1px solid var(--app-border); background: var(--app-surface); color: var(--app-text); }
.app-topbar .icon-btn:hover { border-color: var(--app-primary); color: var(--app-primary); }
.app-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: rgba(var(--app-primary-rgb), .12); color: var(--app-primary); font-weight: 700; font-size: .85rem; }
.app-content { padding: 1.5rem 1.75rem 3rem; flex: 1; }
.app-impersonate { background: #fef3c7; color: #78350f; font-size: .82rem; padding: .35rem 1rem; text-align: center; }
.app-impersonate a { color: #78350f; font-weight: 700; }

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  body.sidebar-open .app-sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  body.sidebar-open .app-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1035; }
  .app-main { margin-left: 0; }
  .app-content { padding: 1rem; }
  .app-search kbd { display: none; }
}
@media print {
  .app-sidebar, .app-topbar, .no-print { display: none !important; }
  .app-main { margin-left: 0; }
  body.app { background: #fff; }
}

/* ---------- Page headings (existing pages use h5.mb-3 / h5.mb-0 as their title) ---------- */
.app-content > h5.mb-3, .app-content > .d-flex > h5.mb-0, .app-content h5.page-title {
  font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em;
}
.app-content h6 { font-weight: 650; }
.page-sub { color: var(--app-muted); margin-top: -.6rem; margin-bottom: 1.2rem; }

/* ---------- Surfaces ---------- */
.card { border: 1px solid var(--app-border); border-radius: var(--app-radius); box-shadow: var(--app-shadow); background: var(--app-surface); }
.card > .table, .card > .table-responsive > .table, .card > div > .table { margin-bottom: 0; }
.card > .table:first-child thead th:first-child, .card > .table-responsive:first-child .table thead th:first-child { border-top-left-radius: var(--app-radius); }
.card > .table:first-child thead th:last-child, .card > .table-responsive:first-child .table thead th:last-child { border-top-right-radius: var(--app-radius); }
.table { --bs-table-bg: transparent; vertical-align: middle; }
.table > thead th {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--app-muted);
  background: color-mix(in srgb, var(--app-bg) 70%, var(--app-surface)); border-bottom: 1px solid var(--app-border); white-space: nowrap;
  padding-top: .7rem; padding-bottom: .7rem;
}
.table > tbody > tr:hover > * { background: rgba(var(--app-primary-rgb), .035); }
.table td, .table th { border-color: var(--app-border); }
.table tfoot td { border-top: 2px solid var(--app-border); }
.form-control, .form-select { border-color: var(--app-border); border-radius: 8px; }
.form-control:focus, .form-select:focus { border-color: rgba(var(--app-primary-rgb), .6); box-shadow: 0 0 0 .2rem rgba(var(--app-primary-rgb), .15); }
.form-label { font-weight: 600; font-size: .82rem; color: var(--app-muted); margin-bottom: .3rem; }
.btn { border-radius: 8px; font-weight: 600; }
.btn-primary { --bs-btn-bg: var(--app-primary); --bs-btn-border-color: var(--app-primary); --bs-btn-hover-bg: var(--app-primary-hover); --bs-btn-hover-border-color: var(--app-primary-hover); --bs-btn-active-bg: var(--app-primary-hover); --bs-btn-disabled-bg: var(--app-primary); --bs-btn-disabled-border-color: var(--app-primary); }
.btn-outline-primary { --bs-btn-color: var(--app-primary); --bs-btn-border-color: var(--app-primary); --bs-btn-hover-bg: var(--app-primary); --bs-btn-hover-border-color: var(--app-primary); --bs-btn-active-bg: var(--app-primary); }
.badge { font-weight: 600; letter-spacing: .02em; border-radius: 6px; }
.alert { border-radius: 6px; }
.dropdown-menu { border-radius: 10px; border-color: var(--app-border); box-shadow: 0 10px 30px rgba(16, 24, 40, .12); }

/* ---------- Dashboard ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 1rem; }
.kpi { padding: 1.1rem 1.2rem; height: 100%; }
.kpi .label { color: var(--app-muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.kpi .label i { display: none; }
.kpi .value { font-size: 1.4rem; font-weight: 700; margin-top: .3rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: .78rem; font-weight: 600; }
.kpi .delta.up { color: #059669; } .kpi .delta.down { color: #dc2626; }
.tone-indigo { background: rgba(99, 102, 241, .12); color: #4f46e5; }
.tone-green { background: rgba(16, 185, 129, .12); color: #059669; }
.tone-amber { background: rgba(245, 158, 11, .14); color: #b45309; }
.tone-rose { background: rgba(244, 63, 94, .12); color: #e11d48; }
.tone-sky { background: rgba(14, 165, 233, .12); color: #0284c7; }
.tone-violet { background: rgba(139, 92, 246, .12); color: #7c3aed; }
.chart-card .card-header { background: transparent; border-bottom: 1px solid var(--app-border); padding: .85rem 1.1rem; display: flex; align-items: center; justify-content: space-between; }
.chart-card .card-header h6 { margin: 0; }
.chart { width: 100%; height: 300px; }
.chart.tall { height: 380px; }
.list-compact .list-group-item { border-color: var(--app-border); padding: .6rem 1.1rem; background: transparent; }
.seg { display: inline-flex; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 10px; padding: 3px; }
.seg a { padding: .3rem .75rem; border-radius: 7px; font-size: .8rem; font-weight: 600; color: var(--app-muted); text-decoration: none; }
.seg a.active { background: var(--app-bg); color: var(--app-text); box-shadow: inset 0 0 0 1px var(--app-border); }

/* ---------- Reports ---------- */
.report-tile { display: flex; gap: .85rem; padding: 1rem 1.1rem; text-decoration: none; color: inherit; height: 100%; transition: transform .12s ease, box-shadow .12s ease; }
.report-tile:hover { border-color: var(--app-primary); color: inherit; }
.report-tile i { font-size: 1.1rem; width: 22px; flex: none; color: var(--app-muted); background: none !important; }
.report-tile .t { font-weight: 650; }
.report-tile .d { color: var(--app-muted); font-size: .8rem; }
.empty-state { text-align: center; color: var(--app-muted); padding: 2.5rem 1rem; }
.empty-state i { font-size: 2rem; display: block; margin-bottom: .5rem; opacity: .6; }

/* Line-item tables (.item-table): on phones a wide table of inputs is unusable, so each
   row reflows into a stacked card with a label above each field. */
@media (max-width: 767.98px) {
  .item-table thead { display: none; }
  .item-table, .item-table tbody, .item-table tfoot, .item-table tr, .item-table td { display: block; width: 100%; }
  .item-table tbody tr { border: 1px solid var(--app-border); border-radius: 10px; padding: 10px 10px 2px; margin-bottom: 10px; background: var(--app-surface); }
  .item-table td { border: none; padding: 0 0 8px; }
  .item-table td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; font-weight: 600; text-transform: uppercase; color: var(--app-muted); margin-bottom: 2px; }
}

/* ---------- Financial statements ---------- */
.stmt-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.stmt-toolbar .form-control, .stmt-toolbar .form-select { width: auto; }
.stmt { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 10px; }
.stmt-head { padding: 1.4rem 1.5rem 1rem; border-bottom: 1px solid var(--app-border); }
.stmt-head .co { font-size: .8rem; color: var(--app-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stmt-head h4 { margin: .15rem 0 .1rem; font-weight: 700; }
.stmt-head .per { color: var(--app-muted); font-size: .85rem; }
.stmt table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stmt th, .stmt td { padding: .42rem 1.5rem; }
.stmt thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--app-muted); font-weight: 700; border-bottom: 1px solid var(--app-border); text-align: right; white-space: nowrap; }
.stmt thead th:first-child { text-align: left; }
.stmt td.n { text-align: right; white-space: nowrap; }
.stmt tr.sec td { padding-top: 1.1rem; font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--app-text); }
.stmt tr.acct td:first-child { padding-left: 2.4rem; }
.stmt tr.acct a { color: inherit; text-decoration: none; }
.stmt tr.acct a:hover { color: var(--app-primary); text-decoration: underline; }
.stmt tr.acct:hover td { background: rgba(var(--app-primary-rgb), .03); }
.stmt tr.sub td { font-weight: 600; border-top: 1px solid var(--app-border); }
.stmt tr.key td { font-weight: 700; background: color-mix(in srgb, var(--app-bg) 60%, var(--app-surface)); }
.stmt tr.grand td { font-weight: 800; font-size: 1.02rem; border-top: 1px solid var(--app-text); border-bottom: 3px double var(--app-text); }
.stmt .pct { color: var(--app-muted); font-size: .8rem; }
.stmt .chg { font-size: .8rem; font-weight: 600; }
.stmt .chg.up { color: #047857; } .stmt .chg.down { color: #b91c1c; }
.stmt-foot { padding: .8rem 1.5rem; color: var(--app-muted); font-size: .78rem; border-top: 1px solid var(--app-border); display: flex; justify-content: space-between; }
.metric { border: 1px solid var(--app-border); border-radius: 10px; padding: .75rem 1rem; background: var(--app-surface); }
.metric .v { font-size: 1.25rem; font-weight: 700; }
.metric .l { font-size: .75rem; color: var(--app-muted); }
