/* ==================================================================================================
   Domain components — owner: design-system agent (feature agents may extend in their page CSS)
   r4 «Birge OS» — spec §9.21–9.24.

   .task-card      board card (components/task_card.html): a white 12px plate (concentric inside the
                   18px column well), 0.5px ring + soft shadow, lifts 1px on hover. States:
                   .is-done (dimmed + struck title), .is-active (open in the inspector), .is-new,
                   Sortable classes. Parts: __head, __type, __done, __title/__link, __meta, __labels,
                   __stats, __assignee, __menu (glass "…")
   .task-row       list row (components/task_row.html). Parts: __check, __main, __title, __key,
                   __labels, __project, __meta. States: .is-done (the strike draws left → right),
                   .is-active, .is-selected (macOS selection: accent fill, every text white)
   .task-key       "WEB-12" monospace key
   .priority       signal bars (prio-* sprite symbols); data-priority="0..4" colors it
   .due            due-date capsule: data-state="overdue|today|soon|later|done"
   .type-icon      task type glyph (bug/feature/…): neutral; --tinted takes data-color
   .user-chip      avatar + name · .project-chip (capsule with a 16px app-icon tile) · .label-chip
   Drag & drop     .sortable-ghost / .sortable-chosen / .sortable-drag / .sortable-fallback
   ================================================================================================== */

/* -- Task key ------------------------------------------------------------------------------------ */
.task-key {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
}

/* -- Priority (signal bars, r4 · 9.23) ------------------------------------------------------------- */
.priority {
  display: inline-grid;
  flex-shrink: 0;
  place-items: center;
  color: var(--text-3);
}
/* Color only where it means something: low/medium are neutral, high is warm, urgent is red. */
.priority[data-priority="1"] { color: var(--text-3); }
.priority[data-priority="2"] { color: var(--text-2); }
.priority[data-priority="3"] { color: var(--warning-ink); }
.priority[data-priority="4"] { color: var(--danger-ink); }
.priority-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

/* -- Task type glyph ----------------------------------------------------------------------------- */
/* Type = a category, not a signal: neutral glyph everywhere (data-color is kept on the markup for
   pickers/legends that want the hue: add .type-icon--tinted). */
.type-icon {
  display: inline-grid;
  flex-shrink: 0;
  place-items: center;
  color: var(--text-3);
}
.type-icon--tinted {
  color: var(--tone-ink);
}

/* -- Due chip (r4 · 9.23) --------------------------------------------------------------------------
   A 20px capsule. Only "overdue" is filled (--danger-solid + white: the one loud signal on a card or
   row); "today" is warm text on --fill-1, "soon" plain text on --fill-1, "later" quiet text,
   "done" struck through. */
.due {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px 0 6px;
  border-radius: var(--radius-full);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.due .icon {
  flex-shrink: 0;
  opacity: 0.85;
}
.due[data-state="overdue"] {
  background: var(--danger-solid);
  color: var(--text-on-accent);
  font-weight: var(--fw-semibold);
}
.due[data-state="overdue"] .icon {
  opacity: 1;
}
.due[data-state="today"] {
  background: var(--fill-1);
  color: var(--warning-ink);
  font-weight: var(--fw-semibold);
}
.due[data-state="soon"] {
  background: var(--fill-1);
  color: var(--text);
}
.due[data-state="later"] {
  padding-inline: 2px;
  color: var(--text-2);
}
.due[data-state="done"] {
  padding-inline: 2px;
  color: var(--text-3);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, currentColor 55%, transparent);
}
/* Overdue count ("⏰ 3" on a project card/row, a team's project, a workload row): filled like the
   overdue due chip — the one red signal there. Markup: <span class="overdue-count"
   title="3 overdue tasks">{% icon "alarm" size=12 %}<span aria-hidden="true">3</span><span
   class="sr-only">3 overdue tasks</span></span> (or the words: "3 overdue"). --sm: 18px, in
   dense rows. */
.overdue-count {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px 0 6px;
  border-radius: var(--radius-full);
  background: var(--danger-solid);
  color: var(--text-on-accent);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}
.overdue-count--sm {
  height: 18px;
  padding: 0 6px 0 5px;
  gap: 3px;
  font-size: var(--fs-2xs);
}

