/* 05 / Monday digest (automation 07): the weekly open-items email on Fernhill paper, with a
   "Who gets what" switch. Every rule is scoped under #digest. */

/* ---------- Avatars (the shared rule: a circle, initials in Inter 600 at .46 of its size) ---------- */

#digest .mt-av {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--s, 24px);
  height: var(--s, 24px);
  border-radius: 50%;
  background: var(--av, #888);
  color: #14120f;
  font-family: var(--font-sans);
  font-size: calc(var(--s, 24px) * 0.46);
  font-weight: 600;
  line-height: 1;
}

/* ---------- Layout: mail (left) and who column (right); one column below 1024 ---------- */

#digest .mt-dg-in {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 16px;
  padding: 14px;
}

#digest .mt-dg-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Dark mail bar above the paper */

#digest .mt-dg-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  font-size: 11.5px;
  color: var(--ash);
}

#digest .mt-dg-bar svg {
  width: 14px;
  height: 14px;
  flex: none;
}

#digest .mt-dg-bar-t {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

#digest .mt-dg-new {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid var(--accent-40);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  transition: opacity 0.4s var(--ease-soft);
}

#digest .mt-dg-new.mt-dg-hide {
  opacity: 0;
}

#digest .mt-dg-dotg {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- The paper email (Fernhill palette, the product colours of this component) ---------- */

#digest .mt-dg-mail {
  box-sizing: border-box;
  --fh-paper: #faf8f3;
  --fh-card: #ffffff;
  --fh-ink: #1f1e1b;
  --fh-muted: #6f6a60;
  --fh-line: #e7e2d8;
  --fh-chip: #f1ede4;
  --fh-fern: #2f6a4f;
  --fh-fern-tint: #e3eee8;
  --fh-red: #c2412d;
  --fh-red-tint: #fbebe7;
  --fh-green: #2f8a5b;
  --fh-green-tint: #e7f3ec;

  position: relative;
  padding: 24px 28px;
  background: var(--fh-paper);
  color: var(--fh-ink);
  border-radius: 0 0 10px 10px;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  transition: opacity 0.6s var(--ease-soft), transform 0.6s var(--ease-soft);
}

/* The whole email rises in once (the timeline sets .is-in) */
#digest .mt-dg-mail.is-anim {
  opacity: 0;
  transform: translateY(18px);
}

#digest .mt-dg-mail.is-anim.is-in {
  opacity: 1;
  transform: none;
}

/* Hidden twin of the email, used only to measure the team view's height (never capped) */
#digest .mt-dg-sb {
  position: absolute;
  left: 0;
  top: 0;
  max-height: none;
  overflow: visible;
  visibility: hidden;
  pointer-events: none;
}

/* Capped email: the foot fades out when there is more below (set by the script) */
#digest .mt-dg-mail.mt-dg-more::after {
  content: "";
  position: sticky;
  bottom: -24px;
  display: block;
  height: 104px;
  margin: -104px -28px -24px;
  background: linear-gradient(to bottom, rgba(250, 248, 243, 0), var(--fh-paper) 85%);
  pointer-events: none;
}

#digest .mt-dg-sample {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--ash);
}

/* The body is what the view switch cross-fades */
#digest .mt-dg-body {
  transition: opacity 0.25s var(--ease-std);
}

#digest .mt-dg-body.is-swap {
  opacity: 0;
}

/* Every animated part of the email eases in when its hide class is removed */
#digest .mt-dg-body * {
  transition: opacity 0.4s var(--ease-soft), transform 0.4s var(--ease-soft);
}

/* Sequence: no transition at all (finishing a run, or switching view) */
#digest .mt-dg-instant,
#digest .mt-dg-instant * {
  transition: none !important;
}

#digest .mt-dg-hide {
  opacity: 0;
}

#digest .mt-dg-hd {
  display: flex;
  align-items: center;
  gap: 12px;
}

#digest .mt-dg-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 26%;
  background: var(--fh-fern);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16.5px;
  line-height: 1;
}

#digest .mt-dg-hdt {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

#digest .mt-dg-from {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--fh-ink);
}

#digest .mt-dg-subj {
  font-size: 11.5px;
  line-height: 1.4;
  letter-spacing: 0.04em;
  color: var(--fh-muted);
  overflow-wrap: anywhere;
}

#digest .mt-dg-title {
  margin: 14px 0 4px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--fh-ink);
}

