/* =============================================================
   WHITE SANDS AI 컨시어지 — ChatGPT 영감 미니멀 레이아웃
   - 흰 배경, 둥근 카드, 둥근 입력바, 우상단 휴지통
   - 데스크톱/모바일 양쪽 노년층 친화 폰트 사이즈
============================================================= */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --ink: #0d0d0d;
  --ink-2: #444444;
  --ink-3: #8e8ea0;
  --line: #ececec;
  --line-2: #dcdcdc;
  --accent: #c2895a;
  --bubble-user: #f0f0f0;
  --bubble-user-ink: #0d0d0d;
  --bubble-ai: #ffffff;
  --bubble-ai-ink: #0d0d0d;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --radius: 18px;
  --radius-sm: 14px;
  --radius-pill: 999px;
  --maxw: 760px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html, body {
  height: 100%;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Segoe UI", system-ui, sans-serif;
  font-size: 22px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, textarea, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- App layout ---------- */
/* grid: 헤더(auto) / 채팅(1fr) / 컴포저(auto)
   - composer 는 자연스럽게 화면 바닥에 위치 (position: fixed 없이)
   - iOS Safari 키보드 올라와도 100dvh 가 자동 조정되어 정상 동작 */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
}

/* ---------- Header ---------- */
.hd {
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.hd-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.hd-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hd-mark {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--ink); color: #fff;
  border-radius: 10px;
  overflow: hidden;
  flex: 0 0 auto;
}
.hd-logo { width: 30px; height: 30px; object-fit: contain; filter: invert(1) brightness(2); }
.hd-logo-fallback { width: 30px; height: 30px; color: #fff; }
.hd-title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.hd-name { font-weight: 700; font-size: 19px; letter-spacing: 0.3px; white-space: nowrap; }
.hd-sub { font-size: 14px; color: var(--ink-3); margin-top: 2px; }

.hd-clear {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  color: var(--ink-2);
  flex: 0 0 auto;
  transition: all 0.12s ease;
}
.hd-clear:hover { background: var(--surface); border-color: var(--ink); color: var(--ink); }
.hd-clear:active { transform: scale(0.94); }

/* ---------- Chat area ---------- */
/* grid 안에서 1fr 영역 — overflow-y 만 자체 스크롤. composer 는 grid 가 따로 잡음 */
.chat {
  overflow-y: auto;
  padding: 24px 16px 16px;
  scroll-behavior: smooth;
  min-height: 0;                    /* grid 내 overflow 가능하게 */
}

.msgs {
  max-width: var(--maxw);
  margin: 0 auto;
  width: 100%;
  display: flex; flex-direction: column; gap: 16px;
}

.msg {
  display: flex; flex-direction: column; gap: 6px;
  animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg.user { align-items: flex-end; }
.msg.ai   { align-items: flex-start; }
.bubble {
  max-width: 90%;
  padding: 13px 17px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 21px;
  line-height: 1.55;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-ink);
  border-top-right-radius: 6px;
}
.msg.ai .bubble {
  background: var(--bubble-ai);
  color: var(--bubble-ai-ink);
  border-top-left-radius: 6px;
}
.msg.user .bubble img.upload-preview {
  max-width: 200px;
  border-radius: 12px;
  margin-bottom: 4px;
}
.bubble.thinking {
  color: var(--ink-3);
  display: inline-flex; gap: 4px; align-items: center;
}
.bubble.thinking span {
  width: 7px; height: 7px; background: currentColor; border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.bubble.thinking span:nth-child(2) { animation-delay: 0.15s; }
.bubble.thinking span:nth-child(3) { animation-delay: 0.30s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Suggest cards (composer 안쪽 위 — 메시지 없을 때만) ---------- */
.suggest-cards {
  max-width: var(--maxw);
  margin: 0 auto 10px;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));    /* minmax(0, 1fr) = 강제 동등 분할 */
  gap: 10px;
}
.suggest-cards.hidden { display: none; }
.sug-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.12s ease;
  min-height: 64px;
  min-width: 0;                                         /* overflow 방지 */
  justify-content: center;
  width: 100%;
}
.sug-card:hover { border-color: var(--ink-3); background: var(--surface-2); }
.sug-card:active { transform: scale(0.98); }
.sug-title {
  font-weight: 600;
  font-size: 17px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sug-sub {
  font-size: 14px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ---------- Composer (grid 마지막 행, 자연스럽게 바닥) ---------- */
.composer {
  background: var(--bg);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 100vw;
}
.composer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  width: 100%;
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 6px 8px 6px 6px;
  transition: border-color 0.12s ease;
}
.composer-inner:focus-within { border-color: var(--ink-3); }

.input {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  border: none;
  border-radius: 0;
  padding: 12px 8px;
  resize: none;
  outline: none;
  background: transparent;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  font-size: 21px;
  line-height: 1.4;
  overflow-y: auto;
  /* 스크롤바 화살표 완전히 숨김 */
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* IE/Edge legacy */
}
.input::-webkit-scrollbar { display: none; }   /* Chrome/Safari/Edge */
.input::placeholder { color: var(--ink-3); }

.icon-btn-plus, .icon-btn-mic {
  border: none;
  background: transparent;
  border-radius: 50%;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: var(--ink-3);                /* 더 옅은 회색으로 미니멀 */
  flex: 0 0 auto;
  transition: color 0.12s ease;
  padding: 0;
}
.icon-btn-plus:hover, .icon-btn-mic:hover { color: var(--ink); background: transparent; }
/* 마이크 아이콘만 +30% 키움 */
.icon-btn-mic svg { width: 26px; height: 26px; }
.icon-btn-mic.recording {
  color: #fff;
  background: var(--accent);
  animation: pulse-bg 1s infinite;
}
@keyframes pulse-bg { 0%,100%{filter:brightness(1);} 50%{filter:brightness(1.1);} }

/* 검정 원형 전송 버튼 (위쪽 화살표) */
.send-btn {
  background: var(--ink);
  border: none;
  border-radius: 50%;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: #fff;
  flex: 0 0 auto;
  transition: all 0.12s ease;
  padding: 0;
}
.send-btn:hover { background: #000; transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }
.send-btn[disabled] { opacity: 0.3; cursor: not-allowed; transform: none; }

.composer-foot {
  max-width: var(--maxw);
  margin: 6px auto 0;
  padding: 0 4px;
  display: flex; justify-content: flex-end; align-items: center;
  font-size: 13px; color: var(--ink-3);
}
.tip { letter-spacing: 0.2px; opacity: 0.7; }

/* ---------- Status pill (헤더 안, 로고 옆 inline — idle 일 때 숨김) ---------- */
.status-pill {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--ink-3);
  display: none;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.status-pill.show { display: inline-flex; }
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #2ecc71;
}
.dot.busy { background: var(--accent); animation: pulse 1s infinite; }
.dot.error { background: #e74c3c; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ---------- Product cards ---------- */
.products {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 100%;
  margin: 8px auto 0;
}
.products > .pcard {
  /* 2열 강제: (100% - 1*gap) / 2 = calc((100% - 10px) / 2) */
  flex: 0 0 calc((100% - 10px) / 2);
  max-width: calc((100% - 10px) / 2);
  min-width: 0;
}
@media (min-width: 720px) {
  .products > .pcard {
    flex: 0 0 220px;
    max-width: 220px;
  }
}
.pcard {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.pcard:hover { border-color: var(--ink); transform: translateY(-1px); }
.pcard-img {
  width: 100%;
  aspect-ratio: 1 / 1;          /* 정사각형 */
  background: var(--surface-2);
  background-size: cover;
  background-position: center;
}
.pcard-body {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pcard-feature {
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pcard-price {
  font-size: 13px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.pcard-retail { font-size: 11px; color: #aaa; text-decoration: line-through; }
.pcard-sale   { font-size: 14px; color: var(--ink); font-weight: 700; }
.pcard-off    { font-size: 12px; color: #e53935; font-weight: 700; }

/* ---------- Action row ---------- */
.actions {
  display: flex; gap: 6px; align-items: center;
  margin-top: 4px;
  font-size: 13px; color: var(--ink-3);
  opacity: 0; transition: opacity 0.12s ease;
}
.msg.ai:hover .actions, .actions.show { opacity: 1; }
.actions button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-3);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
}
.actions button:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.actions button.active { color: var(--accent); }

/* ---------- 이미지 미리보기 (입력칸 위) ---------- */
.upload-preview-bar {
  max-width: var(--maxw);
  margin: 0 auto 6px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.upload-preview-bar img {
  width: 50px; height: 50px;
  object-fit: cover;
  border-radius: 8px;
}
.upload-preview-bar .upload-name { flex: 1; font-size: 14px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-preview-bar .upload-cancel {
  background: transparent;
  border: none;
  color: var(--ink-3);
  font-size: 18px;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid; place-items: center;
}
.upload-preview-bar .upload-cancel:hover { background: var(--line); color: var(--ink); }

/* ============================================================
   Desktop (769px+) — 폰트 다운스케일 (PC에서 적당한 크기)
============================================================ */
@media (min-width: 769px) {
  body { font-size: 16px; }

  .hd-mark { width: 36px; height: 36px; }
  .hd-logo, .hd-logo-fallback { width: 24px; height: 24px; }
  .hd-name { font-size: 15px; }
  .hd-sub { font-size: 12px; }
  .hd-clear { width: 38px; height: 38px; }

  .chat { padding: 24px 20px 16px; }

  .bubble { font-size: 15.5px; padding: 11px 15px; }

  .sug-card { min-height: 60px; padding: 12px 14px; }
  .sug-title { font-size: 14.5px; }
  .sug-sub { font-size: 12.5px; }

  .composer-top .tts-toggle { font-size: 15.6px; }   /* 13 × 1.2 = 15.6 */
  .composer-top .tts-toggle input { width: 18px; height: 18px; }

  .input { font-size: 15.5px; height: 40px; min-height: 40px; max-height: 40px; padding: 10px 8px; }
  .icon-btn-plus, .icon-btn-mic, .send-btn { width: 36px; height: 36px; }
  .composer-inner { padding: 5px 7px 5px 5px; border-radius: 24px; }

  .composer-foot { font-size: 12px; }
}

/* ============================================================
   Mobile (≤480px) — 노년층 친화 (큰 글씨)
============================================================ */
@media (max-width: 480px) {
  .hd-inner { padding: 12px 14px; gap: 10px; }
  .hd-mark { width: 42px; height: 42px; }
  .hd-logo, .hd-logo-fallback { width: 28px; height: 28px; }
  .hd-name { font-size: 18px; }
  .hd-sub { font-size: 13px; }
  .hd-clear { width: 40px; height: 40px; }

  .chat { padding: 14px 12px 14px; }
  .msgs { gap: 14px; }
  .bubble { font-size: 19px; padding: 12px 15px; max-width: 92%; }

  .suggest-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 8px;
  }
  .sug-card { padding: 11px 13px; min-height: 56px; min-width: 0; }
  .sug-title { font-size: 15px; }
  .sug-sub { font-size: 12.5px; }

  .composer-top { margin-bottom: 4px; }
  .composer-top .tts-toggle { font-size: 14.5px; }
  .composer-top .tts-toggle input { width: 16px; height: 16px; }

  .composer { padding: 8px 10px env(safe-area-inset-bottom); }
  .composer-inner { padding: 5px 7px 5px 5px; }
  .input { font-size: 19px; height: 44px; min-height: 44px; max-height: 44px; padding: 11px 8px; }
  .icon-btn-plus, .icon-btn-mic, .send-btn { width: 42px; height: 42px; }
  .composer-foot { font-size: 12.5px; padding: 0 4px; }
}

/* ============================================================
   Widget mode (iframe 내부)
============================================================ */
.app[data-mode="widget"] {
  height: 100%;
  min-height: 0;
}
.app[data-mode="widget"] .hd-inner { padding: 10px 14px; }
.app[data-mode="widget"] .chat { padding: 14px 12px 16px; }
.app[data-mode="widget"] .composer { padding: 6px 10px; }