/* -- Entity chips (r4 · 9.24): capsules on --fill-1 --------------------------------------------- */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 100%;
  font-size: var(--fs-md);
  vertical-align: middle;
}
.user-chip__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chip__sub {
  color: var(--text-2);
  font-size: var(--fs-xs);
}
a.user-chip:hover .user-chip__name {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.user-chip--pill {
  height: 26px;
  padding: 0 10px 0 3px;
  border-radius: var(--radius-full);
  background: var(--fill-1);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
a.user-chip--pill:hover {
  background: var(--fill-2);
}
a.user-chip--pill:hover .user-chip__name {
  text-decoration: none;
}
.project-chip {
  gap: 6px;
  padding-left: 3px;
  background: var(--fill-1);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}
.project-chip.chip--lg {
  padding-left: 5px;
  font-size: var(--fs-sm);
}
.project-chip .icon-tile {
  --size: 16px;
  box-shadow: inset 0 0.5px 0 rgb(255 255 255 / 0.3), inset 0 0 0 0.5px rgb(0 0 0 / 0.06);
}
.project-chip.chip--lg .icon-tile {
  --size: 20px;
}
.project-chip .icon-tile .icon {
  width: 64%;
  height: 64%;
}
a.project-chip:hover {
  background: var(--fill-2);
}
/* Label chip: the neutral chip + the label's color as a dot (color = identity, not a fill).
   Never clipped mid-word: long names ellipsize inside the chip (title attr = full name). */
.label-chip {
  max-width: 160px;
  background: var(--fill-1);
  color: var(--text-2);
  font-weight: var(--fw-medium);
}
a.label-chip:hover,
button.label-chip:hover {
  background: var(--fill-2);
}
.label-chip .chip__dot {
  width: 6px;
  height: 6px;
}

/* -- Task card (board, r4 · 9.21) -----------------------------------------------------------------
   head (type glyph / done · KEY ……… assignee) → title (≤ 3 lines, 14px 500, the strongest thing) →
   meta (priority · due · labels ……… stats). Radius 12 inside the 18px column (concentric), surface
   + 0.5px ring + --shadow-sm; hover lifts 1px; press scales .985. */
.task-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--radius-board-card);
  background: var(--surface);
  box-shadow:
    0 0 0 0.5px var(--card-ring),
    var(--shadow-sm),
    inset 0 0.5px 0 var(--card-highlight);
  color: var(--text);
  cursor: default;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    box-shadow var(--dur-2) ease,
    transform var(--dur-snappy) var(--spring-snappy),
    opacity var(--dur-2) ease,
    background-color var(--dur-2) ease;
  -webkit-touch-callout: none;
}
@media (hover: hover) {
  .task-card:hover {
    box-shadow:
      0 0 0 0.5px var(--line-strong),
      var(--shadow-md),
      inset 0 0.5px 0 var(--card-highlight);
    transform: translateY(-1px);
  }
}
.task-card:active {
  transform: scale(0.985);
  transition-duration: var(--dur-1);
}
.task-card:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px var(--accent),
    0 0 0 5px var(--focus-ring);
}
.task-card.is-active {
  box-shadow:
    0 0 0 2px var(--accent),
    var(--shadow-md);
}
.task-card.is-done {
  opacity: 0.62;
}
.task-card.is-done:hover,
.task-card.is-done:focus-within {
  opacity: 0.85;
}
.task-card__head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 18px;
  color: var(--text-3);
  font-size: var(--fs-xs);
}
.task-card__head > .task-key {
  flex-shrink: 0;
  line-height: 18px;
}
.task-card__type,
.task-card__done {
  display: inline-grid;
  flex-shrink: 0;
  place-items: center;
  width: 14px;
  height: 14px;
}
.task-card__type {
  color: var(--text-3); /* type = category, not a signal: neutral glyph */
}
.task-card__done {
  color: var(--success);
}
.task-card__title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  letter-spacing: -0.006em;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.task-card__link::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.task-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  min-width: 0;
  min-height: 20px;
}
.task-card__meta:not(:has(*)) {
  display: none;
}
.task-card__meta > .priority {
  width: 14px;
}
.task-card__labels {
  display: flex;
  flex: 0 1 auto;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
}
.task-card__labels .chip {
  flex-shrink: 1;
  min-width: 0;
  max-width: 120px;
}
.task-card__labels .chip.task-card__more {
  flex-shrink: 0;
  padding-inline: 6px;
  font-variant-numeric: tabular-nums;
}
.task-card__stats {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: var(--text-3);
  font-size: var(--fs-xs);
}
.task-card__stats .meta {
  color: var(--text-3);
  font-size: var(--fs-xs);
}
.task-card__assignee {
  display: inline-flex;
  margin-left: auto;
}
.task-card.is-done .task-card__title {
  text-decoration: line-through;
  text-decoration-color: var(--text-3);
}
.meta--done {
  color: var(--success-ink);
}
.meta--done .icon {
  color: var(--success);
}
/* The "…" button: a small glass circle over the head row, shown on hover / focus (always on touch).
   (pages/projects.css refines its board behaviour.) */
