/* 参照（案A。EPC-27）。つくる前（.epic-ref）と、できたものの中（.epic-used）で、同じチップを使う。
   寸法は今の部品に合わせる: 絵は左の一覧と同じ .epic-timeline-icon（22px）、チップと「追加」の高さは「記事にする」と同じ 32px
   （指で押す端末・狭い幅は 40px）、小窓は公開範囲の小窓と同じ面（280px・角18px）、小窓の行は 44px。 */
.epic-ref [hidden], .epic-used [hidden] { display: none !important; }

/* つくる前。「参照 すべて 7」・チップの列・「追加」を1行に並べ、列は横に流す。 */
.epic-ref { display: flex; align-items: center; gap: 8px; min-width: 0; color: #5d6d86; font-size: 13px; line-height: 20px; }
.epic-ref-head { display: flex; flex: none; align-items: center; gap: 6px; min-height: 40px; }
.epic-ref-label { flex: none; color: #5d6d86; white-space: nowrap; }
.epic-ref-count { flex: none; color: #111827; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.epic-ref-count:empty { display: none; }
.epic-ref-strip { display: flex; flex: 0 1 auto; gap: 6px; min-width: 0; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
.epic-ref-strip::-webkit-scrollbar { display: none; }
.epic-ref-strip:not(:has(.epic-ref-chip:not([hidden]))) { display: none; }
/* 横に流した列の端に、続きがあることを薄く見せる。 */
.epic-ref-strip[data-overflow="end"] { mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent); }
.epic-ref-strip[data-overflow="start"] { mask-image: linear-gradient(to left, #000 calc(100% - 16px), transparent); }
.epic-ref-strip[data-overflow="both"] { mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent); }

/* 1件のチップ（絵＋名前、つくる前は×）。見た目は 32px の丸い面（「記事にする」と同じ）。押す所は 40px 以上にする:
   ×は 40px 四方（面の上下へはみ出す分は負の余白で吸収）、リンクのチップと「追加」は高さ 40px の中に 32px の面（::before）を描く。 */
.epic-ref-chip { position: relative; isolation: isolate; display: inline-flex; flex: none; align-items: center; gap: 6px; max-width: 220px; min-height: 32px; padding: 0 12px 0 5px; border: 1px solid rgba(15, 23, 42, .1); border-radius: 999px; background: #fff; color: #111827; font-size: 12px; font-weight: 600; line-height: 18px; text-decoration: none; }
.epic-ref-chip:has(.epic-ref-chip-remove:not([hidden])) { padding-right: 0; }
.epic-ref-chip-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.epic-ref-chip-remove { position: relative; display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; margin: -5px -4px -5px -10px; padding: 0; border: 0; border-radius: 999px; background: transparent; color: #5d6d86; }
.epic-ref-chip-remove::before { content: ""; position: absolute; inset: 8px; z-index: -1; border-radius: 999px; }
.epic-ref-chip-remove:hover { color: #111827; }
.epic-ref-chip-remove:hover::before { background: #f1f5f9; }
.epic-ref-chip-remove .epic-icon { width: 12px; height: 12px; }
a.epic-ref-chip, .epic-ref button.epic-ref-add { min-height: 40px; border: 0; background: transparent; }
a.epic-ref-chip::before, .epic-ref button.epic-ref-add::before { content: ""; position: absolute; inset: 4px 0; z-index: -1; border: 1px solid rgba(15, 23, 42, .1); border-radius: 999px; background: #fff; }
a.epic-ref-chip:hover::before { background: #f1f7ff; }
.epic-ref-hidden { flex: none; color: #5d6d86; font-size: 12px; white-space: nowrap; }

/* 足す（形は「記事にする」のボタンと同じ）と、その小窓。小窓の位置は epic-reference が決める（上・左）。 */
.epic-ref button.epic-ref-add { position: relative; isolation: isolate; display: inline-flex; align-items: center; flex: none; margin: 0; padding: 0 12px; color: #0671e8; font-size: 12px; font-weight: 600; line-height: 18px; white-space: nowrap; }
.epic-ref button.epic-ref-add::before { border-color: rgba(6, 113, 232, .22); }
.epic-ref button.epic-ref-add:hover::before, .epic-ref button.epic-ref-add[aria-expanded="true"]::before { background: #f1f7ff; }
.epic-ref-menu { position: fixed; inset: auto; top: 0; left: 0; width: 280px; max-width: calc(100vw - 32px); max-height: min(328px, calc(100dvh - 32px)); margin: 0; padding: 8px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid #e6ebf2; border-radius: 18px; background: #fff; color: #152038; box-shadow: 0 24px 60px rgba(15, 23, 42, .16); }
.epic-ref-menu:popover-open:not([data-placed]) { visibility: hidden; }
.epic-ref-options { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.epic-ref-options > li { min-width: 0; }
.epic-ref-menu .epic-ref-option { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 44px; margin: 0; padding: 0 12px; border-radius: 12px; cursor: pointer; }
.epic-ref-menu .epic-ref-option:hover { background: rgba(15, 23, 42, .04); }
.epic-ref-menu .epic-ref-option:has(input:disabled) { cursor: default; }
.epic-ref-option input { flex: none; margin: 0; }
.epic-ref-option-text { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.epic-ref-option-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #111827; font-size: 13px; font-weight: 600; line-height: 20px; }
.epic-ref-option-kind { color: #5d6d86; font-size: 11px; line-height: 16px; }
.epic-ref-fields { display: none; }

/* プロダクトからつくる窓（「記事にする」など）。指示の上に置く。 */
.epic-ref[data-place="make"] { margin-bottom: 12px; }

/* 入口（話しかける）。入力を開いている間だけ、入力の上に出す。1行目に「参照 すべて 7」と「追加」、2行目にチップの列。 */
.epic-compose .epic-ref { display: none; }
.epic-compose.is-talk:is(.is-open, :has(.epic-compose-form[data-mode="talk"] .epic-compose-input:not(:placeholder-shown))) .epic-ref { display: flex; order: -1; flex: 1 1 100%; flex-wrap: wrap; gap: 4px 8px; min-width: 0; padding: 8px 10px 0; font-size: 12px; line-height: 18px; }
.epic-compose .epic-ref .epic-ref-head { flex: 1 1 auto; min-width: 0; }
.epic-compose .epic-ref .epic-ref-add { order: 1; }
.epic-compose .epic-ref .epic-ref-strip { order: 2; flex: 1 1 100%; }
.epic-compose .epic-ref-chip { max-width: 128px; }

/* チャットの画面の入力。入力の上に、行いっぱいで出す（入力のフォームは2列の grid）。 */
.epic-ref[data-place="chat"] { grid-column: 1 / -1; margin: -4px 0 -4px; }

/* できたものの中。成果物の見出しの下と、チャットの答えの下。 */
.epic-used { display: grid; gap: 8px; min-width: 0; color: #5d6d86; font-size: 13px; line-height: 20px; }
.epic-used-line, .epic-used-cited { display: flex; align-items: center; gap: 8px; min-width: 0; }
.epic-used-cited { flex-wrap: wrap; gap: 0 12px; }
.epic-used-cited .epic-text-link { display: inline-flex; align-items: center; min-height: 40px; }
.epic-used-time { flex: none; color: #64748b; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.epic-used[data-place="heading"] { margin-top: 8px; }
.epic-used[data-place="answer"] { margin-top: 12px; }

/* フォーカスの装飾枠は出さない（フォーカスそのものとキーボード操作は残す）。 */
.epic-ref :is(button, input, label, a):is(:focus, :focus-visible), .epic-ref-menu :is(input, label):is(:focus, :focus-visible), .epic-used a:is(:focus, :focus-visible) { outline: none; box-shadow: none; }

/* 狭い幅（成果物の見出しが2行になる幅）では、参照を見出しの下の行いっぱいに置く。 */
@media (max-width: 480px) {
  .epic-product-heading .epic-used[data-place="heading"] { flex: 1 1 100%; order: 5; margin: 0; }
}

/* 狭い幅では、参照の行を折り返し、チップの列を次の行いっぱいに流す。 */
@media (max-width: 1023.98px) {
  .epic-ref:not([data-place="compose"]) { flex-wrap: wrap; row-gap: 0; }
  .epic-ref:not([data-place="compose"]) .epic-ref-head { flex: 1 1 auto; }
  .epic-ref:not([data-place="compose"]) .epic-ref-add { order: 1; }
  .epic-ref:not([data-place="compose"]) .epic-ref-strip { order: 2; flex: 1 1 100%; }
  .epic-used-line { flex-wrap: wrap; row-gap: 0; }
  .epic-used-line .epic-ref-strip { order: 3; flex: 1 1 100%; }
}

/* つくる前のチップの×（40px）が、横に流す列の上下で切れないように、列の上下に余白を足して打ち消す。 */
.epic-ref .epic-ref-strip { padding-block: 4px; margin-block: -4px; }

/* popover に対応していないブラウザでは、小窓を常に出さない（×で外すことはできる）。 */
@supports not selector(:popover-open) {
  .epic-ref-menu, .epic-ref button.epic-ref-add { display: none; }
}
