/* ===========================================================================
 * agent-card.css — THE agent card, and the section a grid of them lives in.
 *
 * Loads with the design system (after atoms.css, before the page stylesheets),
 * because it is not a page's component: every surface that offers an agent
 * renders THIS one — the home screen's Popular grid, its category shelves,
 * and the Agents page. Markup comes from ONE builder,
 * public/js/utils/agent-card.js (window.HzAgentCard), so no surface
 * hand-assembles a card of its own.
 *
 * ── One component, two compositions ───────────────────────────────────────
 *
 *   TILE  a centred launcher — avatar over name over one quiet meta line —
 *         while the section is wide enough to hold name-safe columns.
 *   ROW   the same card, laid out as a compact landscape row (44px icon, name,
 *         meta, chevron) once it is not.
 *
 * The switch is a CONTAINER query on `.hz-agent-section`, never a viewport
 * media query: a narrow column on a wide desktop is exactly as narrow as a
 * phone, and should reflow the same way. The row is described by RE-POINTING
 * the --hz-agentcard-* register (tokens.css) rather than by a second set of
 * rules, so there is one description of the card at any width.
 *
 * The shell is the shared atom — `.hz-card --raised --flat --xl` — so surface,
 * hairline and radius are the atom's, not this file's. Everything below is
 * layout, and every measurement comes from the register.
 * ========================================================================= */


/* ── Section ──────────────────────────────────────────────────────────────
 * A head (title, optional subtitle, optional trailing action) over a grid.
 * It is the query container for the cards inside it, so each section measures
 * ITSELF: a shelf in a narrow column becomes rows while a wider one beside it
 * stays tiles. `inline-size` only — height still flows from content. */
.hz-agent-section {
  container: hz-agent-section / inline-size;
}

.hz-agent-section-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--hz-agentsection-hdr-gap);
  margin-bottom: var(--hz-agentsection-hdr-offset);
}
.hz-agent-section-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--hz-space-1);
}
/* An <h2> on every surface that uses it (the home screen's shelves, every
   category on the Agents page), so the section is a real
   landmark rather than a styled span — hence the explicit margin reset: the
   component cannot depend on a page-level heading reset. */
.hz-agent-section-title {
  margin: 0;
  font-size: var(--hz-agentsection-title-font-size);
  font-weight: var(--hz-agentsection-title-weight);
  color: var(--hz-agentsection-title-color);
  letter-spacing: var(--hz-tracking-snug);
  line-height: 1.3;
}
.hz-agent-section-sub {
  font-size: var(--hz-agentsection-sub-font-size);
  color: var(--hz-agentsection-sub-color);
  line-height: var(--hz-leading-snug);
}

/* The head's trailing control ("See all" / "Show less"). Quiet by
   default — a section head carries one of these and the title is the thing
   being read — and brand-coloured so it still reads as a control. */
.hz-agent-section-action {
  /* It is a <button>: strip the platform's own chrome before anything else, or
     iOS Safari keeps its default appearance underneath these rules. */
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--hz-space-1);
  padding: var(--hz-space-1) var(--hz-space-2);
  margin-inline-end: calc(var(--hz-space-2) * -1);   /* optical: text to the edge */
  background: none;
  border: none;
  font: inherit;
  font-size: var(--hz-agentsection-action-font-size);
  font-weight: var(--hz-agentsection-action-weight);
  color: var(--hz-agentsection-action-color);
  border-radius: var(--hz-radius-8);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--hz-dur-fast) var(--hz-ease);
}
@media (hover: hover) and (pointer: fine) {
  .hz-agent-section-action:hover { opacity: .78; }
}
.hz-agent-section-action:focus-visible {
  outline: var(--hz-focus-width) solid var(--hz-focus-ring);
  outline-offset: 2px;
}


/* ── Grid ─────────────────────────────────────────────────────────────────
 * `auto-fit` + the card's own minimum column: the row fits as many equal
 * columns as it can and reflows on its own, so no surface repeats a column
 * count per breakpoint. `min(col-min, 100%)` because a fixed track minimum
 * wider than its container does not shrink — it overflows sideways. */
