/* ==========================================================================
   Prepočet farmy — colour system (loaded LAST, after every view stylesheet)

   Three calm, earthy colours tell the parts of the app apart:
     green  = the farm and money coming in   (Farma: Pozemky, Nákup a investície,
              Fotovoltika, Príjmy, Produkty, Dotácie, stáda; income rows / series)
     brown  = costs and the community        (Náklady, Komunita; cost rows / series)
     grey   = finance, settings, structure   (Základ, Úvery, Situácie, Číselníky;
              totals, zebra rows). Grey means "no colour": neutral icons use --grey-text,
              grey stripes are left out (or a hairline --border-strong).
   Status colours (good / warning / critical) are NOT used here – they stay reserved
   for status with an icon + text, and a tile in a bad / warning state never gets a
   green or brown stripe next to its red / orange value.

   Only colour, stripes (inset box-shadows) and tints: no layout changes except the
   padding of the section header band in the editor. Tokens (--green, --green-text,
   --green-soft, --green-tint, same for --brown / --grey) live in app.css, light + dark.
   Hooks are existing markup only (section ids in nav hrefs, data-section, data-group,
   data-key, data-cf-key / data-cf-parent of the cashflow rows, row classes).
   ========================================================================== */

/* ---------- Group variables (default: grey = neutral) ----------
   --grp       marks: icons, the active-state stripe / ring
   --grp-line  decorative stripes (section band, KPI tiles); none for grey */

.ed-nav-link,
.ed-section,
.db-kpi-group {
  --grp: var(--grey-text);
  --grp-line: transparent;
  --grp-text: var(--grey-text);
  --grp-soft: var(--grey-soft);
  --grp-tint: var(--grey-tint);
}

/* Farma → green */
.ed-nav-link:is([href$="/inputs/plots"], [href$="/inputs/items"], [href$="/inputs/herds"], [href$="/inputs/pv"],
  [href$="/inputs/incomes"], [href$="/inputs/products"], [href$="/inputs/subsidies"]),
.ed-nav-link:is([data-section="plots"], [data-section="items"], [data-section="herds"], [data-section="pv"],
  [data-section="incomes"], [data-section="products"], [data-section="subsidies"]),
.ed-section:is([data-section="plots"], [data-section="items"], [data-section="herds"], [data-section="pv"],
  [data-section="incomes"], [data-section="products"], [data-section="subsidies"]),
.db-kpi-group:is([data-group="return"], [data-group="assets"], [data-group="subsidies"], [data-group="products"], [data-group="herds"]) {
  --grp: var(--green);
  --grp-line: var(--green);
  --grp-text: var(--green-text);
  --grp-soft: var(--green-soft);
  --grp-tint: var(--green-tint);
}

/* Komunita a náklady → brown */
.ed-nav-link:is([href$="/inputs/costs"], [href$="/inputs/household"]),
.ed-nav-link:is([data-section="costs"], [data-section="household"]),
.ed-section:is([data-section="costs"], [data-section="household"]),
.db-kpi-group[data-group="household"],
.db-family {
  --grp: var(--brown);
  --grp-line: var(--brown);
  --grp-text: var(--brown-text);
  --grp-soft: var(--brown-soft);
  --grp-tint: var(--brown-tint);
}

/* ---------- Editor: section navigation ---------- */

.ed-nav-link .ed-nav-icon { background: var(--grp-tint); color: var(--grp); }
.ed-nav-link:hover .ed-nav-icon { background: var(--grp-soft); color: var(--grp-text); }
.ed-nav-link.is-active { background: var(--grp-soft); color: var(--grp-text); box-shadow: inset 3px 0 0 var(--grp); }
.ed-nav-link.is-active .ed-nav-icon { background: var(--surface); color: var(--grp-text); }
.ed-nav-link.is-active .ed-nav-count { color: var(--grp-text); }

@media (max-width: 1179px) {
  /* Horizontal pills on phones / tablets: coloured border instead of the side stripe. */
  .ed-nav-link.is-active { border-color: var(--grp); box-shadow: inset 0 0 0 1px var(--grp); }
}

/* ---------- Editor: section header band ----------
   Neutral band + the group's 4 px stripe: the section colour sits on the stripe and the nav,
   so a pale-green band can never be mistaken for a success message. KPI tiles and cards of a
   section carry no section colour (a cost tile in a Farma section must not look like income). */

.ed-section > .section-header:first-child,
.ed-section > :first-child > .section-header:first-child {
  padding: 12px 16px 14px 18px;
  border-radius: var(--radius-lg);
  background: var(--grey-tint);
  box-shadow: inset 4px 0 0 var(--grp-line);
}

/* ---------- Dashboard KPI groups: stripe by group, never next to a bad / warning value ---------- */

