* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", sans-serif; background: #bacee0; color: #111; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; }

.app { position: relative; width: 100%; height: 100%; height: var(--vh, 100dvh); display: flex; flex-direction: column; background: #bacee0; overflow: hidden; }
body { overscroll-behavior: none; }

/* ---- 머리 ---- */
.chat-head { display: flex; align-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 10px 10px 14px; }
.who { display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; flex: 1; }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-text b { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.warn { font-size: 11px; color: #a33; }
.head-icons { display: flex; gap: 2px; }
.ico { background: none; border: none; color: #222; padding: 6px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.ico:hover { background: rgba(0,0,0,.06); }
.ico.sm { padding: 4px 6px; font-size: 11px; color: #555; }
.ico.sm svg { width: 16px; height: 16px; }

.avatar {
  width: 40px; height: 40px; border-radius: 15px; background: #9fb6cb center/cover no-repeat; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 20px; overflow: hidden; cursor: pointer;
}
.avatar.empty::after { content: "🙂"; }

.searchbar { display: flex; align-items: center; gap: 4px; margin: 0 10px 6px; padding: 4px 6px 4px 10px; background: #fff; border-radius: 8px; }
.searchbar input { flex: 1; border: none; outline: none; font: inherit; font-size: 13px; min-width: 0; }
#searchCount { font-size: 12px; color: #777; }

/* ---- 대화 ---- */
/* 카톡 PC 와 비슷한 크기: 글자 13px, 프사 36px, 말풍선 여백 6/9px */
.list-wrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
#list { flex: 1; overflow-y: auto; padding: 4px 10px 12px 14px; }
#list::-webkit-scrollbar { width: 12px; }
#list::-webkit-scrollbar-track { background: transparent; }
#list::-webkit-scrollbar-thumb { background: rgba(70, 85, 100, .35); border: 3px solid transparent; background-clip: padding-box; border-radius: 6px; min-height: 40px; }
#list::-webkit-scrollbar-thumb:hover { background-color: rgba(70, 85, 100, .55); }
#list::-webkit-scrollbar-button { display: none; height: 0; }
.day { text-align: center; margin: 12px 0 8px; }
.day span { background: rgba(0,0,0,.1); color: #fff; font-size: 11px; padding: 4px 12px; border-radius: 12px; }
.to-bottom { position: absolute; right: 16px; bottom: 12px; width: 38px; height: 38px; border-radius: 50%; border: none; background: rgba(255,255,255,.95); color: #333; box-shadow: 0 1px 4px rgba(0,0,0,.18); display: flex; align-items: center; justify-content: center; z-index: 5; }
.to-bottom svg { width: 20px; height: 20px; }
.to-bottom:hover { background: #fff; }
.to-bottom.new::after { content: ""; position: absolute; top: 2px; right: 2px; width: 8px; height: 8px; border-radius: 50%; background: #ff5a4e; }
.row { display: flex; align-items: flex-end; gap: 5px; margin: 4px 0; }
.row.me { justify-content: flex-end; }
.row.bot { padding-left: 46px; }
.row.bot.first { padding-left: 0; margin-top: 10px; gap: 0; }
.row.me.first { margin-top: 10px; }
.row .avatar { align-self: flex-start; width: 36px; height: 36px; border-radius: 14px; font-size: 18px; margin-right: 10px; }
.row.bot.first .time, .row.bot.first .meta { margin-left: 5px; }
.col { display: flex; flex-direction: column; align-items: flex-start; max-width: min(72%, 560px); }
.row.me .col { align-items: flex-end; }
.name { font-size: 12px; color: #3d4752; margin: 1px 0 5px 1px; }
.bubble { position: relative; padding: 6px 9px; border-radius: 6px; font-size: 13px; line-height: 1.42; white-space: pre-wrap; word-break: break-word; background: #fff; }
.me .bubble { background: #fee500; }
/* 묶음의 첫 말풍선에만 꼬리 */
.row.first .bubble::before { content: ""; position: absolute; top: 7px; border-top: 5px solid transparent; border-bottom: 5px solid transparent; }
.row.first .bubble.media::before, .row.first .bubble.big-emoji::before, .row.first .bubble.filebox::before { display: none; }
.row.bot.first .bubble::before { left: -7px; border-right: 6px solid #fff; border-left: 0; }
.row.me.first .bubble::before { right: -7px; border-left: 6px solid #fee500; border-right: 0; }
.row.error.first .bubble::before { border-right-color: #ffe1e1; }
.bubble.media { padding: 0; background: none; border-radius: 12px; overflow: hidden; }
.bubble.media img { display: block; max-width: 230px; max-height: 320px; border-radius: 12px; cursor: zoom-in; }
.bubble.media video { display: block; max-width: 260px; max-height: 340px; border-radius: 12px; background: #000; }
.bubble.big-emoji { background: none !important; padding: 0; font-size: 56px; line-height: 1.1; }
.bubble.filebox { display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 10px 12px; background: #fff !important; }
.filebox .fi { width: 38px; height: 38px; border-radius: 8px; background: #6c8cff; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: none; }
.filebox .fn { display: flex; flex-direction: column; min-width: 0; }
.filebox .fn b { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.filebox .fn small { color: #888; font-size: 11px; margin-top: 2px; }
.filebox a { color: #3b6fd8; font-size: 12px; text-decoration: none; margin-left: auto; padding-left: 6px; }
.sending { opacity: .55; }
.progress { font-size: 10px; color: #556; }
.time { font-size: 10px; color: #556; white-space: nowrap; margin-bottom: 1px; }
.meta { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; margin-bottom: 1px; }
.meta .time { margin-bottom: 0; }
.unread { font-size: 10px; font-weight: 700; color: #e6b800; line-height: 1; }
.row.me.first .meta, .row.me.first > .time { margin-right: 5px; }
.row.error .bubble { background: #ffe1e1; color: #922; font-size: 13px; }
.row.hit .bubble { outline: 2px solid #ff8a00; }
.typing .bubble { display: inline-flex; gap: 4px; padding: 11px 12px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: #999; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

/* ---- 입력창 ---- */
.composer { background: #fff; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.composer textarea { border: none; outline: none; resize: none; font: inherit; font-size: 13px; line-height: 1.4; padding: 12px 14px 4px; min-height: 64px; max-height: 140px; }
.tools { display: flex; align-items: center; gap: 2px; padding: 4px 8px 8px; }
.tools .ico { color: #444; }
.tools .ico.on { color: #000; background: rgba(0,0,0,.07); }
.spacer { flex: 1; }
.send { border: none; border-radius: 4px; background: #fee500; padding: 0 16px; height: 32px; font-size: 13px; }
.send:disabled { background: #f1f1f1; color: #b5b5b5; cursor: default; }

.emoji-panel { background: #fff; border-top: 1px solid #eee; height: 200px; overflow-y: auto; padding: 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; align-content: start; }
.emoji-panel button { border: none; background: none; font-size: 26px; padding: 4px 0; border-radius: 8px; }
.emoji-panel button:hover { background: #f2f2f2; }

/* ---- 서랍 ---- */
.drawer-back { position: absolute; inset: 0; background: rgba(0,0,0,.3); z-index: 5; }
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(320px, 86%); background: #fff; z-index: 6; display: flex; flex-direction: column; overflow-y: auto; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 10px 10px 16px; font-weight: 600; }
.drawer-who { display: flex; align-items: center; gap: 10px; padding: 8px 16px 14px; border-bottom: 1px solid #eee; cursor: pointer; }
.drawer-sec { font-size: 13px; font-weight: 600; padding: 14px 16px 8px; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 0 16px; }
.media-grid > * { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; cursor: pointer; background: #000; }
.file-list { padding: 0 16px; font-size: 13px; }
.file-list a { display: block; color: #333; text-decoration: none; padding: 6px 0; border-bottom: 1px solid #f3f3f3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-note { color: #999; font-size: 12px; padding: 2px 0 6px; grid-column: 1 / -1; background: none !important; aspect-ratio: auto !important; }
.drawer-btn { margin: 20px 16px; padding: 10px; border: 1px solid #ddd; background: #fafafa; border-radius: 6px; }

/* ---- 프로필 ---- */
.profile { position: absolute; inset: 0; z-index: 10; display: none; flex-direction: column; color: #fff;
  background: linear-gradient(170deg, #4a70c9, #1b3d86) center/cover no-repeat; }
.profile.open { display: flex; }
.profile::before { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(0,0,0,.15), transparent 25%, transparent 55%, rgba(0,0,0,.55)); pointer-events: none; }
.p-top { position: relative; display: flex; justify-content: space-between; align-items: flex-start; padding: 12px; z-index: 1; }
.p-left { position: relative; display: flex; gap: 8px; }
.round { width: 32px; height: 32px; border-radius: 50%; border: none; background: rgba(15,25,50,.55); color: #fff; display: flex; align-items: center; justify-content: center; padding: 0; }
.round svg { width: 18px; height: 18px; }
.round.plain { background: none; }
.round.plain svg { width: 20px; height: 20px; }
.p-menu { position: absolute; top: 40px; left: 0; background: #fff; color: #222; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); display: flex; flex-direction: column; min-width: 170px; overflow: hidden; }
.p-menu button { border: none; background: none; text-align: left; padding: 10px 14px; font-size: 13px; }
.p-menu button:hover { background: #f3f3f3; }
.p-mid { position: relative; flex: 1; cursor: zoom-in; display: flex; justify-content: center; align-items: flex-start; padding-top: 14%; }
.music { display: inline-flex; align-items: center; gap: 8px; max-width: 70%; padding: 6px 12px; border-radius: 16px; border: 1px solid rgba(255,255,255,.35); background: rgba(20,30,60,.45); color: #fff; font-size: 12px; cursor: pointer; }
.music #pMusicText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.music .note { opacity: .8; }
.music .play { font-size: 10px; }
.p-bottom { position: relative; padding: 0 22px 24px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.avatar.big { width: 84px; height: 84px; border-radius: 32px; font-size: 40px; margin-bottom: 4px; }
.p-name { display: flex; align-items: center; gap: 6px; font-size: 21px; font-weight: 700; }
.pencil { background: none; border: none; color: rgba(255,255,255,.75); padding: 2px; display: flex; }
.pencil svg { width: 17px; height: 17px; }
.p-status { font-size: 13px; opacity: .9; min-height: 0; }
.p-actions { align-self: stretch; margin-top: 18px; display: flex; align-items: center; border: 1px solid rgba(255,255,255,.4); border-radius: 12px; background: rgba(255,255,255,.08); }
.p-actions button { flex: 1; background: none; border: none; color: #fff; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 14px 0; font-size: 14px; }
.p-actions svg { width: 17px; height: 17px; }
.p-actions .bar { width: 1px; height: 18px; background: rgba(255,255,255,.4); }

/* ---- 친구 정보 ---- */
.modal-back { position: absolute; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; }
.modal { width: min(300px, 92%); background: #fff; border-radius: 4px; padding: 20px 20px 18px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.m-head { display: flex; justify-content: space-between; align-items: center; font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.m-head .ico svg { width: 18px; height: 18px; }
.m-field { display: flex; align-items: center; border-bottom: 1.5px solid #222; padding-bottom: 6px; }
.m-field input { flex: 1; border: none; outline: none; font: inherit; font-size: 15px; min-width: 0; }
.cnt { font-size: 11px; color: #999; }
.m-own { font-size: 12px; color: #888; margin: 10px 0 22px; }
.m-label { display: flex; justify-content: space-between; font-size: 12px; color: #666; margin-bottom: 6px; }
.modal textarea { width: 100%; height: 80px; resize: none; border: 1px solid #ddd; padding: 8px 10px; font: inherit; font-size: 13px; outline: none; }
.m-note { font-size: 12px; color: #666; margin: 10px 0 18px; }
.m-note em { font-style: normal; color: #e8890c; }
.m-btns { display: flex; justify-content: flex-end; gap: 6px; }
.m-btns button { width: 72px; height: 34px; border: 1px solid #ddd; background: #fff; border-radius: 3px; font-size: 13px; }
.m-btns .ok { background: #fee500; border-color: #fee500; }
.m-btns .ok:disabled { background: #f2f2f2; border-color: #f2f2f2; color: #bbb; cursor: default; }

/* ---- 사진 보기, 끌어다 놓기, 알림 ---- */
.viewer { position: absolute; inset: 0; z-index: 40; background: #000; display: none; flex-direction: column; }
.viewer.open { display: flex; }
.v-top { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; color: #ddd; font-size: 13px; }
.stage { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
.stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.thumbs { display: flex; gap: 6px; padding: 10px; overflow-x: auto; }
.thumbs img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; opacity: .55; cursor: pointer; flex: none; }
.thumbs img.on { opacity: 1; outline: 2px solid #fee500; }
.drop { position: absolute; inset: 8px; z-index: 50; border: 3px dashed #fff; border-radius: 12px; background: rgba(60,90,130,.6); color: #fff; font-size: 18px; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.toast { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 60; background: rgba(0,0,0,.75); color: #fff; font-size: 13px; padding: 8px 14px; border-radius: 16px; white-space: nowrap; }

/* ---- 폰 ---- */
@media (pointer: coarse), (max-width: 520px) {
  /* 16px 미만이면 아이폰이 입력할 때 화면을 확대한다 */
  .composer textarea { font-size: 16px; min-height: 46px; padding: 10px 12px 2px; }
  .tools .ico { padding: 8px; }
  .send { height: 36px; padding: 0 18px; }
  .col { max-width: 78%; }
  #list { padding-right: 8px; }
  .bubble.media img { max-width: 200px; }
}

/* ---- 로그인 ---- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; padding: 24px; }
.login { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.login-icon { width: 76px; height: 76px; border-radius: 22px; }
.login h1 { font-size: 20px; margin: 4px 0 10px; color: #23313f; }
.login input { width: 100%; height: 46px; border: 1px solid #c9d4de; border-radius: 6px; padding: 0 14px; font: inherit; font-size: 16px; outline: none; background: #fff; }
.login input:focus { border-color: #8aa2b8; }
.login button { width: 100%; height: 46px; border: none; border-radius: 6px; background: #fee500; font-size: 15px; font-weight: 600; color: #3c1e1e; }
.login button:disabled { opacity: .6; }
.login-err { min-height: 18px; margin: 0; font-size: 13px; color: #b3261e; text-align: center; }