.hz-agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(var(--hz-agentcard-col-min), 100%), 1fr));
  /* One height for every tile in the section, not one height per grid row: a
     caption that wraps in the first row would otherwise make that row taller
     than the one under it, and the grid would read as two grids. */
  grid-auto-rows: 1fr;
  gap: var(--hz-agentcard-grid-gap);
}
/* A page of sections side by side (the Agents screen): every section keeps the
   same columns — `auto-fill` keeps the empty tracks, so a section of one or
   two agents lines up with a full one instead of stretching across the row. */
.hz-agent-grid--fill {
  grid-template-columns: repeat(auto-fill, minmax(min(var(--hz-agentcard-col-min), 100%), 1fr));
}
/* A SHELF of tiles (the Catalog hub's Models and Agents panels): the shared
   card, tile composition, in one row you flick through sideways — composed on
   the shelf atom (atoms.css .hz-shelf: the scroll container and the bleed
   that keeps the raised card's shadow whole). Each tile is --hz-agentcard-shelf-w
   wide and snaps to the start; the gap is the grid's. A shelf keeps the TILE
   whatever its panel's width, so it never sits inside an .hz-agent-section
   (whose container query would lay the cards out as rows): the panel that
   holds it is a plain card. The card rests FLAT (.hz-card--flat) and lifts with
   a shadow on hover only, so the shelf's bleed — the room the atom keeps for
   a card's shadow — is a hairline where nothing hovers (touch: a band of dead
   space under the tiles otherwise), and the md shadow's room, plus the lift,
   where a fine pointer can hover. */
.hz-agent-grid--shelf {
  display: flex;
  gap: var(--hz-agentcard-grid-gap);
  scroll-snap-type: x proximity;
  --hz-shelf-bleed-top: var(--hz-space-1);
  --hz-shelf-bleed-bottom: var(--hz-space-1);
}
@media (hover: hover) and (pointer: fine) {
  .hz-agent-grid--shelf {
    --hz-shelf-bleed-top: calc(var(--hz-shadow-md-bleed-top) - var(--hz-agentcard-hover-lift));
    --hz-shelf-bleed-bottom: var(--hz-shadow-md-bleed-bottom);
  }
}
.hz-agent-grid--shelf > .hz-agent-card {
  flex: 0 0 var(--hz-agentcard-shelf-w);
  width: var(--hz-agentcard-shelf-w);
  scroll-snap-align: start;
}


/* ── Card — the TILE composition ──────────────────────────────────────── */
.hz-agent-card {
  box-sizing: border-box;
  padding: var(--hz-agentcard-pad);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--hz-agentcard-gap);
  min-width: 0;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--hz-dur-fast) var(--hz-ease),
              transform    var(--hz-dur-fast) var(--hz-ease),
              box-shadow   var(--hz-dur-fast) var(--hz-ease);
}
/* NO light-theme fork. The atom already describes this card in both themes —
   a raised surface with a hairline — and the tile used to override light with a
   soft-grey chip (--hz-surface-hover) and `border-color: transparent`.
   That shipped as an invisible card:

     ground   Agents page  #F3F4F8 (--hz-surface-panel-store)
     fill     chip         #F1F1F1 (--hz-surface-hover)
     contrast              1.028:1 — with no edge left to carry it

   The mistake was reading the DARK tile as fill-defined. It is not: its fill
   sits at 1.040:1 on its own canvas, and what separates it is the hairline.
   The light fork kept the (weaker) idea and threw away the part doing the work.
   So the card is the atom on both grounds it has to sit on — the Agents page's
   tinted canvas and the home screen's white — and `verify:store-search` now
   measures that separation rather than trusting it. */
