/* InsuClaw Inbox — brand-dna 토큰 기반 챗봇 UI */

/* ── CSS 변수 (brand-dna design_tokens) ── */
:root {
  --color-hero:           #1B4FD8;
  --color-surface:        #F7F8FC;
  --color-surface-alt:    #FFFFFF;
  --color-text-primary:   #0D1B3E;
  --color-text-secondary: #4B5A7A;
  --color-accent:         #D97706;
  --color-border:         #D1D9EE;

  --font-base:   'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:   'JetBrains Mono', monospace;
  --radius-base: 8px;
  --shadow-sm:   0 1px 3px rgba(13, 27, 62, 0.08);

  /* anti_pattern: 터치타겟 최소 48px 강제 */
  --touch-min: 48px;
}

/* ── 리셋 및 기반 ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-base);
  font-size: 16px;
  color: var(--color-text-primary);
  background: var(--color-surface);
  /* anti_pattern: 가로 스크롤 금지 */
  overflow-x: hidden;
}

/* ── 인박스 레이아웃 컨테이너 ── */
.inbox-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh; /* dynamic viewport height — PWA safe */
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-surface);
}

/* ── HEADER ── */
.inbox-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  height: 56px;
  background: var(--color-hero);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(27, 79, 216, 0.2);
}

.inbox-header__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.inbox-header__logo {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent);
  border-radius: 6px;
  /* Claw 메타포: accent 컬러 핀포인트 */
}

.inbox-header__logo svg {
  width: 18px;
  height: 18px;
  stroke: #FFFFFF;
  fill: none;
  stroke-width: 2.5;
}

.inbox-header__title {
  font-size: 17px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.3px;
}

.inbox-header__menu-btn {
  /* anti_pattern: 48px 미만 터치타겟 금지 */
  width: var(--touch-min);
  height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-base);
  color: #FFFFFF;
}

.inbox-header__menu-btn:active {
  background: rgba(255, 255, 255, 0.12);
}

.inbox-header__menu-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

