/* =========================================
   1. CSS 변수 — Merz Aesthetics 브랜드
   ========================================= */
:root {
  /* 브랜드 색상 */
  --brand-dark:     #1B2A3B;   /* 헤더/사이드바 다크 네이비 */
  --brand-blue:     #0072BC;   /* Merz 포인트 블루 */
  --brand-blue-lt:  #E8F4FB;   /* 블루 라이트 */

  /* 기본 색상 */
  --bg:             #FFFFFF;
  --surface:        #F8F9FA;
  --border:         #E5E7EB;
  --text:           #1A1A2E;
  --text-sub:       #64748B;
  --text-light:     #A0AEC0;

  /* 레이아웃 */
  --sidebar-width:  240px;
  --header-height:  60px;

  /* UI */
  --radius:         10px;
  --radius-sm:      6px;
  --radius-lg:      16px;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:      0 4px 12px rgba(0,0,0,0.10);
  --transition:     all 0.2s ease;

  /* 채팅 */
  --bubble-ai:      #F0F4F8;
  --bubble-user:    #0072BC;
  --bubble-user-text: #FFFFFF;
}

/* =========================================
   2. 리셋 & 기본
   ========================================= */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  word-break: keep-all;
}

html { scroll-behavior: smooth; }

body {
  font-family: "Noto Sans KR", "Inter", -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100dvh;
  font-size: 15px;
  letter-spacing: -0.01em;
  overflow: hidden; /* 뷰 전환 시 스크롤 방지 */
}

button { cursor: pointer; border: none; background: none; font: inherit; }
sup { font-size: 0.65em; vertical-align: super; }
kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-sub);
}

/* Material Symbols 기본 설정 */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}


/* =========================================
   3. 앱 뷰 전환
   ========================================= */
.app-view {
  display: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.app-view.active {
  display: flex;
  flex-direction: column;
}


/* =========================================
   4. 제품 선택 화면
   ========================================= */
#view-select {
  background: var(--brand-dark);
  min-height: 100dvh;
  overflow-y: auto;
}

.select-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 10% 20%, rgba(0,114,188,0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 90% 80%, rgba(0,114,188,0.10) 0%, transparent 55%);
  pointer-events: none;
}

.select-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 2rem 1rem;
}

.select-logo {
  height: 22px;
  width: auto;
}

.select-body {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1.5rem 2rem;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.select-title-block {
  text-align: center;
  margin-bottom: 2.5rem;
}

.select-eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--brand-blue);
  margin-bottom: 0.5rem;
}

.select-title {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700;
  color: #FFFFFF;
  line-height: 1.2;
  margin-bottom: 0.75rem;
}

.select-subtitle {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.60);
  line-height: 1.8;
}

.select-subtitle .text-en {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.40);
}

/* 제품 카드 그리드 */
.product-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  width: 100%;
}

/* 제품 카드 */
.product-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
  transition: var(--transition);
  text-align: center;
  cursor: pointer;
  position: relative;
  color: #fff;
}

.product-card:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.25);
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.3);
  text-decoration: none;
}

.product-card:hover .product-card-arrow {
  opacity: 1;
  transform: translateX(0);
}

.product-card-image-wrap {
  width: 100%;
  aspect-ratio: 3/4;
  background: linear-gradient(160deg, rgba(255,255,255,0.10) 0%, color-mix(in srgb, var(--card-color) 30%, transparent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
}

.product-card-image-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--card-color) 20%, transparent) 0%, transparent 70%);
}

.product-card-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: relative;
  z-index: 1;
  transition: transform 0.3s ease;
}

.product-card:hover .product-card-image {
  transform: scale(1.05);
}

.product-card-info {
  padding: 0.85rem 0.75rem 0.5rem;
  width: 100%;
}

.product-card-name-en {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.90);
  margin-bottom: 0.2rem;
  line-height: 1.3;
}

.product-card-name-ko {
  font-size: 0.8rem;
  font-weight: 400;
  color: rgba(255,255,255,0.55);
}

.product-card-arrow {
  margin-bottom: 0.85rem;
  opacity: 0;
  transform: translateX(-4px);
  transition: var(--transition);
  color: var(--brand-blue);
}

