/* Short path from discovery to a reference-aware image agent. */
.card-image-link, .card-body, .popular-case-link { display: block; }
.popular-case-link { width: 100%; height: 100%; }
.popular-case-link > img, .popular-case-link > picture, .popular-case-link > picture > img { width: 100%; height: 100%; object-fit: cover; }
.card .overlay-actions, .popular-case .overlay-actions { position: absolute; right: 10px; bottom: 10px; z-index: 5; display: flex; gap: 6px; }
.card .overlay-actions .icon-btn, .popular-case .overlay-actions .icon-btn { width: 36px; height: 36px; border-radius: 50%; background: rgba(24,22,25,.65); color: #fff; border: 1px solid #ffffff35; backdrop-filter: blur(12px); }
.overlay-actions .icon-btn.saved svg { fill: #fff; }
.card .overlay-actions .icon-btn:hover, .popular-case .overlay-actions .icon-btn:hover { background: #242126; }
.card-recreate { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-45%); z-index: 6; padding: 12px 22px; border: 1px solid #ffffff65; border-radius: 999px; color: #fff; background: #252126a6; backdrop-filter: blur(15px); font: 500 17px/1.2 inherit; white-space: nowrap; opacity: 0; visibility: hidden; transition: opacity .2s, transform .2s, visibility .2s; box-shadow: 0 6px 24px #0003; cursor: pointer; }
.card-recreate { font-family: inherit; font-size: 17px; font-weight: 500; line-height: 1.2; }
.card-recreate span { margin-left: 8px; }
.card-img-wrap:hover .card-recreate, .card-img-wrap:focus-within .card-recreate, .popular-case:hover .card-recreate, .popular-case:focus-within .card-recreate { opacity: 1; visibility: visible; transform: translate(-50%,-50%); }
/* Remain in the keyboard tab order, even before the card receives focus. */
.card-recreate { visibility: visible; }
.card-recreate:hover { background: #141114d9; }
.card-recreate:focus-visible, .overlay-actions button:focus-visible { outline: 3px solid #ff9859; outline-offset: 3px; opacity: 1; }
.image-agent-dock { position: fixed; bottom: 22px; left: 0; right: 0; display: flex; justify-content: center; pointer-events: none; z-index: 95; padding: 0 16px; }
.image-agent-dock > a { pointer-events: auto; display: flex; align-items: center; gap: 14px; background: #201c21ed; color: #fff; box-shadow: 0 8px 35px #21152640; border: 1px solid #ffffff30; border-radius: 999px; padding: 15px 22px; max-width: 700px; backdrop-filter: blur(20px); }
.image-agent-dock > a > span:first-child { color: #ffad7a; font-size: 23px; }
.image-agent-dock-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #c6bcc5; font-size: 13px; }
.image-agent { --agent-accent: var(--purple); box-sizing: border-box; width: 100%; padding: 0; color: var(--ink); color-scheme: light; }
.image-agent { margin: auto; }
.image-agent *, .image-agent *::before, .image-agent *::after { box-sizing: border-box; }
.image-agent [hidden] { display: none !important; }
.image-agent button, .image-agent textarea, .image-agent select { font: inherit; }
.image-agent button { cursor: pointer; }
.image-agent button:disabled { opacity: .45; cursor: wait; }
.image-agent :focus-visible { outline: 2px solid var(--purple); outline-offset: 4px; }
.image-agent .agent-rich-prompt:focus-visible { outline: none; }
.agent-shell { padding: 24px 0 32px; }
.agent-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.agent-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; color: var(--purple); }
.agent-brand b { color: var(--ink); font-size: 14px; }
.agent-brand > span { font-size: 11px; font-weight: 400; padding-left: 14px; margin-left: 4px; border-left: 1px solid var(--border); color: var(--ink-3); }
.agent-intro { text-align: center; padding: 28px 0 18px; }
.agent-eyebrow { color: var(--purple); font-size: 10px; letter-spacing: 2.7px; font-weight: 600; }
.agent-intro h2 { margin: 12px 0; font-size: clamp(28px,3.4vw,42px); font-weight: 500; line-height: 1.3; letter-spacing: -.9px; color: var(--ink); }
.agent-intro p { margin: 0; font-size: 14px; color: var(--ink-2); line-height: 1.7; }
.agent-mode-badge { display: flex; align-items: center; justify-content: center; gap: 9px; width: fit-content; margin: 0 auto 24px; padding: 9px 23px; border: 1px solid var(--purple-200); color: var(--purple-dark); border-radius: 999px; font-size: 14px; background: var(--purple-50); }
.agent-composer { padding: 0; background: var(--card); border: 1px solid var(--border); border-radius: 25px; box-shadow: 0 18px 55px rgba(47,35,76,.09); overflow: hidden; }
.agent-composer:focus-within { border-color: var(--purple-light); box-shadow: 0 0 0 3px var(--purple-100), 0 18px 55px rgba(47,35,76,.09); }
.agent-composer-body { display: flex; align-items: flex-start; gap: 25px; padding: 25px 25px 12px; }
.agent-references { width: 108px; flex: 0 0 108px; }
.agent-label { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-2); line-height: 1.4; margin-bottom: 12px; }
.agent-label > span { color: var(--ink-3); font-size: 10px; }
.agent-writing { position: relative; flex: 1; min-width: 0; }
.agent-rich-prompt { display: block; width: 100%; height: 205px; resize: vertical; min-height: 140px; max-height: 380px; color: var(--ink); background: transparent; border: 0; padding: 0 24px 0 0; font-size: 17px; line-height: 1.85; outline: none; box-shadow: none; scrollbar-color: var(--purple-200) transparent; }
.agent-rich-prompt:empty::before { content: attr(data-placeholder); color: var(--ink-3); pointer-events: none; }
.agent-prompt-field { position: relative; min-width: 0; }
.agent-inline-reference { display: inline-flex; align-items: center; gap: 7px; padding: 0 8px 0 5px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--ink-2); white-space: nowrap; line-height: 29px; }
.agent-inline-reference img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }
.agent-clear { position: absolute; top: -5px; right: -4px; padding: 3px 8px; background: transparent; border: none; color: var(--ink-3); font-size: 21px !important; }
.agent-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 15px 24px 22px; }
.agent-toolbar-spacer { flex: 1; }
.agent-chip { display: flex; flex-direction: column; gap: 2px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.agent-control-label { color: var(--ink-3); font-size: 10px; }
.agent-chip select { width: auto; max-width: 170px; font-size: 13px; color: var(--ink); border: none; background: transparent; padding: 0 14px 0 0; cursor: pointer; }
.agent-chip select option { background: var(--card); color: var(--ink); }
.agent-send { width: 51px; height: 51px; display: grid; place-items: center; flex: 0 0 auto; border: none; border-radius: 50%; background: var(--agent-accent); color: #fff; margin-left: 4px; transition: background .15s, transform .15s; }
.agent-send:hover { background: var(--purple-dark); transform: translateY(-2px); }
.agent-stop { background: var(--purple-50); border: 1px solid var(--purple-200); border-radius: 999px; color: var(--purple-dark); padding: 9px 12px; }
.agent-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 15px; margin: 12px 4px 0; font-size: 11px; color: var(--ink-2); }
.agent-meta p { margin: 0; line-height: 1.65; }
.agent-meta .is-error { color: #b45309; }
#agent-count { white-space: nowrap; color: var(--ink-3); }
.agent-suggestions { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; margin-top: 25px; }
.agent-suggestions button { background: var(--card); color: var(--ink-2); border: 1px solid var(--border); border-radius: 999px; padding: 10px 16px; font-size: 12px; }
.agent-suggestions button span { margin-left: 13px; color: var(--ink-3); }
.agent-suggestions button:hover { border-color: var(--purple-light); color: var(--purple); background: var(--purple-50); }
.agent-original { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px; color: var(--ink-2); font-size: 12px; }
.agent-original summary { cursor: pointer; }
.agent-original p { margin: 12px 0 6px; color: var(--ink-3); }
.agent-original pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 160px; overflow: auto; font: 12px/1.8 inherit; background: var(--bg); padding: 14px; border-radius: 10px; }
.agent-conversation { margin-bottom: 20px; }
.agent-turn { padding: 18px; background: var(--card); border: 1px solid var(--border); border-radius: 18px; margin-bottom: 15px; }
.agent-user-brief { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 90px; overflow: auto; font-size: 12px; color: var(--ink-2); }
.agent-reply { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.8; }
.agent-output-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.agent-output-grid figure { margin: 0; }
.agent-output-grid img { width: 100%; max-height: 320px; object-fit: contain; border-radius: 12px; }
.agent-output-grid figcaption { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 12px; }
.agent-output-grid button, .agent-output-grid a { color: var(--purple); border: none; background: transparent; padding: 5px 0; }
@media (hover: none), (pointer: coarse) {
  .card-recreate { opacity: 1; transform: translate(-50%,-50%); padding: 10px 17px; font-size: 14px; }
}
@media (max-width: 640px) {
  .agent-shell { padding: 18px 16px 24px; }
  .agent-brand > span, .agent-eyebrow { display: none; }
  .agent-intro { padding: 22px 0 18px; }
  .agent-intro h2 { font-size: 25px; letter-spacing: -.4px; }
  .agent-intro p { font-size: 12px; }
  .agent-composer-body { flex-direction: column; gap: 16px; padding: 18px 16px 8px; }
  .agent-references > .agent-label { width: 100%; margin-bottom: 0; }
  .agent-writing { width: 100%; }
  .agent-rich-prompt { height: 165px; font-size: 16px; line-height: 1.7; }
  .agent-toolbar { gap: 7px; padding: 14px 14px 16px; }
  .agent-toolbar-spacer { display: none; }
  .agent-chip { padding: 6px 8px; min-width: 0; }
  .agent-chip select { font-size: 12px; max-width: 100px; }
  .agent-toolbar .agent-chip:first-child { flex: 1; }
  .agent-send { width: 42px; height: 42px; margin-left: auto; }
  .agent-meta { font-size: 10px; gap: 8px; }
  .agent-suggestions { gap: 7px; margin-top: 18px; }
  .agent-suggestions button { padding: 8px 12px; font-size: 11px; }
  .agent-suggestions button span { display: none; }
  .image-agent-dock { bottom: max(14px,env(safe-area-inset-bottom)); }
  .image-agent-dock > a { max-width: 100%; padding: 12px 17px; gap: 10px; }
  .image-agent-dock > a > span:nth-child(2) { white-space: nowrap; font-size: 13px; }
  .image-agent-dock-hint { max-width: 180px; font-size: 11px; }
  .agent-output-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .card-recreate, .agent-send { transition: none; } }

/* Standalone detail page: ordinary document scrolling, no overlay or scroll lock. */
.image-agent-body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); color-scheme: light; }
.image-agent-body a { text-decoration: none; }
.agent-page, .agent-related { width: min(1160px, calc(100% - 64px)); margin: 0 auto; }
.agent-page-nav { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 28px 0 12px; }
.agent-back { color: var(--ink-2); font-size: 13px; padding: 10px 0; }
.agent-back:hover { color: var(--purple); }
.agent-page-title { margin: 22px 0 0; text-align: center; font-size: 18px; font-weight: 500; color: var(--ink-2); }
.agent-source { display: grid; grid-template-columns: 180px minmax(0,1fr); gap: 28px; border-top: 1px solid var(--border); padding: 32px 0; margin: 0; }
.agent-source-image img { width: 100%; height: auto; max-height: 240px; object-fit: contain; border-radius: 14px; display: block; }
.agent-source-info { min-width: 0; }
.agent-source-info h1 { margin: 0 0 12px; font-size: 23px; line-height: 1.5; overflow-wrap: anywhere; color: var(--ink); }
.agent-source-meta { color: var(--ink-2); font-size: 13px; }
.agent-source-actions { display: flex; gap: 10px; margin-top: 18px; }
.agent-source-actions button { font: inherit; font-size: 12px; color: var(--ink-2); border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; background: var(--card); cursor: pointer; }
.agent-source-actions button.saved { color: var(--purple); border-color: var(--purple); }
.agent-source .agent-original { margin-top: 20px; }
.agent-source-tags { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 18px; }
.agent-source-tags a { color: var(--ink-2); font-size: 12px; }
.agent-source .agent-original pre { font-family: inherit; font-size: 13px; line-height: 1.8; max-height: none; overflow: visible; }
.agent-related { padding: 12px 0 64px; }
.agent-related .section-head h2 { font-size: 22px; color: var(--ink); }
.agent-related .section-head > a { color: var(--purple); font-size: 13px; }
.agent-related .card { background: var(--card); border-color: var(--border); }
.agent-related .card-title { color: var(--ink); }
.agent-related .card-cat { color: var(--ink-2); }
.agent-page a:focus-visible, .agent-source button:focus-visible { outline: 2px solid var(--purple); outline-offset: 4px; }
@media (max-width: 640px) {
  .agent-page, .agent-related { width: calc(100% - 32px); }
  .agent-page-nav { padding: 14px 0 4px; }
  .agent-shell { padding: 12px 0 24px; }
  .agent-source { grid-template-columns: 78px minmax(0,1fr); gap: 16px; padding: 24px 0; }
  .agent-source-info h1 { font-size: 18px; }
  .agent-source-meta { font-size: 11px; }
  .agent-source .agent-original { margin-left: -94px; margin-top: 24px; }
}

.agent-rich-prompt { overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; cursor: text; }
.agent-inline-reference { vertical-align: middle; user-select: all; margin: 0 3px; white-space: nowrap; font-size: .95em; }
.agent-mention-hint { margin: 10px 4px 0; color: var(--ink-2); font-size: 11px; line-height: 1.6; }
.agent-mention-menu { position: fixed; z-index: 10000; box-sizing: border-box; padding: 8px; border: 1px solid var(--border); border-radius: 17px; background: var(--card); box-shadow: var(--shadow-hover); overflow-y: auto; color: var(--ink); font-family: inherit; }
.agent-mention-menu[hidden] { display: none; }
.agent-mention-option { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; margin: 0 0 4px; border: 1px solid transparent; border-radius: 11px; background: var(--bg); color: inherit; font: inherit; font-size: 16px; text-align: left; cursor: pointer; }
.agent-mention-option:last-child { margin-bottom: 0; }
.agent-mention-option:hover, .agent-mention-option[aria-selected=true] { background: var(--purple-50); border-color: var(--border); }
.agent-mention-option img, .agent-mention-create { width: 46px; height: 46px; flex: 0 0 46px; object-fit: cover; border-radius: 8px; }
.agent-mention-create { display: grid; place-items: center; background: var(--card); color: var(--purple); font-size: 30px; }
.agent-meta #agent-count.is-error { color: #b45309; }

/* Reference images float over the text, identical to the AI Image Generator. */
.image-agent .agent-composer-body { position: relative; display: block; }
.image-agent .agent-references { position: absolute; top: 12px; left: 14px; z-index: 6; width: fit-content; max-width: calc(100% - 28px); }
.image-agent .agent-references > .agent-label { display: none; }
.image-agent .agent-ref-list { position: relative; display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; width: fit-content; max-width: 100%; min-width: 88px; min-height: 112px; padding: 12px 12px 6px 6px; overflow-x: auto; scrollbar-width: none; }
.image-agent .agent-ref-list::-webkit-scrollbar { display: none; }
.image-agent .agent-writing { width: 100%; }
.image-agent .agent-rich-prompt { padding-left: 96px; }
.image-agent #agent-prompt-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.image-agent .agent-reference { position: relative; width: 72px; height: 96px; flex: 0 0 auto; aspect-ratio: auto; overflow: visible; border: 1.5px solid var(--border); border-radius: 13px; background: var(--card); }
.image-agent .agent-reference:nth-child(2) { border-color: var(--agent-accent); }
.image-agent .agent-reference-open { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; border-radius: 11px; cursor: grab; }
.image-agent .agent-reference-open img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 11px; }
.image-agent .studio-reference-order { display: none; }
.image-agent .agent-reference:nth-child(2) .studio-reference-order { background: var(--purple); }
.image-agent .studio-reference-remove { top: -8px; right: -8px; z-index: 6; border: 1px solid var(--border); padding: 0; opacity: 0; }
.image-agent .agent-reference:hover .studio-reference-remove, .image-agent .agent-reference:focus-within .studio-reference-remove { opacity: 1; }
.image-agent .agent-add { order: -1; width: 72px; height: 96px; flex: 0 0 auto; display: grid; place-items: center; padding: 0; border: 1px dashed var(--purple-200); border-radius: 13px; background: var(--bg); }
.image-agent .agent-add:hover, .image-agent .agent-add:focus-visible { border-color: var(--agent-accent); background: var(--purple-50); }
.image-agent .studio-upload-plus b { width: 26px; height: 26px; font-size: 18px; background: var(--card); color: var(--purple); box-shadow: none; }
.image-agent .agent-reference.drag-over { border-color: var(--purple); transform: scale(.97); }
.image-agent .agent-composer.drop-active { outline: 2px dashed var(--agent-accent); outline-offset: -5px; background: var(--purple-50); }
@media (hover: hover) and (min-width: 641px) {
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) { display: block; width: 88px; height: 112px; padding: 0; overflow: visible; }
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) .agent-reference { position: absolute; inset: 8px; width: auto; height: auto; box-shadow: 0 4px 14px rgba(47,35,76,.16); }
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) .agent-reference:nth-child(2) { z-index: 4; }
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) .agent-reference:nth-child(3) { z-index: 3; transform: rotate(-5deg) translate(-7px,3px); }
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) .agent-reference:nth-child(4) { z-index: 2; transform: rotate(-9deg) translate(-13px,6px); }
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) .agent-reference:nth-child(n+5) { display: none; }
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) .studio-reference-remove { display: none; }
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) .agent-add { position: absolute; right: -2px; bottom: -2px; z-index: 5; width: 34px; height: 34px; border: 2px solid var(--card); border-radius: 50%; background: var(--card); box-shadow: 0 3px 10px rgba(47,35,76,.16); }
  .image-agent .agent-ref-list.has-refs:not(:hover):not(:focus-within):not(.is-sorting) .studio-upload-plus b { width: auto; height: auto; background: transparent; font-size: 19px; }
}
.agent-refview { width: min(880px, calc(100% - 32px)); max-width: none; max-height: calc(100dvh - 32px); margin: auto; padding: 0; border: 1px solid var(--border); border-radius: 22px; background: var(--card); color: var(--ink); color-scheme: light; }
.agent-refview::backdrop { background: rgba(30,27,46,.3); backdrop-filter: blur(10px); }
.agent-refview .studio-refview-dialog { width: 100%; box-sizing: border-box; background: var(--card); box-shadow: var(--shadow-hover); }
.agent-refview .studio-refview-count { color: var(--ink-2); }
.agent-refview .studio-refview-image { background: var(--bg); }
.agent-refview .studio-refview-delete { background: #fff1f2; color: #be123c; }
.agent-refview .studio-refview-delete:hover { background: #ffe4e6; color: #be123c; }
.agent-refview button { font-family: inherit; cursor: pointer; border: 0; }
.agent-refview .studio-refview-close { background: transparent; color: var(--ink-2); font-size: 28px; }
.agent-refview .studio-refview-close:hover { background: var(--purple-50); color: var(--purple); }
.agent-refview .studio-refview-thumb { border: 2px solid transparent; }
.agent-refview .studio-refview-thumb.active { border-color: var(--purple); }
.agent-refview .studio-refview-thumbs { max-height: calc(100dvh - 220px); overflow-y: auto; padding: 3px; }
.agent-refview .studio-refview-thumb { flex-shrink: 0; }
.agent-refview button:focus-visible { outline: 2px solid var(--purple); outline-offset: 3px; }
@media (max-width: 640px) {
  .image-agent .agent-references { width: 100%; max-width: 100%; }
  .image-agent .agent-ref-list { width: 100%; max-width: 100%; }
  .agent-refview .studio-refview-thumbs { max-width: 100%; max-height: 60px; overflow-x: auto; }
  .image-agent .studio-reference-remove { opacity: 1; }
}
@media (hover: none) { .image-agent .studio-reference-remove { opacity: 1; } }

/* Removed from view: source card, original-prompt details, eyebrow, brand, hints, meta line. */
.agent-source, .agent-original, .agent-eyebrow, .agent-page-nav .agent-brand,
.agent-mention-hint, .agent-meta { display: none !important; }

/* Related grid: cards dissolve into the background with a plain View more entry. */
.agent-related-mask { position: relative; padding-bottom: 64px; }
.agent-related-fade { position: absolute; left: 0; right: 0; bottom: 0; height: 420px; background: linear-gradient(to bottom, rgba(251,250,255,0) 0%, rgba(251,250,255,.65) 45%, var(--bg) 78%); pointer-events: none; }
.agent-related-more { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; background: transparent; border: 0; color: var(--ink); font-size: 14px; font-weight: 600; }
.agent-related-more:hover { color: var(--purple); background: transparent; }

/* Balanced columns for the related grid: even bottoms, no lopsided gap. */
.agent-related .masonry-cols { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; padding: 22px 0 10px; align-items: start; }
.agent-related .masonry-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
@media (max-width: 900px) { .agent-related .masonry-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
