/* Editor section "Reprodukcia" – reprodukčný plánovač (views/editor/herds.js, docs/SPEC_HERD.md §3).
   Prefix .hd-. Phone first: everything fits 360 px without horizontal page scroll, inputs ≥ 16 px and
   tap targets ≥ 40 px on touch. Colours only through app.css tokens. */

.hd-root { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.hd-root > .section-header { margin-bottom: 0; }
.hd-head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hd-link { color: var(--link); }
.hd-pad { margin: 0; padding: 12px 14px; }

/* ---- overview (≥ 2 herds) and animals from Nákup -------------------------------------- */
.hd-overview { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.hd-overview[hidden] { display: none; }
.hd-overview-title, .hd-from-title { margin: 0; font-size: 15px; font-weight: 650; }
.hd-from-items {
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
  padding: 14px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface);
}
.hd-from-items[hidden] { display: none; }
.hd-from-text { margin: 0; font-size: 13.5px; color: var(--text-2); line-height: 1.5; }
.hd-from-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.hd-from-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; min-width: 0;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.hd-from-row:first-child { border-top: 0; }
.hd-from-name { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.hd-from-meta { color: var(--text-2); font-size: 13px; }
/* R6 pasture flag of a bought group (zima.js setAnimalItemPasture) and the winter fold beside the parameter folds (R20) */
.hd-from-row .hd-from-pasture { min-height: 44px; align-items: center; }
.hd-body > .hd-winter { margin-top: -6px; }

/* ---- herd cards ------------------------------------------------------------------------- */
.hd-list { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.hd-list:empty { display: none; }
.hd-herd { container: hdherd / inline-size; scroll-margin-top: calc(var(--header-h) + 12px); }
.hd-herd.is-off { border-style: dashed; }
/* Phones: below the sticky year bar (editor2.css .ys-bar, 52 px) when a herd card or its results are revealed. */
@media (max-width: 899px) {
  .ed-section:has(.hd-year:not([hidden])) :is(.hd-herd, .hd-results) { scroll-margin-top: calc(var(--header-h) + 64px); }
}
.hd-herd.is-off .hd-results { opacity: 0.75; }
.hd-herd.hd-flash { box-shadow: 0 0 0 3px var(--focus-ring), var(--shadow-sm); transition: box-shadow 0.3s; }

.hd-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; background: var(--surface-2);
}
.hd-heading { display: flex; align-items: flex-start; gap: 12px; min-width: 0; flex: 1 1 240px; }
.hd-icon {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px;
  border-radius: var(--radius); background: var(--brand-soft); color: var(--brand-strong);
}
.hd-titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.hd-title { margin: 0; font-size: 16px; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.hd-badge-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.hd-badges { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.hd-source { margin: 0; font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.hd-source[hidden] { display: none; }
.hd-actions { display: flex; align-items: center; gap: 6px; }
.hd-actions .toggle { margin-right: 6px; font-size: 13.5px; }

.hd-body { display: flex; flex-direction: column; gap: 16px; padding: 16px 20px 20px; min-width: 0; }

/* ---- result (always on top) ----------------------------------------------------------- */
.hd-results { display: flex; flex-direction: column; gap: 10px; min-width: 0; scroll-margin-top: calc(var(--header-h) + 12px); }
.hd-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@container hdherd (min-width: 600px) { .hd-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@container hdherd (min-width: 1150px) { .hd-tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.hd-overview .hd-tiles { grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.hd-tiles .kpi { box-shadow: none; background: var(--surface-2); }
.hd-tiles .kpi-value { font-size: 19px; font-variant-numeric: tabular-nums; }
.hd-tiles .kpi-sub { font-variant-numeric: tabular-nums; }
.hd-tile--slaughter, .hd-tile--growth { background: var(--accent-soft) !important; }
.hd-steady-note { margin: 0; font-size: 12.5px; color: var(--text-2); line-height: 1.45; }
.hd-steady-note:empty { display: none; }
.hd-booked, .hd-takeover {
  display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 10px 12px;
  border-radius: var(--radius); font-size: 13.5px; line-height: 1.5; overflow-wrap: anywhere;
}
.hd-booked { background: var(--good-soft); color: var(--text); }
.hd-booked.is-off { background: var(--surface-2); color: var(--text-2); }
.hd-booked > .icon, .hd-takeover > .icon { flex: none; margin-top: 3px; }
.hd-booked > .icon { color: var(--good-text); }
.hd-booked.is-off > .icon { color: var(--text-2); }
.hd-booked strong { font-weight: 650; font-variant-numeric: tabular-nums; }
.hd-takeover { background: var(--surface-2); color: var(--text-2); }
.hd-takeover[hidden] { display: none; }
.hd-alerts { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.hd-alerts:empty { display: none; }

/* ---- collapsible sub-cards ------------------------------------------------------------- */
.hd-forms { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.hd-fold { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.hd-fold[open] { border-color: var(--border-strong); }
.hd-fold-sum {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-height: 44px; padding: 10px 40px 10px 14px;
  position: relative; list-style: none; cursor: pointer; border-radius: var(--radius);
}
.hd-fold-sum::-webkit-details-marker { display: none; }
.hd-fold-sum::after {
  content: ""; position: absolute; top: 50%; right: 16px; width: 8px; height: 8px;
  border-right: 1.8px solid var(--text-2); border-bottom: 1.8px solid var(--text-2);
  transform: translateY(-70%) rotate(45deg); transition: transform 0.15s;
}
.hd-fold[open] > .hd-fold-sum::after { transform: translateY(-20%) rotate(-135deg); }
.hd-fold-sum:hover { background: var(--surface-3); }
.hd-fold-sum:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hd-fold-title { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; font-size: 14.5px; }
.hd-fold-title > .icon { color: var(--accent); }
.hd-fold-meta { min-width: 0; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hd-fold-body { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 4px 14px 14px; }

.hd-form {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  gap: 12px 16px; align-items: start; min-width: 0;
}
.hd-form > * { min-width: 0; }
.hd-span-2, .hd-sub, .hd-calc { grid-column: 1 / -1; }
.hd-sub {
  margin: 6px 0 -4px; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: none;
}
.hd-form > .hd-sub:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.hd-calc {
  margin: 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2);
  font-size: 13px; color: var(--text); line-height: 1.45; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.hd-calc[hidden] { display: none; }
.hd-field[hidden] { display: none; }
.hd-field .toggle { align-items: flex-start; }
.hd-field .months-picker { margin-top: 8px; }
.hd-field .months-picker[hidden] { display: none; }
.hd-field--flag .input, .hd-field--flag .months-picker { box-shadow: 0 0 0 2px var(--warning); border-radius: var(--radius-sm); }
.hd-hint { display: inline; }
.hd-range { color: var(--text-2); }
.hd-warn { color: var(--warning-text); font-weight: 600; }
.hd-est { color: var(--warning-text); }
.hd-fix-wrap { display: inline-flex; margin-left: 6px; vertical-align: middle; }

/* ---- per year --------------------------------------------------------------------------- */
.hd-years > .hd-fold-body { gap: 16px; }
.hd-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 14px; min-width: 0; }
.hd-table-wrap { max-width: 100%; }
.hd-table th, .hd-table td { white-space: nowrap; }

/* ---- live read-out while editing a long form ---------------------------------------------- */
.hd-live {
  position: sticky; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); z-index: 15;
  display: flex; align-items: center; align-self: center; gap: 8px; width: min(100%, 560px); min-width: 0; min-height: 44px;
  padding: 8px 14px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); font: inherit; font-size: 13.5px; font-weight: 600; text-align: left; cursor: pointer;
}
.hd-live[hidden] { display: none; }
.hd-live:focus-visible { outline: none; box-shadow: var(--shadow), 0 0 0 3px var(--focus-ring); }
.hd-live-icon { flex: none; display: grid; place-items: center; color: var(--brand-strong); }
.hd-live-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hd-live-go { flex: none; display: inline-flex; align-items: center; gap: 2px; font-size: 12.5px; color: var(--link); }

.hd-source-list { margin: 0 0 8px; padding-left: 18px; font-size: 12.5px; line-height: 1.5; }
.hd-source-list a { overflow-wrap: anywhere; }
.hd-sources[hidden] { display: none; }

/* ---- hook in Nákup (views/editor/items.js, details of an animal item) -------------------------- */
.hd-itemline {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0; padding: 8px 10px;
  border-radius: var(--radius-sm); background: var(--brand-soft); font-size: 13px; line-height: 1.45; min-width: 0;
}
.hd-itemline[hidden] { display: none; }
.hd-itemline-label { font-weight: 650; }
.hd-itemline-text { flex: 1 1 200px; min-width: 0; color: var(--text); overflow-wrap: anywhere; }
.hd-itemline-link { color: var(--link); white-space: nowrap; }
.hd-itemline-link[hidden] { display: none; }
@media (pointer: coarse), (max-width: 720px) {
  .hd-itemline .btn-sm { min-height: 40px; height: auto; }
  .hd-itemline-link { display: inline-flex; align-items: center; min-height: 40px; }
}

/* ---- narrow cards / phones ----------------------------------------------------------------- */
@container hdherd (max-width: 560px) {
  .hd-head { padding: 12px 14px; }
  .hd-body { padding: 12px 12px 14px; gap: 14px; }
  .hd-fold-body { padding: 4px 12px 12px; }
  .hd-tiles .kpi { padding: 10px 12px; }
  .hd-tiles .kpi-value { font-size: 17px; }
}
@media (max-width: 480px) {
  .hd-tiles, .hd-overview .hd-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .hd-live { padding-inline: 12px; font-size: 13px; }
  .hd-live-go-label { display: none; }
  .hd-head-actions, .hd-head-actions .btn { width: 100%; }
  .hd-root .section-actions { width: 100%; }
}
@media (pointer: coarse), (max-width: 720px) {
  .hd-root .btn-sm { min-height: 40px; height: auto; }
  .hd-root .btn-icon.btn-sm { width: 40px; height: 40px; }
  .hd-actions .toggle, .hd-field .toggle { min-height: 40px; align-items: center; }
  .hd-fold-sum { min-height: 48px; }
  .hd-from-btn { min-height: 40px; }
  .hd-root .hd-link { display: inline-block; min-height: 24px; }
  .hd-head-actions .btn { min-height: 44px; }
  .hd-source .hd-link { display: inline-flex; align-items: center; min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .hd-fold-sum::after, .hd-herd.hd-flash { transition: none; }
}
@media print {
  .hd-actions, .hd-remove, .hd-live, .hd-head-actions, .hd-from-items, .hd-fix-wrap { display: none !important; }
  .hd-herd, .hd-fold { break-inside: avoid; }
}