.product-card-arrow .material-symbols-outlined {
  font-size: 16px;
}

.select-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1.25rem 1rem;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.25);
  border-top: 1px solid rgba(255,255,255,0.06);
}


/* =========================================
   5. 채팅 화면 레이아웃
   ========================================= */
#view-chat {
  background: var(--bg);
}

.page-layout {
  display: flex;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}


/* =========================================
   6. 사이드바 (PC)
   ========================================= */
.page-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--brand-dark);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  transition: transform 0.25s ease;
  z-index: 200;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
  height: 18px;
  width: auto;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 0.75rem;
}

.sidebar-nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  padding: 0 0.5rem;
  margin-bottom: 0.5rem;
}

.sidebar-product-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  cursor: pointer;
  text-align: left;
  color: rgba(255,255,255,0.65);
  margin-bottom: 2px;
}

.sidebar-product-btn:hover,
.sidebar-product-btn.active {
  background: rgba(255,255,255,0.08);
  color: #FFFFFF;
  text-decoration: none;
}

.sidebar-product-btn.active {
  background: rgba(0,114,188,0.20);
  color: #FFFFFF;
}

.sidebar-product-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-product-name {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar-name-en {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
}

.sidebar-name-ko {
  font-size: 0.72rem;
  font-weight: 400;
  color: rgba(255,255,255,0.45);
}

.sidebar-product-btn.active .sidebar-name-ko {
  color: rgba(255,255,255,0.65);
}

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-back-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: rgba(255,255,255,0.50);
  transition: var(--transition);
}

.sidebar-back-btn:hover {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.85);
  text-decoration: none;
}

.sidebar-back-btn .material-symbols-outlined {
  font-size: 16px;
}

/* 사이드바 모바일 오버레이 */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
}


/* =========================================
   7. 메인 콘텐츠 영역
   ========================================= */
.page-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  min-width: 0;
}


/* =========================================
   8. 헤더
   ========================================= */
.page-header {
  height: var(--header-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

/* 햄버거 버튼 (모바일만 표시) */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-sub);
  flex-shrink: 0;
  transition: var(--transition);
}
.mobile-menu-btn:hover {
  background: var(--surface);
}

/* 모바일 칩 바 (모바일만 표시) */
.product-chip-bar {
  display: none;
  flex: 1;
  overflow-x: auto;
  gap: 0.4rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 0 0.25rem;
  align-items: center;
}
.product-chip-bar::-webkit-scrollbar { display: none; }

.product-chip {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  padding: 0.35rem 0.75rem;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text-sub);
  transition: var(--transition);
  flex-shrink: 0;
  cursor: pointer;
}
.product-chip:hover {
  border-color: var(--brand-blue);
  color: var(--brand-blue);
  text-decoration: none;
}
.product-chip.active {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
  color: #FFFFFF;
}

/* PC 제품 정보 표시 */
.header-product-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.header-product-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.header-product-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header-product-name-en {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.header-product-name-ko {
  font-size: 0.75rem;
  color: var(--text-sub);
}


.header-back-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-sub);
  border: 1px solid var(--border);
  transition: var(--transition);
  flex-shrink: 0;
}
.header-back-btn:hover {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.header-back-btn .material-symbols-outlined { font-size: 16px; }


/* =========================================
   9. 채팅 영역
   ========================================= */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  scroll-behavior: smooth;
}

.chat-container {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* 시스템 메시지 */
.chat-system-msg {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-light);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.chat-system-msg::before,
.chat-system-msg::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
  max-width: 80px;
}

/* 메시지 공통 */
.chat-message {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  max-width: 85%;
}

/* AI 메시지 */
.chat-message.chat-ai {
  align-self: flex-start;
}

.chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.chat-avatar .material-symbols-outlined { font-size: 16px; }

.chat-content-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chat-sender {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-sub);
  padding-left: 2px;
}

.chat-bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
}

.chat-bubble {
  padding: 0.75rem 1rem;
  border-radius: 18px 18px 18px 4px;
  font-size: 0.9rem;
  line-height: 1.7;
  background: var(--bubble-ai);
  color: var(--text);
  max-width: 100%;
  word-break: break-word;
}

