/* ===========================================
   Control plane: the Inbox, Home's Needs you line (M1-08), UI Slice 1
   A compact list and the selected item: stacked on phones (list first), two
   columns from 1024. Tokens only; mobile-first min-width queries.
   =========================================== */

/* Header: title, then the Mine/All and kind filters. */

.page-header.inbox-page__header {
  align-items: flex-start;
  gap: var(--spacing-md);
}

.inbox-page__filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  max-width: 100%;
}

/* A segmented control. The current option is never a fill alone: it adds
   the selection pattern's inset 2px outline in --color-text-emphasis, plus
   aria-current. */
.inbox-seg {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.inbox-seg__link {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target);
  padding: 0 var(--spacing-md);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.inbox-seg__link + .inbox-seg__link {
  border-left: 1px solid var(--color-border);
}

.inbox-seg__link:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  text-decoration: none;
}

.inbox-seg__link[aria-current] {
  background: var(--color-surface-active);
  box-shadow: inset 0 0 0 2px var(--color-text-emphasis);
  color: var(--color-text-emphasis);
  font-weight: var(--font-semibold);
}

.inbox-page__note {
  margin-bottom: var(--spacing-md);
}

/* The list, then the selected item; side by side from 1024. */

.inbox-page__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--spacing-lg);
  align-items: start;
}

.card.inbox-list:hover,
.card.inbox-detail:hover {
  border-color: var(--color-border);
}

.inbox-list {
  min-width: 0;
}

.inbox-list__empty,
.inbox-list__others {
  padding: var(--spacing-lg);
}

.inbox-list__others {
  border-top: 1px solid var(--color-border-subtle);
}

.inbox-rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.inbox-rows li + li .inbox-row {
  border-top: 1px solid var(--color-border-subtle);
}

/* A row: kind and age, the title, then agent and reference. */
.inbox-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "kind agent age"
    "title title title"
    "ref ref ref";
  gap: var(--spacing-xs) var(--spacing-sm);
  align-items: center;
  min-height: var(--touch-target);
  padding: var(--spacing-md) var(--spacing-lg);
  color: var(--color-text);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.inbox-row > .inbox-kind {
  grid-area: kind;
}

.inbox-row:hover {
  background: var(--color-surface-hover);
  text-decoration: none;
}

/* The selected row: a fill plus the 2px inline-start bar (selection
   pattern), with aria-current. */
.inbox-row[aria-current="true"] {
  background: var(--color-surface-active);
  box-shadow: inset 2px 0 0 var(--color-text-emphasis);
}

.inbox-row__agent,
.inbox-row__ref,
.inbox-row__age,
.inbox-row__assignee {
  color: var(--color-text-muted);
}

.inbox-row__agent {
  grid-area: agent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inbox-row__title {
  grid-area: title;
  overflow-wrap: anywhere;
  color: var(--color-text-emphasis);
  font-weight: var(--font-medium);
  line-height: var(--leading-snug);
}

.inbox-row__assignee {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--font-normal);
}

.inbox-row__ref,
.inbox-row__age {
  font-size: var(--text-xs);
}

.inbox-row__ref {
  grid-area: ref;
  overflow-wrap: anywhere;
}

.inbox-row__age {
  grid-area: age;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Kind badges lead with their shape: Answer (needs you, the one solid
   accent badge) a diamond, Review a check, Fix a triangle. */
.badge.inbox-kind {
  justify-self: start;
}

.badge.inbox-kind::before {
  content: "";
  flex: 0 0 auto;
  width: 0.75rem;
  height: 0.75rem;
  background-color: currentColor;
  -webkit-mask: var(--cp-shape-queued) center / contain no-repeat;
  mask: var(--cp-shape-queued) center / contain no-repeat;
}

.badge.inbox-kind--answer::before {
  -webkit-mask-image: var(--cp-shape-needs);
  mask-image: var(--cp-shape-needs);
}

.badge.inbox-kind--review::before {
  -webkit-mask-image: var(--cp-shape-done);
  mask-image: var(--cp-shape-done);
}

.badge.inbox-kind--fix::before {
  -webkit-mask-image: var(--cp-shape-stalled);
  mask-image: var(--cp-shape-stalled);
}

/* The selected item */

.inbox-detail {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  min-width: 0;
  padding: var(--spacing-lg);
}

.inbox-detail__body {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.inbox-detail__kind {
  margin: 0;
}

.inbox-detail__title {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--color-text-emphasis);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

.inbox-facts,
.inbox-not-yet {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  margin: 0;
  padding-left: 0;
  overflow-wrap: anywhere;
  color: var(--color-text);
  font-size: var(--text-sm);
}

.inbox-facts a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.inbox-not-yet {
  color: var(--color-text-muted);
}

.inbox-detail__actions {
  align-items: center;
}

.inbox-detail__form {
  display: inline-flex;
  margin: 0;
}

/* A held email or reply (spec PR 2b): its text exactly as received or as it
   would be sent, escaped, wrapped and scrollable, never rendered markup. */

.inbox-email {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  min-width: 0;
}

.inbox-email__label {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
}

.inbox-email__text {
  max-height: 24rem;
  margin: 0;
  padding: var(--spacing-md);
  overflow: auto;
  overflow-wrap: anywhere;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-background-subtle);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  white-space: pre-wrap;
  tab-size: 2;
}

.inbox-detail__meta {
  margin-top: var(--spacing-xs);
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--color-border-subtle);
  font-variant-numeric: tabular-nums;
}