#digest .mt-dg-to {
  margin: 0;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--fh-line);
  font-size: 14.5px;
  color: var(--fh-muted);
}

#digest .mt-dg-blk {
  margin: 18px 0 0;
}

#digest .mt-dg-bh {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--fh-ink);
}

#digest .mt-dg-bh .mt-dg-n {
  font-weight: 500;
  color: var(--fh-muted);
}

#digest .mt-dg-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  flex: none;
}

/* Empty states: a green check and a line */

#digest .mt-dg-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  font-size: 14.5px;
  color: var(--fh-green);
}

#digest .mt-dg-ck {
  width: 14px;
  height: 14px;
  flex: none;
}

/* Overdue rows: red wash, a 3px red bar that grows in */

#digest .mt-dg-od {
  position: relative;
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  padding: 10px 12px 10px 15px;
  background: var(--fh-red-tint);
  border-radius: 6px;
}

#digest .mt-dg-od::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 6px 0 0 6px;
  background: var(--fh-red);
  transform-origin: 50% 0;
  transform: scaleY(1);
  transition: transform 0.4s var(--ease-soft);
}

#digest .mt-dg-od.mt-dg-hide::before {
  transform: scaleY(0);
}

#digest .mt-dg-own {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--fh-ink);
  white-space: nowrap;
}

#digest .mt-dg-task {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#digest .mt-dg-tt {
  font-size: 15.5px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--fh-ink);
}

#digest .mt-dg-od .mt-dg-from {
  font-size: 13.5px;
  font-weight: 400;
  color: var(--fh-muted);
}

#digest .mt-dg-pill {
  padding: 2px 9px;
  border: 1px solid rgba(194, 65, 45, 0.4);
  border-radius: 999px;
  font-size: 13px;
  line-height: 1.5;
  color: #ad3a26;
  white-space: nowrap;
}

/* Due rows, grouped by owner */

#digest .mt-dg-grp {
  margin-top: 12px;
}

#digest .mt-dg-gh {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

#digest .mt-dg-gn {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--fh-ink);
}

#digest .mt-dg-gk {
  font-size: 13.5px;
  color: var(--fh-muted);
}

#digest .mt-dg-due {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 7px 0 7px 26px;
  border-bottom: 1px solid var(--fh-line);
}

#digest .mt-dg-due:last-child {
  border-bottom: 0;
}

#digest .mt-dg-dl {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#digest .mt-dg-tl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  max-width: 100%;
  font-size: 15.5px;
  line-height: 1.3;
  color: var(--fh-fern);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

#digest .mt-dg-tl svg {
  width: 12px;
  height: 12px;
  flex: none;
}

#digest .mt-dg-dm {
  font-size: 13.5px;
  color: var(--fh-muted);
}

#digest .mt-dg-dd {
  padding: 2px 7px;
  background: var(--fh-chip);
  border-radius: 4px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--fh-ink);
  white-space: nowrap;
}

/* Done last week: a green panel with the count */

#digest .mt-dg-done {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 14px;
  margin-top: 18px;
  padding: 14px 16px;
  background: var(--fh-green-tint);
  border: 1px solid #cfe6d8;
  border-radius: 8px;
}

#digest .mt-dg-ring {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--fh-green);
  color: #fff;
  transition: opacity 0.35s var(--ease-soft), transform 0.35s var(--ease-soft);
}

#digest .mt-dg-ring.mt-dg-hide {
  opacity: 0;
  transform: scale(0.6);
}

#digest .mt-dg-ring svg {
  width: 16px;
  height: 16px;
}

#digest .mt-dg-dn {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}

#digest .mt-dg-num {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--fh-ink);
}

#digest .mt-dg-dl2 {
  font-size: 15px;
  color: var(--fh-muted);
}

#digest .mt-dg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#digest .mt-dg-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 3px;
  background: var(--fh-card);
  border: 1px solid var(--fh-line);
  border-radius: 999px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--fh-ink);
  white-space: nowrap;
}

#digest .mt-dg-foot {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--fh-line);
  font-size: 13.5px;
  color: var(--fh-muted);
}

/* ---------- Who column ---------- */

#digest .mt-dg-who {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

#digest .mt-dg-who-h {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}

#digest .mt-dg-who-h .mono {
  font-size: 11.5px;
}

