/* Folds – ui.js collapsible(), card({ fold }) and foldBar() (docs/SPEC_V4.md §3 R10, docs/UI_GUIDE.md „Zbaliť a rozbaliť“).
   Prefix .fold-; the fold's root gets .fold (+ .is-folded while folded), its header [data-fold-head].
   Phone rules: the chevron button and the bar buttons are ≥ 44 px, the whole header row toggles (≥ 48 px built),
   nothing has a fixed width, long titles and summaries wrap. */

.fold { min-width: 0; }

/* the safety net: a child the view shows again while folded stays hidden (collapsible() also sets `hidden`) */
.fold.is-folded > :not([data-fold-head]):not([data-fold-keep]):not(summary) { display: none !important; }

[data-fold-head] { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* the chevron button: 44 × 44 px target, pulled into the header's padding so the title does not move far */
.fold-toggle {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin: -10px 0 -10px -12px; padding: 0;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text-2); cursor: pointer;
}
.fold-toggle:hover { background: var(--surface-3); color: var(--text); }
.fold-toggle:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.fold-chevron { transition: transform 0.15s ease-out; }
.fold-toggle[aria-expanded="false"] .fold-chevron { transform: rotate(-90deg); }
@media (prefers-reduced-motion: reduce) { .fold-chevron { transition: none; } }

/* a bare heading used as the header: the button sits inline before the text */
:is(h1, h2, h3, h4, h5, h6)[data-fold-head] > .fold-toggle { vertical-align: middle; margin: -12px 0 -12px -12px; }

/* the one-line summary, shown only while folded */
.fold-summary {
  display: block; margin: 2px 0 0; min-width: 0;
  font-size: 13px; font-weight: 400; line-height: 1.4; color: var(--text-2);
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}

/* ---- built: collapsible({ … }) ---- */
.fold-head { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 4px 6px; min-height: 48px; padding: 12px 0 4px; }
.fold-head > .fold-toggle { margin-top: -10px; }
.fold-heading { flex: 1 1 min(200px, calc(100% - 44px)); min-width: 0; }
.fold-title { display: flex; align-items: center; gap: 6px; margin: 0; min-height: 24px; font-size: 15px; font-weight: 650; overflow-wrap: anywhere; }
.fold-title-icon { flex: none; color: var(--accent); }
.fold-subtitle { margin: 2px 0 0; font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.fold-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.fold-body { min-width: 0; padding: 4px 0 8px; }
.fold.is-folded > .fold-head { padding-bottom: 8px; }

/* ---- in place on a card() / .section-header ---- */
/* the chevron and the title stay on one line on a 320 px phone (the actions may wrap under them) */
.card-header[data-fold-head], .section-header[data-fold-head] { align-items: flex-start; column-gap: 6px; }
.card-header[data-fold-head] > .card-heading { flex: 1 1 min(220px, calc(100% - 44px)); }
.section-header[data-fold-head] > .section-heading { flex: 1 1 min(320px, calc(100% - 44px)); }
.card-header[data-fold-head] > .fold-toggle { margin-top: -11px; }
.card.fold.is-folded > .card-header { padding-bottom: 16px; }
.section-header[data-fold-head] > .fold-toggle { align-self: flex-start; margin-top: -8px; }

/* ---- <details> through collapsible(details) ---- */
.fold--details > summary .fold-summary { flex-basis: 100%; }

/* ---- „Zbaliť všetko · Rozbaliť všetko“ ---- */
.fold-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 2px 4px; min-width: 0; }
.fold-bar-btn { max-width: 100%; white-space: normal; height: auto; min-height: 32px; }
.fold-bar-sep { color: var(--muted); }

@media (max-width: 640px) {
  .card.fold.is-folded > .card-header { padding-bottom: 14px; }
}
@media (pointer: coarse), (max-width: 720px) {
  /* stronger than a screen's own .btn-sm rule (Cashflow: .view-cashflow .btn-sm 40 px – R10-cashflow-40px) */
  .fold-bar-btn, .fold-bar > .fold-bar-btn.btn-sm { min-height: 44px; }
}
