/* static/css/results_wide.css — Comfortable density on wide screens.
 *
 * Comfortable stays ONE card per row at every width and always shows everything (no clamp,
 * no "Show all", no Full metadata toggle). Below 1600px it is exactly the card in
 * results.css; from 1600px up each result card reads as ONE item in three zones:
 *
 *     photo 240px  |  text, never wider than 560px  |  keywords, the rest (at least 440px)
 *
 * separated by space only (40px), no dividers, no coloured edge. Rules: DESIGN.md (spacing
 * 4/8/12/16/24/32/40, type 12/13/15/20, weights 400/600, no uppercase tracked labels, one
 * border per group, 4.5:1 text, 32px targets with a 2px focus ring).
 *
 * Two gates. The @media block is page-level (padding, colour tokens) and makes each card's
 * wrapper a size container; the card layout itself is an @container query on that wrapper,
 * so a sidebar dragged wide at 1600px falls back to the plain card instead of crushing the
 * zones. Below 1600px no rule here matches anything, not even the container. The list is NOT
 * width-capped: the export and Edit-all bars above it are full width, and a centred, capped
 * list visibly stepped inside them ("escaping the frame").
 *
 * Same contract as results.css: every rule is scoped under [data-density="comfortable"], so
 * without results_density.js (or this file's link tag) the page is unchanged (C3). No node is
 * moved and there is still one .kw-area per card (C8): .rbody becomes a two-column grid around
 * its own children, .ractions dissolves (display: contents) so its buttons sit in the photo
 * zone's grid, and the field labels are re-ordered after their text with CSS order. Only
 * .rcard-ok cards change; error, late and queued cards keep the plain card.
 */

@media (min-width: 1600px) {
  #p-images:has(#img-list[data-density="comfortable"]),
  #p-video:has(#vid-list[data-density="comfortable"]) { padding-inline: 40px; }
  :is(#img-list, #vid-list)[data-density="comfortable"] > * {
    container-type: inline-size;
    container-name: rc;
    min-width: 0;
  }
  /* Colour tokens: the app's own palette (app.css :root and [data-theme="light"]), so the wide
     card reads as the same product as the card below 1600px: the --s1 surface, the tan
     --border, --text / --dim, the gold keyword chips with their hairline border, and the gold
     focus ring. The one value that is not an app token is the light meta colour: --muted is
     4.0:1 on --s1, so the meta text uses the same warm hue darkened to 4.9:1. Every text colour
     holds 4.5:1 on --rw-card (tests/test_results_layout.py measures it). */
  :is(#img-list, #vid-list)[data-density="comfortable"] {
    --rw-card: var(--s1);
    --rw-line: var(--border);
    --rw-title: var(--text);
    --rw-body: var(--text);
    --rw-file: var(--dim);
    --rw-meta: var(--muted);
    --rw-chip: rgba(var(--gold-rgb), .07);
    --rw-chip-high: var(--gold-bg);
    --rw-chip-low: rgba(var(--gold-rgb), .035);
    --rw-chip-hover: rgba(var(--gold-rgb), .15);
    --rw-chip-line: rgba(var(--gold-rgb), .28);
    --rw-chip-fg: #e6dabf;
    --rw-hover: var(--s2);
    --rw-ring: var(--gold);
  }
  [data-theme="light"] :is(#img-list, #vid-list)[data-density="comfortable"] {
    --rw-meta: #736955;
    --rw-chip: #f8eccf;
    --rw-chip-high: #fbf3dc;
    --rw-chip-low: #fdf7e6;
    --rw-chip-hover: #f3e2bb;
    --rw-chip-line: rgba(176, 125, 0, .3);
    --rw-chip-fg: #6f560f;
  }
}

/* 1200 = 240 photo + 40 + a text column + 40 + the 440px keyword minimum + 48 padding. At a
   1600px screen with the default 272px sidebar the wrapper is ~1239px, so this switches on
   with it. */