.db-kpi-group .kpi,
.db-family .kpi { box-shadow: inset 3px 0 0 var(--grp-line), var(--shadow-sm); }
.db-kpi-group .kpi:is(.kpi--bad, .kpi--warning),
.db-family .kpi:is(.kpi--bad, .kpi--warning) { box-shadow: var(--shadow-sm); }
.db-kpi-group-title .icon { color: var(--grp); }

/* Live summary strip above every section: a thin top stripe only where the meaning is fixed
   (NPV = farm return, total investment and the community's month = money out / community);
   everything else neutral, and no stripe at all on a tile in a bad / warning state. */
.ed-strip .ed-kpi[data-key="npv"] { box-shadow: inset 0 3px 0 var(--green); }
.ed-strip .ed-kpi:is([data-key="capex"], [data-key="family"]) { box-shadow: inset 0 3px 0 var(--brown); }
.ed-strip .ed-kpi:is(.kpi--bad, .kpi--warning) { box-shadow: none; }

/* Komunita: brown accents instead of the green brand (own produce stays green: it comes from the farm). */
.hh-switch-icon,
.hh-off-icon { background: var(--brown-soft); color: var(--brown-text); }
.hh-wallet-icon { color: var(--brown-text); }
.hh-starter-icon,
.hh-cat-group-head > .icon,
.hh-sit-group-title > .icon,
.hh-sit-cats > .ed2-h4 > .icon { color: var(--brown); }

/* ---------- Neutral information: grey, so it never reads as "success" green ---------- */

.alert-info { background: var(--grey-tint); border-color: var(--border-strong); }
.alert-info .alert-icon { color: var(--grey-text); }
.ed2-situations-note,
.an-whatif-controls .an-note { background: var(--grey-tint); }
.ed2-situations-note > .icon { color: var(--grey-text); }
.ed2-loan-icon { background: var(--grey-soft); color: var(--grey-text); }
.as-btn.has-new .as-btn-count { background: var(--primary); color: var(--accent-contrast); }

/* ---------- Cashflow and P&L tables ---------- */

/* Row colour by meaning: every row names its meaning in data-cf-key (cashflow.js renderTable),
   child rows name their group in data-cf-parent. Cashflow groups: income / hhIncome / selfUse /
   grants (money in) and cost / capex / hhCost / private (money out); P&L lines: income (Tržby),
   cost and expensedCapex. Tax, odvody and the payout to the owner stay neutral (finance). */
.cf-table tr:is([data-cf-key="income"], [data-cf-key="hhIncome"], [data-cf-key="selfUse"], [data-cf-key="grants"],
  [data-cf-parent="income"], [data-cf-parent="hhIncome"], [data-cf-parent="selfUse"], [data-cf-parent="grants"]) {
  --cf-c: var(--green);
  --cf-text: var(--green-text);
  --cf-tint: var(--green-tint);
  --cf-soft: var(--green-soft);
}
.cf-table tr:is([data-cf-key="cost"], [data-cf-key="capex"], [data-cf-key="expensedCapex"], [data-cf-key="hhCost"], [data-cf-key="private"],
  [data-cf-parent="cost"], [data-cf-parent="capex"], [data-cf-parent="hhCost"], [data-cf-parent="private"]) {
  --cf-c: var(--brown);
  --cf-text: var(--brown-text);
  --cf-tint: var(--brown-tint);
  --cf-soft: var(--brown-soft);
}

/* Zebra (visible rows only), light grey. Specificity (0,2,1) on purpose: it beats the sticky
   column's surface (.data-table th:first-child, same weight, earlier file) but not the row
   hover (0,2,3) or the row kinds below. Negative cash cells keep their status tint. */
.cf-table tbody :where(tr:nth-child(even of :not([hidden]))) > :where(th, td):not(.cf-cash-neg) { background: var(--grey-tint); }

/* Coloured group header rows: tint + stripe, coloured +/− sign. Neutral groups: hairline only. */
.cf-table tbody tr.cf-row--group > :is(th, td):not(.cf-cash-neg) { background: var(--cf-tint, var(--surface)); }
.cf-table tbody tr.cf-row--group:hover > :is(th, td):not(.cf-cash-neg) { background: var(--cf-soft, var(--surface-2)); }
.cf-table tbody tr.cf-row--group > th { box-shadow: inset 4px 0 0 var(--cf-c, var(--border-strong)), inset -1px 0 0 var(--grid); }
.cf-table tbody tr .cf-op { color: var(--cf-text, var(--muted)); }

/* P&L lines (Tržby, Prevádzkové náklady): same stripe without the tint. */
.cf-table tbody tr.cf-row--line > th { box-shadow: inset 4px 0 0 var(--cf-c, transparent), inset -1px 0 0 var(--grid); }

