/* The task list: rows and their toggles, the open row, the edit form, the
   delay dialog, and how rows lay out on a phone and on a touchscreen. */

/* Task list. A row's `data-urgency` (0 most urgent .. 6 least) selects its
   tint and edge bar from the urgency tokens. */
.rows {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-1);
}

.row[data-urgency="0"] {
  --row-bg: var(--color-urgency-0-bg);
  --row-bar: var(--color-urgency-0-bar);
}

.row[data-urgency="1"] {
  --row-bg: var(--color-urgency-1-bg);
  --row-bar: var(--color-urgency-1-bar);
}

.row[data-urgency="2"] {
  --row-bg: var(--color-urgency-2-bg);
  --row-bar: var(--color-urgency-2-bar);
}

.row[data-urgency="3"] {
  --row-bg: var(--color-urgency-3-bg);
  --row-bar: var(--color-urgency-3-bar);
}

.row[data-urgency="4"] {
  --row-bg: var(--color-urgency-4-bg);
  --row-bar: var(--color-urgency-4-bar);
}

.row[data-urgency="5"] {
  --row-bg: var(--color-urgency-5-bg);
  --row-bar: var(--color-urgency-5-bar);
}

.row[data-urgency="6"] {
  --row-bg: var(--color-urgency-6-bg);
  --row-bar: var(--color-urgency-6-bar);
}

/* A row is a <details>: one line when closed, everything when open. */
.row {
  border-left: 0.25rem solid var(--row-bar, var(--color-border-subtle));
  border-radius: var(--radius-md);
  background: var(--row-bg, var(--color-bg-surface));
}

.row[data-done] {
  background: var(--color-bg-sunken);
}

/* The always-visible line (the <summary>). Fixed-size parts never shrink;
   the title takes the rest and ends in an ellipsis. */
.row-line {
  /* Scrolling a row into view clears the bar and the quick-add box. */
  scroll-margin-top: calc(var(--bar-height, 0px) + 5rem);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--size-row-compact);
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
  list-style: none;
}

.row-line::-webkit-details-marker {
  display: none;
}

@media (pointer: coarse) {
  .row-line {
    min-height: var(--size-row-comfortable);
    padding: var(--space-2) var(--space-3);
  }
}

/* The row's toggles. Done is always there; doing, today and blocked show in
   the line only while switched on. The others wait in a small flyout under the
   done circle, which opens on hover or keyboard focus (and, on a touchscreen,
   in the open row, where they are text buttons). */
.row-toggles {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.row-marks {
  display: contents;
}

.row-more {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: calc(-1 * var(--space-3));
  z-index: 5;
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-bg-surface);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-duration-fast) var(--motion-easing-standard);
}

/* Bridges the gap between the circle and the flyout so the pointer can cross. */
.row-more::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: var(--space-3);
}

.row-toggles:hover .row-more,
.row-toggles:focus-within .row-more {
  opacity: 1;
  pointer-events: auto;
}

/* An open row has the same buttons below, so the flyout steps aside (and
   with it leaves the tab order and the accessibility tree). */
.row[open] .row-more {
  display: none;
}

/* Without hover (touch) there is no flyout: the open row has the buttons. */
@media (hover: none) {
  .row-more {
    display: none;
  }
}

/* The done toggle: an empty circle, filled with a tick when done. */
.row-check {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 2px solid var(--color-border-strong);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-accent-on);
  cursor: pointer;
}

.row-check:hover {
  border-color: var(--color-accent-base);
}

.row-check[aria-pressed="true"] {
  border-color: var(--color-accent-base);
  background: var(--color-accent-base);
}

.row-check[aria-pressed="true"]::after {
  content: "";
  width: 0.75rem;
  height: 0.75rem;
  background: currentColor;
  mask: url("/static/icons/check.svg") center / contain no-repeat;
}

/* The doing toggle: an outlined play triangle, filled while the task is in
   progress. Same size, stroke and colour as the done circle. */
.row-doing {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-border-strong);
  cursor: pointer;
}