.task-card__menu {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--glass-sheen), var(--mat-thick);
  -webkit-backdrop-filter: var(--mat-filter);
  backdrop-filter: var(--mat-filter);
  box-shadow: var(--glass-rim), var(--shadow-sm);
  color: var(--text-2);
  opacity: 0;
  transition: opacity var(--dur-2) ease;
}
.task-card:is(:hover, :focus-within) .task-card__menu,
.task-card__menu[aria-expanded="true"] {
  opacity: 1;
}
@media (pointer: coarse) {
  .task-card__menu {
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: none;
    opacity: 1;
  }
}
@media (prefers-reduced-motion: no-preference) {
  .task-card.is-new {
    animation: card-in var(--dur-bouncy) var(--spring-bouncy) both;
  }
}
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
}

/* -- Task row (list, r4 · 9.22) -------------------------------------------------------------------- */
.task-row {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 12px;
  min-height: var(--row-h-list);
  padding: 4px 14px 4px 16px;
  background: var(--surface);
  transition: background-color var(--dur-1) ease;
}
.task-row + .task-row {
  box-shadow: inset 0 0.5px 0 var(--line-subtle);
}
@media (hover: hover) {
  .task-row:hover {
    background: var(--surface-2);
  }
}
.task-row.is-active {
  background: var(--accent-softer);
}
.task-row__main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.task-row__main > .task-key {
  flex-shrink: 0;
}
/* The title; when the task completes a strike draws across it, left → right. */
.task-row__title {
  min-width: 0;
  overflow: hidden;
  background: linear-gradient(currentColor, currentColor) no-repeat 0 55% / 0% 1px;
  color: var(--text);
  font-size: var(--type-body);
  font-weight: var(--fw-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
  transition:
    background-size var(--dur-3) var(--ease-out),
    color var(--dur-2) ease;
}
.task-row__title::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
}
.task-row__title:focus-visible {
  outline: none;
}
.task-row:has(.task-row__title:focus-visible) {
  box-shadow: inset 0 0 0 2px var(--accent);
}
.task-row .check-circle,
.task-row__meta > :is(a, button),
.task-row__labels,
.task-row__project {
  position: relative;
  z-index: 1;
}
.task-row.is-done .task-row__title {
  background-size: 100% 1px;
  color: var(--text-3);
}
/* Selected (bulk selection) — the macOS selection: an accent plate with 8px corners; every text
   inside turns white by swapping the text tokens. Neighbouring selected rows join into one plate.
   (Loses focus → :root.is-window-inactive swaps --selection-bg/fg to the muted gray.) */