/* ── MESSAGE STREAM ── */
.inbox-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden; /* anti_pattern: 가로 스크롤 금지 */
  padding: calc(56px + 16px) 16px calc(80px + 16px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

/* ── 버블 공통 ── */
.bubble {
  display: flex;
  flex-direction: column;
  max-width: 280px; /* 375 × 0.75 */
}

.bubble__body {
  padding: 12px 14px;
  border-radius: var(--radius-base);
  font-size: 16px; /* anti_pattern: 12px 미만 금지 */
  line-height: 1.5;
  word-break: break-word;
}

.bubble__time {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

/* 시스템 버블 (좌측) */
.bubble--system {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble--system .bubble__body {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
  border-radius: var(--radius-base) var(--radius-base) var(--radius-base) 0;
  box-shadow: var(--shadow-sm);
}

/* 설계사 버블 (우측) */
.bubble--agent {
  align-self: flex-end;
  align-items: flex-end;
}

.bubble--agent .bubble__body {
  background: var(--color-hero);
  color: #FFFFFF;
  border-radius: var(--radius-base) var(--radius-base) 0 var(--radius-base);
}

/* 발신자 전환 시 더 큰 간격 */
.bubble + .bubble--agent,
.bubble--agent + .bubble--system {
  margin-top: 16px;
}

/* ── 파일 첨부 썸네일 버블 ── */
.bubble__attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-sm);
}

.bubble__attachment-icon {
  width: 48px;
  height: 48px;
  min-width: 48px;
  background: rgba(217, 119, 6, 0.08);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bubble__attachment-icon svg {
  width: 22px;
  height: 22px;
  stroke: var(--color-accent);
  fill: none;
  stroke-width: 2;
}

.bubble__attachment-info {
  flex: 1;
  min-width: 0;
}

.bubble__attachment-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble__attachment-size {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* ── 파일 첨부 미리보기 (전송 전) ── */
.inbox-attachment-preview {
  position: fixed;
  bottom: 80px;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-surface-alt);
  border-top: 1px solid var(--color-border);
  padding: 8px 16px;
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 90;
}

.inbox-attachment-preview.is-visible {
  display: flex;
}

.inbox-attachment-preview__thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.inbox-attachment-preview__thumb svg {
  width: 22px;
  height: 22px;
  stroke: var(--color-accent);
  fill: none;
  stroke-width: 2;
}

.inbox-attachment-preview__name {
  flex: 1;
  font-size: 14px;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-attachment-preview__remove {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  border-radius: 50%;
}

.inbox-attachment-preview__remove:active {
  background: rgba(75, 90, 122, 0.1);
}

.inbox-attachment-preview__remove svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

/* ── INPUT BAR (fixed bottom) ── */
.inbox-input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  height: 80px;
  background: var(--color-surface-alt);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  padding-bottom: env(safe-area-inset-bottom, 0); /* PWA safe-area */
  z-index: 100;
}

/* 파일 첨부 버튼 */
.inbox-input-bar__attach-btn {
  width: var(--touch-min); /* anti_pattern: 48px 미만 금지 */
  height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  cursor: pointer;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.inbox-input-bar__attach-btn:active {
  background: rgba(75, 90, 122, 0.08);
  border-color: var(--color-hero);
}

/* 주소록 버튼 */
.inbox-input-bar__contact-btn {
  width: var(--touch-min);
  height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  cursor: pointer;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.inbox-input-bar__contact-btn:active {
  background: rgba(75, 90, 122, 0.08);
  border-color: var(--color-hero);
}

/* feather 아이콘 공통 */
.inbox-input-bar__attach-btn svg,
.inbox-input-bar__contact-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

/* 텍스트 입력 */
.inbox-input-bar__text {
  flex: 1;
  height: 44px;
  padding: 0 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 22px;
  font-family: var(--font-base);
  font-size: 16px; /* anti_pattern: 12px 미만 금지 */
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.inbox-input-bar__text::placeholder {
  color: var(--color-text-secondary);
  font-size: 14px;
}

.inbox-input-bar__text:focus {
  border-color: var(--color-hero);
  box-shadow: 0 0 0 3px rgba(27, 79, 216, 0.12);
}

/* 전송 버튼 — Primary CTA (화면당 1개) */
/* anti_pattern: Primary 1개, 48px 이상 */
.inbox-input-bar__send-btn {
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-hero); /* hero 색만 허용 */
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #FFFFFF;
  flex-shrink: 0;
  /* motion: subtle — button-press */
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.inbox-input-bar__send-btn:hover {
  box-shadow: 0 4px 12px rgba(27, 79, 216, 0.3);
  transform: translateY(-1px); /* motion: lift */
}

.inbox-input-bar__send-btn:active {
  transform: scale(0.94); /* micro_interaction: button-press */
  box-shadow: none;
}

.inbox-input-bar__send-btn:disabled {
  background: var(--color-border);
  cursor: not-allowed;
  transform: none;
}

.inbox-input-bar__send-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  margin-left: 2px; /* send 아이콘 시각 중심 보정 */
}

/* ── 빈 상태 ── */
.inbox-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--color-text-secondary);
  font-size: 15px;
  text-align: center;
  gap: 8px;
}

.inbox-empty svg {
  width: 40px;
  height: 40px;
  stroke: var(--color-border);
  fill: none;
  stroke-width: 1.5;
}

/* ── ISS-008 분석 결과 카드 ── */

/* 카드 컨테이너: 시스템 버블 폭·정렬 계승 */
.analysis-card {
  align-self: flex-start;
  align-items: flex-start;
  width: 100%;
  max-width: 320px;           /* 375px 기준 여백 확보 */
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  /* motion: fade-in entrance */
  animation: card-enter 0.25s ease forwards;
}

@keyframes card-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── 헤더 ── */
.analysis-card__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--color-border);
}

.analysis-card__header-icon {
  width: 20px;
  height: 20px;
  min-width: 20px;
  stroke: var(--color-hero);
  fill: none;
  stroke-width: 2;
}

.analysis-card__header-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.analysis-card__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-hero);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.analysis-card__filename {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── 게이지 영역 ── */
.analysis-card__gauge {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 14px 12px;
}

/* CSS 원형 게이지 — conic-gradient (외부 라이브러리 없음) */
.analysis-card__gauge-ring {
  position: relative;
  width: 64px;
  height: 64px;
  min-width: 64px;
  border-radius: 50%;
  /* 트랙: 연한 border */
  background: conic-gradient(
    var(--gauge-color, var(--color-hero)) var(--arc, 0deg),
    var(--color-border) var(--arc, 0deg)
  );
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* 게이지 중앙 흰 원 (도넛 효과) */
.analysis-card__gauge-ring::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--color-surface-alt);
}