.row-doing::after {
  content: "";
  width: 1.25rem;
  height: 1.25rem;
  background: currentColor;
  mask: url("/static/icons/play-outline.svg") center / contain no-repeat;
}

.row-doing:hover,
.row-doing[aria-pressed="true"] {
  color: var(--color-accent-base);
}

.row-doing[aria-pressed="true"]::after {
  mask-image: url("/static/icons/play.svg");
}

/* An in-progress row has a bar twice as thick. The content is pulled back
   by the difference so rows still line up. */
.row[data-doing] {
  border-left-width: 0.5rem;
}

.row[data-doing] .row-line {
  padding-left: calc(var(--space-3) - 0.25rem);
}

/* The open row lines up under the title, not under the done circle: past the
   padding, the circle and the marks (up to three) that come before the title
   on a wide row. A phone puts the marks on the second line, so only the
   (bigger) circle counts there. */
.row {
  --check: 1.25rem;
  --lead: calc(
    var(--space-3) + var(--check) + var(--space-3) + var(--marks, 0) *
      (1.25rem + var(--space-3))
  );
}

.row[data-marks="1"] {
  --marks: 1;
}

.row[data-marks="2"] {
  --marks: 2;
}

.row[data-marks="3"] {
  --marks: 3;
}

.row .row-detail,
.row .row-actions {
  padding-left: var(--lead);
}

.row[data-doing] .row-detail,
.row[data-doing] .row-actions {
  padding-left: calc(var(--lead) - 0.25rem);
}

.group-head h2 {
  margin: var(--space-3) 0 var(--space-1);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

/* The blocked toggle: an outlined "no" sign, tinted red while the task is
   blocked. Same size and stroke as the other row icons. */
.row-blocked {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-border-strong);
  cursor: pointer;
}

.row-blocked::after {
  content: "";
  width: 1.25rem;
  height: 1.25rem;
  background: currentColor;
  mask: url("/static/icons/stop.svg") center / contain no-repeat;
}

.row-blocked:hover,
.row-blocked[aria-pressed="true"] {
  color: var(--color-danger-base);
}

.row-blocked[aria-pressed="true"]::after {
  mask-image: url("/static/icons/stop-filled.svg");
}

/* A blocked task is dimmed: it is waiting, not asking for attention. */
.row[data-blocked] .row-title {
  color: var(--color-text-secondary);
}

/* The expand chevron: points right when closed, down when open. */
.row-line::after {
  content: "";
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--color-text-secondary);
  border-bottom: 2px solid var(--color-text-secondary);
  transform: rotate(-45deg);
  transition: transform var(--motion-duration-base) var(--motion-easing-standard);
}

.row[open] .row-line::after {
  transform: rotate(45deg);
}

.row[data-done] .row-title {
  font-weight: var(--font-weight-regular);
  color: var(--color-text-muted);
  text-decoration: line-through;
}

/* The today toggle: a small calendar with a T, filled in while the task is
   planned for today. Same size, stroke and colour as the other row icons. */
.row-today {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-border-strong);
  cursor: pointer;
}

.row-today::after {
  content: "";
  width: 1.25rem;
  height: 1.25rem;
  background: currentColor;
  mask: url("/static/icons/today.svg") center / contain no-repeat;
}

.row-today:hover,
.row-today[aria-pressed="true"] {
  color: var(--color-accent-base);
}

.row-today[aria-pressed="true"]::after {
  mask-image: url("/static/icons/today-filled.svg");
}

/* A suggestion's first button: the same calendar, in the done circle's place
   (done waits in the flyout and the open row). */
.row-add {
  color: var(--color-text-muted);
}

/* Overdue: the due date stands out. */
.row-due[data-overdue] {
  color: var(--color-danger-base);
  font-weight: var(--font-weight-semibold);
}

/* A repeating task that is behind: the icon turns red, with how many periods
   have passed since the due date (how many new instances a calendar would have
   started). */
.repeat-missed {
  color: var(--color-danger-base);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
}

/* A recurring task. */
.icon-repeat {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  vertical-align: -0.1em;
  background: currentColor;
  mask: url("/static/icons/repeat.svg") center / contain no-repeat;
}

