/* =========================================================
   임베딩 지도(semantic.html) — style.css의 토큰·유리·채팅 컴포넌트 위에 얹는 화면 전용 스타일
   레이아웃: 왼쪽 지도 카드 + 오른쪽 대화 카드(좁은 화면에서는 위아래)
   ========================================================= */

/* 지도 점 색: 3가지 묶음만 쓴다(산점도는 모든 쌍이 맞닿으므로 dataviz all-pairs 검증을 통과한 첫 3색).
   유사도는 한 색(파랑) 밝기 단계. 다크는 표면 위에서 다시 고른 단계 */
:root {
  --fam-whisky: var(--g1);
  --fam-maker: var(--g2);
  --fam-concept: var(--g3);
  --seq-lo: #cde2fb;
  --seq-hi: #0d366b;
  --query-ink: #141414;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --seq-lo: #1c2f55; --seq-hi: #cde2fb; --query-ink: #f3f5ff; }
}
:root[data-theme="dark"] { --seq-lo: #1c2f55; --seq-hi: #cde2fb; --query-ink: #f3f5ff; }

main.sem {
  box-sizing: border-box;
  width: min(1600px, calc(100% - 2 * var(--sp-4)));
  padding: var(--sp-4) 0 var(--sp-5);
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); gap: var(--sp-4);
  height: calc(100vh - 84px); min-height: 600px;
}

/* ---------- 지도 카드 ---------- */
.sem-map { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: var(--sp-3); padding: var(--sp-4); min-height: 0; min-width: 0; }
.sem-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--sp-3); }
.sem-head h1 { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -0.02em; }
.sem-head .lead { margin-top: 2px; font-size: var(--fs-sm); color: var(--c-text-2); max-width: 70ch; }
.sem-select { min-height: 36px; font-size: var(--fs-sm); font-weight: 600; color: var(--c-text-2); }
.segmented button[disabled] { opacity: .45; cursor: not-allowed; }

.sem-legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); color: var(--c-text-2); }
.sem-legend .chip { min-height: 30px; }
.sem-legend .chip[aria-pressed="false"] { opacity: .5; text-decoration: line-through; }
.sem-legend .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px var(--chart-surface); }
.sem-legend .count { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--c-text-3); font-weight: 400; }
.sem-ramp { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--c-text-3); font-family: var(--font-mono); }
.sem-ramp .bar { width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--seq-lo), var(--seq-hi)); }
.sem-ramp[hidden] { display: none; }
.sem-legend .q-key { display: inline-flex; align-items: center; gap: 6px; }
.sem-legend .q-key svg { width: 14px; height: 14px; }

.sem-stage { position: relative; min-height: 0; }
.sem-viz { height: 100%; min-height: 360px; cursor: grab; touch-action: none; }
.sem-viz:active { cursor: grabbing; }
.sem-viz svg { display: block; width: 100%; height: 100%; }
.sem-note { font-size: var(--fs-xs); color: var(--c-text-3); line-height: 1.5; }

