:root {
  --navy: #1b3a5c;
  --coral: #f1685e;
  --cream: #f6efdf;
  /* 따뜻한 컬쳐임팩트 팔레트 (변수명은 기존 유지, 값만 웜톤으로) */
  --ios-blue: #1b3a5c;          /* 링크·강조 = 네이비 */
  --ios-gray-bubble: #f3ecdf;   /* 상대 말풍선 = 웜 크림 */
  --ios-bg: #fdfaf4;            /* 대화 배경 = 따뜻한 종이 */
  --ios-grouped-bg: #f6f0e4;    /* 목록·패널 배경 */
  --ios-separator: #eadfcc;     /* 구분선 */
  --ios-secondary: #a1927f;     /* 보조 텍스트 = 웜 그레이 */
  --text: #33291f;              /* 본문 = 따뜻한 다크브라운 */
  --warm-shadow: 0 3px 14px rgba(120, 90, 60, .08);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior-y: none; }
body {
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue",
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--ios-grouped-bg);
  color: var(--text);
}
.screen { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; background: var(--ios-bg); }
.hidden { display: none !important; }

/* ── 입장 화면 (브랜드 유지) ── */
#login-screen { justify-content: center; align-items: center; background: var(--navy); }
.login-box {
  background: #fffdf8; border-radius: 28px; padding: 40px 32px; width: min(90%, 360px);
  text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.login-logo { width: 170px; max-width: 65%; margin-bottom: 8px; }
.login-box h1 { color: var(--navy); font-size: 26px; margin-bottom: 6px; }
.login-sub { color: #888; font-size: 13px; margin-bottom: 24px; }
.login-box input {
  width: 100%; padding: 13px 16px; border: 2px solid #e6dcc9; border-radius: 16px;
  font-size: 16px; margin-bottom: 12px; outline: none;
}
.login-box input:focus { border-color: var(--coral); }
.user-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 6px; }
.user-pill {
  background: #fff; border: 2px solid #e6dcc9; border-radius: 999px;
  padding: 10px 20px; font-size: 15px; font-weight: 700; color: var(--navy); cursor: pointer;
}
.user-pill:hover { border-color: var(--coral); color: var(--coral); }
.pin-who { font-size: 16px; font-weight: 700; color: var(--navy); margin-bottom: 10px; }
.linklike {
  background: none !important; border: none; color: var(--ios-secondary) !important;
  font-size: 13px; cursor: pointer; margin-top: 10px; font-weight: 400 !important;
}
.admin-btn {
  background: #fff; border: 1.5px solid var(--ios-separator); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; font-weight: 700; color: var(--navy); cursor: pointer;
}
.login-err { color: #c0392b; font-size: 13px; margin-top: 8px; min-height: 18px; text-align: center; }

/* 메시지별 음성 읽기 버튼 */
.speak-btn {
  background: none; border: none; color: var(--ios-secondary); font-size: 13px;
  cursor: pointer; padding: 1px 6px; margin-left: 2px;
}
.speak-btn:hover { color: var(--coral); }

/* 프로필 원본 사진 뷰어 */
.img-viewer {
  position: fixed; inset: 0; background: rgba(20,15,10,.9); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px; cursor: zoom-out;
}
.img-viewer[hidden] { display: none; }
.img-viewer img { max-width: 100%; max-height: 90dvh; border-radius: 14px; }
.iv-close {
  position: absolute; top: 16px; right: 18px; background: rgba(255,255,255,.15);
  border: none; color: #fff; font-size: 20px; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
}

/* PIN 변경 모달 폼 */
.pin-form { display: flex; flex-direction: column; gap: 8px; }
.pin-form input {
  border: 1.5px solid #ddd2c0; border-radius: 14px; padding: 11px 14px;
  font-size: 16px; outline: none; text-align: center; letter-spacing: 4px;
}
.pin-form input:focus { border-color: var(--coral); }
.pin-form button {
  background: var(--coral); color: #fff; border: none; border-radius: 999px;
  padding: 11px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.modal-head .linklike { background: none; border: none; color: var(--ios-secondary); cursor: pointer; font-size: 13px; }

/* ── 출력물 보관함 모달 ── */
.modal {
  position: fixed; inset: 0; background: rgba(51,41,31,.45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fffdf8; border-radius: 22px; padding: 18px; width: min(440px, 100%);
  max-height: 76dvh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head strong { color: var(--navy); font-size: 16px; }
.modal-hint { font-size: 12px; color: var(--ios-secondary); margin-bottom: 10px; line-height: 1.6; }
.file-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%; text-align: left; background: #fff; border: 1px solid var(--ios-separator);
  border-radius: 14px; padding: 11px 14px; margin-bottom: 7px; cursor: pointer; font-size: 14px;
}
.file-row:hover { border-color: var(--coral); }
.file-name { font-weight: 600; color: var(--text); word-break: break-all; }
.file-meta { font-size: 11px; color: var(--ios-secondary); flex-shrink: 0; }
.login-box button {
  width: 100%; padding: 13px; background: var(--coral); color: #fff; border: none;
  border-radius: 16px; font-size: 16px; font-weight: 700; cursor: pointer;
}
.login-box button:active { filter: brightness(.92); }

/* ── 방 목록 (iOS 그룹 리스트 느낌) ── */
#rooms-screen { background: var(--ios-grouped-bg); }
.rooms-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: rgba(253,250,244,.94); border-bottom: 1px solid var(--ios-separator);
}
.header-logo { height: 30px; }
#my-name-label { font-size: 14px; color: var(--navy); font-weight: 700; }
.ai-status-bar { padding: 8px 18px; font-size: 12px; color: var(--ios-secondary); }
.room-list { padding: 4px 14px; display: flex; flex-direction: column; gap: 10px; }
.room-card {
  background: #fffdf8; border-radius: 22px; padding: 16px; cursor: pointer;
  display: flex; align-items: center; gap: 14px;
  transition: background .1s; box-shadow: var(--warm-shadow);
}
.room-card:active { background: #f6efe2; }
.room-icon {
  width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 22px; flex-shrink: 0; background: var(--ios-grouped-bg);
}
.room-icon.culture { background: #fdeae5; }
.room-icon.ceo { background: #e7edf4; }
.room-info strong { display: block; font-size: 16px; color: var(--text); }
.room-info small { color: var(--ios-secondary); font-size: 12px; }
.room-lock { margin-left: auto; color: #cbbda8; font-size: 16px; }
.room-icon.custom { background: #e7f6ef; }
.room-del {
  margin-left: auto; background: none; border: none; color: #c0392b;
  font-size: 15px; cursor: pointer; padding: 4px 8px; font-weight: 700;
}
.room-card.room-add { border: 2px dashed #d8cbb4; background: transparent; box-shadow: none; border-radius: 22px; }
.room-card.room-add .room-info strong { color: var(--ios-secondary); }

/* ── 채팅 (iMessage 스타일) ── */
.chat-header {
  display: flex; align-items: center; padding: 8px 12px;
  background: rgba(253,250,244,.92); color: var(--text);
  border-bottom: 1px solid var(--ios-separator);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  position: relative;
}
#back-btn {
  background: none; border: none; color: var(--coral); font-size: 30px; cursor: pointer;
  line-height: 1; padding: 0 8px; z-index: 1;
}
.chat-title {
  position: absolute; left: 0; right: 0; text-align: center; pointer-events: none;
}
.voice-btn {
  margin-left: auto; background: none; border: 1.5px solid var(--ios-separator);
  border-radius: 999px; font-size: 16px; cursor: pointer; padding: 4px 10px; z-index: 1;
}
.voice-btn.on { border-color: var(--coral); background: #fdeae5; }
.chat-title strong { font-size: 15px; display: block; font-weight: 700; color: var(--navy); }
.chat-title small { font-size: 11px; color: var(--ios-secondary); }

.messages { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 2px; background: var(--ios-bg); }

.msg-row { display: flex; margin-top: 8px; align-items: flex-end; gap: 8px; }
.msg-row.mine { justify-content: flex-end; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: flex;
  align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff;
  align-self: flex-end; margin-bottom: 2px;
  background: linear-gradient(180deg, #c4b49e, #a8957c);
}
.avatar-img {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  align-self: flex-end; margin-bottom: 2px; box-shadow: 0 1px 3px rgba(120,90,60,.2);
}
#my-name-label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.mini-av { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.mini-av-txt {
  background: #c4b49e; color: #fff; display: inline-flex; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 700;
}
.avatar.ai-saeroyi { background: linear-gradient(180deg, #35608f, var(--navy)); }
.avatar.ai-joyseo { background: linear-gradient(180deg, #9a6cc0, #7a4d9e); }
.avatar.ai-team { background: linear-gradient(180deg, #3aa17e, #2b7a5f); }
.msg-body { max-width: 74%; display: flex; flex-direction: column; }
.msg-row.mine .msg-body { align-items: flex-end; }
.sender-name { font-size: 11px; color: var(--ios-secondary); margin: 0 0 2px 12px; }
.sender-name .badge {
  font-size: 9px; background: var(--ios-blue); color: #fff; border-radius: 6px;
  padding: 1px 5px; margin-left: 4px; vertical-align: 1px;
}
.bubble-line { display: flex; align-items: flex-end; gap: 6px; }
.msg-row.mine .bubble-line { flex-direction: row-reverse; }
.bubble {
  padding: 9px 14px; border-radius: 22px; font-size: 15px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
  background: var(--ios-gray-bubble); color: var(--text);
  box-shadow: 0 1px 2px rgba(120,90,60,.07);
}
.msg-row.mine .bubble {
  background: var(--coral); color: #fff;
}
.bubble a { color: var(--ios-blue); text-decoration: underline; word-break: break-all; }
.msg-row.mine .bubble a { color: #fff; }
/* 사진 메시지 */
.chat-img {
  max-width: min(240px, 100%); max-height: 320px; border-radius: 16px;
  display: block; cursor: pointer;
}
.bubble:has(> .chat-img:only-child) { padding: 4px; background: transparent; }
#img-btn, #mic-btn {
  background: none; border: none; font-size: 22px; cursor: pointer; padding: 4px 2px;
  flex-shrink: 0;
}
#mic-btn.recording {
  animation: micPulse 1.2s ease-in-out infinite;
  filter: drop-shadow(0 0 4px #ff3b30);
}
@keyframes micPulse { 50% { transform: scale(1.25); opacity: .7; } }
#chat-screen.dragging::after {
  content: '사진을 놓으면 전송됩니다'; position: absolute; inset: 0;
  background: rgba(27,58,92,.55); color: #fff; display: flex; align-items: center;
  justify-content: center; font-size: 18px; font-weight: 700; z-index: 20;
  border: 3px dashed #fff; pointer-events: none;
}

/* 파일 첨부 칩 */
.file-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fffdf8; border: 1px solid #ddd2c0; border-radius: 16px;
  padding: 8px 14px; font-size: 13.5px; color: var(--navy) !important;
  text-decoration: none !important; font-weight: 600; word-break: break-all;
}
.msg-row.mine .file-chip { background: rgba(255,255,255,.9); }

/* AI 대기열 */
.queue-bar {
  background: #fff8e6; border-top: 1px solid #f0e2b6; padding: 6px 14px;
  font-size: 12px; color: #6b5b2a; display: flex; align-items: center;
  gap: 8px; flex-wrap: wrap;
}
.q-title { font-weight: 700; flex-shrink: 0; }
.q-item {
  background: #fffdf8; border: 1px solid #e8dcb0; border-radius: 999px;
  padding: 3px 6px 3px 10px; display: inline-flex; align-items: center; gap: 4px;
}
.q-del {
  background: none; border: none; color: #c0392b; font-size: 12px;
  cursor: pointer; padding: 0 3px; font-weight: 700;
}

/* 댓글/대댓글 */
.cmt-wrap { margin-top: 2px; }
.msg-row.mine .cmt-wrap { text-align: right; }
.cmt-toggle {
  background: none; border: none; color: var(--ios-secondary); font-size: 11px;
  cursor: pointer; padding: 1px 4px;
}
.cmt-toggle:hover { color: var(--ios-blue); }
.cmt-thread {
  background: var(--ios-grouped-bg); border-radius: 18px; padding: 10px 14px;
  margin-top: 3px; max-width: 100%; text-align: left; font-size: 13px;
}
.cmt-item { padding: 3px 0; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.cmt-item.reply { margin-left: 18px; }
.cmt-item.reply::before { content: '↳'; color: #b0b0b6; }
.cmt-sender { font-weight: 700; font-size: 12px; color: var(--navy); flex-shrink: 0; }
.cmt-body { word-break: break-word; }
.cmt-time { font-size: 10px; color: #b0b0b6; }
.cmt-reply {
  background: none; border: none; color: var(--ios-secondary); font-size: 10.5px;
  cursor: pointer; padding: 0 2px;
}
.cmt-reply:hover { color: var(--ios-blue); }
.cmt-replybox { margin-left: 18px; }
.cmt-input {
  width: 100%; border: 1px solid #ddd2c0; border-radius: 14px; padding: 7px 12px;
  font-size: 13px; font-family: inherit; outline: none; margin-top: 4px; background: #fff;
}
.cmt-input:focus { border-color: var(--coral); }

/* 읽음 표시: 해당 메시지까지 읽은 참여자 */
.read-marker {
  text-align: right; font-size: 10.5px; color: #b3a48f; margin: 2px 4px 0 0;
}

/* 새 메시지 알림 버튼 */
#chat-screen { position: relative; }
.new-msg-chip {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 118px;
  background: var(--navy); color: #fff; border: none; border-radius: 999px;
  padding: 8px 18px; font-size: 13px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 5;
}

.msg-row.system { justify-content: center; margin-top: 12px; }
.msg-row.system .bubble {
  background: none; color: var(--ios-secondary); font-size: 11.5px; border-radius: 0;
  text-align: center; padding: 0 20px;
}
.timestamp { font-size: 10px; color: #c2b5a3; flex-shrink: 0; margin-bottom: 2px; }
.tag-review { color: #ff9500; font-weight: 700; }
.tag-team { color: #2b7a5f; font-weight: 700; }
.tag-pending { color: #b8860b; font-weight: 700; }
.tag-approve { color: #34c759; font-weight: 700; }
.tag-reject { color: #ff3b30; font-weight: 700; }
.msg-row.mine .tag-review, .msg-row.mine .tag-approve, .msg-row.mine .tag-reject { color: #fff; text-decoration: underline; }

.typing { padding: 6px 16px; font-size: 12px; color: var(--ios-secondary); background: var(--cream); }
.typing::after { content: '⋯'; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ── AI 작업 로그 ── */
.msg-row.log { margin-left: 38px; margin-top: 6px; }
.log-details {
  background: var(--ios-grouped-bg); border-radius: 16px;
  padding: 8px 14px; font-size: 12px; color: #5c5044; max-width: 76%;
}
.log-details summary { cursor: pointer; font-weight: 600; color: var(--ios-secondary); list-style: none; }
.log-details summary::-webkit-details-marker { display: none; }
.log-lines {
  margin-top: 6px; font-family: "SF Mono", Consolas, "Courier New", monospace;
  display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--ios-secondary);
}
.livelog {
  padding: 8px 16px; font-size: 11.5px;
  color: #5c5044; background: var(--cream); border-top: 1px solid var(--ios-separator);
}
.livelog-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.livelog-header {
  font-size: 13px; font-weight: 600; color: var(--ios-blue);
  display: flex; align-items: center; gap: 6px; min-width: 0;
}
.ai-stop-btn {
  background: #fff; border: 1.5px solid #ff3b30; color: #ff3b30;
  border-radius: 999px; padding: 3px 13px; font-size: 12px; font-weight: 700;
  cursor: pointer; flex-shrink: 0;
}
.ai-stop-btn:hover { background: #ff3b30; color: #fff; }
.ai-stop-btn:disabled { opacity: .5; cursor: default; }
.spin { display: inline-block; animation: spinstar 2.5s linear infinite; color: var(--coral); }
@keyframes spinstar { to { transform: rotate(360deg); } }
.livelog-lines {
  margin-top: 4px; font-family: "SF Mono", Consolas, "Courier New", monospace;
  max-height: 90px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  color: var(--ios-secondary);
}
.livelog-lines div { animation: loglineIn .15s ease-out; }
@keyframes loglineIn { from { opacity: 0; transform: translateY(3px); } }

/* ── 입력창 (iMessage 스타일) ── */
.composer { background: var(--ios-bg); border-top: 1px solid var(--ios-separator); padding: 6px 10px calc(8px + env(safe-area-inset-bottom)); }
.mention-btns { display: flex; gap: 6px; margin-bottom: 6px; }
.mention-btn {
  border: none; border-radius: 999px; padding: 5px 13px; font-size: 12px; cursor: pointer;
  font-weight: 600; background: var(--ios-grouped-bg); color: var(--ios-blue);
}
.mention-btn.joyseo { color: #7a4d9e; }
.mention-btn.team { color: #2b7a5f; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#msg-input {
  flex: 1; border: 1.5px solid #ddd2c0; border-radius: 22px; padding: 9px 16px;
  font-size: 15px; font-family: inherit; resize: none; outline: none; max-height: 120px;
  background: var(--ios-bg);
}
#msg-input:focus { border-color: var(--coral); }

/* ── 모바일 최적화 ── */
@media (max-width: 520px) {
  /* iOS는 입력창 글씨가 16px 미만이면 화면을 확대시킴 → 방지 */
  #msg-input, .cmt-input, .login-box input { font-size: 16px; }
  .messages { padding: 12px 10px 6px; }
  .msg-body { max-width: 80%; }
  .mention-btn { padding: 7px 14px; font-size: 13px; }   /* 터치 영역 확대 */
  .cmt-toggle { padding: 4px 8px; font-size: 12px; }
  .cmt-reply { padding: 3px 6px; font-size: 12px; }
  .q-del, .room-del { padding: 8px 10px; }
  .chat-img { max-width: min(210px, 78vw); }
  .livelog-lines { max-height: 66px; }
  /* 헤더 버튼: 모바일에선 아이콘 위주로 컴팩트하게 */
  .rooms-header { flex-wrap: wrap; gap: 4px 6px; padding: 10px 12px; }
  .admin-btn { padding: 5px 9px; font-size: 11px; }
  #my-name-label span:last-child { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
#chat-screen { will-change: transform; } /* 스와이프 백 애니메이션 부드럽게 */
#send-btn {
  background: var(--coral); color: #fff; border: none; border-radius: 50%;
  width: 34px; height: 34px; font-size: 18px; font-weight: 700; cursor: pointer;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  margin-bottom: 1px;
}
#send-btn:active { filter: brightness(.9); }