/* How big a task is: five slots filled from the bottom (the SVG's fainter
   slots are the empty ones). A task with no size gets an empty placeholder of the same width, so dates
   line up down the list. */
.row-size {
  display: inline-block;
  width: 0.55rem;
  height: 1.1rem;
  margin-left: var(--space-2);
  vertical-align: -0.2em;
  background: currentColor;
}

.row-size-none {
  background: none;
}

/* Stands in for " · " and the repeat icon on rows that don't repeat, so dates
   line up. */
.row-repeat-none {
  display: inline-block;
  width: 1.6em;
}

/* The copy that sits with the marks on a phone. */
.row-size-lead {
  display: none;
}

.icon-size-1 { mask: url("/static/icons/size-1.svg") center / contain no-repeat; }
.icon-size-2 { mask: url("/static/icons/size-2.svg") center / contain no-repeat; }
.icon-size-3 { mask: url("/static/icons/size-3.svg") center / contain no-repeat; }
.icon-size-4 { mask: url("/static/icons/size-4.svg") center / contain no-repeat; }
.icon-size-5 { mask: url("/static/icons/size-5.svg") center / contain no-repeat; }

.row-title {
  flex: 1 1 0;
  /* Always leave the title some room: the tags give way first. */
  min-width: 6rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--font-weight-medium);
}

.row[open] .row-title {
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* At most two chips, each capped in width; the full list is in the details. */
.row-tags {
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  gap: var(--space-1);
}

/* When space runs out only the first chip shrinks (ending in an ellipsis);
   the others stay whole so "+2" is never cut. */
.row-tags:empty {
  display: none;
}

.row-tags .tag {
  flex: none;
}

.row-tags .tag:first-child {
  flex: 0 1 auto;
}

.row[open] .row-tags {
  display: none;
}

.row-link {
  flex: none;
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.row-meta {
  flex: none;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

/* The title, tags, link and meta live in a body box. On a desktop it adds
   nothing (`display: contents`), so they sit in the row's one line. */
.row-body {
  display: contents;
}

/* On a phone the line is two: the done circle gets a column of its own on the
   left, bigger to tap, and beside it the body wraps into a title line and a
   line of tags, link and meta. `order` and a zero-height full-width item force
   the break. The width is the "small" breakpoint (media queries can't use
   variables). */
@media (max-width: 40rem) {
  /* A phone row is one line: the done circle, the title and the due date.
     Everything else (marks, tags, link, repeat and size) waits in the open
     row, where the buttons show what is switched on. */
  .row-marks,
  .row-size-lead,
  .row-tags,
  .row-link,
  .row-extra,
  .row-meta .row-size,
  .row-repeat-none {
    display: none;
  }

  .row,
  .row[data-marks] {
    --check: 1.75rem;
    --marks: 0;
  }

  .row-check,
  .row-add {
    width: 1.75rem;
    height: 1.75rem;
  }

  .row-add::after {
    width: 1.75rem;
    height: 1.75rem;
  }

  .row-check[aria-pressed="true"]::after {
    width: 1rem;
    height: 1rem;
  }
}

/* The expanded view: a facts line (an icon and a word for each of doing,
   blocked, today, size and repeat), then tags, the link and the notes, each
   under the title. */
.row-facts,
.row-tags-open,
.row-link-open,
.row-notes {
  margin: 0;
  padding: 0 var(--space-3) var(--space-2);
  font-size: var(--font-size-sm);
}

.row-facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  color: var(--color-text-secondary);
}

.fact {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
}

.fact .icon {
  width: 1rem;
  height: 1rem;
}

.fact .row-size {
  width: 0.45rem;
  height: 0.9rem;
  margin: 0;
  vertical-align: baseline;
}

.fact-late {
  color: var(--color-danger-base);
  font-weight: var(--font-weight-semibold);
}

.row-tags-open {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.row-link-open {
  overflow-wrap: anywhere;
}

/* Wide rows show these icons in the line, so the facts line is for phones. */
@media not all and (max-width: 40rem) {
  .row-facts {
    display: none;
  }
}

.row-notes {
  white-space: pre-wrap;
}

.empty {
  padding: var(--space-5) var(--space-3);
  text-align: center;
  color: var(--color-text-muted);
}

/* A row being edited: the fields stacked, then Save and Cancel. */
.row-edit {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-bg-surface);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
}

/* The delay dialog: a title, one box, and its buttons. */
.dialog-small {
  width: min(22rem, calc(100vw - 2 * var(--space-4)));
}

.dialog-small .row-actions {
  padding: var(--space-4) 0 0;
}

.delay-input {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--size-tap);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-bg-surface);
  color: var(--color-text-primary);
  font: inherit;
}

