/* ════════════════════════════════════════════════════════════════
   UTM 생성 모달 — utm.js 짝 (2026-09-15 신설)
   · profile.js/aws-cost.css 패턴 그대로: 모듈이 자기 DOM을 만들고, 토큰은
     common.css 의 :root 변수를 참조만 한다(재정의 금지). 라이트 테마 전용.
   ════════════════════════════════════════════════════════════════ */
.utm-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.utm-overlay[hidden] { display: none; }

.utm-modal {
  background: #fff; border-radius: 16px;
  width: 100%; max-width: 520px; max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: 0 12px 44px rgba(16, 24, 40, .22);
  overflow: hidden;
}

/* ── 헤더 ── */
.utm-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line, #ECEEF1); flex: 0 0 auto;
}
.utm-head h3 {
  margin: 0; font-size: 15px; font-weight: 700; color: var(--text, #1A1D21);
}
.utm-head-btns { display: flex; align-items: center; gap: 4px; }
.utm-reset {
  border: none; background: none; font-size: 11.5px; font-weight: 600; cursor: pointer;
  color: var(--muted, #79818B); padding: 6px 8px; border-radius: 8px;
}
.utm-reset:hover { background: var(--surface-2, #F4F5F7); color: var(--text, #1A1D21); }
.utm-x {
  border: none; background: none; font-size: 15px; cursor: pointer;
  color: var(--muted, #79818B); padding: 4px 9px; border-radius: 8px;
}
.utm-x:hover { background: var(--surface-2, #F4F5F7); color: var(--text, #1A1D21); }

/* ── 대화 영역 ── */
.utm-msgs {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 14px 18px; display: flex; flex-direction: column; gap: 10px;
}
.utm-empty {
  color: var(--muted, #79818B); font-size: 12.5px; line-height: 1.6;
  text-align: center; padding: 30px 10px;
}
.utm-msg {
  max-width: 84%; padding: 9px 12px; border-radius: 14px;
  font-size: 13px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
.utm-msg.user {
  align-self: flex-end; background: var(--sage-tint-2, #DCE5DE); color: var(--text, #1A1D21);
  border-bottom-right-radius: 4px;
}
.utm-msg.bot {
  align-self: flex-start; background: var(--surface-2, #F4F5F7); color: var(--text, #1A1D21);
  border-bottom-left-radius: 4px;
}
/* 마크다운으로 그린 봇 답변 — pre-wrap 이면 <p> 사이 줄바꿈이 한 번 더 들어가 벌어진다 */
.utm-msg.bot.md { white-space: normal; }
.utm-msg.md > :first-child { margin-top: 0; }
.utm-msg.md > :last-child { margin-bottom: 0; }
.utm-msg.md p { margin: 0 0 6px; }
.utm-msg.md ul, .utm-msg.md ol { margin: 4px 0 6px; padding-left: 18px; }
.utm-msg.md li { margin: 2px 0; }
.utm-msg.md strong { font-weight: 700; }
.utm-msg.md code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
  background: rgba(16, 24, 40, .06); border-radius: 4px; padding: 1px 4px; word-break: break-all;
}
.utm-msg.md a { color: var(--brand, #3E4D41); text-decoration: underline; word-break: break-all; }
/* 성과 조회 — 날짜별 표(요청할 때만 나온다). 말풍선 폭을 넘으면 표만 가로로 스크롤 */
.utm-msg.md table {
  display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse;
  margin: 6px 0; font-size: 12px; font-variant-numeric: tabular-nums;
}
.utm-msg.md th, .utm-msg.md td {
  border-bottom: 1px solid var(--line, #ECEEF1); padding: 4px 8px; text-align: right; white-space: nowrap;
}
.utm-msg.md th:first-child, .utm-msg.md td:first-child { text-align: left; }
.utm-msg.md th { font-weight: 700; color: var(--text-2, #4A5159); }
.utm-msg.err {
  align-self: flex-start; background: var(--neg-bg, #FCEDED); color: var(--neg-strong, #B53030);
  border-bottom-left-radius: 4px;
}
/* 점 펄스 — 첫 텍스트/링크가 올 때까지(도구 호출 도는 동안) */
.utm-typing {
  align-self: flex-start; display: inline-flex; gap: 4px;
  padding: 11px 14px; border-radius: 14px; border-bottom-left-radius: 4px;
  background: var(--surface-2, #F4F5F7);
}
.utm-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted, #79818B);
  animation: utmDot 1.1s ease-in-out infinite;
}
.utm-typing i:nth-child(2) { animation-delay: .15s; }
.utm-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes utmDot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .utm-typing i { animation: none; opacity: .6; } }

/* ── 링크 결과 카드 ── */
.utm-link-card {
  align-self: flex-start; max-width: 92%;
  border: 1px solid var(--line-strong, #D6DAE0); border-radius: 12px;
  background: #fff; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px;
}
.utm-link-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.utm-link-note {
  font-size: 11px; font-weight: 600; color: var(--muted, #79818B);
  font-variant-numeric: tabular-nums;
}
.utm-link-ch {
  align-self: flex-start; font-size: 10.5px; font-weight: 700; color: var(--brand, #3E4D41);
  background: var(--sage-tint, #EAEFEB); border-radius: 999px; padding: 2px 9px;
}
.utm-link-url {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5; color: var(--text, #1A1D21);
  word-break: break-all; user-select: all;
}
.utm-link-copy {
  align-self: flex-end; font-size: 11.5px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line-strong, #D6DAE0); background: var(--surface, #FAFBFC);
  color: var(--text-2, #4A5159); border-radius: 8px; padding: 5px 10px;
}
.utm-link-copy:hover { background: var(--surface-2, #F4F5F7); color: var(--text, #1A1D21); }
.utm-link-copy.on { color: var(--pos, #1F8A4C); border-color: var(--pos-bg, #E7F4EC); background: var(--pos-bg, #E7F4EC); }

/* ── 입력 ── */
.utm-input-row {
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line, #ECEEF1);
}
.utm-input {
  flex: 1 1 auto; resize: none; max-height: 108px; min-height: 20px;
  font: inherit; font-size: 13px; line-height: 1.5; color: var(--text, #1A1D21);
  border: 1px solid var(--line-strong, #D6DAE0); border-radius: 12px;
  padding: 9px 12px; background: var(--surface, #FAFBFC);
  /* ⛔ rows="1" 기본 높이가 이 폰트/줄간격과 딱 안 맞아 내용이 없어도 세로 스크롤이
     생겼다(2026-09-15 지적). overflow는 기본 숨김 — autoGrow()가 108px(max-height)를
     넘을 때만 JS로 auto 로 바꿔 켠다. */
  overflow-y: hidden;
}
.utm-input:focus { outline: none; border-color: var(--brand, #3E4D41); }
.utm-send {
  /* ⛔ 입력창 한 줄 높이(패딩 9px×2 + 줄높이 20px + 테두리 2px = 40px)와 맞춘다.
     36px으로 고정해 뒀을 때 입력창보다 낮아 아래쪽이 안 맞았다(2026-09-15 지적). */
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px; border: none;
  background: var(--brand, #3E4D41); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.utm-send:hover { background: var(--brand-ink, #2E3A30); }
.utm-send:disabled { opacity: .4; cursor: not-allowed; }
.utm-send svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

@media (max-width: 639px) {
  .utm-overlay { padding: 0; align-items: flex-end; }
  .utm-modal {
    width: 100%; max-width: none; border-radius: 18px 18px 0 0;
    max-height: 92vh;
  }
  .utm-x { width: 40px; height: 40px; }
  .utm-input { font-size: 16px; }   /* iOS 자동 줌 방지 */
}