#digest .mt-dg-who-t {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16.5px;
  line-height: 1.2;
  color: var(--bone);
}

#digest .mt-dg-views {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#digest .mt-dg-view {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--bone);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.2s, box-shadow 0.2s, border-color 0.2s;
}

#digest .mt-dg-view:hover {
  background: hsl(42 30% 94% / 0.03);
}

#digest .mt-dg-view[aria-pressed="true"] {
  background: hsl(42 30% 94% / 0.04);
  box-shadow: inset 2px 0 0 var(--accent);
}

#digest .mt-dg-avs {
  display: flex;
  align-items: center;
}

#digest .mt-dg-avs .mt-av + .mt-av {
  margin-left: -8px;
  box-shadow: 0 0 0 1.5px var(--surface);
}

#digest .mt-dg-vt {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#digest .mt-dg-vn {
  font-size: 15.5px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--bone);
}

#digest .mt-dg-vsn {
  display: none;
}

#digest .mt-dg-vs {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  line-height: 1.4;
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}

#digest .mt-dg-vr {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

#digest .mt-dg-vc {
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.1em;
  text-align: right;
}

#digest .mt-dg-send {
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ash);
  transition: color 0.3s, border-color 0.3s;
}

#digest .mt-dg-send.is-ok {
  color: var(--ok);
  border-color: hsl(152 60% 48% / 0.4);
}

#digest .mt-dg-who-f {
  margin: auto 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
}

/* ---------- Replay: a pill under the stage content, hidden (row kept) until the run ends ---------- */

#digest .mt-dg-replay {
  grid-column: 1 / -1;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--bone);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

#digest .mt-dg-replay[hidden] {
  display: inline-flex;
  visibility: hidden;
  pointer-events: none;
}

#digest .mt-dg-replay:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#digest .mt-dg-replay svg {
  width: 14px;
  height: 14px;
}

/* Static and reduced motion: no Replay, so its row goes too */
#digest .mt-dg-in.is-final .mt-dg-replay {
  display: none;
}

#digest .mt-dg-line {
  max-width: 44rem;
  margin: 24px 0 0;
  text-align: left;
}

/* ---------- Narrow layout (below 1024): who column becomes a row of pills above the email ---------- */

@media (max-width: 1023px) {
  #digest .mt-dg-who {
    order: -1;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
  }

  #digest .mt-dg-who-h,
  #digest .mt-dg-who-f,
  #digest .mt-dg-avs,
  #digest .mt-dg-vs,
  #digest .mt-dg-vr {
    display: none;
  }

  #digest .mt-dg-views {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  #digest .mt-dg-view {
    display: block;
    width: auto;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
  }

  #digest .mt-dg-view[aria-pressed="true"] {
    box-shadow: none;
    background: hsl(42 30% 94% / 0.06);
    border-color: var(--accent);
    color: var(--accent);
  }

  #digest .mt-dg-vn {
    display: none;
  }

  #digest .mt-dg-vsn {
    display: inline;
    font-size: 15px;
    line-height: 1.3;
    color: inherit;
  }
}

@media (min-width: 1024px) {
  #digest .mt-dg-in {
    grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
    gap: 24px;
    padding: 24px;
  }

  /* Desktop: the email scrolls inside a 640px window */
  #digest .mt-dg-mail:not(.mt-dg-sb) {
    max-height: 640px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--fh-line) transparent;
  }

  /* The who panel is as tall as the email beside it; its footnote sits at the foot */
  #digest .mt-dg-who {
    align-self: stretch;
  }
}

/* ---------- Phones: tighter email, rows stacked (owner and pill, then the task) ---------- */

@media (max-width: 600px) {
  #digest .mt-dg-in {
    padding: 10px;
  }

  #digest .mt-dg-mail {
    padding: 16px;
  }

  #digest .mt-dg-title {
    font-size: 19px;
  }

  #digest .mt-dg-od {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "own pill"
      "task task";
    row-gap: 6px;
  }

  #digest .mt-dg-own {
    grid-area: own;
  }

  #digest .mt-dg-pill {
    grid-area: pill;
  }

  #digest .mt-dg-task {
    grid-area: task;
  }

  #digest .mt-dg-due {
    padding-left: 22px;
  }

  #digest .mt-dg-done {
    padding: 12px 14px;
  }

  #digest .mt-dg-view,
  #digest .mt-dg-replay {
    min-height: 44px;
  }
}