@media (hover: hover) and (pointer: fine) {
  .hz-agent-card:hover {
    border-color: var(--hz-brand-border);
    transform: translateY(var(--hz-agentcard-hover-lift));
    box-shadow: var(--hz-shadow-md);
  }
}
/* The link form (HzAgentCard opts.href): a card, not a text link. */
a.hz-agent-card { color: inherit; text-decoration: none; }
.hz-agent-card:active { transform: scale(var(--hz-agentcard-press-scale)); }
.hz-agent-card:focus-visible {
  outline: var(--hz-agentcard-focus-width) solid var(--hz-agentcard-focus-color);
  outline-offset: var(--hz-agentcard-focus-offset);
}

/* The icon. A SHARE of the tile (not a fixed size) so it stays optically
   constant as the grid reflows, clamped so it never gets silly at either end. */
.hz-agent-card-av {
  width: var(--hz-agentcard-av-ratio);
  min-width: var(--hz-agentcard-av-min);
  max-width: var(--hz-agentcard-av-max);
  height: auto;
  aspect-ratio: 1;
  margin: 0 auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--hz-agentcard-av-radius);
  font-size: var(--hz-agentcard-av-font-size);
  line-height: 1;
  overflow: hidden;
  box-shadow: var(--hz-shadow-sm);
}
.hz-agent-card-av .av-img { width: 100%; height: 100%; object-fit: cover; }

/* Top-packed, never centred or bottom-anchored. Grid items stretch to the
   tallest tile in the grid, so free space has to land somewhere: never above
   the name, where it lifts one card's name off the line its neighbours' names
   sit on. It lands between the description and the price instead (the copy
   grows to fill the tile, the price is pushed to its foot — see below). */
.hz-agent-card-copy {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--hz-space-1);
  align-items: center;
}

/* The name, WHOLE — never ellipsised. It used to be one line with an
   ellipsis, on the theory that a scanned list should not spend a second line
   on a name. Localized names broke that: «Репетитор по английскому» became
   «Репетитор по англий…», and five tutors in a row read as the same card —
   the one word that told them apart was the one cut off. A name is what a
   person picks by, so the card makes room for it: it wraps at word breaks,
   and the tile grid already equalises a row's heights (a row list scrolls).

   The same recipe as the description below, for the same reasons:
   `overflow-wrap: anywhere` so one unbreakable token (a long compound, a
   handle-like name) wraps instead of widening the card past its column — the
   copy is `min-width: 0` — and NO `text-wrap: balance | pretty`, which WebKit
   balances over overflow-wrap's in-word opportunities, cutting ordinary words
   in half on iOS. Android draws the same (core/ui AgentCard.kt: no maxLines). */
.hz-agent-card-name {
  width: 100%;
  min-width: 0;
  font-size: var(--hz-agentcard-name-font-size);
  font-weight: var(--hz-agentcard-name-weight);
  color: var(--hz-agentcard-name-color);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/* The tags row — the Catalog's two words about a card, under the name: the
   type chip ("Model" / "Agent", drawn only where a list MIXES the two) and the
   outcome badge ("Everyday tasks", "Realistic video"). Each is the pill atom
   at its compact size, so ink and fill are the atom's; this is layout only.
   Centred on a tile, start-aligned on a row (below). A long badge wraps as a
   whole pill onto the next line rather than breaking inside its own words;
   one that could not fit even alone is ellipsised, never widening the card. */
.hz-agent-card-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--hz-agentcard-tags-gap);
  max-width: 100%;
  min-width: 0;
}
.hz-agent-card-tags .hz-pill {
  max-width: 100%;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;   /* so the ellipsis applies to the pill's own text */
}

.hz-agent-card-tags .hz-agent-card-badge { color: var(--hz-agentcard-badge-color); }

/* ONE meta line: what the agent does, plus a price where the surface passes
   one. Two meta lines is the split this component replaced — the tile said one
   thing and the row said another, and they drifted. */