.analysis-card__gauge-score {
  position: relative;
  z-index: 1;
  font-size: 18px;
  font-weight: 700;
  color: var(--gauge-color, var(--color-hero));
  line-height: 1;
}

.analysis-card__gauge-unit {
  position: relative;
  z-index: 1;
  font-size: 10px;
  color: var(--color-text-secondary);
  margin-top: 1px;
}

/* 점수 구간 색 */
.analysis-card__gauge--high { --gauge-color: var(--color-hero); }
.analysis-card__gauge--mid  { --gauge-color: #D97706; }   /* accent */
.analysis-card__gauge--low  { --gauge-color: #D97706; }   /* accent — 경고 */

.analysis-card__gauge-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.analysis-card__gauge-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.analysis-card__gauge-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.4;
}

/* anti-pattern: abbr 툴팁 — 전문용어 인라인 설명 */
.analysis-card__gauge-desc abbr,
.analysis-card__lack-text abbr {
  text-decoration: underline dotted var(--color-text-secondary);
  cursor: help;
}

.analysis-card__gauge-note {
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.4;
}

/* 연동 데이터 없음 상태 */
.analysis-card__gauge-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  color: var(--color-text-secondary);
}

.analysis-card__gauge-empty svg {
  width: 28px;
  height: 28px;
  stroke: var(--color-border);
  fill: none;
  stroke-width: 2;
}

.analysis-card__gauge-empty p {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.analysis-card__gauge-empty-sub {
  font-size: 12px !important;
  font-weight: 400 !important;
}

/* ── 사각지대 영역 — accent 좌측 보더 ── */
.analysis-card__lack {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 14px;
  padding: 10px 12px;
  background: rgba(217, 119, 6, 0.06); /* accent tint */
  border-left: 3px solid var(--color-accent);
  border-radius: 0 var(--radius-base) var(--radius-base) 0;
  margin-bottom: 12px;
}

.analysis-card__lack-icon {
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin-top: 1px;
  stroke: var(--color-accent);
  fill: none;
  stroke-width: 2;
}

.analysis-card__lack-body {
  flex: 1;
  min-width: 0;
}

.analysis-card__lack-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-accent);
  margin-bottom: 3px;
}

.analysis-card__lack-text {
  font-size: 13px;           /* anti-pattern: 12px 미만 금지 → 13px */
  color: var(--color-text-primary);
  line-height: 1.45;
  word-break: keep-all;
}

/* ── 추천 상품 ── */
.analysis-card__recommend {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px 10px;
  font-size: 12px;
  color: var(--color-text-secondary);
}

.analysis-card__recommend svg {
  width: 13px;
  height: 13px;
  min-width: 13px;
  stroke: var(--color-text-secondary);
  fill: none;
  stroke-width: 2;
}

/* ── Primary CTA — "상세 보기" ── */
/* anti-pattern: 화면당 primary CTA 1개, 48px+ 터치타겟, hero 색 */
.analysis-card__cta {
  padding: 0 14px 14px;
}

.analysis-card__cta-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: var(--touch-min);  /* anti-pattern: 48px 미만 금지 */
  background: var(--color-hero); /* anti-pattern: hero 색만 허용 */
  color: #FFFFFF;
  font-family: var(--font-base);
  font-size: 15px;               /* anti-pattern: 12px 미만 금지 */
  font-weight: 600;
  border-radius: var(--radius-base);
  text-decoration: none;
  /* motion: subtle button-press + lift */
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.analysis-card__cta-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.analysis-card__cta-btn:hover {
  box-shadow: 0 4px 12px rgba(27, 79, 216, 0.28);
  transform: translateY(-1px);  /* motion: lift */
}

.analysis-card__cta-btn:active {
  transform: scale(0.97);       /* motion: button-press */
  box-shadow: none;
}

/* ── 타임스탬프 ── */
.analysis-card__time {
  display: block;
  padding: 0 14px 10px;
}

/* ── 모바일 375px 안전 보장 ── */
@media (max-width: 390px) {
  .analysis-card {
    max-width: calc(100vw - 48px); /* 좌우 마진 확보 — 가로스크롤 금지 */
  }
}

/* ── Contact Picker 폴백 안내 ── */
.contact-fallback-toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text-primary);
  color: #FFFFFF;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius-base);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 200;
}

.contact-fallback-toast.is-visible {
  opacity: 1;
}
