/* ═══════════════════════════════════════════════════════════════
   Financials page (public/js/financials.js). Everything is scoped under
   .fin / fin- so nothing leaks into the rest of the CRM. Uses the house
   tokens from theme.css (--ink, --rule, --brand …).
   ═══════════════════════════════════════════════════════════════ */
.page-content.page-wide { max-width: none; }
/* .main is a flex item that grows to fit its widest child; on this page the
   grid scrolls inside its own box instead of stretching the whole page. */
.main:has(> .page-content.page-wide) { min-width: 0; }

.fin { --fin-bc: #eef1f5; --fin-crm: #fdf3e6; --fin-ovr: #2f6fd6; --fin-billed: #e6f3ec; --fin-sub: #eef2f7; --fin-total: #e3e9f1; --fin-sel: #2f6fd6; }
.fin [hidden] { display: none !important; }
.fin-spacer { flex: 1; }
.fin-p { color: var(--ink-3); margin: 0 0 12px; }
.fin-muted { color: var(--ink-3); }
.fin-neg { color: var(--bad); }
.fin-zero { color: #a3aab7; }

/* Header strip: month, sub-tabs, status */
.fin-head { display: flex; align-items: center; gap: 16px; margin: -8px 0 12px; flex-wrap: wrap; }
.fin-monthnav { display: flex; align-items: center; gap: 4px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 2px 4px; }
.fin-monthnav span { min-width: 124px; text-align: center; font-weight: 600; color: var(--ink); }
.fin-icon { background: none; border: none; font-size: 19px; line-height: 1; padding: 2px 9px; border-radius: 4px; cursor: pointer; color: var(--ink-2); }
.fin-icon:hover { background: var(--rule-2); }
.fin-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); }
.fin-tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: 7px 12px; font: inherit; color: var(--ink-3); cursor: pointer; margin-bottom: -1px; }
.fin-tabs button:hover { color: var(--ink); }
.fin-tabs button.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--brand); }
.fin-badge { background: var(--brand); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; font-weight: 700; margin-left: 2px; }
.fin-status { color: var(--ink-3); font-size: 12px; }

/* Toolbar */
.fin-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.fin-toolbar .form-control { width: auto; padding: 6px 10px; height: 32px; }
.fin-toolbar #finSearch { width: 260px; }
.fin-check { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-3); user-select: none; font-size: 13px; }

