/* ==========================================================================
   Cashflow view (views/cashflow.js) — every class is prefixed .cf-
   Uses only app.css tokens; tables build on .table-wrap / .data-table.
   ========================================================================== */

.cf-root { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.cf-root > .cf-header { margin-bottom: 0; }
.cf-body, .cf-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------- Summary tiles + own-funds quick edit ---------- */
.cf-kpis { align-items: stretch; }
.cf-kpi-input .kpi-label-text { cursor: pointer; }
.cf-kpi-input .input-affix { max-width: 240px; }
.cf-kpi-input .input { font-size: 16px; font-weight: 650; }
.cf-alert-slot:empty { display: none; }
@media (max-width: 480px) {
  .cf-kpi-input { grid-column: 1 / -1; }
}

/* ---------- Toolbar ---------- */
.cf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.cf-toolbar-group { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.cf-toolbar-group[hidden] { display: none; }
.cf-toolbar-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.cf-toolbar-note { font-size: 12.5px; color: var(--text-2); max-width: 300px; line-height: 1.35; }
.cf-toolbar-note[hidden] { display: none; }
.cf-toolbar-spacer { flex: 1 1 auto; }
.cf-year .input { width: auto; min-width: 132px; height: 32px; }
.cf-items .toggle { align-items: center; font-size: 13.5px; font-weight: 550; }

@media (max-width: 640px) {
  .cf-toolbar { padding: 10px 12px; gap: 10px 14px; }
  .cf-toolbar-spacer { display: none; }
  .cf-toolbar-note { max-width: none; flex-basis: 100%; }
  .cf-year .input { height: 40px; }
}

/* ---------- Charts ---------- */
.cf-charts { min-width: 0; }

/* ---------- Tables ---------- */
.cf-card { min-width: 0; }
.cf-card > .card-body { min-width: 0; }
.cf-table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cf-card .cf-table-wrap { max-height: min(74vh, 780px); overflow: auto; }

.cf-table { width: max-content; min-width: 100%; }
.cf-table th, .cf-table td { padding: 7px 12px; }
.cf-table thead th { vertical-align: bottom; line-height: 1.25; }
.cf-table thead th.cf-col-label { text-align: left; }
.cf-th-sub { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }

/* Row headers (first column): sticky via .data-table, allow wrapping of long names */
.cf-table tbody th {
  font-weight: 400;
  color: var(--text);
  white-space: normal;
  min-width: 220px;
  max-width: 320px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.cf-table tbody tr:hover th { background: var(--surface-2); }

/* Spolu column */
.cf-table th.cf-col-total, .cf-table td.cf-col-total { border-left: 1px solid var(--border-strong); font-weight: 600; }
.cf-table thead th.cf-col-total { color: var(--text); }

/* Operator glyph (+ / − / =) and chevron spacer so labels line up */
.cf-op {
  display: inline-block;
  width: 12px;
  margin-right: 6px;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  vertical-align: baseline;
}
.cf-chev-space { display: inline-block; width: 20px; }

/* Group expander (label is the button) */
.cf-expander {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 0 2px 0 0;
  margin: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-align: left;
  cursor: pointer;
}
.cf-expander:hover span { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--border-strong); }
.cf-expander:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cf-chevron { flex: none; color: var(--muted); transition: transform 0.15s ease; }
.cf-expander[aria-expanded="true"] .cf-chevron { transform: rotate(90deg); }

/* Row kinds — scoped under .cf-table so they beat `.data-table th:first-child` (0,2,1) and
   `.cf-table tbody th` (0,1,2); sticky first cells get the same background as their row. */
.cf-table .cf-row--group > th, .cf-table .cf-row--group > td { font-weight: 650; }
.cf-table .cf-level-1 > th { padding-left: 60px; }
.cf-table .cf-level-2 > th { padding-left: 76px; }
.cf-table .cf-row--cat > th, .cf-table .cf-row--cat > td { color: var(--text-2); }
.cf-table .cf-row--item > th, .cf-table .cf-row--item > td { font-size: 12.5px; color: var(--text-2); }
.cf-table .cf-row--subtotal > th, .cf-table .cf-row--subtotal > td {
  font-weight: 650;
  border-top: 1px solid var(--border-strong);
}
.cf-table .cf-row--total > th, .cf-table .cf-row--total > td {
  font-weight: 700;
  background: var(--surface-2);
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
}
.cf-table .cf-row--cash > th, .cf-table .cf-row--cash > td { font-weight: 700; }
.cf-table .cf-row--muted > th, .cf-table .cf-row--muted > td { color: var(--text-2); font-size: 12.5px; }
.cf-table .cf-row--break > th, .cf-table .cf-row--break > td { border-top: 1px solid var(--border-strong); }
.cf-table .cf-row--break > th, .cf-table .cf-row--break > td,
.cf-table .cf-row--subtotal > th, .cf-table .cf-row--subtotal > td,
.cf-table .cf-row--total > th, .cf-table .cf-row--total > td { padding-top: 9px; }

/* Negative numbers keep the shared .is-negative colour; rows that dim text must not win over it */
.cf-table td.is-negative { color: var(--critical-text); }

/* Negative cash: tinted cell + icon (colour is never the only signal — the minus sign stays) */
.cf-table td.cf-cash-neg { background: var(--critical-soft); }
.cf-table tbody tr:hover td.cf-cash-neg { background: var(--critical-soft); }
.cf-cash-icon { display: inline-block; margin-right: 4px; vertical-align: -2px; color: var(--critical); }

/* DSCR status */
.cf-table td.cf-dscr-bad { color: var(--critical-text); font-weight: 600; }
.cf-table td.cf-dscr-warn { color: var(--warning-text); font-weight: 600; }

/* ---------- Explanations ---------- */
.cf-card > .card-footer { padding-top: 10px; padding-bottom: 12px; }
.cf-help > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  list-style: none;
  border-radius: 4px;
}
.cf-help > summary::-webkit-details-marker { display: none; }
.cf-help > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.15s ease;
}
.cf-help[open] > summary::after { transform: rotate(225deg) translate(-2px, -2px); }
.cf-help > summary:hover { color: var(--text); }
.cf-help > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cf-help-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 12px 28px;
  margin: 12px 0 2px;
}
.cf-help-item { min-width: 0; }
.cf-help-list dt { font-size: 13px; font-weight: 650; color: var(--text); }
.cf-help-list dd { margin: 2px 0 0; font-size: 13px; line-height: 1.5; color: var(--text-2); }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .cf-root, .cf-body, .cf-main { gap: 16px; }
  .cf-table th, .cf-table td { padding: 6px 10px; }
  .cf-table tbody th { min-width: 150px; max-width: 46vw; }
  .cf-table .cf-level-1 > th { padding-left: 54px; }
  .cf-table .cf-level-2 > th { padding-left: 68px; }
  .cf-card .cf-table-wrap { max-height: 70vh; }
}

@media (prefers-reduced-motion: reduce) {
  .cf-chevron, .cf-help > summary::after { transition: none; }
}

@media print {
  .cf-toolbar, .cf-alert-slot .alert-actions { display: none; }
  .cf-card .cf-table-wrap { max-height: none; overflow: visible; }
  .cf-help-list { display: block; }
}