.delay-input::placeholder {
  color: var(--color-text-muted);
}

.row-hint {
  margin: var(--space-3) 0 0;
  padding: var(--space-1) var(--space-3);
  border-left: 0.25rem solid var(--color-danger-base);
  font-size: var(--font-size-sm);
}

.row-edit .row-actions {
  padding: 0;
}

.row-edit-title {
  margin: 0;
  font-size: var(--font-size-lg);
}

/* A deleted task: muted, with a Restore button where the toggles were. */
.row-deleted .row-line {
  cursor: default;
}

.row-deleted .row-line::after {
  content: none;
}

.row-deleted .row-title {
  color: var(--color-text-muted);
}

.load-more {
  display: flex;
  justify-content: center;
  padding: var(--space-3);
}

/* Where the page is the full width of the screen (phones and tablets, below
   the desktop width in base.css) the list runs edge to edge like a native
   list: square rows, no gaps, a hairline between them. */
@media not all and (min-width: 72rem) {
  .rows {
    margin-inline: calc(-1 * var(--space-4));
    gap: 0;
  }

  /* A line between the quick-add box and the list. Tabs without a box (Done,
     Deleted) go straight from the tab underline to the rows. */
  .quick + .rows {
    border-top: 1px solid var(--color-border-strong);
  }

  /* The line under each row is its urgency colour darkened toward the strong
     border colour, so it shows on every tint in both themes. */
  .row {
    --row-line: color-mix(
      in srgb,
      var(--row-bar, var(--color-border-subtle)) 50%,
      var(--color-border-strong)
    );
    box-shadow: inset 0 -1px 0 var(--row-line);
  }

  .row,
  .row-edit {
    border-radius: 0;
  }

  .row-edit {
    border-inline: 0;
  }

  /* The bar and the quick-add box stick across the full width, so rows
     scrolling under them don't show in the page's side margins. */
  .tabbar,
  .quick {
    margin-inline: calc(-1 * var(--space-4));
    padding-inline: var(--space-4);
  }

  .group-head h2 {
    margin-inline: var(--space-4);
  }
}

/* On a touchscreen the three row toggles keep their look but get a larger
   area to tap: an invisible margin around each, still clear of the next. */
@media (pointer: coarse) {
  .row-check,
  .row-doing,
  .row-today,
  .row-blocked {
    position: relative;
  }

  .row-check::before,
  .row-doing::before,
  .row-today::before,
  .row-blocked::before {
    content: "";
    position: absolute;
    inset: -0.4rem;
  }
}

/* The buttons in an open row are small, and the three toggles read as
   switches: filled when on. */
.row .row-actions .btn {
  min-height: 1.75rem;
  padding: 0 var(--space-3);
  font-size: var(--font-size-sm);
}

.row .row-actions .btn-icon {
  min-width: 2.5rem;
  min-height: 2.25rem;
  padding: 0;
}

/* The open row's seven buttons stay on one line on a phone (360px and up): a
   little narrower, with less between them. */
@media (max-width: 40rem) {
  .row .row-actions {
    gap: var(--space-1);
  }

  .row .row-actions .btn-icon {
    min-width: 2.25rem;
  }

  /* A suggestion has an eighth button (done), so those are narrower still. */
  .row .row-actions:has(> :nth-child(8)) .btn-icon {
    min-width: 2rem;
  }
}

.row .row-actions .btn[aria-pressed="true"] {
  background: var(--color-accent-base);
  border-color: var(--color-accent-base);
  color: var(--color-accent-on);
}
