/* ════════════════════════════════════════════════════════════════════
   Tasks tab — team task tracker (rendered by public/js/pages/tasks.js).
   Mirrors the house form/card conventions used by the Settings + Funds
   tabs: canonical var(--input) controls, var(--surface-card) cards with a
   hover lift, a 3px left accent stripe (the .fund-card pattern), mono 13px
   type, var(--border) hairlines, and var(--font-mono) pills.
   ════════════════════════════════════════════════════════════════════ */

/* ── Priority palette (0 urgent … 3 low) ────────────────────────────────
   --task-pc carries the priority colour; set it on whatever wears a
   .task-prio-<key> (legend item, card meta) or .task-border-<key> (card
   root) and descendants inherit it for dots, numbers, and the stripe. */
.task-prio-urgent,    .task-border-urgent    { --task-pc: #e40014; }
.task-prio-important, .task-border-important { --task-pc: #f97316; }
.task-prio-medium,    .task-border-medium    { --task-pc: #eab308; }
.task-prio-low,       .task-border-low       { --task-pc: #3b82f6; }

.task-prio-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--task-pc, var(--muted-foreground));
  flex: 0 0 auto;
}

/* ── Colour-dot priority picker (replaces the priority <select>) ────────
   A radiogroup of round dots — red/orange/yellow/blue — used in the add
   form and (with a leading "All" chip) in the filter bar. The selected dot
   lights up with a ring in its own priority colour; the rest sit dimmed. */
.task-prio-picker {
  display: inline-flex; align-items: center; gap: 9px;
  min-height: 37px; padding: 0 2px;
}
.task-prio-pick {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0;
  background: transparent; border: none; border-radius: 50%;
  cursor: pointer; opacity: .38;
  transition: opacity .15s ease, transform .15s ease, box-shadow .15s ease;
}
.task-prio-pick .task-prio-dot { width: 14px; height: 14px; }
.task-prio-pick:hover { opacity: .85; }
.task-prio-pick[aria-checked="true"] {
  opacity: 1; transform: scale(1.06);
  box-shadow: 0 0 0 2px var(--surface-card), 0 0 0 4px var(--task-pc, var(--ring));
}
.task-prio-pick:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
/* "All" reset chip leading the filter picker — text, not a dot. */
.task-prio-pick-all {
  width: auto; height: 22px; border-radius: 999px; padding: 0 11px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .04em;
  color: var(--muted-foreground); border: 1px solid var(--border);
  opacity: .75;
}
.task-prio-pick-all:hover { opacity: 1; }
.task-prio-pick-all[aria-checked="true"] {
  opacity: 1; transform: none; box-shadow: none;
  color: var(--foreground); border-color: var(--border-strong);
  background: var(--surface-tinted);
}

/* ── Add-task form (mirrors .fund-field / .settings-row controls) ────── */
.task-form { display: flex; flex-direction: column; gap: 14px; }
.task-input,
.task-select {
  background: var(--input); color: var(--foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; font-family: var(--font-mono); font-size: 13px;
}
.task-input { width: 100%; }
.task-input::placeholder { color: var(--muted-foreground); }
.task-input:focus,
.task-select:focus { outline: none; border-color: var(--ring); }
.task-select { cursor: pointer; }

.task-form-controls {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
}
.task-field {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0; flex: 1 1 180px;
}
.task-field-narrow { flex: 0 1 150px; }
.task-field-label {
  font-size: 10px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .1em; font-weight: 500;
}
.task-add-btn { flex: 0 0 auto; }
.task-add-status { flex: 0 0 auto; align-self: center; }

/* ── Priority legend (right side of the add-card title) ─────────────── */
.task-legend {
  display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px 14px;
  margin-left: auto; font-weight: 400;
}
.task-legend-title {
  font-size: 10px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .1em; font-weight: 500;
}
.task-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; }
.task-legend-num {
  font-family: var(--font-mono); font-weight: 600;
  color: var(--task-pc, var(--foreground));
}
.task-legend-label { color: var(--muted-foreground); }

/* ── Toolbar: owner filter + sort + text/category/priority filters ──────
   The Owner / Sort segmented controls reuse the project-standard
   .section-toggle / .seg-btn component (defined in deals.css, loaded
   globally) — no local restyle, so they look + behave like every other
   toggle (incl. the `:hover:not(.active)` rule that keeps the selected pill
   readable on hover). Only the toolbar layout lives here. */
.tasks-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  margin-bottom: 18px;
}
.tasks-tool { display: inline-flex; align-items: center; gap: 10px; }
.tasks-tool-label {
  font-size: 10px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .1em; font-weight: 500;
}

/* Search + category + priority filters share the toolbar with the segmented
   controls. The search tool grows to take up the slack on a wide row. */
.tasks-tool-grow { flex: 1 1 200px; min-width: 150px; }
.task-filter-search {
  position: relative; display: flex; align-items: center; width: 100%;
}
.task-filter-search svg {
  position: absolute; left: 11px; width: 14px; height: 14px;
  color: var(--muted-foreground); pointer-events: none;
}
.task-filter-input { width: 100%; padding-left: 34px; }
.task-filter-select { cursor: pointer; }
/* Always rendered so toggling a filter never reflows the bar — greyed and
   non-interactive until a filter is active. */
.task-filter-clear { flex: 0 0 auto; }
.task-filter-clear:disabled { opacity: .4; cursor: default; pointer-events: none; }

/* ── Completed-column month filter (lives in the card title) ─────────────
   A custom month picker + "Show all" toggle narrow Completed to one calendar
   month by completion date. margin-left:auto floats the group to the right
   edge of the title row, mirroring the add-card priority legend. The
   "Show all" button reuses the global .seg-btn (active = inverted pill). */
.tasks-completed-filter {
  display: inline-flex; align-items: center; gap: 8px;
  margin-left: auto; font-weight: 400;
}
.task-completed-all { flex: 0 0 auto; }

/* Trigger pill — opens the popover; shows the active month (or "All months").
   Native <input type="month"> can't grey out empty months, hence this custom
   widget. */
.task-month-picker { position: relative; display: inline-flex; }
.task-month-trigger {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--input); color: var(--foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 8px; font-family: var(--font-mono); font-size: 12px;
  cursor: pointer; transition: border-color .15s ease;
}
.task-month-trigger:hover { border-color: var(--border-strong); }
.task-month-trigger[aria-expanded="true"] { border-color: var(--ring); }
.task-month-trigger svg { width: 13px; height: 13px; color: var(--muted-foreground); flex: 0 0 auto; }
.task-month-trigger-label { white-space: nowrap; }
.task-month-chevron { transition: transform .15s ease; }
.task-month-trigger[aria-expanded="true"] .task-month-chevron { transform: rotate(180deg); }

/* Popover: year nav + 3×4 month grid. */
.task-month-pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
  width: 216px; padding: 10px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 14px 32px rgba(0, 0, 0, .30);
}
.task-month-pop[hidden] { display: none; }
.task-month-pop-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.task-month-year {
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  color: var(--foreground); letter-spacing: .04em;
}
.task-month-nav {
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--muted-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-size: 15px; line-height: 1;
  transition: color .15s, border-color .15s;
}
.task-month-nav:hover:not(:disabled) { color: var(--foreground); border-color: var(--border-strong); }
.task-month-nav:disabled { opacity: .3; cursor: default; }

