/* ============================================================
   카카오톡 PC 레이아웃을 참고한 화면
   ============================================================ */
:root {
  --yellow: #fee500;
  --yellow-press: #f5dc00;
  --brown: #3c1e1e;
  --ink: #191919;
  --ink-2: #4a4a4a;
  --gray: #8e8e8e;
  --gray-2: #b4b4b4;
  --line: #ececec;
  --rail: #ececed;
  --hover: #f6f6f6;
  --active: #ebebeb;
  --room-bg: #bacee0;
  --bubble: #ffffff;
  --badge: #fa5b43;
  --font: "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: #fff; letter-spacing: -0.2px; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 6px; color: #555; flex: none; }
.icon-btn:hover { background: rgba(0,0,0,.06); color: var(--ink); }
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn.sm svg { width: 18px; height: 18px; }

/* ---------------- 로그인 ---------------- */
.login { min-height: 100%; background: var(--yellow); display: grid; place-items: center; padding: 32px 20px; }
.login-box { width: 100%; max-width: 300px; display: flex; flex-direction: column; align-items: stretch; }
.login-logo { width: 84px; height: 84px; margin: 0 auto 44px; border-radius: 26px; }
.login-fields { display: flex; flex-direction: column; background: #fff; border: 1px solid rgba(0,0,0,.12); }
.login-fields input { border: 0; border-bottom: 1px solid rgba(0,0,0,.1); padding: 13px 14px; font-size: 14px; outline: none; background: #fff; border-radius: 0; }
.login-fields input:last-child, .login-fields input:has(+ input[hidden]) { border-bottom: 0; }
.login-fields input::placeholder { color: #a6a6a6; }
.login-btn { margin-top: 8px; height: 44px; background: #f6f6f6; color: #b4b4b4; border: 1px solid rgba(0,0,0,.1); font-size: 14px; }
.login-btn:not(:disabled) { background: var(--brown); color: #fff; border-color: var(--brown); }
.login-btn:disabled { cursor: default; }
.login-err { min-height: 20px; margin: 12px 0 0; font-size: 12.5px; color: #d13a2b; text-align: center; }
.login-foot { margin: 36px 0 0; font-size: 12px; color: rgba(60,30,30,.55); text-align: center; }

/* ---------------- 레이아웃 ---------------- */
.app { display: grid; grid-template-columns: 68px 340px minmax(0, 1fr); height: 100dvh; }
.rail { background: var(--rail); display: flex; flex-direction: column; align-items: center; padding: 28px 0 16px; gap: 6px; }
.rail-btn { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; color: #9a9a9a; }
.rail-btn svg { width: 26px; height: 26px; }
.rail-btn[data-tab="chats"] svg { fill: currentColor; stroke: none; }
.rail-btn:hover { color: #555; }
.rail-btn.active { color: var(--ink); }
.rail-gap { flex: 1; }

.panel { min-width: 0; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: #fff; }
.tab { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 16px 10px 20px; }
.panel-head h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.4px; }
.panel-search { margin: 4px 16px 10px; display: flex; align-items: center; gap: 6px; background: #f4f4f4; border-radius: 18px; padding: 0 12px; height: 34px; color: #9a9a9a; }
.panel-search svg { width: 16px; height: 16px; flex: none; }
.panel-search input { flex: 1; border: 0; background: none; outline: none; font-size: 13px; color: var(--ink); min-width: 0; }
.panel-search input::placeholder { color: #a8a8a8; }
.panel-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.panel-note { margin: 0 20px 10px; font-size: 12px; color: var(--gray); }
.conn-bar { margin: 0 16px 8px; padding: 8px 12px; border-radius: 8px; background: #fff3f0; color: #c2412d; font-size: 12.5px; }

.group-title { width: 100%; display: flex; align-items: center; gap: 4px; padding: 8px 20px 4px; font-size: 12px; color: var(--gray); }
.group-title svg { width: 14px; height: 14px; margin-left: auto; transition: transform .15s; }
.group.collapsed .group-title svg { transform: rotate(-90deg); }
.group.collapsed .rooms { display: none; }
.group + .rooms { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 4px; }

.rooms { list-style: none; margin: 0; padding: 0; }
.room-row { display: flex; align-items: center; gap: 12px; height: 72px; padding: 0 16px 0 20px; cursor: pointer; position: relative; }
.room-row:hover { background: var(--hover); }
.room-row.selected { background: var(--active); }
.room-row.busy { opacity: .5; pointer-events: none; }
.room-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.room-top { display: flex; align-items: baseline; gap: 6px; }
.room-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-count { font-size: 13px; color: var(--gray-2); flex: none; }
.room-time { margin-left: auto; font-size: 11px; color: #a0a0a0; flex: none; padding-left: 6px; }
.room-bottom { display: flex; align-items: center; gap: 8px; }
.room-preview { flex: 1; min-width: 0; font-size: 12.5px; color: var(--gray); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.4; word-break: break-all; }
.badge { flex: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--badge); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; line-height: 1; }
.fav-x { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 50%; display: none; place-items: center; color: #999; background: #fff; box-shadow: 0 0 0 1px var(--line); font-size: 13px; }
.room-row:hover .fav-x { display: grid; }
.rooms-more { padding: 16px; text-align: center; font-size: 12px; color: var(--gray-2); }
.rooms-empty { padding: 30px 20px; text-align: center; font-size: 13px; color: var(--gray); }

/* 프로필 (카카오톡식 둥근 사각형) */
.avatar { width: 48px; height: 48px; border-radius: 38%; flex: none; overflow: hidden; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 17px; background: #c7d1db; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }

/* 검색 결과 */
.results { list-style: none; margin: 0; padding: 0; }
.result { padding: 12px 20px; border-bottom: 1px solid #f3f3f3; cursor: pointer; }
.result:hover { background: var(--hover); }
.result-meta { display: flex; gap: 6px; font-size: 12px; color: var(--gray); margin-bottom: 3px; }
.result-meta b { color: var(--ink-2); font-weight: 600; }
.result-text { font-size: 13px; word-break: break-all; }
mark { background: #fff1a8; color: inherit; padding: 0 1px; }

/* 설정 */
.settings { padding: 4px 0; }
.set-row { display: flex; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid #f3f3f3; font-size: 13px; }
.set-row span { color: var(--gray); }
.set-row strong { font-weight: 600; text-align: right; word-break: break-all; }
.set-btn { display: block; width: calc(100% - 40px); margin: 16px 20px 0; height: 40px; border-radius: 6px; background: #f4f4f4; font-size: 13px; }
.set-btn:hover { background: #ececec; }
.set-btn.danger { color: #d13a2b; }

/* ---------------- 대화방 ---------------- */
.room { position: relative; background: var(--room-bg); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.room-empty { margin: auto; text-align: center; color: rgba(0,0,0,.35); font-size: 13px; }
.room-empty img { width: 64px; height: 64px; border-radius: 20px; opacity: .55; filter: grayscale(.3); }
.room-view { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }
.room-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 12px 18px; }
.room-head .back { display: none; }
.room-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.room-title strong { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-title span { font-size: 11.5px; color: rgba(0,0,0,.45); }
.room-head .icon-btn { color: rgba(0,0,0,.55); }
.room-head .icon-btn:hover { background: rgba(0,0,0,.07); }
.room-search { display: flex; align-items: center; gap: 4px; margin: 0 14px 8px; background: rgba(255,255,255,.75); border-radius: 18px; padding: 0 6px 0 14px; height: 34px; }
.room-search input { flex: 1; border: 0; background: none; outline: none; font-size: 13px; }
.room-search span { font-size: 12px; color: var(--gray); }

.msg-scroll { flex: 1; overflow-y: auto; min-height: 0; padding: 4px 0 12px; }
.load-older { display: block; margin: 8px auto 4px; padding: 6px 14px; border-radius: 14px; background: rgba(0,0,0,.08); font-size: 12px; color: rgba(0,0,0,.55); }
.msgs { display: flex; flex-direction: column; padding: 0 14px 0 16px; }

.day { align-self: center; margin: 16px 0 10px; padding: 4px 14px; border-radius: 14px; background: rgba(0,0,0,.09); color: rgba(0,0,0,.55); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.day svg { width: 14px; height: 14px; }
.sys { align-self: center; margin: 8px 0; padding: 4px 12px; border-radius: 12px; background: rgba(0,0,0,.07); color: rgba(0,0,0,.5); font-size: 12px; text-align: center; max-width: 85%; word-break: break-all; }

.m { display: flex; gap: 8px; margin-top: 3px; }
.m.first { margin-top: 10px; }
.m .avatar { visibility: hidden; }
.m.first .avatar { visibility: visible; }
.m .body { min-width: 0; max-width: min(70%, 520px); display: flex; flex-direction: column; align-items: flex-start; }
.m .who { font-size: 12px; color: var(--ink-2); margin: 1px 0 4px 2px; }
.m .line { display: flex; align-items: flex-end; gap: 5px; max-width: 100%; }
.bubble { position: relative; background: var(--bubble); border-radius: 4px 14px 14px 14px; padding: 7px 10px; font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; min-width: 0; }
.m:not(.first) .bubble { border-radius: 14px; }
.m .time { font-size: 10.5px; color: rgba(0,0,0,.45); white-space: nowrap; flex: none; padding-bottom: 1px; }
.m.me { justify-content: flex-end; }
.m.me .avatar { display: none; }
.m.me .body { align-items: flex-end; }
.m.me .line { flex-direction: row-reverse; }
.m.me .bubble { background: var(--yellow); border-radius: 14px 4px 14px 14px; }
.m.me:not(.first) .bubble { border-radius: 14px; }
.m.pending .bubble { opacity: .6; }
.m.hit .bubble { box-shadow: 0 0 0 2px #ff9f1a; }
.bubble a { color: #0b57d0; text-decoration: underline; }
.bubble.file { display: flex; align-items: center; gap: 8px; }
.bubble.file svg { width: 20px; height: 20px; flex: none; }

.to-bottom { position: absolute; right: 18px; bottom: 150px; display: flex; align-items: center; gap: 2px; padding: 6px 10px 6px 14px; border-radius: 16px; background: rgba(255,255,255,.95); color: var(--ink-2); font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.to-bottom svg { width: 16px; height: 16px; }
.drop-zone { position: absolute; inset: 0; background: rgba(186,206,224,.88); display: grid; place-items: center; z-index: 5; border: 2px dashed rgba(0,0,0,.25); margin: 8px; border-radius: 12px; font-size: 14px; color: rgba(0,0,0,.6); pointer-events: none; }

.composer { background: #fff; border-top: 1px solid rgba(0,0,0,.06); display: flex; flex-direction: column; padding: 10px 12px calc(8px + env(safe-area-inset-bottom)) 16px; }
.composer textarea { border: 0; outline: none; resize: none; font-size: 13.5px; line-height: 1.5; min-height: 60px; max-height: 160px; padding: 2px 0; background: none; }
.composer textarea::placeholder { color: #b8b8b8; }
.composer-bar { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.composer-bar .icon-btn { color: #7a7a7a; }
.composer-hint { font-size: 11px; color: #c2c2c2; margin-left: 4px; }
.send-btn { margin-left: auto; height: 32px; padding: 0 14px; border-radius: 4px; background: #f5f5f5; color: #b4b4b4; font-size: 13px; border: 1px solid #ececec; }
.send-btn:not(:disabled) { background: var(--yellow); color: var(--ink); border-color: var(--yellow); }
.send-btn:not(:disabled):hover { background: var(--yellow-press); }
.upload-bar { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.upload-bar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50%; }
.upload-bar i { flex: 1; height: 4px; background: #eee; border-radius: 2px; overflow: hidden; }
.upload-bar b { display: block; height: 100%; width: 0; background: #f5c400; transition: width .2s; }

.toast { position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 16px); background: rgba(25,25,25,.88); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 모바일 ---------------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .rail { grid-row: 2; flex-direction: row; justify-content: space-around; padding: 4px 0 calc(4px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); }
  .rail-gap { display: none; }
  .panel { grid-row: 1; border-right: 0; }
  .room { grid-row: 1 / 3; grid-column: 1; }
  .app:not(.in-room) .room { display: none; }
  .app.in-room .panel, .app.in-room .rail { display: none; }
  .room-head .back { display: inline-grid; margin-left: -8px; }
  .room-head { padding-left: 12px; }
  .composer-hint { display: none; }
  .m .body { max-width: 78%; }
  .bubble { font-size: 14.5px; }
  .room-name { font-size: 15px; }
  .room-preview { font-size: 13px; }
}

/* v1.2: 사진, 파일, 이전 대화, 사진 크게 보기 */
.media-grid { display: grid; gap: 3px; border-radius: 12px; overflow: hidden; max-width: min(260px, 100%); background: rgba(0,0,0,.06); }
.media-grid.n2, .media-grid.n4 { grid-template-columns: 1fr 1fr; }
.media-grid.n3 { grid-template-columns: 1fr 1fr 1fr; }
.media-grid img { display: block; width: 100%; height: 100%; max-height: 360px; object-fit: cover; cursor: zoom-in; background: #dfe6ee; }
.media-grid.n1 img { height: auto; }
.media-grid:not(.n1) img { aspect-ratio: 1; }
button.bubble { font: inherit; color: inherit; text-align: left; cursor: pointer; border: 0; }
.bubble.media-empty { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.bubble.media-empty svg, .bubble.file svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; }
.bubble.file span { text-decoration: underline; text-underline-offset: 2px; }
.icon-btn.active { background: var(--yellow); color: var(--ink); }
.load-older:disabled { opacity: .7; cursor: progress; }
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.86); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 88vh; object-fit: contain; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lightbox-save { position: fixed; right: 18px; bottom: 18px; background: var(--yellow); color: var(--ink); padding: 9px 16px; border-radius: 18px; font-weight: 700; text-decoration: none; }
.media-file { display: flex; flex-direction: column; gap: 4px; max-width: min(260px, 100%); }
.media-caption { display: flex; align-items: center; gap: 5px; font: inherit; font-size: 12px; color: var(--ink-2); background: rgba(255,255,255,.7); border: 0; border-radius: 8px; padding: 4px 8px; cursor: pointer; text-align: left; min-width: 0; }
.media-caption svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; }
.media-caption span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
