/* ==========================================================================
   Regenerácia – know-how library, tips everywhere and cross-view hooks – prefix .kh-
   (views/editor/regen-library.js, views/regen-tips.js; docs/SPEC_REGEN_KNOWHOW.md §2, docs/SPEC_REGEN.md §3)
   Phone first: one column, chip rows scroll sideways inside their own box (never the page), ≥ 16 px inputs and
   ≥ 40 px tap targets on touch. Colours only through tokens: green = farm / regeneration (theme.css colour
   system), status colours only for warnings.
   ========================================================================== */

/* The library root is scrolled to on a deep link (?guide= / ?practice=) and on opening a page: stop below the header. */
.kh-lib { scroll-margin-top: calc(var(--header-h) + 112px); } /* like the editor's fields (editor.css) */
@media (max-width: 899px) { .kh-lib { scroll-margin-top: calc(var(--header-h) + 12px); } }

/* ---- tip bar (every section) ---- */
.kh-tips { display: grid; gap: 8px; min-width: 0; }
.kh-tips[hidden] { display: none; }
.kh-tip {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: start;
  padding: 10px 12px; border: 1px solid var(--border); border-left: 3px solid var(--green);
  border-radius: var(--radius); background: var(--green-tint); min-width: 0;
}
.kh-tip--warning { border-left-color: var(--warning); }
.kh-tip-icon { color: var(--green-text); display: inline-flex; padding-top: 2px; }
.kh-tip-body { min-width: 0; }
.kh-tip-flag { display: block; font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--warning-text); margin-bottom: 2px; }
.kh-tip-flag[hidden] { display: none; }
.kh-tip-text { margin: 0; font-size: 14px; line-height: 1.45; color: var(--text); overflow-wrap: anywhere; }
.kh-tip-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.kh-tip-more { padding-left: 0; color: var(--green-text); }
.kh-tip-more[hidden], .kh-tip-close[hidden] { display: none; }