.task-month-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.task-month-cell {
  padding: 7px 0; text-align: center;
  background: var(--surface-card); color: var(--foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 11.5px; cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.task-month-cell:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-tinted); }
.task-month-cell.is-selected {
  border-color: var(--ring); background: var(--foreground); color: var(--background);
}
/* Months with no completions — greyed and non-interactive. */
.task-month-cell.is-empty,
.task-month-cell:disabled {
  opacity: .32; cursor: default;
  color: var(--muted-foreground); background: transparent;
}
/* The current month stays clickable even when empty — mark it with an accent
   ring so it reads as reachable rather than greyed out. */
.task-month-cell.is-current:not(.is-selected) {
  border-color: var(--ring); color: var(--foreground);
}
.task-month-cell:focus-visible,
.task-month-nav:focus-visible,
.task-month-trigger:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }

/* ── Two-column board ──────────────────────────────────────────────────
   Columns stretch to equal height (the taller of the two) so both bento
   cards always match — and the Completed drop zone is always full-height
   beside a long Pending list, so you can drop by moving left↔right at any
   height without scrolling up to the box. */
.tasks-columns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
  align-items: stretch;
}
.tasks-col { margin-bottom: 0; transition: border-color .15s ease, box-shadow .15s ease; }
.tasks-col.is-drop-target {
  border-color: var(--ring);
  box-shadow: inset 0 0 0 1px var(--ring);
}
/* min-height keeps an empty column a valid drop target. */
.tasks-list { display: flex; flex-direction: column; gap: 12px; min-height: 48px; }
.tasks-empty { padding: 6px 2px; }

/* ── Task card (mirrors .fund-card: surface-card, hover lift, stripe) ── */
.task-card {
  position: relative; overflow: hidden;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px 12px 18px;
  background: var(--surface-card);
  border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color .15s ease, transform .15s ease, opacity .15s ease;
  cursor: grab;   /* draggable between Pending / Completed columns */
}
.task-card:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.task-card.is-busy { opacity: .5; pointer-events: none; }

/* Pointer-drag: the original dims in place as a "gap", while a solid clone
   (.task-drag-floater) is reparented to <body> and tracks the cursor 1:1. */
.task-card.is-dragging { opacity: .32; }
.task-drag-floater {
  position: fixed; top: 0; left: 0; margin: 0;
  z-index: 1000; pointer-events: none;
  transition: none !important;                 /* no lag — exact cursor tracking */
  transform: translate(-9999px, -9999px);      /* parked until first move */
  box-shadow: 0 14px 32px rgba(0, 0, 0, .30);
  cursor: grabbing;
}
/* While a drag is live, force the grabbing cursor everywhere and kill text
   selection so the page doesn't highlight under the moving clone. */
