@layer components {
  /* An agent's page: header, search and tabs, then the list in its own frame (Ui::ConversationRowComponent). */
  .agent-page { gap: 16px; }
  .agent-page-head {
    display: grid; align-items: center; gap: 12px 12px;
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas: "avatar name . new" "avatar subtitle . new" "search search search tabs";
  }
  .agent-page-head .agent-page-counts { display: contents; }
  .agent-page-back { display: none; }
  .agent-page-avatar {
    grid-area: avatar; align-self: start; display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; margin-top: 2px; border-radius: 8px;
    color: var(--agent-color); background: color-mix(in oklch, var(--agent-color) 14%, transparent);
  }
  .agent-page-name { grid-area: name; margin: 0; font-size: 22px; line-height: 1.2; align-self: end; }
  .agent-page-subtitle { grid-area: subtitle; margin: 0; color: var(--muted-foreground); font-size: 13px; align-self: start; }
  .agent-page-new { grid-area: new; align-self: center; }
  .agent-page-search {
    grid-area: search; position: relative; display: flex; align-items: center; min-width: 0;
    height: 36px; padding: 0 12px; gap: 8px; border: 1px solid var(--input); border-radius: var(--radius-md);
    background: var(--background); color: var(--muted-foreground);
  }
  .agent-page-search:focus-within { border-color: var(--jx-accent); box-shadow: 0 0 0 3px var(--ring); }
  .agent-page-search svg { flex: none; }
  .agent-page-search-input {
    flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: 0; background: transparent;
    color: var(--foreground); font: inherit; font-size: 14px; box-shadow: none; appearance: none;
  }
  .agent-page-search-input::-webkit-search-cancel-button { appearance: none; }
  .agent-page-tabs { grid-area: tabs; display: flex; gap: 8px; }
  .list-tab {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border: 1px solid var(--border);
    border-radius: 999px; background: var(--background); color: var(--foreground); font-size: 14px; font-weight: 500;
    text-decoration: none; white-space: nowrap;
  }
  .list-tab:is(:hover, :active) { background: var(--muted); text-decoration: none; }
  .list-tab[aria-current=page] { border-color: transparent; background: var(--foreground); color: var(--background); }
  .list-tab-count { color: var(--muted-foreground); font-weight: 400; }
  .list-tab[aria-current=page] .list-tab-count { color: inherit; }
  .list-tab:focus-visible { outline: 2px solid var(--jx-accent); outline-offset: 2px; }

  .agent-page-body { display: flex; flex-direction: column; gap: 12px; }
  .agent-page-banner {
    display: flex; align-items: center; gap: 10px; margin: 0 0 8px; padding: 12px 14px; border: 1px solid var(--border);
    border-radius: var(--radius-lg); background: var(--muted); color: var(--muted-foreground); font-size: 14px;
  }
  .agent-page-banner svg { flex: none; }

  .conversation-group + .conversation-group { margin-top: 8px; }
  .conversation-group:not(:has(.conversation-row)) { display: none; }
  .conversation-group-title {
    margin: 0; padding: 8px 12px 4px; color: var(--muted-foreground); font-size: 13px; font-weight: 500;
    letter-spacing: 0.04em; text-transform: uppercase;
  }
  .conversation-list ul { list-style: none; margin: 0; padding: 0; }
  .conversation-list li:not(:has(.conversation-row)) { display: none; }

  /* One row: the title's link stretches over it, the menu button stays above. */
  .conversation-row {
    position: relative; display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 12px;
    border-radius: 6px;
  }
  .conversation-row:is(:hover, :focus-within, :has(.menu:not([hidden]))) { background: var(--muted); }
  .conversation-row-avatar {
    flex: none; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
    border-radius: 999px; background: var(--muted); color: var(--muted-foreground);
  }
  .conversation-row-avatar--agent { border-radius: 8px; color: var(--agent-color); background: color-mix(in oklch, var(--agent-color) 14%, transparent); }
  .conversation-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .conversation-row-title {
    color: var(--foreground); font-size: 15px; font-weight: 500; text-decoration: none;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .conversation-row.is-unread .conversation-row-title { font-weight: 700; }
  .conversation-row-title::after { content: ""; position: absolute; inset: 0; border-radius: 6px; }
  .conversation-row-title:focus-visible { outline: none; }
  .conversation-row-title:focus-visible::after { outline: 2px solid var(--jx-accent); outline-offset: -2px; }
  .conversation-row-excerpt {
    margin: 0; color: var(--muted-foreground); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .conversation-row-meta, .conversation-row-date { flex: none; color: var(--muted-foreground); font-size: 13px; }
  .conversation-row-flag { flex: none; display: inline-flex; width: 8px; }
  .conversation-row-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--jx-accent); }
  .conversation-row-chevron { flex: none; display: inline-flex; color: var(--muted-foreground); }
  .conversation-row-more {
    position: relative; z-index: 1; flex: none; display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: transparent;
    color: var(--muted-foreground); cursor: pointer; opacity: 0;
  }
  .conversation-row:focus-within .conversation-row-more, .conversation-row-more[aria-expanded=true] { opacity: 1; }
  /* A tap hovers too, and iOS Safari drops the click of a tap whose hover reveals content: a real hover only. */
  @media (hover: hover) { .conversation-row:hover .conversation-row-more { opacity: 1; } }
  /* Without a hover the ⋯ stays in reach. */
  @media (hover: none) { .conversation-row-more { opacity: 1; } }
  .conversation-row-more:hover { background: var(--accent); color: var(--foreground); }
  .conversation-row-more:focus-visible { outline: 2px solid var(--jx-accent); outline-offset: 1px; }
  .conversation-row:not(.has-menu) { padding-right: 12px; }
  .conversation-row--editing { gap: 8px; }
  .conversation-row--editing .input { flex: 1; min-width: 0; }
  .conversation-row--editing:hover { background: transparent; }
  .conversation-title-error { color: var(--destructive); font-size: 13px; }

  .agent-page-pages { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-top: 12px; color: var(--muted-foreground); font-size: 14px; }
  .agent-page-range { margin: 0; margin-right: auto; }
  .agent-page-per { display: flex; align-items: center; gap: 8px; margin: 0; }
  .agent-page-per select.input { height: 36px; min-width: 72px; }
  .agent-page-numbers { display: flex; align-items: center; gap: 4px; }
  .page-link {
    display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px; padding: 0 8px;
    border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--background);
    color: var(--foreground); font-size: 14px; text-decoration: none;
  }
  a.page-link:is(:hover, :active) { background: var(--muted); text-decoration: none; }
  .page-link[aria-current=page] { border-color: transparent; background: var(--foreground); color: var(--background); }
  span.page-link { color: var(--muted-foreground); opacity: 0.5; }
  .page-gap { padding: 0 4px; }

  /* Loading and failure: the frame gives way to the skeleton while Turbo marks it busy, and to the alert on failure. */
  .agent-page-list[aria-busy=true], [data-state=error] .agent-page-list { display: none; }
  .list-state--loading { display: none; flex-direction: column; gap: 4px; }
  .agent-page-body:has(.agent-page-list[aria-busy=true]) .list-state--loading { display: flex; }
  .list-skeleton-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 16px; min-height: 60px; padding: 10px 12px; }
  .list-skeleton-row--avatar { grid-template-columns: 24px 1fr auto; gap: 8px 12px; padding-left: 12px; }
  .list-skeleton-avatar { grid-column: 1; grid-row: 1 / span 2; width: 24px; height: 24px; border-radius: 50%; background: var(--muted); }
  .list-skeleton-row--avatar .list-skeleton-line:not(.list-skeleton-line--date) { grid-column: 2; }
  .list-skeleton-row--avatar .list-skeleton-line--date { grid-column: 3; }
  .list-skeleton-line { height: 12px; border-radius: 6px; background: var(--muted); }
  .list-skeleton-line--0 { width: 24%; } .list-skeleton-line--1 { width: 18%; }
  .list-skeleton-line--2 { width: 30%; } .list-skeleton-line--3 { width: 22%; }
  .list-skeleton-line--long { width: 56%; grid-column: 1; }
  .list-skeleton-line--date { grid-column: 2; grid-row: 1 / span 2; width: 36px; }
  .list-state--error { flex-direction: column; align-items: flex-start; gap: 12px; }
  .list-state--error:not([hidden]) { display: flex; }
  .list-state-alert {
    display: flex; align-items: center; gap: 10px; align-self: stretch; margin: 0; padding: 12px 14px;
    border: 1px solid color-mix(in oklch, var(--jx-no) 35%, transparent); border-radius: var(--radius-lg);
    background: var(--jx-no-soft); color: var(--foreground); font-size: 14px;
  }
  .list-state-alert svg { flex: none; color: var(--jx-no); }
  .list-state--empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 16px; text-align: center; }
  .list-state-icon {
    display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px;
    background: var(--muted); color: var(--muted-foreground);
  }
  .list-state-title { margin: 0; font-size: 15px; font-weight: 600; }
  .list-state-hint { margin: 0; color: var(--muted-foreground); font-size: 13px; }
  .list-state-hint--short { display: none; }
  .list-state-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }

  /* The skeleton waits a beat: a fast answer never flashes it. */
  @media (prefers-reduced-motion: no-preference) {
    .list-state--loading { animation: list-state-in 1ms linear 200ms backwards; }
    @keyframes list-state-in { from { opacity: 0; } }
  }

  @media (pointer: coarse) {
    .conversation-row-more { opacity: 1; width: var(--tap); height: var(--tap); margin-right: -8px; }
    .list-tab, .page-link, .agent-page-per select.input { min-height: var(--tap); }
  }

  /* Phone and tablet: back arrow, name and « + » on one line, search and tabs below (the floating bar stays). */
  @media (max-width: 1099px) {
    .agent-page { gap: 12px; }
    .agent-page-head {
      grid-template-columns: auto auto 1fr auto;
      grid-template-areas: "back avatar name new" "search search search search" "tabs tabs tabs tabs";
    }
    .agent-page-back {
      grid-area: back; position: relative; display: inline-flex; align-items: center; justify-content: center;
      width: var(--tap); height: var(--tap); margin-left: -10px; color: var(--foreground); text-decoration: none;
    }
    .agent-page-avatar { align-self: center; margin-top: 0; }
    .agent-page-name { align-self: center; font-size: 24px; }
    .agent-page-subtitle { display: none; }
    .agent-page-new { width: var(--tap); height: var(--tap); padding: 0; border-color: transparent; background: transparent; color: var(--foreground); box-shadow: none; }
    .agent-page-new:is(:hover, :active) { background: var(--accent); color: var(--foreground); }
    .agent-page-new-label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .conversation-row { padding: 10px 0; gap: 10px; }
    .conversation-row-title { font-size: 16px; }
    .conversation-row-excerpt { font-size: 14px; }
    .conversation-group-title { padding-inline: 0; }
    .list-skeleton-row--avatar { grid-template-columns: 40px 1fr auto; }
    .list-skeleton-avatar { width: 40px; height: 40px; }
    .list-state-hint--long, .list-state-new { display: none; }
    .list-state-hint--short { display: inline; }
    .agent-page-pages { justify-content: space-between; }
  }
}