/* 지도 표시 요소 */
.sem-pt { stroke: var(--chart-surface); stroke-width: 1.5; transition: opacity .2s ease; }
.sem-pt.dim { opacity: .14; }
.sem-pt.recede { opacity: .42; }
.sem-label { font-size: 11px; font-weight: 700; fill: var(--c-text); paint-order: stroke; stroke: var(--chart-surface); stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.sem-label.landmark { font-size: 12px; font-weight: 800; fill: var(--c-text-2); }
.sem-label.top { font-size: 12px; font-weight: 800; fill: var(--c-text); }
.sem-hover { fill: none; stroke: var(--c-text); stroke-width: 2; pointer-events: none; }
.sem-sel { fill: none; stroke: var(--c-primary); stroke-width: 2.5; pointer-events: none; }
.sem-nn-link { stroke: var(--c-primary); stroke-width: 1.5; stroke-dasharray: 3 4; opacity: .8; pointer-events: none; }
.sem-q-link { stroke: var(--query-ink); stroke-width: 1.5; opacity: .7; pointer-events: none; }
.sem-q-ring { fill: none; stroke: var(--query-ink); stroke-width: 2; pointer-events: none; }
.sem-q-badge circle { fill: var(--query-ink); stroke: var(--chart-surface); stroke-width: 2; }
.sem-q-badge text { fill: var(--chart-surface); font: 800 10px/1 var(--font-sans); text-anchor: middle; dominant-baseline: central; }
.sem-q-mark { fill: var(--query-ink); stroke: var(--chart-surface); stroke-width: 2; cursor: pointer; }
.sem-q-mark.past { fill: var(--mark-muted); }
.sem-q-label { font: 800 12px/1 var(--font-sans); fill: var(--query-ink); paint-order: stroke; stroke: var(--chart-surface); stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.sem-q-label.past { fill: var(--c-text-3); font-weight: 700; }
@media (prefers-reduced-motion: reduce) { .sem-pt { transition: none; } }

/* 점 상세: 지도 위 왼쪽 아래 */
.sem-detail { position: absolute; left: var(--sp-3); bottom: var(--sp-3); z-index: 5; width: min(380px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow-y: auto;
  padding: var(--sp-4); border-radius: 18px; background: var(--glass-strong); display: grid; gap: var(--sp-3); font-size: var(--fs-sm); color: var(--c-text-2); }
.sem-detail[hidden] { display: none; }
.sem-detail-head { display: flex; align-items: flex-start; gap: var(--sp-2); }
.sem-detail-head h2 { flex: 1; min-width: 0; font-size: var(--fs-base); font-weight: 800; color: var(--c-text); }
.sem-detail-head small { display: block; font-size: var(--fs-xs); font-weight: 600; color: var(--c-text-3); margin-top: 2px; }
.sem-doc { margin: 0; font-size: var(--fs-sm); line-height: 1.6; color: var(--c-text-2); }
.sem-sub { font-size: var(--fs-xs); font-weight: 700; color: var(--c-text-3); }
.sem-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* 표로 보기(색만으로 구분하기 어려운 경우의 대안) */
.sem-table { position: absolute; inset: var(--sp-3); z-index: 6; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: var(--sp-3); padding: var(--sp-4); border-radius: 18px; background: var(--glass-strong); }
.sem-table[hidden] { display: none; }
.sem-table-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.sem-table-head h2 { font-size: var(--fs-base); font-weight: 800; margin-right: auto; }
.sem-table-head input { min-height: 36px; padding: 0 var(--sp-3); border-radius: var(--radius-ctl); border: 1px solid var(--glass-edge); background: var(--glass-solid); color: var(--c-text); font-size: var(--fs-sm); }
.sem-table .table-wrap { overflow: auto; min-height: 0; }
.sem-table table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.sem-table th { position: sticky; top: 0; background: var(--glass-solid); text-align: left; font-size: var(--fs-xs); color: var(--c-text-3); font-weight: 700; padding: 6px 8px; }
.sem-table td { padding: 6px 8px; border-top: 1px solid var(--glass-edge); color: var(--c-text-2); }
.sem-table td.num { font-family: var(--font-mono); text-align: right; }
.sem-table tr.is-top td { background: var(--c-primary-soft); }
.linkish { all: unset; cursor: pointer; font-weight: 700; color: var(--c-text); border-radius: 6px; }
.linkish:hover { color: var(--c-primary-ink); text-decoration: underline; text-underline-offset: 3px; }
.linkish:focus-visible { box-shadow: var(--focus); }
.type-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

/* ---------- 대화 카드: 떠 있는 창(.chat-panel) 대신 화면에 고정된 칸 ---------- */
.sem-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.sem-chat .chat-log { padding: var(--sp-4); }
.chat-q-tag { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 20px; margin-right: 6px; padding: 0 6px; border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .22); font: 800 var(--fs-xs)/1 var(--font-sans); }
.chat-turn.is-past .chat-user { opacity: .78; }
.chat-turn.is-active .chat-user { box-shadow: 0 0 0 2px var(--c-bg), 0 0 0 4px var(--c-primary-line); }
.chat-turn.is-active .refocus { display: none; }
.cite { all: unset; display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; margin: 0 1px; padding: 0 4px; border-radius: 6px;
  background: var(--c-primary-soft); color: var(--c-primary-ink); font: 800 11px/1 var(--font-sans); cursor: pointer; vertical-align: 1px; }
.cite:hover { background: var(--c-primary); color: #fff; }
.cite:focus-visible { box-shadow: var(--focus); }

/* Top-5 후보 카드 */
.top5 { display: grid; gap: var(--sp-2); padding: var(--sp-3); border-radius: 16px; border: 1px solid var(--glass-edge); background: color-mix(in srgb, var(--chart-surface) 80%, transparent); }
.top5-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.top5-head strong { font-size: var(--fs-sm); color: var(--c-text); }
.top5-head span { font-size: var(--fs-xs); color: var(--c-text-3); }
.top5-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.top5-row { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 22px minmax(0, 1fr) 92px; align-items: center; gap: var(--sp-2);
  padding: 6px 6px; border-radius: 10px; cursor: pointer; }
.top5-row:hover { background: var(--c-primary-soft); }
.top5-row:focus-visible { box-shadow: var(--focus); }
.top5-row .rank { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--query-ink); color: var(--chart-surface); font: 800 11px/1 var(--font-sans); }
.top5-row .name { min-width: 0; display: grid; gap: 1px; }
.top5-row .name b { font-size: var(--fs-sm); color: var(--c-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top5-row .name small { font-size: var(--fs-xs); color: var(--c-text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top5-row .score { display: grid; gap: 3px; justify-items: end; font: 500 var(--fs-xs)/1 var(--font-mono); color: var(--c-text-2); }
.top5-row .track { width: 100%; height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.top5-row .fill { height: 100%; border-radius: 0 3px 3px 0; background: var(--s1); }
.top5-hist { display: grid; gap: 4px; }
.top5-hist svg { display: block; width: 100%; height: 64px; }
.top5-hist .bin { fill: var(--mark-muted); }
.top5-hist .bin.is-top { fill: var(--s1); }
.top5-hist .rule { stroke: var(--query-ink); stroke-width: 1.5; stroke-dasharray: 3 3; }
.top5-hist text { fill: var(--c-text-3); font: 500 10px/1 var(--font-mono); }
.top5-hist .cap { font-size: var(--fs-xs); color: var(--c-text-3); }

@media (max-width: 980px) {
  main.sem { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  .sem-viz { height: 62vh; min-height: 380px; }
  .sem-chat { height: 72vh; min-height: 480px; }
}
@media (max-width: 520px) {
  .topbar .brand-text small { display: none; }
  .sem-head .filters { width: 100%; }
  .top5-row { grid-template-columns: 22px minmax(0, 1fr) 72px; }
}