.chat-time {
  font-size: 0.68rem;
  color: var(--text-light);
  white-space: nowrap;
  padding-bottom: 2px;
}

/* 사용자 메시지 */
.chat-message.chat-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message.chat-user .chat-bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-radius: 18px 18px 4px 18px;
}

.chat-message.chat-user .chat-bubble-row {
  flex-direction: row-reverse;
}

/* 로딩 애니메이션 */
.chat-loading {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}
.chat-loading span {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: loadingDots 1.4s infinite ease-in-out both;
}
.chat-loading span:nth-child(2) { animation-delay: 0.2s; }
.chat-loading span:nth-child(3) { animation-delay: 0.4s; }
@keyframes loadingDots {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}


/* =========================================
   10. 입력 영역
   ========================================= */
.chat-input-area {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  transition: var(--transition);
  max-width: 720px;
  margin: 0 auto;
}

.chat-input-wrap:focus-within {
  border-color: var(--brand-blue);
  background: var(--bg);
  box-shadow: 0 0 0 3px rgba(0,114,188,0.10);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  padding: 0.15rem 0;
}
.chat-input::placeholder { color: var(--text-light); }

.chat-input-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.chat-voice-out-btn,
.chat-mic-btn,
.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.chat-voice-out-btn {
  color: var(--text-light);
  background: transparent;
}
.chat-voice-out-btn:hover { background: var(--border); color: var(--text); }
.chat-voice-out-btn.active { color: var(--brand-blue); }

.chat-mic-btn {
  color: var(--text-sub);
  background: transparent;
}
.chat-mic-btn:hover { background: var(--border); color: var(--text); }
.chat-mic-btn.recording {
  background: #fee2e2;
  color: #dc2626;
  animation: micPulse 1.5s infinite;
}

.chat-send-btn {
  background: var(--brand-blue);
  color: #FFFFFF;
}
.chat-send-btn:hover { background: #005a96; }
.chat-send-btn:disabled { background: var(--border); color: var(--text-light); cursor: not-allowed; }

.chat-input-hint {
  max-width: 720px;
  margin: 0.4rem auto 0;
  font-size: 0.72rem;
  color: var(--text-light);
  padding-left: 0.25rem;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); }
  50%       { box-shadow: 0 0 0 8px rgba(220,38,38,0); }
}

/* 음성 입력 상태 표시 */
.voice-status {
  max-width: 720px;
  margin: 0 auto 0.5rem;
  padding: 0.5rem 0.85rem;
  background: #FEF2F2;
  border: 1px solid #FCA5A5;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: #DC2626;
  display: none;
  align-items: center;
  gap: 0.4rem;
}
.voice-status.active { display: flex; }
.voice-status .material-symbols-outlined { font-size: 15px; }


/* =========================================
   11. 반응형 — 모바일 (≤ 1024px)
   ========================================= */
@media (max-width: 1024px) {
  /* 사이드바: 드로어로 변환 */
  .page-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: var(--shadow-md);
  }
  .page-sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.active { display: block; }

  /* 헤더: 모바일 레이아웃 */
  .mobile-menu-btn { display: flex; }
  .product-chip-bar { display: flex; }
  .header-product-info { display: none; }
  .header-back-btn { display: none; }


  /* 페이지 메인: 전체 너비 */
  .page-main { width: 100%; }

  /* 제품 그리드: 모바일 2열 */
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  /* 제품 카드 이미지 비율 조정 */
  .product-card-image-wrap {
    aspect-ratio: 3/3.5;
    padding: 1rem;
  }

  .select-body { padding: 1rem 1rem 2rem; }
  .select-title-block { margin-bottom: 1.75rem; }

  /* 채팅 입력 힌트 숨김 */
  .chat-input-hint { display: none; }
}

@media (max-width: 480px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
  }
  .select-title { font-size: 1.6rem; }
  .chat-area { padding: 1rem 0.75rem; }
  .chat-input-area { padding: 0.6rem 0.75rem; }
}

/* =========================================
   12. 스크롤바 스타일
   ========================================= */
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.chat-area::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* =========================================
   13. 유틸리티
   ========================================= */
.hidden { display: none !important; }