/* Home: the Needs you line, above the roster. A tint of the accent with
   its hairline and the needs-you diamond; the counts are tabular. */

.card.needs-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-sm) var(--spacing-md);
  margin: 0 0 var(--spacing-xl);
  padding: var(--spacing-md) var(--spacing-lg);
  border-color: var(--color-primary-border);
  background: var(--color-primary-surface);
}

.card.needs-bar:hover {
  border-color: var(--color-primary-border);
}

/* Nothing waits on the member: a calm neutral line, the diamond muted. */
.card.needs-bar[data-needs-you="0"],
.card.needs-bar[data-needs-you="0"]:hover {
  border-color: var(--color-border);
  background: var(--color-surface);
}

.needs-bar .agent-page__heading {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm);
  color: var(--color-text-emphasis);
}

.needs-bar .agent-page__heading::before {
  content: "";
  flex: 0 0 auto;
  width: 0.875rem;
  height: 0.875rem;
  background-color: var(--color-primary);
  -webkit-mask: var(--cp-shape-needs) center / contain no-repeat;
  mask: var(--cp-shape-needs) center / contain no-repeat;
}

.needs-bar[data-needs-you="0"] .agent-page__heading::before {
  background-color: var(--color-text-muted);
}

.needs-bar__counts {
  flex: 1 1 12rem;
  margin: 0;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.control-home__note kbd {
  padding: 0 var(--spacing-xs);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xs);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* A card's count of items waiting on the member. Needs-you is the one solid
   accent badge (design §A.1, §D.6), so this link is drawn the same way as the
   nav count. It sits inline after the name and role and wraps with them. */
.roster-card__needs {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  min-height: 1.75rem;
  padding: 0 var(--spacing-sm);
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-semibold);
  text-decoration: none;
}

.roster-card__needs::before {
  content: "";
  flex: 0 0 auto;
  width: 0.625rem;
  height: 0.625rem;
  background-color: currentColor;
  -webkit-mask: var(--cp-shape-needs) center / contain no-repeat;
  mask: var(--cp-shape-needs) center / contain no-repeat;
}

.roster-card__needs:hover,
.roster-card__needs:focus-visible {
  text-decoration: underline;
}

.roster-card__needs:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* The g i hint is for keyboards: hidden on phones and touch-only screens. */
.control-home__note--shortcut {
  display: none;
}

@media (pointer: coarse) {
  .roster-card__needs {
    min-height: var(--touch-target);
  }
}

@media (min-width: 640px) {
  .control-home__note--shortcut {
    display: block;
  }
}

@media (min-width: 640px) and (hover: none) and (pointer: coarse) {
  .control-home__note--shortcut {
    display: none;
  }
}

@media (min-width: 1024px) {
  .inbox-page__layout {
    grid-template-columns: minmax(18rem, 2fr) minmax(0, 3fr);
    gap: var(--spacing-xl);
  }

  /* Nothing listed, so no detail pane beside the list. */
  .inbox-page__layout--single {
    grid-template-columns: minmax(0, 1fr);
  }

  .inbox-detail {
    padding: var(--spacing-xl) var(--spacing-2xl);
  }
}

@media (forced-colors: active) {
  .badge.inbox-kind::before,
  .needs-bar .agent-page__heading::before,
  .roster-card__needs::before {
    forced-color-adjust: none;
    background-color: CanvasText;
  }

  .roster-card__needs {
    border: 1px solid LinkText;
  }

  .inbox-seg__link[aria-current],
  .inbox-row[aria-current="true"] {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
}
