/* ==========================================================================
   Jednotná karta úlohy (views/task-sheet.js, docs/SPEC_V3.md §B1) — prefix .ts-
   One sheet for every task list (Plán, Domov „Dnes“, the origin screens) and the small building blocks of the origin
   screens (taskListBlock, taskBadge). Colours only through tokens (app.css / v2.css: green = farm, brown = community,
   grey = office, amber = legal). Phone first: one column, nothing wider than the phone, ≥ 44 px targets on touch,
   16 px inputs. Linked by index.html; views/task-sheet.js ensureTaskSheetStyles() adds it only when it is missing.
   ========================================================================== */

.ts-body { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ts-sec { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ts-sec-title { margin: 0; font-size: 15px; font-weight: 700; }
.ts-note { margin: 0; color: var(--text-2); font-size: 13.5px; line-height: 1.4; overflow-wrap: anywhere; }
.ts-note:focus, .ts-facts:focus { outline: none; }
.ts-link {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--link);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.ts-link:hover { text-decoration: underline; }
.ts-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
/* „Súvisí aj s“: the other places of the task (task-links originsOf) – small chips back to each */
.ts-rel-list { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.ts-rel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 36px;
  padding: 4px 10px 4px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.ts-rel:hover { background: var(--surface-2); text-decoration: none; }
.ts-rel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-rel-icon { display: grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); }
.ts-rel-label { min-width: 0; overflow-wrap: anywhere; }
.ts-legal-what { color: var(--text); }

/* ---- Why / origin: the chip back to the origin screen ---- */
.ts-why { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ts-why-text { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
/* v5 R25: a work carried over from last year – „Skopírované z 2026“ (a calm tag, not a link) */
.ts-copied {
  align-self: flex-start;
  margin: 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--green-soft, var(--surface-2));
  color: var(--green-text, var(--text-2));
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.ts-origin {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 40px;
  padding: 6px 10px 6px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.ts-origin:hover { background: var(--surface-3); text-decoration: none; }
.ts-origin:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-origin-icon { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--green-soft); color: var(--green-text); }
/* green = farm (herd, plot, section, record, guide), brown = community and production, amber = legal, grey = plan / office */
.ts-origin[data-origin-kind="custom"] .ts-origin-icon, .ts-origin[data-origin-kind="community"] .ts-origin-icon,
.ts-origin[data-origin-kind="product"] .ts-origin-icon, .ts-origin[data-origin-kind="member"] .ts-origin-icon { background: var(--brown-soft); color: var(--brown-text); }
.ts-origin[data-origin-kind="obligation"] .ts-origin-icon, .ts-origin[data-origin-kind="legal"] .ts-origin-icon { background: var(--warning-soft); color: var(--warning-text); }
.ts-origin[data-origin-kind="planEntry"] .ts-origin-icon, .ts-origin[data-origin-kind="plan"] .ts-origin-icon,
.ts-origin[data-origin-kind="milestone"] .ts-origin-icon, .ts-origin[data-origin-kind="energy"] .ts-origin-icon,
.ts-origin[data-origin-kind="catalogue"] .ts-origin-icon { background: var(--grey-soft); color: var(--grey-text); }
.ts-origin-label { min-width: 0; overflow-wrap: anywhere; }
.ts-origin-go { display: grid; place-items: center; flex: none; color: var(--text-2); }

/* ---- Status: big buttons, done = primary ---- */
.ts-status { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 96px), 1fr)); gap: 8px; }
.ts-st {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 52px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ts-st:hover { background: var(--surface-2); }
.ts-st:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-st > svg { flex: none; }
.ts-st-text { display: flex; flex-direction: column; min-width: 0; }
.ts-st-label { font-size: 15px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.ts-st-sub { color: var(--text-2); font-size: 12.5px; line-height: 1.25; overflow-wrap: anywhere; }
/* done = the primary action (solid fill with white text uses --primary, AA in dark mode too) */
.ts-st--done:not(.is-on) { border-color: var(--primary); background: var(--primary); color: var(--accent-contrast, #fff); }
.ts-st--done:not(.is-on):hover { background: var(--primary-hover, var(--primary)); }
.ts-st--done:not(.is-on) .ts-st-sub { color: inherit; opacity: 0.9; }
.ts-st.is-on { border-color: var(--green); background: var(--green-tint, var(--green-soft)); cursor: default; }
.ts-st--skipped.is-on { border-color: var(--border-strong); background: var(--surface-2); }
.ts-st--open.is-on { border-color: var(--border-strong); background: var(--surface-2); }
/* A phone: „Hotovo“ alone on the first row (big, with its sub-line), „Vynechať“ and „Čaká“ side by side below – no word
   breaks inside a label at 320 – 420 px */
@media (max-width: 420px) {
  .ts-status { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ts-status[data-count="3"] > .ts-st--done, .ts-status[data-count="1"] > .ts-st { grid-column: 1 / -1; }
  .ts-st { padding: 8px 10px; }
  .ts-st-label { overflow-wrap: normal; }
}
@media (max-width: 340px) {
  .ts-st:not(.ts-st--done) .ts-st-sub { display: none; }
}

/* ---- Facts ---- */
.ts-facts { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.ts-fact { display: grid; grid-template-columns: minmax(0, 104px) minmax(0, 1fr); gap: 10px; font-size: 14px; line-height: 1.4; }
.ts-fact dt { color: var(--text-2); }
.ts-fact dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---- The day of a daily work ---- */
.ts-occ { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0; font-size: 14px; cursor: pointer; }
.ts-occ input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--green); }
.ts-occ-ro { cursor: default; color: var(--text-2); }

/* ---- Who: scope and member picks ---- */
.ts-scope { align-self: stretch; }
.ts-scope .segmented-item { flex: 1 1 0; min-width: 0; white-space: normal; }
.ts-picks { display: flex; flex-direction: column; gap: 6px; }
.ts-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ts-pick:hover { background: var(--surface-2); }
.ts-pick.is-active { border-color: var(--green); background: var(--green-tint, var(--green-soft)); }
.ts-pick:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ts-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--grey-soft);
  color: var(--grey-text);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1;
}
.ts-avatar.ri-tone-green { background: var(--green-soft); color: var(--green-text); }
.ts-avatar.ri-tone-brown { background: var(--brown-soft); color: var(--brown-text); }
.ts-avatar.ri-tone-none { background: transparent; color: var(--muted); border: 1px dashed var(--border-strong); }
.ts-pick-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ts-pick-name { font-weight: 600; overflow-wrap: anywhere; }
.ts-pick-sub { color: var(--text-2); font-size: 12.5px; overflow-wrap: anywhere; }
.ts-reassign-request { align-self: flex-start; white-space: normal; }

/* ---- When, note, actions ---- */
.ts-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 10px 12px; }
.ts-fields > * { min-width: 0; }
.ts-body input[type="time"], .ts-body input[type="date"], .ts-body textarea { min-height: 44px; font-size: 16px; }
.ts-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ts-actions .btn { white-space: normal; }

/* ---- Legal duty, history ---- */
.ts-legal { gap: 4px; }
.ts-penalty { color: var(--warning-text); }
.ts-history { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.ts-hist { position: relative; padding: 2px 0 2px 16px; color: var(--text-2); font-size: 13.5px; line-height: 1.4; overflow-wrap: anywhere; }
.ts-hist::before { content: ""; position: absolute; left: 3px; top: 0.6em; width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); }
.ts-hist[data-status="done"]::before { background: var(--green); }

/* ---- Building blocks of the origin screens: taskListBlock, taskBadge ---- */
.ts-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.ts-badge[hidden] { display: none; }
.ts-badge[data-tone="bad"] { background: var(--critical-soft); color: var(--critical-text); }
.ts-list-block { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ts-lb-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ts-lb-title { margin: 0; font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.ts-lb-list { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.ts-lb-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 0 8px 0 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.ts-lb-row.is-overdue { border-color: var(--critical-soft); }
.ts-lb-checkwrap {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ts-lb-checkwrap[hidden] { display: none; }
.ts-lb-checkwrap.is-disabled { cursor: default; }
.ts-lb-check {
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid var(--green);
  border-radius: 50%;
  background: var(--surface);
  cursor: inherit;
}
.ts-lb-check::after {
  content: "";
  width: 6px;
  height: 11px;
  margin-top: -2px;
  border: solid var(--accent-contrast, #fff);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 120ms ease-out;
}
.ts-lb-check:checked { background: var(--green); border-color: var(--green); }
.ts-lb-check:checked::after { transform: rotate(45deg) scale(1); }
.ts-lb-check:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-lb-check:disabled { opacity: 0.55; }
.ts-lb-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  min-height: 44px;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ts-lb-row > .ts-lb-main:first-child { padding-left: 12px; }
.ts-lb-checkwrap[hidden] + .ts-lb-main { padding-left: 12px; }
.ts-lb-main:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.ts-lb-title-text { font-size: 14.5px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.ts-lb-meta { color: var(--text-2); font-size: 12.5px; line-height: 1.3; overflow-wrap: anywhere; }
.ts-lb-row.is-done .ts-lb-title-text { color: var(--text-2); text-decoration: line-through; }
.ts-lb-row.is-skipped .ts-lb-title-text { color: var(--muted); }
.ts-lb-flag { flex: none; padding: 2px 8px; border-radius: 999px; background: var(--critical-soft); color: var(--critical-text); font-size: 12px; font-weight: 700; white-space: nowrap; }
.ts-lb-flag[hidden] { display: none; }
.ts-lb-empty { margin: 0; color: var(--text-2); font-size: 13.5px; }
.ts-lb-empty[hidden] { display: none; }
.ts-lb-more { align-self: flex-start; min-height: 36px; padding: 0 2px; border: 0; background: none; color: var(--link); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.ts-lb-more[hidden] { display: none; }
.ts-lb-plan {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 2px;
  min-height: 36px;
  color: var(--link);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
}
.ts-lb-plan:hover { text-decoration: underline; }
.ts-lb-plan:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
/* Plán → Týždeň filtered to one origin (?povod=): „Len úlohy: Stádo Králiky ✕“ */
.ri-povod {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0 0 8px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2, var(--surface));
  scroll-margin-top: calc(var(--header-h, 56px) + 12px); /* ?povod= scrolls it under the sticky header */
}
.ri-povod[hidden] { display: none; }
.ri-povod-icon { display: inline-flex; flex: none; color: var(--text-2); }
.ri-povod-text { flex: 1 1 auto; min-width: 0; font-size: 13.5px; line-height: 1.3; overflow-wrap: anywhere; }
.ri-povod-text strong { font-weight: 700; }
.ri-povod-link { flex: none; color: var(--link); font-size: 13.5px; font-weight: 600; text-decoration: none; padding: 8px 4px; }
.ri-povod-clear {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text-2);
  cursor: pointer;
}
.ri-povod-clear:focus-visible, .ri-povod-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Touch: ≥ 44 px targets ---- */
@media (pointer: coarse) {
  .ts-link, .ts-origin, .ts-lb-more, .ts-lb-plan, .ri-povod-link { min-height: 44px; }
  .ts-rel { min-height: 44px; }
  .ri-povod-link { display: inline-flex; align-items: center; }
  .ri-povod-clear { width: 44px; height: 44px; }
  .ts-actions .btn, .ts-reassign-request, .ts-sheet .modal-footer .btn { min-height: 44px; }
  .ts-sheet .modal-close { min-width: 44px; min-height: 44px; }
  .ts-scope .segmented-item { min-height: 44px; }
}
@media (max-width: 420px) {
  .ts-fact { grid-template-columns: minmax(0, 92px) minmax(0, 1fr); }
  .ts-lb-row { flex-wrap: wrap; }
  /* the text stays beside the 44 px done toggle (a flex-basis of auto would push a long title onto a line of its own);
     only „po termíne“ wraps under it */
  .ts-lb-main { flex: 1 1 calc(100% - 52px); }
  .ts-lb-flag { margin: 0 0 8px 48px; }
}

/* ==========================================================================
   v4 R8 (round 12): „Ako dlho to trvalo?“ – time chips (sheet of a done task and the „Hotovo“ panel), the device setting,
   and the non-modal „Hotovo“ bottom panel (.ts-done) that follows every „Hotovo“. Phone first: chips wrap, ≥ 44 px targets
   on touch, the minute field 16 px, the panel above the bottom tab bar and never wider than the screen.
   ========================================================================== */
.ts-timechips { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ts-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.ts-chip {
  min-width: 56px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ts-chip:hover { background: var(--surface-2); }
.ts-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-chip.is-on, .ts-chip[aria-pressed="true"] { border-color: var(--green); background: var(--green-soft); color: var(--green-text); }
.ts-chip:disabled { opacity: 0.55; cursor: default; }
.ts-chip-customwrap { max-width: 12.5rem; }
.ts-chip-customwrap[hidden] { display: none; }
.ts-chip-custom .input { min-height: 44px; font-size: 16px; }
.ts-time { gap: 8px; }
.ts-time-clear { align-self: flex-start; }
.ts-time-clear[hidden] { display: none; }
.ts-asktime, .ts-done-ask {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.3;
  cursor: pointer;
}
.ts-asktime input, .ts-done-ask input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--green); }

.ts-done {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 990; /* under a sheet's backdrop (1000), over the page */
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(26rem, calc(100vw - 32px));
  max-height: min(78vh, 640px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg, 12px);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: ts-done-in 0.16s ease-out;
}
@keyframes ts-done-in { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ts-done { animation: none; } }
.ts-done-head { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.ts-done-title { display: flex; flex: 1 1 auto; flex-direction: column; gap: 1px; min-width: 0; margin: 0; font-size: 15.5px; font-weight: 700; line-height: 1.3; }
.ts-done-kicker { color: var(--green-text); font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.ts-done-name { min-width: 0; overflow-wrap: anywhere; }
.ts-done-x {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text-2);
  cursor: pointer;
}
.ts-done-x:hover { background: var(--surface-2); }
.ts-done-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-done-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ts-done-q { margin: 0; font-size: 14.5px; font-weight: 600; }
.ts-done-hint { margin: 0; color: var(--text-2); font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.ts-done-people { min-width: 0; }
.ts-done-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ts-done-actions .btn { flex: 1 1 auto; min-height: 44px; white-space: normal; }
.ts-done-actions .ts-done-undo { flex: 0 1 auto; }
html[data-tabbar] .ts-done { bottom: calc(var(--tabbar-space, 0px) + 8px); }
/* Phone: a bottom sheet the width of the screen (above the tab bar), chips three to a row */
@media (max-width: 720px) {
  .ts-done { left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 72vh; }
  html[data-tabbar] .ts-done { bottom: calc(var(--tabbar-space, 0px) + 4px); max-height: calc(100vh - var(--tabbar-space, 0px) - 64px); }
}
@media (pointer: coarse) {
  .ts-chip { min-height: 44px; }
  .ts-done-x { width: 44px; height: 44px; }
}
@media (max-width: 360px) {
  /* narrow phones: shorter chips that wrap, but never a target under 44 px (round 13 QA – „1 h“ was 40 px wide at 320) */
  .ts-chip { min-width: 44px; padding: 0 10px; font-size: 13.5px; }
}
@media print { .ts-done { display: none !important; } }
body.modal-open .ts-done { display: none; } /* a sheet over the panel hides it until it closes */
/* Round 12 fix R12-01: „Urobil(a)“ – who did a task the owner marks done (the done panel and the done sheet) */
.ts-doer { display: flex; align-items: center; gap: 10px; min-width: 0; margin: 0 0 8px; }
.ts-doer-label { flex: 0 0 auto; font-size: 14px; font-weight: 600; color: var(--text-2); }
.ts-doer .ts-doer-select { flex: 1 1 auto; min-width: 0; max-width: 100%; min-height: 44px; font-size: 16px; }