@container rc (min-width: 1200px) {
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard { margin-bottom: 24px; }

  /* ── The card: one surface, one border, zones separated by space ─────────────────────── */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok,
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok:hover {
    gap: 40px;
    padding: 24px;
    align-items: flex-start;
    background: var(--rw-card);
    border: 1px solid var(--rw-line);
    border-radius: 12px;
    box-shadow: none;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok :is(button, .btn, .kchip, .krm):focus-visible {
    outline: 2px solid var(--rw-ring);
    outline-offset: 2px;
  }

  /* ── Photo zone: picture; name + buttons; swatches (real ones only); score ──────────── */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok > .rcard-head {
    width: 240px;
    min-width: 0;
    padding: 0;
    gap: 12px;
    align-self: flex-start;
    background: none;
    border: 0;
  }
  /* One fixed 4:3 frame (240 x 180) for every photo, the picture fitted inside it, never
     cropped, on a quiet mat. The photo zone sets a card's height on a big screen, so with the
     natural ratio a portrait stood 240px tall beside a 160px landscape and the list read as
     random card heights (owner, 2026-10-15). 4:3 is the compromise: a 3:2 landscape loses only
     a thin band of mat, a portrait sits centred at 120px wide. No max-height: the frame is
     the width plus the ratio, so the card can never grow past it. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rthumb {
    align-self: center;
    width: 100%;
    height: auto;
    max-width: none;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    border: 0;
    border-radius: 8px;
    background: var(--rw-hover);
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rthumb-ph {
    width: 100%;
    max-width: none;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border: 0;
    border-radius: 8px;
  }
  /* Row 1 is the filename with Regenerate + Share on the right; everything else (swatches,
     then the score) takes a full row of its own in source order, centred under the picture.
     Explicit rows only, so a hidden item leaves no gap. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rfi {
    flex: none;
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px 4px;
    align-items: center;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rfile {
    grid-row: 1;
    grid-column: 1;
    font-family: var(--mono, ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace);
    font-size: 13px;
    line-height: 1.4;
    color: var(--rw-file);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .ractions { display: contents; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok :is(.color-info, .rbadges),
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .ractions > * { grid-column: 1 / -1; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok :is(.color-info, .rbadges) { justify-self: center; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .ractions .regen-btn { grid-row: 1; grid-column: 2; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .ractions .sharecard-btn { grid-row: 1; grid-column: 3; }
  /* Ghost icon buttons: no border, a quiet fill on hover. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .ractions :is(.regen-btn, .sharecard-btn) {
    width: 36px;
    height: 36px;
    border: 0;
    background: none;
    color: var(--rw-file);
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .ractions :is(.regen-btn, .sharecard-btn):hover:not(:disabled) {
    background: var(--rw-hover);
    color: var(--rw-title);
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .ractions > .btn:not(.regen-btn, .sharecard-btn) {
    height: 32px;
    justify-content: center;
    font-size: 13px;
    font-weight: 400;
  }
  /* Restored results carry grey placeholder swatches: the row only shows with real colours. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .color-info { margin: 0; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .color-info:not(:has(.color-swatch:not(.color-swatch-ph))) { display: none; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .cp-label { display: none; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .color-palette { justify-content: center; flex-wrap: nowrap; gap: 4px; }

  /* Score + the Distinct / Overlap pill, centred under the picture. Done / count / Optimizing stay hidden
     (results.css), and so does the row when it holds neither (Money Score only scores live
     runs, so a restored list has no score). */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbadges {
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbadges:has(.ms-badge[data-score], .bx-badge) { display: flex; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbadges .ms-badge[data-score] {
    display: inline-flex;
    align-items: baseline;
    height: auto;
    padding: 0;
    border: 0;
    background: none;
    opacity: 1;
    font-size: 0;
    letter-spacing: 0;
    text-transform: none;
    line-height: 1;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbadges .ms-badge[data-score]::before {
    content: attr(data-score);
    font-size: 20px;
    font-weight: 600;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbadges .ms-badge[data-score]::after {
    content: "/100";
    font-size: 12px;
    font-weight: 400;
    color: var(--rw-meta);
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbadges .ms-badge-high { color: var(--gold); }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbadges .ms-badge-mid { color: var(--rw-title); }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbadges .ms-badge-low { color: var(--rw-file); }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok :is(.rbadges .bx-badge, .agency-row > *) {
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
  }

  /* ── .rbody: the text zone and the keyword zone ─────────────────────────────────────── */
  /* The text items auto-place down column 1; the keyword field spans every row of column 2.
     The trailing 1fr row takes any spare height, so the text never spreads apart. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok > .rbody {
    padding: 0;
    display: grid;
    grid-template-columns: minmax(0, 560px) minmax(440px, 1fr);
    grid-template-rows: repeat(12, auto) 1fr;
    column-gap: 40px;
    align-items: start;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok > .rbody > * {
    grid-column: 1;
    min-width: 0;
    margin: 0 0 12px;
    padding: 0;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok > .rbody > :is(.agency-check, .video-compliance, .vmeta-badges) { margin-bottom: 8px; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok > .rbody > :is(.agency-check, .video-compliance, .vmeta-badges):empty { display: none; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .agency-row { margin: 0; gap: 8px; }

  /* Title and description: no uppercase label above; the counter follows the text, quiet.
     The word "Title" / "Description" stays in the DOM (font-size 0) for screen readers.
     The title's counter shows on hover or focus, and always once card_limits.js colours it
     (near or over the agency's limit: its inline colour is then no longer var(--muted)). */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fg-field:has(> .fv) { display: flex; flex-direction: column; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fg-field:has(> .fv[data-field="title"]) {
    flex-direction: row;
    align-items: baseline;
    gap: 12px;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fg-field:has(> .fv) > .fl-field {
    order: 1;
    margin: 4px 0 0;
    align-self: flex-end;
    font-size: 0;
    letter-spacing: 0;
    text-transform: none;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fg-field:has(> .fv[data-field="title"]) > .fl-field {
    flex: none;
    margin: 0;
    align-self: baseline;
    opacity: 0;
    transition: opacity .15s;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fg-field:has(> .fv[data-field="title"]):is(:hover, :focus-within) > .fl-field,
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fg-field:has(> .fv[data-field="title"]) > .fl-field:has(.char-cnt:not([style*="--muted"])) { opacity: 1; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fl-field :is(.char-cnt, .kw-cnt-lbl, .kw-char-cnt) {
    font-size: 12px;
    font-weight: 400;
    white-space: nowrap;
  }
  /* The counters' default inline colour is var(--muted); the meta token holds 4.5:1 on white.
     A warning colour (amber / red from card_limits.js) is left alone. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fl-field :is(.char-cnt, .kw-cnt-lbl, .kw-char-cnt)[style*="--muted"] { color: var(--rw-meta) !important; }

  /* The editable text has no box of its own; hover tints it, focus rings it. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbody .fv {
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbody .fv:hover {
    background: var(--rw-hover);
    box-shadow: 0 0 0 4px var(--rw-hover);
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .rbody .fv:focus {
    background: none;
    box-shadow: none;
    outline: 2px solid var(--rw-ring);
    outline-offset: 4px;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fv[data-field="title"] {
    flex: 1 1 auto;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--rw-title);
  }
  /* 60ch keeps a line at 75 characters or fewer: the full 560px measured up to 82 in the app
     font (15px Segoe UI averages ~6.5px a character against ch's 8px). The cap is on the FIELD
     (at the text's 15px, so ch matches), so its right-aligned counter ends where the text does. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fg-field:has(> .fv[data-field="description"]) {
    max-width: 60ch;
    font-size: 15px;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fv[data-field="description"] {
    font-size: 15px;
    line-height: 1.6;
    color: var(--rw-body);
  }

  /* ── Keyword zone ─────────────────────────────────────────────────────────────────────── */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok > .rbody > .fg-field:has(> .kw-area) {
    grid-column: 2;
    grid-row: 1 / -1;
    margin: 0;
  }
  /* One line, left-aligned: "Keywords", the counts, Chips | Text, ⇅ Value, Copy. The row's gap
     and the toggle's margin-left:auto / gap are inline styles in the card markup, hence the
     !important. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .fg-field:has(> .kw-area) > .fl-field {
    gap: 12px !important;
    flex-wrap: wrap;
    row-gap: 8px;
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0;
    text-transform: none;
    color: var(--rw-title);
  }
  /* "(48 / 50) · 477 chars" reads as one quiet meta run. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-char-cnt { margin-left: -8px; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-char-cnt::before { content: "· "; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-view-tog {
    margin-left: 0 !important;
    gap: 0 !important;
    height: 32px;
    border: 1px solid var(--rw-line);
    border-radius: 8px;
    overflow: hidden;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-tog-btn {
    height: 100%;
    padding: 0 12px;
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--rw-file);
    font-size: 13px;
    font-weight: 400;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-tog-btn:hover { background: var(--rw-hover); color: var(--rw-title); }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-tog-btn.active { background: var(--gold-bg); color: var(--rw-chip-fg); font-weight: 600; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok :is(.kw-copy-btn, .ms-sort-btn) {
    height: 32px;
    padding: 0 12px !important;
    border: 1px solid var(--rw-line);
    border-radius: 8px;
    background: none;
    color: var(--rw-body);
    font-size: 13px !important;
    font-weight: 400;
  }
    /* Hover as the app's ghost buttons do: the border turns gold. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok :is(.kw-copy-btn, .ms-sort-btn):hover { border-color: var(--gold); color: var(--rw-chip-fg); }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .ms-sort-btn.ms-sorted { color: var(--rw-chip-fg); border-color: var(--gold); background: var(--gold-bg); }

  /* Chips: the app's golden chip (fill, hairline gold border, deep-gold text), squarer and
     roomier. Money Score's three value shades stay, softly. The ×
     shows on hover or keyboard focus and stays in the DOM (and the tab order) otherwise. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-area,
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-area:hover {
    gap: 8px;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kchip {
    max-width: 100%;
    gap: 4px;
    padding: 4px 12px;
    border: 1px solid var(--rw-chip-line);
    border-radius: 6px;
    background: var(--rw-chip);
    color: var(--rw-chip-fg);
    font-size: 13px;
    font-weight: 400;
    line-height: 16px;
    overflow-wrap: anywhere;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kchip-ms-high { background: var(--rw-chip-high); }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kchip-ms-low { background: var(--rw-chip-low); color: var(--rw-chip-fg); }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kchip:hover {
    background: var(--rw-chip-hover);
    border-color: var(--gold);
    transform: none;
  }
  /* Laid over the chip's right padding, so a hidden × leaves no dead space after the label
     and showing it never re-flows the chips. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kchip .krm {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    padding: 0;
    font-size: 12px;
    line-height: 1;
    color: inherit;
    opacity: 0;
    transition: opacity .15s;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kchip:is(:hover, :focus-visible, :focus-within) .krm { opacity: .7; }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kchip .krm:hover { opacity: 1; color: var(--err); }
  /* "Add keyword…" is part of the chip flow, with no border until it is focused. */
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kinput {
    min-width: 120px;
    padding: 4px 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 13px;
    line-height: 16px;
    color: var(--rw-title);
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kinput::placeholder { color: var(--rw-meta); }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kinput:focus {
    border-color: var(--rw-line);
    outline: 2px solid var(--rw-ring);
    outline-offset: 2px;
  }
  :is(#img-list, #vid-list)[data-density="comfortable"] .rcard-ok .kw-textarea { font-size: 13px; }
}