/* Child rows (categories, items): a thin rail in the group colour. */
.cf-table tbody tr[data-cf-parent] > th { box-shadow: inset 4px 0 0 var(--cf-soft, transparent), inset -1px 0 0 var(--grid); }

/* Totals and subtotals: grey band, hairline rail (grey = no colour). */
.cf-table tbody tr.cf-row--total > :is(th, td):not(.cf-cash-neg) { background: var(--grey-soft); }
.cf-table tbody tr.cf-row--total > th { box-shadow: inset 4px 0 0 var(--border-strong), inset -1px 0 0 var(--grid); }
.cf-table tbody tr.cf-row--subtotal > th { box-shadow: inset 4px 0 0 var(--grey-soft), inset -1px 0 0 var(--grid); }

/* Block headings: Farma green, Komunita brown. */
.cf-table tbody tr.cf-row--section[data-cf-key="farmHead"] > th { color: var(--green-text); }
.cf-table tbody tr.cf-row--section[data-cf-key="household"] > th { color: var(--brown-text); }

/* ---------- Plán ---------- */

.pl-m-inc :is(.pl-m-label, .pl-m-value),
.pl-typ-inc :is(.pl-typ-label, .pl-typ-value),
.pl-cal-cols > :nth-child(2) { color: var(--green-text); }
.pl-m-cost :is(.pl-m-label, .pl-m-value),
.pl-typ-cost :is(.pl-typ-label, .pl-typ-value),
.pl-cal-cols > :nth-child(3) { color: var(--brown-text); }
.pl-m-debt :is(.pl-m-label, .pl-m-value),
.pl-typ-debt :is(.pl-typ-label, .pl-typ-value),
.pl-cal-cols > :nth-child(4) { color: var(--grey-text); }

/* Income amounts on chips: farm green, not the "good" status green. */
.pl-chip.is-in .pl-chip-amount { color: var(--green-text); }

.pl-g-budgetrow--income .pl-g-mini { background: var(--green); }
.pl-g-budgetrow--cost .pl-g-mini { background: var(--brown); }
.pl-g-budgetrow--debt .pl-g-mini { background: var(--grey); }
.pl-g-cell.is-negative .pl-g-mini { background: var(--critical); }

.pl-bd-group.pl-bd--in { box-shadow: inset 3px 0 0 var(--green); }
.pl-bd-group.pl-bd--out { box-shadow: inset 3px 0 0 var(--brown); }
.pl-bd-group.pl-bd--sum { box-shadow: inset 3px 0 0 var(--border-strong); background: var(--grey-tint); }
.pl-bd--in > .pl-bd-head { color: var(--green-text); }
.pl-bd--out > .pl-bd-head { color: var(--brown-text); }
/* Splátky úverov: grey like every other "splátky" in the plan. The month breakdown lists farm
   costs, community costs and loan repayments in this order (all .pl-bd--out), so three cost
   groups in a row only exist when the third one is the repayments. (Without Komunita the
   repayments group cannot be told apart from the costs yet: needs a pl-bd--debt hook.) */
.pl-bd-group.pl-bd--out + .pl-bd-group.pl-bd--out + .pl-bd-group.pl-bd--out { box-shadow: inset 3px 0 0 var(--border-strong); }
.pl-bd--out + .pl-bd--out + .pl-bd--out > .pl-bd-head { color: var(--grey-text); }

/* Cash line with separate finances: farm green, community brown. */
.pl-cash-svg:has(.pl-cash-line--comm) .pl-cash-line:not(.pl-cash-line--comm) { stroke: var(--green); }
.pl-cash-svg:has(.pl-cash-line--comm) .pl-cash-area { fill: var(--green); }
.pl-cash-svg .pl-cash-line--comm { stroke: var(--brown); }

/* Lane colours: plan.js laneColor() sets them by meaning (inline --pl-c from charts.js
   themeTokens()): Príjmy green (income), Náklady and Komunita brown (cost / community), Úvery
   grey; Míľniky, Pozemky, Nákup a investície (violet, never green) and Situácie keep categorical
   slots. Validated with the dataviz palette validator in both modes (see plan.js). */

/* Status always wins over the group colour. */
.pl-m-cell.is-negative :is(.pl-m-label, .pl-m-value),
.pl-typ-cell.is-negative .pl-typ-value { color: var(--critical-text); }

/* ---------- Print: stripes and tints off ---------- */

@media print {
  .db-kpi-group .kpi, .db-family .kpi, .ed-strip .ed-kpi { box-shadow: none; }
  .ed-section > .section-header:first-child,
  .ed-section > :first-child > .section-header:first-child { background: none; }
  .cf-table tbody tr > :is(th, td) { background: none; }
}
