/* ==========================================================================
   Regenerácia (views/editor/regen.js, docs/SPEC_REGEN_SIM.md §5) – prefix .rg-
   Phone first: cards stack, wide tables scroll inside .table-wrap, ≥ 16 px inputs and ≥ 40 px tap
   targets on touch. Colours only through tokens; the section belongs to the green „Farma“ group
   (theme.css assigns the group variables by section id – the rule below has a higher specificity
   than theme.css's grey default, so the load order does not matter).
   ========================================================================== */

.ed-nav-link[href$="/inputs/regen"],
.ed-nav-link[data-section="regen"],
.ed-section[data-section="regen"] {
  --grp: var(--green);
  --grp-line: var(--green);
  --grp-text: var(--green-text);
  --grp-soft: var(--green-soft);
  --grp-tint: var(--green-tint);
}

.rg { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.rg > * { min-width: 0; }
.rg-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.rg-body[hidden], .rg-panel[hidden] { display: none; }
.rg-panel { min-width: 0; }
.rg-panel > * { min-width: 0; }
.rg-list { margin: 4px 0 0; padding-left: 20px; display: grid; gap: 4px; }
.rg-intro p { margin: 0; }
.rg-intro .rg-list { margin-bottom: 8px; }
.rg-switch-on[hidden], .rg-intro[hidden] { display: none; }
.rg-fin-line { margin: 0; color: var(--text-2); }
.rg-pad { padding: 8px 12px; margin: 0; }

/* ---- tabs ---- */
.rg-tabs { position: relative; }
.rg-tabs .tab { white-space: nowrap; }
@media (pointer: coarse), (max-width: 720px) {
  .rg-tabs.tabs--pills .tab { height: 40px; padding: 0 14px; }
}

/* ---- toolbars (variant, scope, year) ---- */
.rg-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 16px; min-width: 0; }
.rg-toolbar > .field { margin: 0; min-width: 0; flex: 1 1 220px; max-width: 360px; }
.rg-toolbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.rg-sim-status { color: var(--text-2); }
@media (max-width: 640px) {
  .rg-toolbar > .field { max-width: none; flex-basis: 100%; }
  .rg-toolbar-actions { margin-left: 0; width: 100%; }
  .rg-toolbar-actions .btn { flex: 1 1 auto; }
}

/* ---- tiles ---- */
.rg-tiles { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
.rg-tile .kpi-value { font-size: 20px; }
@media (max-width: 480px) {
  .rg-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rg-tile .kpi-value { font-size: 17px; overflow-wrap: anywhere; }
}

/* ---- chips (plots, herds) ---- */
.rg-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.rg-chip { max-width: 100%; }
.rg-chip > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.rg-chip-check { display: none; }
.rg-chip.is-active .rg-chip-check { display: inline-flex; }
.rg-chips-empty { padding: 6px 0; }
@media (pointer: coarse) {
  .rg-chip { height: 40px; padding-inline: 14px; }
}

/* ---- Prostredie ---- */
.rg-preset-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; }
.rg-preset-row > .field { flex: 1 1 280px; min-width: 0; margin: 0; }
.rg-env-info .field-label { color: var(--text-2); }
.rg-differs .field-label::after { content: " · upravené"; color: var(--text-2); font-weight: 500; }
.rg-pe { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.rg-pe-summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-height: 44px; padding: 8px 12px;
  cursor: pointer; list-style: none;
}
.rg-pe-summary::-webkit-details-marker { display: none; }
.rg-pe-summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2); transform: rotate(-45deg); transition: transform 0.15s; flex: none; }
.rg-pe[open] > .rg-pe-summary::before { transform: rotate(45deg); }
.rg-pe-head { display: flex; flex-direction: column; min-width: 0; flex: 1 1 180px; }
.rg-pe-title { font-weight: 650; overflow-wrap: anywhere; }
.rg-pe-meta { color: var(--text-2); font-size: 12.5px; }
.rg-pe-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.rg-pe-body { padding: 0 12px 12px; }
.rg-pe-body > p { margin: 0; }

/* ---- Plán postupov ---- */
.rg-var-list { min-width: 0; }
.rg-var {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.rg-var.is-editing { border-color: var(--grp, var(--accent)); box-shadow: inset 3px 0 0 var(--grp, var(--accent)); }
.rg-var-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; flex: 1 1 220px; }
.rg-var-name { overflow-wrap: anywhere; }
.rg-var-meta { color: var(--text-2); font-size: 12.5px; }
.rg-var-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.rg-var-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rg-variant-editor .card-body > .form-grid { margin: 0; }
.rg-practice-details p { margin: 0; }
.rg-costs { color: var(--text-2); }
.rg-rot-info p { margin: 0; }

/* ---- Pasenie ---- */
.rg-plan .card-heading { flex: 1 1 auto; min-width: 0; }
.rg-plan-head .field { margin: 0; }
.rg-plan-head .field-label { font-size: 12.5px; color: var(--text-2); }
.rg-plan-head .input { font-weight: 650; }
.rg-add-plan { justify-content: flex-start; }
.rg-warnings:empty { display: none; }