.task-row.is-selected {
  --text: var(--selection-fg);
  --text-2: color-mix(in srgb, var(--selection-fg) 85%, transparent);
  --text-3: color-mix(in srgb, var(--selection-fg) 72%, transparent);
  --fill-1: color-mix(in srgb, var(--selection-fg) 16%, transparent);
  --fill-2: color-mix(in srgb, var(--selection-fg) 24%, transparent);
  --line: color-mix(in srgb, var(--selection-fg) 28%, transparent);
  --avatar-ring: var(--selection-bg);
  border-radius: 8px;
  background: var(--selection-bg);
  color: var(--text);
}
.task-row.is-selected,
.task-row.is-selected + .task-row {
  box-shadow: none;
}
.task-row.is-selected + .task-row.is-selected {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  box-shadow: inset 0 0.5px 0 color-mix(in srgb, var(--selection-fg) 18%, transparent);
}
.task-row.is-selected:has(+ .task-row.is-selected) {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.task-row.is-selected :where(input[type="checkbox"]):checked {
  box-shadow: 0 0 0 1.5px var(--selection-fg);
}
.task-row.is-selected .check-circle:not([aria-checked="true"]),
.task-row.is-selected :is(.type-icon, .priority, .task-row__ghost) {
  color: var(--text-2);
}
.task-row.is-selected .due[data-state="overdue"] {
  background: var(--selection-fg);
  color: var(--danger-solid);
}
.task-row__labels {
  display: flex;
  flex-shrink: 1;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}
/* Labels: two chips at most, then "+N" (task_row.html). The strip never cuts a chip mid-word: it
   keeps its size while the title gives way, a long name ellipsizes inside its own chip, and in
   narrow rows the chips become colour dots (the name stays in the tooltip and for screen readers)
   — like the list view's middle tier. The row is the container, so every row of a list switches
   together; rows that also show a project chip switch earlier. Phones wrap labels under the title
   instead. (The list view's own tiers in pages/projects.css take precedence there.) */
@media (min-width: 768px) {
  .task-row {
    container: task-row / inline-size;
  }
  .task-row__labels {
    flex-shrink: 0;
  }
  .task-row__labels .chip {
    max-width: 120px;
  }
  @container task-row (max-width: 639px) {
    .task-row__labels .label-chip {
      width: 18px;
      padding: 0;
      justify-content: center;
    }
    .task-row__labels .label-chip .chip__text {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }
  }
  @container task-row (max-width: 859px) {
    .task-row:has(.task-row__project) .task-row__labels .label-chip {
      width: 18px;
      padding: 0;
      justify-content: center;
    }
    .task-row:has(.task-row__project) .task-row__labels .label-chip .chip__text {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }
  }
}
.task-row__more {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.task-row__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}
.task-row__meta .due {
  min-width: 0;
}
/* Desktop: due and priority sit in fixed slots so dates line up down a list whatever their length
   (and whether a row has a priority); project chips end on one edge before them. */
@media (min-width: 768px) {
  .task-row__meta > .task-row__cell--due {
    display: inline-flex;
    justify-content: flex-start;
    min-width: 72px;
  }
  .task-row__meta > .task-row__cell--priority {
    display: inline-flex;
    justify-content: center;
    min-width: 16px;
  }
}
.task-row__cell-text {
  display: none;
  min-width: 0;
  overflow: hidden;
  color: var(--text-2);
  font-size: var(--fs-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Phones: two lines — the title, then key · type · labels · due · priority … assignee. */
@media (max-width: 767px) {
  .task-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    padding: 12px 48px 12px 50px;
  }
  .task-row .check-circle {
    position: absolute;
    top: 12px;
    left: 14px;
  }
  .task-row__main,
  .task-row__meta {
    display: contents;
  }
  .task-row__title {
    flex: 1 1 100%;
    order: -1;
    white-space: normal;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
  /* A clamped title can wrap: strike it with text-decoration (the drawn strike is one line). */
  .task-row.is-done .task-row__title {
    background-size: 0% 1px;
    text-decoration: line-through;
    text-decoration-color: color-mix(in srgb, currentColor 55%, transparent);
  }
  .task-row .task-row__cell--assignee {
    position: absolute;
    top: 10px;
    right: 12px;
  }
  /* Empty values carry no information on a phone (open the task to set them). */
  .task-row .task-row__ghost,
  .task-row__labels:not(:has(.chip)),
  .task-row__cell--due:not(:has(.due)),
  .task-row__cell--priority:has(.priority[data-priority="0"]),
  .task-row__cell--priority:not(:has(.priority)),
  .task-row__cell--assignee:has(.avatar--empty) {
    display: none;
  }
  .task-row__labels {
    flex-wrap: wrap;
    overflow: visible;
  }
}
/* .task-rows--compact (on the rows' container, e.g. My tasks): phones keep every row to two lines —
   label chips shrink to their colour dots (names stay in the tooltip / for screen readers), a
   long project name ellipsizes, the row runs to the edge (no assignee column). */
@media (max-width: 767px) {
  .task-rows--compact .task-row {
    padding-right: 14px;
  }
  .task-rows--compact .task-row__labels {
    flex-wrap: nowrap;
  }
  .task-rows--compact .task-row__labels .label-chip {
    width: 18px;
    padding: 0;
    justify-content: center;
  }
  .task-rows--compact .task-row__labels .label-chip .chip__text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .task-rows--compact .task-row__project {
    display: flex;
    flex: 1 1 0;
    order: 1;
    min-width: 30px; /* the project's icon tile at least; the name ellipsizes */
  }
  .task-rows--compact .task-row__project .project-chip {
    min-width: 0;
    max-width: 100%;
  }
}

/* -- Favorite star (components/favorite_button.html) --------------------------------------------- */
.favorite-toggle.is-on,
.favorite-toggle.is-on:hover {
  background: transparent;
  color: var(--c-yellow);
}
@media (prefers-reduced-motion: no-preference) {
  .favorite-toggle.is-on .icon {
    animation: pop 380ms var(--spring-bouncy);
  }
}

/* -- Drag & drop (SortableJS) -------------------------------------------------------------------- */
.sortable-ghost {
  opacity: 0.35;
}
.task-card.sortable-ghost,
.task-row.sortable-ghost {
  opacity: 1;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  box-shadow: none;
  outline: 1.5px dashed color-mix(in srgb, var(--accent) 50%, transparent);
  outline-offset: -1.5px;
  transform: none;
}
.task-card.sortable-ghost > *,
.task-row.sortable-ghost > * {
  visibility: hidden;
}
.sortable-chosen {
  cursor: grabbing;
}
.sortable-drag,
.sortable-fallback {
  opacity: 1 !important;
  transform: rotate(1.5deg) scale(1.02);
  box-shadow:
    0 0 0 0.5px var(--card-ring),
    var(--shadow-lift) !important;
  cursor: grabbing;
}
.drag-handle {
  color: var(--text-3);
  cursor: grab;
  touch-action: none;
}
.drag-handle:active {
  cursor: grabbing;
}