body.tasks-dragging { cursor: grabbing; user-select: none; }
body.tasks-dragging * { cursor: grabbing !important; }

.task-stripe {
  position: absolute; top: 0; bottom: 0; left: 0; width: 3px;
  background: var(--task-pc, var(--border)); opacity: .7;
}

.task-body {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; gap: 7px;
}
.task-title {
  font-size: 13px; font-weight: 500; color: var(--foreground);
  line-height: 1.45; word-break: break-word;
}
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.task-prio {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-family: var(--font-mono); font-weight: 600;
  color: var(--task-pc, var(--foreground));
}
.task-crumb,
.task-owner {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-tinted); border: 1px solid var(--border);
  color: var(--muted-foreground); letter-spacing: .02em;
}
.task-owner svg { width: 11px; height: 11px; }
.task-stamp { font-size: 11px; color: var(--muted-foreground); }
.task-stamp-sep { margin: 0 6px; opacity: .5; }
/* Creator / completer name — lifted out of the muted stamp so the "by
   <name>" reads at a glance. Stays legible on a staleness-tinted card too
   (foreground is the tint-safe text colour). */
.task-stamp-author { color: var(--foreground); opacity: .8; font-weight: 500; }

/* ── Tick (complete) + delete controls ─────────────────────────────── */
.task-check {
  flex: 0 0 auto; width: 22px; height: 22px; margin-top: 1px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--border-strong); border-radius: 6px;
  background: transparent; color: transparent;   /* tick hidden until hover */
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.task-check svg { width: 14px; height: 14px; }
.task-check:hover { border-color: var(--profit); color: var(--profit); }

.task-del {
  flex: 0 0 auto; width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--muted-foreground);
  border-radius: var(--radius); cursor: pointer; opacity: 0;
  transition: color .15s, opacity .15s, background .15s;
}
.task-del svg { width: 14px; height: 14px; }
.task-card:hover .task-del { opacity: 1; }
.task-del:hover { color: var(--loss); background: rgba(228, 0, 20, .08); }

/* ── Completed state ───────────────────────────────────────────────── */
.task-card.is-done { background: var(--surface-elevated); }
.task-card.is-done .task-stripe { background: var(--border-strong); opacity: 1; }
.task-card.is-done .task-check {
  border-color: var(--profit); background: var(--profit);
  color: var(--background);                        /* solid green box + tick */
}
.task-card.is-done .task-title { text-decoration: line-through; color: var(--muted-foreground); }
.task-card.is-done .task-prio { opacity: .6; }

/* ── Staleness tint ─────────────────────────────────────────────────────
   Pending tasks warm up as they age: fresh = the normal card surface, then
   surface → amber → a deep red at 30 days old (capped there). JS sets the
   inline --stale custom property (0..1 = age / 30 days); the colour math
   lives here so it re-themes automatically on a light/dark flip.

   Anchors + max blend are tuned PER THEME so the blended surface always
   lands on the legible side of the text colour: dark amber/red on the near-
   black dark surface (light text stays readable), light amber/red on the
   white light surface (dark text stays readable). */
:root {
  --task-stale-warn: #8a6a16;   /* dark amber — stays dark over the black card */
  --task-stale-red:  #c4141d;
  --task-stale-max:  82%;
}
:root[data-theme="light"] {
  --task-stale-warn: #fcd34d;   /* light amber — stays light over the white card */
  --task-stale-red:  #ef4444;
  --task-stale-max:  60%;
}
.task-card.is-stale {
  /* Hue: amber for the first half, then lerp amber→red for the second half.
     The negative percentage clamps to 0% while --stale < .5, so it reads as
     pure amber until the halfway (≈15-day) mark. */
  --task-stale-hue: color-mix(in srgb,
    var(--task-stale-red) calc((var(--stale) - 0.5) * 200%),
    var(--task-stale-warn));
  /* Blend that hue into the card surface, scaling the amount with age. */
  background: color-mix(in srgb,
    var(--task-stale-hue) calc(var(--stale) * var(--task-stale-max)),
    var(--surface-card));
}
/* Keep secondary text + chips readable once the surface is tinted. The
   foreground-derived tones auto-flip with the theme. */
.task-card.is-stale .task-stamp { color: color-mix(in srgb, var(--foreground) 72%, transparent); }
.task-card.is-stale .task-crumb,
.task-card.is-stale .task-owner {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: color-mix(in srgb, var(--foreground) 78%, transparent);
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .tasks-columns { grid-template-columns: 1fr; }
  .task-legend { margin-left: 0; width: 100%; }
}

/* Keyboard focus rings — match the rest of the app. */
.task-check:focus-visible,
.task-del:focus-visible,
.task-select:focus-visible,
.task-input:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