/* ---- charts ---- */
.rg-charts { min-width: 0; }
.rg-charts > * { min-width: 0; }
.rg-charts > [hidden] { display: none; }

/* ---- Simulácia: editable results table ---- */
.rg-simtable-wrap { border: 0; border-radius: 0; }
.rg-simtable { width: max-content; min-width: 100%; }
.rg-simtable th, .rg-simtable td { padding: 4px 6px; vertical-align: middle; }
.rg-simtable thead th { padding: 8px 6px; text-align: center; }
.rg-simtable thead th.rg-th-metric { text-align: left; }
.rg-simtable tbody th { min-width: 150px; max-width: 200px; white-space: normal; text-align: left; font-weight: 550; padding: 6px 10px; }
.rg-m-label { display: block; }
.rg-m-unit { display: block; color: var(--text-2); font-size: 11.5px; font-weight: 400; }
.rg-cell-inner { position: relative; display: flex; align-items: center; }
.rg-cell .input-affix { width: 96px; }
.rg-cell .input { height: 32px; padding: 0 24px 0 6px; font-size: 13px; }
.rg-cell-reset {
  position: absolute; right: 1px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 26px;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--link); cursor: pointer;
}
.rg-cell-reset:hover { background: var(--surface-3); }
.rg-cell-reset[hidden] { display: none; }
.rg-simtable td.rg-cell.is-overridden { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.rg-simtable td.rg-cell.is-overridden .input { border-color: var(--accent); font-weight: 650; }
.rg-simtable .is-year:not(.is-overridden) { background: var(--grp-tint, var(--surface-2)); }
.rg-simtable thead th.is-year { color: var(--grp-text, var(--text)); box-shadow: inset 0 -2px 0 var(--grp, var(--accent)); }
.rg-simtable .is-inactive .input, .rg-simtable td.is-inactive { color: var(--muted); }
.rg-crop-cell, .rg-band-cell { color: var(--text-2); font-size: 12px; white-space: normal; min-width: 96px; max-width: 120px; text-align: center; }
/* .data-table td (nowrap, right) is more specific than the class alone: the crop name must wrap inside its year column */
.rg-simtable td.rg-crop-cell, .rg-simtable td.rg-band-cell { white-space: normal; text-align: center; overflow-wrap: anywhere; }
/* plot costs without catalogue direct costs (the margin is too high) */
.rg-cell-flag {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 18px; height: 18px; margin-left: 4px;
  border-radius: 999px; background: var(--warning-soft); color: var(--warning-text); font-size: 12px; font-weight: 700;
}
.rg-cell-flag[hidden] { display: none; }
.rg-simtable td.rg-cell.is-flagged:not(.is-overridden) .input { border-color: var(--warning); }
/* an override typed for another crop of the plot-year: kept, not used */
.rg-simtable td.rg-cell.is-stale .input { border-color: var(--warning); border-style: dashed; }
.rg-soil-note:empty { display: none; }
.rg-row-band th, .rg-row-crop th { font-weight: 400; color: var(--text-2); }
@media (pointer: coarse) {
  .rg-cell .input-affix { width: 112px; }
  .rg-cell .input { height: 40px; font-size: 16px; padding-right: 42px; }
  /* UI_GUIDE §11: ≥ 40 × 40 px tap target */
  .rg-cell-reset { width: 40px; height: 40px; right: 0; }
}
@media (max-width: 480px) {
  /* phones: a narrow label column, so at least two years fit beside it */
  .rg-simtable tbody th { min-width: 104px; max-width: 124px; font-size: 12.5px; padding: 6px 8px; }
  .rg-simtable thead th.rg-th-metric { font-size: 12px; }
}
.rg-assumptions summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.rg-assumptions p { margin: 8px 0 0; }

/* ---- Pôda ---- */
.rg-soil-table th .rg-m-unit { display: inline; margin-left: 6px; }
.rg-soil-table td { white-space: normal; }
.rg-soil-table tbody th { white-space: normal; min-width: 160px; }
@media (max-width: 480px) {
  /* phones: the sticky indicator column wraps, so the values scroll beside it instead of hiding behind it */
  .rg-soil-table tbody th { min-width: 112px; max-width: 136px; font-size: 12.5px; padding: 6px 8px; }
  .rg-soil-table th .rg-m-unit { display: block; margin-left: 0; font-weight: 400; }
  .rg-soil-table thead th { white-space: normal; vertical-align: bottom; }
  .rg-soil-table td { min-width: 92px; }
}

/* ---- Porovnanie ---- */
.rg-compare-wrap { border: 0; border-radius: 0; }
.rg-compare-table th[data-variant-id] { text-align: right; min-width: 130px; white-space: normal; }
.rg-cmp-name { display: block; color: var(--text); }
.rg-cmp-kind, .rg-cmp-delta { display: block; color: var(--text-2); font-size: 11.5px; font-weight: 400; }
.rg-cmp-delta:empty { display: none; }
.rg-compare-table .is-active { background: var(--grp-tint, var(--surface-2)); }
.rg-compare-table thead th.is-active { box-shadow: inset 0 -2px 0 var(--grp, var(--accent)); }
.rg-compare-table tbody th { white-space: normal; min-width: 170px; }
@media (max-width: 480px) {
  /* phones: a narrower sticky label column, so one and a half variants are visible beside it */
  .rg-compare-table tbody th { min-width: 116px; max-width: 136px; font-size: 12.5px; padding: 6px 8px; }
  .rg-compare-table th[data-variant-id] { min-width: 112px; }
}

/* ---- Knižnica ---- */
.rg-lib-state[hidden], .rg-lib-host[hidden] { display: none; }
/* Know-how · Kalendár · Ako simulátor počíta: one line, a 40 px target on touch (like .kh-tabs). */
.rg-lib-seg { max-width: 100%; }
.rg-lib-seg .segmented-item { white-space: normal; line-height: 1.2; text-align: center; }
@media (pointer: coarse), (max-width: 720px) {
  .rg-lib-seg .segmented-item { height: auto; min-height: 40px; padding: 4px 10px; }
}

/* ---- touch: ≥ 40 px tap targets for the small buttons and the disclosure rows of the section ---- */
@media (pointer: coarse) {
  .rg .btn-sm { height: 40px; }
  .rg .btn-icon.btn-sm { width: 40px; }
  .rg-assumptions summary { display: flex; align-items: center; min-height: 40px; }
}

@media print {
  .rg-cell-reset, .rg-toolbar-actions { display: none; }
}

/* ==========================================================================
   v5 R23 (docs/SPEC_V5.md §3 R23) in Príjmy / Náklady (views/editor/flows.js): the chip under a row's name is a button that opens
   the sheet „Odkiaľ je toto číslo“ (.rs- styles in cashflow.css); the card „Zo simulácie regenerácie“ lists the items with their
   source chips. Tokens only, ≥ 44 px targets on touch, nothing wider than the phone.
   ========================================================================== */
button.ed2-regen-src {
  display: inline-flex; align-items: center; max-width: 100%; min-width: 0; margin: 0; padding: 0; border: 0; background: none;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
button.ed2-regen-src:focus-visible { outline: none; }
button.ed2-regen-src:focus-visible > .ed2-regen-pill { box-shadow: 0 0 0 3px var(--focus-ring); }
.ed2-regen-pill > .icon { flex: none; color: var(--green-text); }
.ed2-regen-src[data-regen-src="full"] > .ed2-regen-pill, .ed2-regen-src[data-regen-src="part"] > .ed2-regen-pill { background: var(--grey-soft); color: var(--grey-text); }
.ed2-regen-src[data-regen-src="suspect"] > .ed2-regen-pill { background: var(--warning-soft); color: var(--warning-text); }
.ed2-regen-src[data-regen-src="suspect"] > .ed2-regen-pill > .icon { color: var(--warning-text); }
.ed2-src-item, .ed2-src-chip-btn {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; max-width: 100%; min-width: 0;
  margin: 0; padding: 2px 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.ed2-src-chip-btn { margin-left: 6px; vertical-align: middle; }
.ed2-src-item-label { min-width: 0; overflow-wrap: anywhere; }
.ed2-src-item:hover .ed2-src-item-label { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--border-strong); }
.ed2-src-item:focus-visible, .ed2-src-chip-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ed2-regen-card--items td:first-child { white-space: normal; overflow-wrap: anywhere; min-width: 0; }
/* round-14 fix P15: on a phone the headers wrap and the cells come closer, so „Spolu za horizont“ fits at 320 px */
@media (max-width: 420px) {
  .ed2-regen-card--items th { white-space: normal; }
  .ed2-regen-card--items th, .ed2-regen-card--items td { padding-left: 6px; padding-right: 6px; }
  .ed2-regen-card--items .ed2-src-own { white-space: normal; }
}
@media (pointer: coarse), (max-width: 720px) {
  .ed2-src-item, .ed2-src-chip-btn { min-height: 44px; }
  button.ed2-regen-src { min-height: 44px; }
}
/* Regenerácia → „Variant vo financiách“: what counts from the simulation and what stays the farm's own (→ Cashflow) */
.rg-fin-sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-width: 0; }
.rg-fin-sources-text { margin: 0; flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.rg-fin-details { flex: none; display: inline-flex; align-items: center; gap: 2px; }
@media (pointer: coarse), (max-width: 720px) {
  .rg-fin-details { min-height: 44px; }
}
/* Prehľad tile „Simulátor vo financiách“: „N položiek zo simulácie, M vašich“ (views/regen-tips.js) */
.kh-db-tile-note { font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }
.kh-db-tile-note[hidden] { display: none; }
