/* =====================================================================
   Cash Flow System – design tokens & layout
   ===================================================================== */
:root {
  --brand: #2563eb;
  --brand-rgb: 37, 99, 235;
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;
  --radius: .75rem;
  --app-bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: rgba(255,255,255,.08);
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
}
[data-bs-theme="dark"] {
  --app-bg: #0b1120;
  --surface: #111827;
  --surface-2: #0f172a;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --sidebar-bg: #020617;
  --sidebar-text: #94a3b8;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

html, body { height: 100%; }
body {
  background: var(--app-bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: .9rem;
}
a { color: var(--brand); }
.text-muted, .form-text { color: var(--muted) !important; }

/* ---------- buttons & brand ---------- */
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: color-mix(in srgb, var(--brand) 85%, black); --bs-btn-hover-border-color: color-mix(in srgb, var(--brand) 85%, black); --bs-btn-active-bg: color-mix(in srgb, var(--brand) 75%, black); }
.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); }
.text-brand { color: var(--brand) !important; }
.bg-brand { background: var(--brand) !important; color: #fff; }
.btn { border-radius: .55rem; }
.btn-icon { display: inline-flex; align-items: center; gap: .4rem; }
.form-control, .form-select { border-radius: .55rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(var(--brand-rgb), .15); }
.form-label { font-weight: 600; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; text-transform: uppercase; letter-spacing: .02em; }
.required::after { content: " *"; color: #dc2626; }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-text);
  position: fixed; inset: 0 auto 0 0; z-index: 1040; display: flex; flex-direction: column;
  transition: width .2s ease, transform .2s ease;
}
.sidebar .brand { height: var(--topbar-h); display: flex; align-items: center; gap: .65rem; padding: 0 1.1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar .brand .logo { width: 34px; height: 34px; border-radius: .6rem; background: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; overflow: hidden; }
.sidebar .brand .logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.sidebar .brand .name { font-weight: 700; font-size: .95rem; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .brand small { display: block; font-weight: 400; color: var(--sidebar-text); font-size: .72rem; }
.sidebar nav { flex: 1; overflow-y: auto; padding: .75rem .6rem 2rem; }
.sidebar .nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 1rem .75rem .35rem; white-space: nowrap;
  display: flex; align-items: center; width: 100%; background: none; border: 0; text-align: left; cursor: pointer; }
.sidebar .nav-section:hover { color: #cbd5e1; }
.sidebar .nav-section i { margin-left: auto; font-size: .7rem; transition: transform .15s ease; }
.sidebar .nav-group.collapsed .nav-section i { transform: rotate(-90deg); }
.sidebar .nav-group.collapsed .nav-group-items { display: none; }
body.sidebar-collapsed .sidebar .nav-group.collapsed .nav-group-items { display: block; }
.sidebar nav { overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #334155 transparent; }
.sidebar .nav-link { color: var(--sidebar-text); display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem; border-radius: .55rem; white-space: nowrap; font-size: .87rem; }
.sidebar .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; flex: none; }
.sidebar .nav-link:hover { background: var(--sidebar-active); color: #fff; }
.sidebar .nav-link.active { background: rgba(var(--brand-rgb), .25); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.sidebar .nav-link .badge { margin-left: auto; }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; transition: margin-left .2s ease; }
.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem; position: sticky; top: 0; z-index: 1030;
}
.topbar .page-title { font-weight: 700; font-size: 1.05rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content { padding: 1.25rem; flex: 1; }
.app-footer { padding: .75rem 1.25rem; color: var(--muted); font-size: .75rem; }

body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .sidebar .brand .name, body.sidebar-collapsed .sidebar .nav-section,
body.sidebar-collapsed .sidebar .nav-link span, body.sidebar-collapsed .sidebar .nav-link .badge { display: none; }
body.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  body.sidebar-open .sidebar { transform: none; }
  .main { margin-left: 0 !important; }
  body.sidebar-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1035; }
  .content { padding: .9rem; }
}

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); font-weight: 600; padding: .85rem 1.1rem; display: flex; align-items: center; gap: .5rem; }
.card-header .actions { margin-left: auto; display: flex; gap: .4rem; }
.card-body { padding: 1.1rem; }
.kpi { display: flex; align-items: center; gap: 1rem; }
.kpi .icon { width: 48px; height: 48px; border-radius: .8rem; display: grid; place-items: center; font-size: 1.35rem; flex: none; }
.kpi .value { font-size: 1.45rem; font-weight: 700; line-height: 1.1; }
.kpi .label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi a { text-decoration: none; color: inherit; }
.icon-blue { background: rgba(37,99,235,.12); color: #2563eb; }
.icon-amber { background: rgba(217,119,6,.12); color: #d97706; }
.icon-green { background: rgba(22,163,74,.12); color: #16a34a; }
.icon-red { background: rgba(220,38,38,.12); color: #dc2626; }
.icon-violet { background: rgba(124,58,237,.12); color: #7c3aed; }
.icon-slate { background: rgba(100,116,139,.15); color: #64748b; }

/* ---------- tables ---------- */
.table { --bs-table-bg: transparent; margin-bottom: 0; vertical-align: middle; }
.table > :not(caption) > * > * { padding: .55rem .7rem; border-color: var(--border); }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table-hover > tbody > tr:hover > * { background: rgba(var(--brand-rgb), .04); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-sm > :not(caption) > * > * { padding: .35rem .5rem; }
div.dt-container .dt-search input { border-radius: .55rem; }
div.dt-container { font-size: .85rem; }
.dt-layout-row { padding: .4rem .2rem; }

/* ---------- status badges ---------- */
.status { display: inline-flex; align-items: center; gap: .35rem; padding: .22rem .6rem; border-radius: 999px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; }
.status-0 { background: #f1f5f9; color: #475569; }
.status-10 { background: #fef3c7; color: #b45309; }
.status-20 { background: #dbeafe; color: #1d4ed8; }
.status-30 { background: #e0e7ff; color: #4338ca; }
.status-40, .status-45 { background: #fae8ff; color: #a21caf; }
.status-50 { background: #ffedd5; color: #c2410c; }
.status-60 { background: #dcfce7; color: #15803d; }
.status-90, .status-99 { background: #fee2e2; color: #b91c1c; }
[data-bs-theme="dark"] .status { background: rgba(255,255,255,.08) !important; }

/* ---------- timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 11px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline li { position: relative; padding: 0 0 1rem 2.1rem; }
.timeline li .dot { position: absolute; left: 4px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand); }
.timeline li .when { font-size: .72rem; color: var(--muted); }

/* ---------- workflow stepper ---------- */
.stepper { display: flex; gap: 0; overflow-x: auto; }
.stepper .step { flex: 1; min-width: 110px; text-align: center; position: relative; font-size: .75rem; color: var(--muted); }
.stepper .step .circle { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto .35rem; background: var(--surface-2); border: 2px solid var(--border); font-size: .95rem; position: relative; z-index: 1; }
.stepper .step:not(:last-child)::after { content: ""; position: absolute; top: 16px; left: 50%; width: 100%; height: 2px; background: var(--border); }
.stepper .step.done .circle { background: #16a34a; border-color: #16a34a; color: #fff; }
.stepper .step.done:not(:last-child)::after { background: #16a34a; }
.stepper .step.current .circle { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 0 0 4px rgba(var(--brand-rgb), .2); }
.stepper .step.current { color: var(--text); font-weight: 600; }
.stepper .step.bad .circle { background: #dc2626; border-color: #dc2626; color: #fff; }

/* ---------- line editors ---------- */
.line-table input, .line-table select { min-width: 90px; }
.line-table td { vertical-align: top; }
.line-table .ts-wrapper { min-width: 180px; }
.totals-bar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: .75rem 1.1rem; display: flex; align-items: center; gap: 1rem; z-index: 5; border-radius: 0 0 var(--radius) var(--radius); }
.totals-bar .total { font-size: 1.25rem; font-weight: 700; }
.amount { font-variant-numeric: tabular-nums; }

/* ---------- misc ---------- */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }
.notif-dropdown { width: 360px; max-height: 460px; overflow-y: auto; }
.notif-item { white-space: normal; border-bottom: 1px solid var(--border); }
.notif-item.unread { background: rgba(var(--brand-rgb), .06); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(var(--brand-rgb), .15); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.code, pre.sql, textarea.code { font-family: Consolas, "Cascadia Mono", monospace; font-size: .82rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.page-actions .spacer { flex: 1; }
.nav-tabs .nav-link { color: var(--muted); }
.nav-tabs .nav-link.active { color: var(--brand); font-weight: 600; }
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 150px; }
.login-bg { min-height: 100vh; background: radial-gradient(1200px 600px at 10% 10%, rgba(var(--brand-rgb), .25), transparent), radial-gradient(900px 500px at 90% 90%, rgba(124,58,237,.18), transparent), var(--app-bg); }
.login-card { max-width: 420px; width: 100%; }
.dl-grid { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.dl-grid dt { color: var(--muted); font-weight: 500; font-size: .8rem; }
.dl-grid dd { margin: 0; font-weight: 500; }
.sap-preview table td { font-size: .8rem; }
.pvtUi { color: var(--text); }
.pvtTable { font-size: .8rem !important; }
[data-bs-theme="dark"] .pvtTable thead tr th, [data-bs-theme="dark"] .pvtTable tbody tr th { background: #1f2937 !important; color: #e5e7eb; }
[data-bs-theme="dark"] .pvtTable tbody tr td { background: #111827 !important; color: #e5e7eb; }
[data-bs-theme="dark"] .pvtAxisContainer, [data-bs-theme="dark"] .pvtVals { background: #0f172a !important; border-color: #1f2937 !important; }
.ts-control { border-radius: .55rem; }
.ts-wrapper.single .ts-control, .ts-wrapper.multi .ts-control { background: var(--bs-body-bg); color: var(--text); border-color: var(--bs-border-color); }
.ts-control .item, .ts-control input { color: var(--text) !important; }
.ts-control input::placeholder { color: var(--muted); }
.ts-dropdown { background: var(--surface); color: var(--text); border-color: var(--border); }
.ts-dropdown .active { background: rgba(var(--brand-rgb), .15); color: var(--text); }
.ts-wrapper.multi .ts-control > div { background: rgba(var(--brand-rgb), .15); color: var(--text); border-color: transparent; }
.swal2-popup { font-size: .9rem !important; }
@media print { .sidebar, .topbar, .no-print { display: none !important; } .main { margin: 0 !important; } }

/* ---- help / user manual */
.help-content { max-width: 900px; line-height: 1.65; }
.help-content h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 1rem; }
.help-content h2 { font-size: 1.3rem; font-weight: 600; margin-top: 2rem; padding-top: .5rem; border-top: 1px solid var(--bs-border-color); scroll-margin-top: 80px; }
.help-content h3 { font-size: 1.08rem; font-weight: 600; margin-top: 1.4rem; scroll-margin-top: 80px; }
.help-content table { width: 100%; margin: .75rem 0 1.25rem; font-size: .9rem; border-collapse: collapse; }
.help-content th, .help-content td { border: 1px solid var(--bs-border-color); padding: .4rem .6rem; vertical-align: top; }
.help-content th { background: var(--bs-tertiary-bg); font-weight: 600; }
.help-content blockquote { border-left: 4px solid var(--brand); background: rgba(var(--brand-rgb), .07); padding: .6rem 1rem; border-radius: .25rem; margin: 1rem 0; }
.help-content blockquote p:last-child { margin-bottom: 0; }
.help-content code { background: var(--bs-tertiary-bg); padding: .05rem .3rem; border-radius: .2rem; }
.help-content li { margin-bottom: .2rem; }
.help-toc { position: sticky; top: 80px; font-size: .875rem; }
.help-toc a { display: block; padding: .2rem 0 .2rem .75rem; color: var(--bs-secondary-color); text-decoration: none; border-left: 2px solid transparent; }
.help-toc a:hover, .help-toc a.active { color: var(--brand); border-left-color: var(--brand); }
.help-card { transition: transform .12s, box-shadow .12s; }
.help-card:hover { transform: translateY(-2px); box-shadow: 0 .5rem 1rem rgba(0,0,0,.08); }
.help-card .icon { font-size: 1.6rem; color: var(--brand); }
.help-hit mark { padding: 0 .1rem; background: rgba(var(--brand-rgb), .25); color: inherit; }
@media print { .sidebar, .topbar, .no-print, .help-toc { display: none !important; } .help-content { max-width: none; } }
