:root {
  --page-bg: #ffffff;
  --bg: #ececec;
  --bar-bg: #ffffff;
  --border: #e2e2e2;
  --bubble-bg: #ffffff;
  --text-main: #1c1c1c;
  --text-sub: #9a9a9a;
  --text-name: #8f8f8f;
  --accent: #ff5b7a;
  --pill-bg: #ffffff;
  --pill-active-bg: #1c1c1c;
  font-size: 16px;
}

* { box-sizing: border-box; }

/* Twemoji: 폰트 대신 이미지로 렌더링되는 이모지 - 텍스트와 자연스럽게 어울리도록 크기/정렬 보정 */
img.emoji {
  height: 1.2em;
  width: 1.2em;
  margin: 0 .04em 0 .08em;
  vertical-align: -0.2em;
  display: inline-block;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  color: var(--text-main);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--border), 0 0 18px rgba(0,0,0,0.08);
  position: relative;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 6px;
}
.back {
  grid-column: 1;
  justify-self: start;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: #1c1c1c;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  text-decoration: none;
}
.back svg { width: 22px; height: 22px; }
.peer {
  grid-column: 2;
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-width: 0;
}
.peer h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.peer h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  color: var(--text-main);
}
.pink-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 2px 16px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #b0b0b0;
}
.pink-banner span { color: #a8a8a8; }
.icons {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 14px;
  color: #1c1c1c;
  flex-shrink: 0;
}
.icons svg { width: 21px; height: 21px; }

.months {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 14px 12px;
  scrollbar-width: none;
}
.months::-webkit-scrollbar { display: none; }
.month-pill {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: #6f6f6f;
  background: var(--pill-bg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-variant-numeric: tabular-nums;
}
.month-pill:hover { background: #f5f5f5; }
.month-pill.active {
  color: #ffffff;
  background: var(--pill-active-bg);
  border-color: var(--pill-active-bg);
  font-weight: 700;
}

.days {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding: 0 14px 10px;
  scrollbar-width: none;
  border-top: 1px solid var(--border);
  margin-top: -1px;
  padding-top: 8px;
}
.days::-webkit-scrollbar { display: none; }
.days:empty { display: none; }
.day-pill {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  font-size: 10px;
  font-weight: 500;
  color: #9a9a9a;
  background: transparent;
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-variant-numeric: tabular-nums;
}
.day-pill .day-num {
  font-size: 12.5px;
  font-weight: 700;
  color: #4a4a4a;
}
.day-pill:hover { background: #f5f5f5; }
.day-pill.active {
  color: rgba(255,255,255,0.75);
  background: var(--accent);
  border-color: var(--accent);
}
.day-pill.active .day-num { color: #ffffff; }

/* ---------- chat area ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 40px;
  scroll-behavior: smooth;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.55) transparent;
}
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb { background:#fff; border:1px solid rgba(0,0,0,.15); background-clip:padding-box; border-radius:999px; }
.chat::-webkit-scrollbar-thumb:hover { background:#fff; border-color:rgba(0,0,0,.28); }
.chat-inner {
  display: flex;
  flex-direction: column;
}

.day-divider {
  text-align: center;
  margin: 18px 0 14px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-sub);
}
.day-divider:first-child { margin-top: 4px; }
.day-divider span {
  background: rgba(0,0,0,0.05);
  padding: 4px 11px;
  border-radius: 999px;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 14px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, #ffd1dc, #ff5b7a);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar .fallback {
  display: none;
  width: 100%; height: 100%;
  align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 13px;
}

.msg-body { min-width: 0; }

.sender-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-name);
  margin: 0 0 4px;
}

.bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.bubble {
  background: var(--bubble-bg);
  color: var(--text-main);
  padding: 9px 13px;
  border-radius: 18px;
  border-top-left-radius: 4px;
  font-size: 14.5px;
  line-height: 1.48;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 250px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.03);
}

.time {
  font-size: 10.5px;
  color: var(--text-sub);
  flex-shrink: 0;
  padding-bottom: 3px;
  white-space: nowrap;
}

/* ---------- drive link wrapper ---------- */
.drive-link-wrap {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.drive-link-wrap:hover .attach-card,
.drive-link-wrap:hover .attach-media,
.drive-link-wrap:hover .live-card {
  filter: brightness(0.96);
}

/* ---------- attachment cards ---------- */
.attach-card {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bubble-bg);
  border-radius: 18px;
  border-top-left-radius: 4px;
  padding: 12px 15px;
  max-width: 230px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.03);
}
.attach-media {
  display: block;
  border-radius: 18px;
  border-top-left-radius: 4px;
  max-width: 240px;
  max-height: 320px;
}
.photo-media, .sticker-media { object-fit: cover; }
.sticker-media { max-width: 140px; max-height: 140px; border-radius: 12px; }
.video-media, .voice-media { max-width: 240px; }
.voice-media { height: 40px; }
.attach-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f1f1f1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}
.attach-icon.photo { background: #eef4ff; }
.attach-icon.video { background: #fff0f0; }
.attach-icon.voice { background: #f0f4ff; }
.attach-icon.call { background: #eafaf0; }
.attach-icon.sticker { background: #fff8e8; }
.attach-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.attach-label {
  font-size: 13.5px;
  font-weight: 600;
  color: #333;
}
.attach-sub {
  font-size: 11.5px;
  color: var(--text-sub);
}

.live-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1c1c1c;
  color: #fff;
  border-radius: 18px;
  border-top-left-radius: 4px;
  padding: 10px 16px;
  max-width: 230px;
  font-size: 13.5px;
  font-weight: 600;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.live-card.ended { background: #565656; }

/* ---------- jump to latest button ---------- */
.jump {
  position: absolute;
  right: 18px;
  bottom: 22px;
  z-index: 20;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #1c1c1c;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.jump svg { width: 18px; height: 18px; }
.jump.show { opacity: 1; pointer-events: auto; }

.empty-state {
  text-align: center;
  color: var(--text-sub);
  font-size: 13px;
  padding: 60px 20px;
}

/* ---------- search overlay ---------- */
.search-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.search-overlay[hidden] { display: none; }
.search-bar {
  background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  flex-shrink: 0;
}
.search-back {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  color: #1c1c1c;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.search-back svg { width: 21px; height: 21px; }
.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: #f1f1f1;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-main);
  min-width: 0;
}
.search-input::placeholder { color: #a0a0a0; }
.search-clear {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: #9a9a9a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.search-clear svg { width: 20px; height: 20px; }
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0 30px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.55) transparent;
}
.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-track { background: transparent; }
.search-results::-webkit-scrollbar-thumb { background:#fff; border:1px solid rgba(0,0,0,.15); background-clip:padding-box; border-radius:999px; }
.search-results::-webkit-scrollbar-thumb:hover { background:#fff; border-color:rgba(0,0,0,.28); }
.search-meta {
  padding: 10px 16px 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-sub);
}
.search-empty {
  text-align: center;
  color: var(--text-sub);
  font-size: 13px;
  padding: 60px 20px;
}
.search-result-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.search-result-item:hover,
.search-result-item:active { background: rgba(0,0,0,0.03); }
.search-result-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 3px;
}
.search-result-snippet {
  font-size: 13.5px;
  color: var(--text-main);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-result-snippet mark {
  background: var(--accent);
  color: #ffffff;
  border-radius: 3px;
  padding: 0 1px;
}

/* ---------- jump-to-message highlight ---------- */
@keyframes bubbleFlash {
  0% { box-shadow: 0 0 0 3px rgba(255,91,122,0.55), 0 1px 1px rgba(0,0,0,0.03); }
  100% { box-shadow: 0 1px 1px rgba(0,0,0,0.03); }
}
.msg-row.flash .bubble,
.msg-row.flash .attach-card,
.msg-row.flash .live-card {
  animation: bubbleFlash 1.6s ease-out;
}