/* ---- chips, search ---- */
.kh-tabs.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
.kh-tabs .segmented-item { white-space: normal; line-height: 1.2; min-height: 40px; padding: 4px 8px; text-align: center; justify-content: center; }
.kh-chiprow.kh-months { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); overflow: visible; }
.kh-months .kh-chip { justify-content: center; padding-left: 4px; padding-right: 4px; min-width: 0; }
@media (min-width: 900px) { .kh-chiprow.kh-months { grid-template-columns: repeat(12, minmax(0, 1fr)); } }
.kh-chiprow { display: flex; flex-wrap: nowrap; gap: 6px; overflow-x: auto; min-width: 0; padding-bottom: 4px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.kh-chip { flex: 0 0 auto; white-space: nowrap; }
.kh-chip--farm { border-color: var(--green); font-weight: 600; }
.kh-chip-count { font-variant-numeric: tabular-nums; }
@media (min-width: 900px) {
  .kh-filter-group .kh-chiprow, .kh-quick, .kh-areas { flex-wrap: wrap; overflow-x: visible; }
}
.kh-searchrow { position: relative; min-width: 0; }
.kh-searchrow .kh-search { width: 100%; padding-left: 36px; }
.kh-search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.kh-filters { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.kh-filters-summary { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; cursor: pointer; font-weight: 600; list-style: none; }
.kh-filters-summary::-webkit-details-marker { display: none; }
.kh-filter-count:not(:empty) { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--green-soft); color: var(--green-text); font-size: 12px; text-align: center; }
.kh-filter-groups { display: grid; gap: 10px; padding: 4px 12px 12px; min-width: 0; }
.kh-filter-group { display: grid; gap: 4px; min-width: 0; }
.kh-filter-label { font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.kh-result-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.kh-result-line, .kh-coef-head { margin: 0; color: var(--text-2); font-size: 13.5px; }
.kh-honesty, .kh-disclaimer { margin: 0; }

/* ---- result cards ---- */
.kh-results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); min-width: 0; }
.kh-card { display: flex; align-items: stretch; min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.kh-card:hover { border-color: var(--border-strong); }
.kh-card-main {
  flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding: 12px; text-align: left;
  background: none; border: 0; color: inherit; font: inherit; cursor: pointer; border-radius: var(--radius);
}
.kh-card-main:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.kh-card-topic { color: var(--green-text); font-weight: 600; }
.kh-card-title { font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.kh-summary-more > summary { cursor: pointer; color: var(--link); font-weight: 600; font-size: 14px; min-height: 40px; display: flex; align-items: center; }
.kh-summary-more[open] > summary { margin-bottom: 4px; }
.kh-card-summary { color: var(--text-2); font-size: 13.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.kh-card-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 2px; }
.kh-card-fav { align-self: flex-start; margin: 6px 6px 0 0; font-size: 18px; line-height: 1; color: var(--muted); }
.kh-card-fav.is-active, .kh-fav.is-active { color: var(--green-text); }
.kh-card-fav[hidden], .kh-fav[hidden] { display: none; }
.kh-nohits[hidden], .kh-more[hidden], .kh-reset[hidden] { display: none; }
.kh-sub { margin: 8px 0 0; font-size: 15px; }

/* ---- guide / practice page ---- */
.kh-page { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.kh-page > * { min-width: 0; }
.kh-back { align-self: flex-start; }
.kh-page-head { display: grid; gap: 6px; }
.kh-page-topic { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--green-text); }
.kh-page-title { margin: 0; font-size: 20px; line-height: 1.3; overflow-wrap: anywhere; }
.kh-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.kh-summary { margin: 0; font-size: 15px; line-height: 1.5; }
.kh-meta { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0; font-size: 14px; }
.kh-meta dt { color: var(--text-2); }
.kh-meta dd { margin: 0; overflow-wrap: anywhere; }
.kh-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.kh-actions[hidden], .kh-actions .btn[hidden] { display: none; }
.kh-fav-star { font-size: 16px; line-height: 1; }
.kh-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0; padding: 8px 12px; border-radius: var(--radius); background: var(--green-tint); color: var(--text); font-size: 14px; }
.kh-status[hidden] { display: none; }
.kh-status > .icon { color: var(--green-text); }
.kh-status-link { color: var(--link); font-weight: 600; }
.kh-block { border-top: 1px solid var(--border); padding-top: 12px; display: grid; gap: 8px; min-width: 0; }
.kh-block-title { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 15px; }
.kh-block-title > .icon { color: var(--green-text); flex: 0 0 auto; }
.kh-list { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.kh-steps { margin: 0; padding-left: 22px; display: grid; gap: 12px; }
.kh-step-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.kh-step-title { font-weight: 600; }
.kh-step-text { margin: 4px 0 0; line-height: 1.5; color: var(--text); }
.kh-mats, .kh-nums { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.kh-mat, .kh-num { display: grid; gap: 2px; padding: 8px 12px; border-top: 1px solid var(--border); min-width: 0; }
.kh-mat:first-child, .kh-num:first-child { border-top: 0; }
.kh-mat-head, .kh-num-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; }
.kh-mat-name, .kh-num-label { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.kh-mat-price, .kh-num-value { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text); }
.kh-num-value { white-space: normal; text-align: right; overflow-wrap: anywhere; }
.kh-mat-qty { color: var(--text-2); }
.kh-mat-note { display: block; margin-top: 2px; overflow-wrap: anywhere; }
.kh-mat-total { display: flex; justify-content: space-between; gap: 12px; margin: 4px 0 0; padding: 0 12px; }
.kh-num-src { overflow-wrap: anywhere; }
.kh-ratios { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.kh-ratios dt { font-weight: 600; }
.kh-ratios dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .kh-ratios { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kh-ratios dd { margin-bottom: 8px; }
}
.kh-legal, .kh-corrections, .kh-sources { margin: 0; padding-left: 18px; display: grid; gap: 10px; }
.kh-legal p, .kh-correction p { margin: 0; }
.kh-correction { padding-left: 4px; }
.kh-claim { color: var(--text-2); }
.kh-claim-label, .kh-fix-label { font-weight: 600; }
.kh-fix { margin-top: 4px !important; }
.kh-srcs, .kh-src, .kh-sources { overflow-wrap: anywhere; }
.kh-conf { display: block; }
.kh-related { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.kh-related-label { font-size: 13px; color: var(--text-2); margin-right: 2px; }
.kh-link-chip { text-decoration: none; white-space: normal; height: auto; min-height: 32px; text-align: left; max-width: 100%; }
.kh-warnings .kh-list { margin-top: 2px; }

/* ---- own notes ---- */
.kh-notes { display: grid; gap: 10px; min-width: 0; }
.kh-notes-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.kh-notes-empty[hidden], .kh-note-form[hidden], .kh-note-del[hidden] { display: none; }
.kh-note { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.kh-note-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.kh-note-guide { font-weight: 600; overflow-wrap: anywhere; }
.kh-note-text { width: 100%; }
.kh-note-actions { display: flex; justify-content: flex-end; }
.kh-note-form { display: grid; gap: 8px; }

/* ---- principles ---- */
.kh-principles { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.kh-principle { display: grid; gap: 6px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.kh-principle-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.kh-principle-name { font-weight: 600; }
.kh-principle-short { margin: 0; color: var(--text-2); font-size: 13.5px; }
.kh-pscore { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; color: var(--text-2); }
.kh-pscore.is-high { color: var(--green-text); }
.kh-pscore.is-low { color: var(--warning-text); }
.kh-why summary { cursor: pointer; color: var(--link); font-size: 13.5px; min-height: 32px; display: flex; align-items: center; }
.kh-why p { margin: 4px 0; font-size: 13.5px; }

/* ---- seasonal calendar (Knižnica → Kalendár, Plán → Úlohy) ---- */
.kh-season { display: grid; gap: 10px; min-width: 0; }
.kh-season[hidden] { display: none; }
.kh-season--card { padding: 16px; }
.kh-season-card-title { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 16px; }
.kh-season-card-title > .icon { color: var(--green-text); }
.kh-season-sub { margin: 0; }
.kh-season-tools { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; min-width: 0; }
.kh-season-tools .kh-areas { flex: 1 1 260px; }
.kh-season-yearwrap { display: grid; gap: 2px; }
.kh-season-year { min-width: 110px; }
.kh-season-all[hidden], .kh-season-addall[hidden], .kh-season-empty[hidden], .kh-season-grazing[hidden] { display: none; }
.kh-season-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.kh-season-title { margin: 0; font-size: 15px; }
.kh-season-status { margin: 0; color: var(--green-text); }
.kh-season-status[hidden] { display: none; }
.kh-season-grazing { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.kh-season-graze { display: flex; gap: 6px; align-items: flex-start; color: var(--text-2); font-size: 13.5px; }
.kh-season-graze > .icon { color: var(--green-text); flex: 0 0 auto; margin-top: 2px; }
.kh-season-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.kh-season-item { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.kh-season-text { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }
.kh-season-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.kh-season-meta { font-size: 12.5px; color: var(--text-2); margin-right: auto; }
.kh-season-how { font-size: 13.5px; color: var(--link); }
.kh-season-done { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--green-text); }
.kh-season-done[hidden], .kh-season-add[hidden] { display: none; }
.pl-m-regen > .icon { color: var(--green-text); }

/* ---- Prehľad card ---- */
.kh-db-host[hidden] { display: none; }
.kh-db .card-heading { min-width: 0; }
.kh-db-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 10px; }
.kh-db-tile { display: grid; gap: 2px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2); min-width: 0; }
.kh-db-tile[data-key="score"] { box-shadow: inset 3px 0 0 var(--green); }
.kh-db-tile[data-key="finance"] { box-shadow: inset 3px 0 0 var(--grey); }
.kh-db-tile-label { font-size: 12.5px; color: var(--text-2); }
.kh-db-tile-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kh-db-tile.is-negative .kh-db-tile-value { color: var(--critical-text); }
.kh-db-tile-sub { font-size: 12.5px; color: var(--text-2); }
.kh-db-sub { margin: 4px 0 0; font-size: 14px; }
.kh-db-gaplist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.kh-db-gap { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 10px; align-items: start; }
.kh-db-gap-score { min-width: 52px; box-sizing: border-box; height: 32px; padding: 0 8px; border-radius: 999px; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; background: var(--green-soft); color: var(--green-text); font-weight: 600; font-variant-numeric: tabular-nums; }
.kh-db-gap-body { display: grid; gap: 2px; min-width: 0; }
.kh-db-gap-name { font-weight: 600; }
.kh-db-gap-text { font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.kh-db-how { white-space: nowrap; color: var(--link); font-weight: 600; font-size: 13.5px; display: inline-flex; align-items: center; min-height: 32px; }
@media (max-width: 480px) {
  .kh-db-gap { grid-template-columns: 56px minmax(0, 1fr); }
  .kh-db-how { grid-column: 2; }
  .kh-db .card-header { flex-wrap: wrap; }
}

/* ---- Ako simulátor počíta ---- */
.kh-formulas { min-width: 0; }
.kh-formula { padding: 0; min-width: 0; }
.kh-formula-summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; padding: 8px 16px; cursor: pointer; font-weight: 600; }
.kh-formula-title { min-width: 0; overflow-wrap: anywhere; }
.kh-formula-count { font-weight: 400; white-space: nowrap; }
.kh-formula-text { margin: 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); font-family: var(--font-mono); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.kh-coefs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.kh-coef { display: grid; gap: 4px; padding: 0 0 10px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.kh-coef.is-overridden { padding-left: 10px; box-shadow: inset 3px 0 0 var(--green); }
.kh-coef-label { font-weight: 500; overflow-wrap: anywhere; }
.kh-coef-value { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.kh-coef-value .input-affix, .kh-coef-input { max-width: 200px; }
.kh-coef-fixed { font-variant-numeric: tabular-nums; }
.kh-coef-reset[hidden] { display: none; }
.kh-coef-meta { overflow-wrap: anywhere; }
.kh-coef-note { margin: 0; }
.kh-coef-hint:empty { display: none; }
.kh-coef-hint.text-warning { color: var(--warning-text); }
.kh-coef-search[hidden] { display: none; }

/* ---- dialogs ---- */
.kh-modal-body { min-width: 0; }
.kh-preview { margin: 0; padding-left: 20px; display: grid; gap: 6px; max-height: 50vh; overflow-y: auto; }
.kh-preview li { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; font-size: 13.5px; }
.kh-preview-date { font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.kh-cost-picks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.kh-cost-total { margin: 0; font-weight: 600; }
@media (max-width: 640px) {
  .kh-sheet.modal { width: 100%; max-height: 92vh; }
}

/* ---- touch: ≥ 16 px inputs, ≥ 40 px tap targets ---- */
@media (pointer: coarse) {
  .kh-chip { height: 40px; }
  .kh-tip-close, .kh-card-fav, .kh-note-del, .kh-coef-reset { min-width: 40px; min-height: 40px; }
  .kh-tip-more, .kh-actions .btn, .kh-status .btn, .kh-season .btn, .kh-db-open, .kh-back, .kh-more, .kh-reset { min-height: 40px; }
  .kh-db-how, .kh-season-how, .kh-status-link, .kh-link-chip, .kh-why summary, .kh-note-guide { min-height: 40px; display: inline-flex; align-items: center; }
  .kh-lib .input, .kh-season .input, .kh-formulas .input, .kh-modal .input, .kh-sheet .input { font-size: 16px; }
  /* „Pridať úlohy do Plánu“ (Prepojené úlohy): the year, „Zrušiť“, „Pridať n úloh“ and ✕ are phone targets ≥ 44 px */
  .kh-modal .modal-footer .btn, .kh-modal .input, .kh-modal .select { min-height: 44px; }
  .kh-modal .modal-close { min-width: 44px; min-height: 44px; }
}