.hz-agent-card-meta {
  width: 100%;
  min-width: 0;
  display: flex;
  /* A COLUMN on a tile: the description, then the price under it. Left to wrap,
     the pill rode beside a short description and dropped below a long one, so
     two tiles side by side disagreed about where the price lives for no reason
     the user can see. Stacking makes every tile the same object — avatar, name,
     description, price — and the grid's equal rows absorb the line. */
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  /* Grows to the foot of the tile, so the price below can be pinned there. */
  flex: 1 1 auto;
  gap: var(--hz-agentcard-meta-gap);
  min-height: var(--hz-agentcard-meta-min-h);
  font-size: var(--hz-agentcard-meta-font-size);
  font-weight: var(--hz-agentcard-meta-weight);
  color: var(--hz-agentcard-meta-color);
  line-height: 1.2;
}
/* The agent's own tagline (utils/agent-card.js falls back to the media-type
   label when it has none) — ALWAYS shown in full, never clamped or ellipsised,
   in both compositions.

   It used to be clamped (two lines on a tile, one on a row), and that cut real
   copy mid-thought: «Получай столько, сколько стоишь · Закрывай каждую…» on a
   tile, and five of seven rows on a 390px phone. A tagline is the agent's
   SHORT description — authored to be read whole, and short by contract (the
   repo's own agents are held to a length budget in tests/agents/index.test.js)
   — so the card makes room for it rather than cutting it. Height is cheap
   here: the tile grid already equalises its rows, and a row list scrolls.

   `overflow-wrap: anywhere` so one unbreakable token (a URL, a long compound)
   wraps instead of pushing the card wider than its column. Deliberately NO
   `text-wrap: balance | pretty` alongside it: WebKit balances over the
   in-word break opportunities overflow-wrap creates, so on iOS a balanced
   tagline gets ordinary words cut in half (scripts/verify-course-home.js
   guards exactly that pair). Separators are kept off the start of a line by
   the builder instead (utils/agent-card.js, typeset()). */