/* Legend */
.fin-legend { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 8px; font-size: 12px; color: var(--ink-3); }
.fin-legend i { display: inline-block; width: 14px; height: 11px; vertical-align: -1px; margin-right: 4px; border: 1px solid var(--rule); }
.fin-lg-bc { background: var(--fin-bc); }
.fin-lg-crm { background: var(--fin-crm); }
.fin-lg-ovr { background: linear-gradient(225deg, var(--fin-ovr) 0 5px, #fff 5px); }
.fin-lg-billed { background: var(--fin-billed); padding: 0 4px; color: var(--ink); }
.fin-keys { color: #9aa1ad; }

/* Grid */
.fin-scroller { overflow: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); }
table.fin-grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; background: var(--paper); font-size: 12.5px; }
.fin-grid th, .fin-grid td { border-right: 1px solid var(--rule-2); border-bottom: 1px solid var(--rule-2); padding: 3px 6px; height: 25px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.fin-grid thead th {
  position: sticky; top: 0; z-index: 3; background: var(--ink); color: #fff; font-weight: 600; font-size: 12px;
  white-space: normal; vertical-align: bottom; height: 46px; line-height: 1.2; cursor: pointer; user-select: none;
  border-right-color: #2a3654; border-bottom: none; border-top: 3px solid var(--ink);
}
.fin-grid thead th.fin-g-bc { border-top-color: #8a96ab; }
.fin-grid thead th.fin-g-cur { border-top-color: #c79a3b; }
.fin-grid thead th.fin-g-month { border-top-color: #3fa877; }
.fin-grid thead th.fin-g-after { border-top-color: var(--brand); }
.fin-grid thead th.fin-cur-month { background: #22324f; }
.fin-sort { color: var(--brand); margin-left: 3px; }
.fin-grid .fin-num { text-align: right; font-variant-numeric: tabular-nums; }
.fin-grid .fin-sticky { position: sticky; z-index: 1; }
.fin-grid thead th.fin-sticky { z-index: 4; }
.fin-grid td.fin-sticky { background: var(--paper); }
.fin-grid .fin-last-sticky { box-shadow: 2px 0 0 var(--rule); }
.fin-grid tbody tr:hover td { background-image: linear-gradient(rgba(23, 34, 59, .04), rgba(23, 34, 59, .04)); }
.fin-grid td.fin-bc { background-color: var(--fin-bc); color: #47536a; }
.fin-grid td.fin-crm { background-color: var(--fin-crm); color: #6b4a14; }
.fin-grid td.fin-ovr { background-image: linear-gradient(225deg, var(--fin-ovr) 0 6px, transparent 6px) !important; }
.fin-grid td.fin-billed { font-weight: 700; color: var(--ink); background-color: var(--fin-billed); }
.fin-grid td.fin-calc { background-color: #f5f7fa; font-weight: 600; color: var(--ink); }
.fin-grid td.fin-sel { outline: 2px solid var(--fin-sel); outline-offset: -2px; }
.fin-grid td.fin-pmcell { font-weight: 600; color: var(--ink); }
.fin-grid td[data-k="job_no"] { color: var(--ink); }
.fin-flag { display: inline-block; font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: 3px; margin-left: 4px; vertical-align: 1px; }
.fin-nobc { background: #fdecc8; color: #7a5200; }
.fin-closed { background: #f6d5d5; color: #8b1d1d; }
.fin-setup { background: #e4ecf7; color: #234a7d; }
.fin-joblink { color: inherit; text-decoration: underline; text-decoration-color: rgba(0, 0, 0, 0.3); text-underline-offset: 2px; }
.fin-joblink:hover { text-decoration-color: currentColor; }
.fin-ok { color: #1d6b3a; font-weight: 700; }
.fin-todo { color: #8b1d1d; font-weight: 700; }
.fin-setup-checks { white-space: nowrap; }
.fin-setup-checks span { margin-right: 8px; }
.fin-grid tr.fin-section td { background: #fbf6ea; font-weight: 600; color: #6b5413; height: 30px; border-top: 2px solid var(--rule); }
.fin-grid tr.fin-sub td { background: var(--fin-sub); font-weight: 700; color: var(--ink); }
.fin-grid tfoot td { position: sticky; bottom: 0; z-index: 2; background: var(--fin-total); font-weight: 700; color: var(--ink); border-top: 2px solid var(--rule); height: 40px; vertical-align: top; }
.fin-grid tfoot td.fin-sticky { z-index: 3; }
.fin-billedline { display: block; font-size: 11px; font-weight: 600; color: var(--good); }
.fin-grid tr.fin-empty td { color: var(--ink-3); text-align: center; height: 60px; white-space: normal; }

/* Cell editor (appended to body) */
.fin-editor { position: fixed; z-index: 1200; font: 12.5px/1.35 'Public Sans', 'Segoe UI', sans-serif; border: 2px solid #2f6fd6; border-radius: 2px; padding: 2px 5px; background: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.18); outline: none; color: #17223b; }
textarea.fin-editor { resize: both; }

/* Context menu (appended to body) */
.fin-menu { position: fixed; z-index: 1300; background: #fff; border: 1px solid #dfe3ea; border-radius: 6px; box-shadow: 0 12px 32px rgba(23,34,59,.16); padding: 4px; min-width: 220px; font-size: 13px; }
.fin-menu[hidden] { display: none; }
.fin-menu button { display: flex; width: 100%; border: none; border-radius: 4px; background: transparent; padding: 7px 10px; text-align: left; font: inherit; color: #17223b; cursor: pointer; }
.fin-menu button:hover { background: #eef2f7; }
.fin-menu hr { border: none; border-top: 1px solid #eceff3; margin: 4px 0; }
.fin-hint { color: #8a92a2; margin-left: auto; font-size: 11px; }

/* Dialog extras */
.fin-preview { background: #f3f5f8; border-radius: 4px; padding: 8px 10px; margin: -8px 0 16px; font-size: 12.5px; color: var(--ink-2); }

/* Report tables (summary, checks, log) */
.fin-kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.fin-scroll-x { overflow-x: auto; }
table.fin-report { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 13px; }
.fin-report th, .fin-report td { padding: 7px 10px; border-bottom: 1px solid var(--rule-2); text-align: left; white-space: nowrap; }
.fin-report th { font-size: 12px; color: #fff; font-weight: 600; background: var(--ink); }
.fin-report .fin-num { text-align: right; }
.fin-report tr.fin-total td { font-weight: 700; background: var(--fin-total); color: var(--ink); }
.fin-report tr.fin-minor td { color: var(--good); font-weight: 600; background: #f2f8f4; }
.fin-report .fin-wrap { white-space: normal; min-width: 160px; }
.fin-report .fin-actions { white-space: nowrap; text-align: right; }
.fin-excel-urls code, .fin-keybox code, .fin-steps code { font-size: 12px; background: #f3f5f8; padding: 1px 5px; border-radius: 3px; word-break: break-all; }
.fin-small { font-size: 11.5px; margin-top: 3px; }
.fin-howto { margin-top: 12px; }
.fin-howto summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.fin-steps { margin: 8px 0 0 18px; padding: 0; line-height: 1.6; color: var(--ink-2); }
.fin-keybox { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: #fbf6ea; border: 1px solid #ecdcb9; border-radius: 6px; }
.fin-keybox code { font-size: 13px; background: #fff; }
.fin-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 7px; border: 1px solid rgba(0,0,0,.15); cursor: pointer; }