.hz-agent-card-type {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* Stars price — the only number on the card, so it is a quiet pill rather than
   a second voice. Tabular figures keep the column of prices from jittering
   between 1, 9 and 10.

   On a TILE it is pinned to the foot of the card (`margin-top: auto` inside a
   meta that fills the copy). Descriptions are shown whole, so they run one,
   two or three lines; a price that followed the description would float at a
   different height in every tile of a row. Pinned, the prices across a row sit
   on one line, where they can be compared. */
.hz-agent-card-price {
  flex: none;
  margin-top: auto;
  display: inline-flex;
  align-items: baseline;
  padding: var(--hz-agentcard-price-pad);
  border-radius: var(--hz-agentcard-price-radius);
  background: var(--hz-agentcard-price-bg);
  color: var(--hz-agentcard-price-color);
  font-size: var(--hz-agentcard-price-font-size);
  font-weight: var(--hz-agentcard-price-weight);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}
.hz-agent-card-price-num  { color: var(--hz-agentcard-price-num-color); font-weight: var(--hz-weight-bold); }
.hz-agent-card-price-star { color: var(--hz-agentcard-price-star-color); margin-inline-start: 2px; line-height: 1; }
.hz-agent-card-price-unit { margin-inline-start: var(--hz-agentcard-price-unit-gap); }

/* The chevron belongs to the ROW composition only: a centred launcher tile
   reads as tappable without one, while a row in a divider list needs to say
   where it goes. */
.hz-agent-card-arrow { display: none; }
.hz-agent-card-arrow svg { display: block; width: 100%; height: 100%; }


/* ── Card — the ROW composition ───────────────────────────────────────────
 * Same card, same builder, same markup: only the register moves. 600px is the
 * width at which three name-safe columns stop fitting. */
@container hz-agent-section (max-width: 600px) {
  .hz-agent-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
  }
  .hz-agent-card {
    display: grid;
    grid-template-columns: var(--hz-agentcard-av-size-dense) minmax(0, 1fr) auto;
    align-items: center;
    width: 100%;
    min-height: var(--hz-agentcard-row-min-h);
    aspect-ratio: auto;
    gap: var(--hz-agentcard-gap-dense);
    padding: var(--hz-agentcard-pad-dense) 0;
    text-align: start;
    /* The list is the surface here; the row is a line in it. */
    background: transparent;
    border: none;
    border-bottom: var(--hz-agentcard-row-divider);
    border-radius: 0;
    box-shadow: none;
  }
  .hz-agent-card:last-child { border-bottom-color: transparent; }
  /* A row must not lift: a list of rows that lift is a list that tears. */
  .hz-agent-card:active { transform: none; }
  .hz-agent-card-av {
    width:     var(--hz-agentcard-av-size-dense);
    min-width: var(--hz-agentcard-av-size-dense);
    max-width: var(--hz-agentcard-av-size-dense);
    height:    var(--hz-agentcard-av-size-dense);
    aspect-ratio: auto;
    margin: 0;
    /* No radius here: an avatar is the same circle at every size
       (--hz-radius-avatar, via --hz-agentcard-av-radius on the base rule). */
    font-size: var(--hz-agentcard-av-font-size-dense);
  }
  .hz-agent-card-copy {
    width: auto;
    margin-top: 0;
    align-items: flex-start;
  }
  .hz-agent-card-name { font-size: var(--hz-agentcard-name-font-size-dense); line-height: 1.2; }
  /* The tags line up on the copy's left edge, like the pills below them. */
  .hz-agent-card-tags { justify-content: flex-start; }
  .hz-agent-card-meta {
    /* The same stack as the tile — name, description, price — left-aligned.
       The description gets the copy's FULL width and wraps as far as it needs.

       It used to share one line with the price and ellipsise beside it. That
       left the description whatever the pill did not take — measured at 320px
       with the widest Russian unit, 74px, about a dozen characters — so on a
       phone almost every tagline was cut. Un-clamping it in that slot would
       only have traded the ellipsis for a five-line sliver. Stacked, it reads
       at the copy's full width (two lines at most for the longest tagline on
       a 320px phone), and the name keeps every pixel it had: the price still
       never shares the name's line or becomes a column beside the chevron
       (which would cost the NAME 118px at 320px). The pills line up on the
       copy's left edge, so a column of prices can still be compared down the
       list. */
    flex: none;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: var(--hz-agentcard-meta-gap-dense);
    font-size: var(--hz-agentcard-meta-font-size-dense);
  }
  /* No foot to pin to: the row has no fixed height. */
  .hz-agent-card-price { margin-top: 0; }
  .hz-agent-card-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width:  var(--hz-agentcard-arrow-size);
    height: var(--hz-agentcard-arrow-size);
    border-radius: var(--hz-radius-pill);
    background: var(--hz-agentcard-arrow-bg);
    color: var(--hz-agentcard-arrow-color);
  }
}
@container hz-agent-section (max-width: 600px) {
  @media (hover: hover) and (pointer: fine) {
    /* A row highlights in place; it never lifts off the list. */
    .hz-agent-card:hover {
      transform: none;
      box-shadow: none;
      border-color: transparent;
      border-bottom: var(--hz-agentcard-row-divider);
      background: var(--hz-surface-hover);
    }
  }
}


/* ── Narrow viewport, no container queries ────────────────────────────────
 * Safari < 16 and Firefox < 110 never run the block above, so a phone would
 * get one full-width tile per line. Two columns is the graceful floor: the
 * same card, simply tiled, and nothing else in the file has to be repeated. */
@media (max-width: 640px) {
  .hz-agent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hz-agent-section-hdr { margin-bottom: var(--hz-agentsection-hdr-offset-dense); }
}


/* ── Touch targets ────────────────────────────────────────────────────────
 * A coarse pointer needs the design-system 44px minimum (--hz-tap-min; Apple
 * HIG / WCAG 2.5.8). The card itself clears it everywhere (the row's floor is
 * 64px, the tile's avatar alone is 48px); this is for the head's control. */
@media (pointer: coarse) {
  .hz-agent-section-action { min-height: var(--hz-tap-min); }
}


/* ── Reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .hz-agent-card { transition: none; }
  .hz-agent-card:hover  { transform: none; }
  .hz-agent-card:active { transform: none; }
  .hz-agent-section-action { transition: none; }
}
