/* ========== 채팅 페이지 스타일 (텔레그램 스타일) ========== */

/* 채팅 페이지에서는 body padding-bottom 제거 (chat-container가 직접 높이 관리) */
body.main-page:has(.chat-container) {
  padding-bottom: 0;
}

.chat-container {
  display: flex;
  height: calc(100vh - var(--header-h, 56px) - var(--nav-h, 60px));
  max-width: 1200px;
  margin: 0 auto;
  background: var(--pet-card, #fff);
  overflow: hidden;
}

/* ── 좌측: 채팅방 목록 ── */
.chat-sidebar {
  width: 360px;
  min-width: 360px;
  border-right: 1px solid var(--pet-border, #EDE9E6);
  display: flex;
  flex-direction: column;
  background: var(--pet-card, #fff);
}

.chat-sidebar-header {
  padding: 16px 20px 0;
  border-bottom: 1px solid var(--pet-border, #EDE9E6);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.chat-sidebar-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--pet-text, #2D3436);
  margin: 0;
}

.chat-room-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.chat-room-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 12px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.chat-room-item:hover {
  background: #F5F3F1;
}

.chat-room-item.active {
  background: #EEEBE8;
}

.chat-room-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--pet-border, #EDE9E6);
}

.chat-room-avatar-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pet-primary, #FF6B6B), var(--pet-secondary, #4ECDC4));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.chat-room-info {
  flex: 1;
  min-width: 0;
}

.chat-room-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.chat-room-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--pet-text, #2D3436);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-time {
  font-size: 12px;
  color: var(--pet-text-muted, #B2BEC3);
  flex-shrink: 0;
  margin-left: 8px;
}

.chat-room-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-room-last-msg {
  font-size: 13px;
  color: var(--pet-text-muted, #B2BEC3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-room-badge {
  background: var(--pet-primary, #FF6B6B);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
  margin-left: 8px;
}

.chat-room-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--pet-text-muted, #B2BEC3);
  text-align: center;
}

.chat-room-empty i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.chat-room-empty p {
  font-size: 14px;
  line-height: 1.5;
}

/* ── 우측: 메시지 영역 ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #F8F6F4;
  min-width: 0;
  min-height: 0;
}

.chat-main-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pet-text-muted, #B2BEC3);
  font-size: 15px;
}

.chat-main-empty i {
  font-size: 48px;
  margin-bottom: 12px;
  display: block;
  opacity: 0.4;
}

.chat-main-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--pet-border, #EDE9E6);
  background: var(--pet-card, #fff);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.chat-main-back {
  display: none;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--pet-text, #2D3436);
  cursor: pointer;
  padding: 4px;
}

.chat-main-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-main-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--pet-text, #2D3436);
}

/* 나가기 버튼 */
.chat-exit-btn {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 16px;
  color: var(--pet-text-muted, #B2BEC3);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
}
.chat-exit-btn:hover {
  color: var(--pet-primary, #FF6B6B);
  background: rgba(255,107,107,0.08);
}

/* 메시지 영역 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.chat-msg-date-divider {
  text-align: center;
  padding: 12px 0;
  font-size: 12px;
  color: var(--pet-text-muted, #B2BEC3);
}

.chat-msg-date-divider span {
  background: rgba(0,0,0,0.05);
  padding: 4px 12px;
  border-radius: 12px;
}

.chat-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-bottom: 2px;
}

.chat-msg-row.is-mine {
  flex-direction: row-reverse;
}

.chat-msg-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-msg-row:not(.is-mine) .chat-msg-bubble {
  background: #fff;
  color: var(--pet-text, #2D3436);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.chat-msg-row.is-mine .chat-msg-bubble {
  background: var(--pet-primary, #FF6B6B);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg-time {
  font-size: 11px;
  color: var(--pet-text-muted, #B2BEC3);
  flex-shrink: 0;
  line-height: 1;
  margin-bottom: 4px;
}

.chat-msg-read {
  font-size: 11px;
  color: var(--pet-secondary, #4ECDC4);
  flex-shrink: 0;
  line-height: 1;
  margin-bottom: 4px;
}

.chat-msg-read i {
  font-size: 12px;
  color: #4ECDC4;
}

/* 입력 영역 */
.chat-input-area {
  padding: 12px 20px;
  border-top: 1px solid var(--pet-border, #EDE9E6);
  background: var(--pet-card, #fff);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.chat-input-area textarea {
  flex: 1;
  border: 1px solid var(--pet-border, #EDE9E6);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: 'Noto Sans KR', sans-serif;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s;
  overflow-y: hidden;
}

.chat-input-area textarea:focus {
  border-color: var(--pet-primary, #FF6B6B);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--pet-primary, #FF6B6B);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.chat-send-btn:hover {
  background: #FF5252;
}

.chat-send-btn:active {
  transform: scale(0.92);
}

.chat-send-btn:disabled {
  background: var(--pet-text-muted, #B2BEC3);
  cursor: not-allowed;
}

/* 로딩 스피너 */
.chat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--pet-text-muted, #B2BEC3);
}

.chat-loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--pet-border, #EDE9E6);
  border-top-color: var(--pet-primary, #FF6B6B);
  border-radius: 50%;
  animation: chatSpin 0.8s linear infinite;
}

@keyframes chatSpin {
  to { transform: rotate(360deg); }
}

/* ── 반응형 (모바일 768px 이하) ── */
@media (max-width: 768px) {
  .chat-container {
    height: calc(100vh - var(--header-h, 56px) - var(--nav-h, 60px));
  }

  .chat-sidebar {
    width: 100%;
    min-width: 100%;
  }

  .chat-main {
    display: none;
    width: 100%;
  }

  .chat-container.show-main .chat-sidebar {
    display: none;
  }

  .chat-container.show-main .chat-main {
    display: flex;
  }

  .chat-main-back {
    display: block;
  }

  .chat-msg-bubble {
    max-width: 85%;
  }
}

/* ── 하단 네비 배지 ── */
.nav-badge {
  position: absolute;
  top: 2px;
  right: 50%;
  transform: translateX(14px);
  background: var(--pet-primary, #FF6B6B);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

.bottom-nav a {
  position: relative;
}

/* ── 로그인 요청 모달 ── */
.login-required-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 0.34s;
}

.login-required-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s;
}

.login-required-modal {
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px 24px;
  max-width: 320px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  transform: translateY(16px) scale(0.94);
  opacity: 0;
  transition:
    transform 0.42s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.36s cubic-bezier(0.22, 1, 0.36, 1);
}

.login-required-overlay.active .login-required-modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.login-required-icon {
  font-size: 36px;
  color: var(--pet-primary, #FF6B6B);
  margin-bottom: 12px;
}

.login-required-msg {
  font-size: 15px;
  color: var(--pet-text, #2D3436);
  margin: 0 0 20px;
  line-height: 1.5;
}

.login-required-actions {
  display: flex;
  gap: 10px;
}

.login-required-cancel {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--pet-border, #EDE9E6);
  border-radius: 10px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--pet-text-muted, #B2BEC3);
}

.login-required-ok {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--pet-primary, #FF6B6B);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-required-ok:disabled,
.login-required-cancel:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.login-required-ok:disabled {
  background: var(--pet-primary, #FF6B6B);
}

/* ── 공통 확인 모달 (AppConfirmModal) ── */
.app-confirm-overlay {
  z-index: 10000;
}

.app-confirm-message {
  white-space: pre-line;
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── DM 버튼 스타일 ── */
.btn-dm {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  color: inherit;
  display: inline-flex;
  align-items: center;
}

.btn-dm:hover {
  color: var(--pet-primary, #FF6B6B);
}

/* ── 탭 UI ── */
.chat-tabs {
  display: flex;
  width: 100%;
  margin-top: 8px;
}

.chat-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--pet-text-muted, #B2BEC3);
  transition: all 0.2s;
  font-family: 'Noto Sans KR', sans-serif;
}

.chat-tab.active {
  color: var(--pet-primary, #FF6B6B);
  border-bottom-color: var(--pet-primary, #FF6B6B);
}

.chat-tab:hover:not(.active) {
  color: var(--pet-text, #2D3436);
}

/* ── 쪽지 목록 ── */
.dm-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.dm-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 12px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: 'Noto Sans KR', sans-serif;
}

.dm-item:hover {
  background: #F5F3F1;
}

.dm-item.unread {
  background: #FFF8F8;
}

.dm-item.unread:hover {
  background: #FFF0F0;
}

/* ── 쪽지 보내기 모달 ── */
.dm-send-overlay,
.dm-detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 0.34s;
}

.dm-send-overlay.active,
.dm-detail-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s;
}

.dm-send-modal,
.dm-detail-modal {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  transform: translateY(16px) scale(0.94);
  opacity: 0;
  transition:
    transform 0.42s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.36s cubic-bezier(0.22, 1, 0.36, 1);
}

.dm-send-overlay.active .dm-send-modal,
.dm-detail-overlay.active .dm-detail-modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.dm-send-header,
.dm-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.dm-send-avatar,
.dm-detail-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.dm-send-name,
.dm-detail-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--pet-text, #2D3436);
}

.dm-detail-info {
  display: flex;
  flex-direction: column;
}

.dm-detail-time {
  font-size: 12px;
  color: var(--pet-text-muted, #B2BEC3);
  margin-top: 2px;
}

.dm-detail-cnts {
  font-size: 14px;
  line-height: 1.6;
  color: var(--pet-text, #2D3436);
  padding: 12px;
  background: #F8F6F4;
  border-radius: 10px;
  margin-bottom: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.dm-send-modal textarea,
.dm-detail-modal textarea {
  width: 100%;
  border: 1px solid var(--pet-border, #EDE9E6);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  font-family: 'Noto Sans KR', sans-serif;
  resize: none;
  outline: none;
  margin-bottom: 16px;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.dm-send-modal textarea:focus,
.dm-detail-modal textarea:focus {
  border-color: var(--pet-primary, #FF6B6B);
}

.dm-send-actions,
.dm-detail-actions {
  display: flex;
  gap: 8px;
}

.dm-send-cancel,
.dm-detail-close {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--pet-border, #EDE9E6);
  border-radius: 10px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--pet-text-muted, #B2BEC3);
  font-family: 'Noto Sans KR', sans-serif;
}

.dm-send-submit,
.dm-detail-reply {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--pet-primary, #FF6B6B);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Noto Sans KR', sans-serif;
}

.dm-send-submit:hover,
.dm-detail-reply:hover {
  background: #FF5252;
}

.dm-send-submit:disabled,
.dm-detail-reply:disabled {
  background: var(--pet-text-muted, #B2BEC3);
  cursor: not-allowed;
}

.dm-detail-open-chat {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--pet-primary, #FF6B6B);
  border-radius: 10px;
  background: #fff;
  color: var(--pet-primary, #FF6B6B);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Noto Sans KR', sans-serif;
}

.dm-detail-open-chat:hover {
  background: #FFF0F0;
}

.dm-detail-open-chat:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── 종이비행기 전송 애니메이션 ── */
.dm-send-modal {
  position: relative;
  overflow: hidden;
}
.dm-send-plane-anim {
  position: absolute;
  bottom: 60px;
  left: 50%;
  font-size: 32px;
  color: var(--pet-primary, #FF6B6B);
  opacity: 1;
  filter: drop-shadow(0 4px 12px rgba(255, 107, 107, 0.5));
  transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.9s ease, filter 0.9s ease;
  pointer-events: none;
  z-index: 10;
}
.dm-send-plane-anim.fly {
  transform: translate(140px, -200px) rotate(-25deg) scale(1.5);
  filter: drop-shadow(0 8px 24px rgba(255, 107, 107, 0));
  opacity: 0;
}

/* ── 분리 배지 (대화/쪽지) ── */
.nav-badge-chat {
  background: var(--pet-primary, #FF6B6B);
}
.nav-badge-dm {
  background: var(--pet-secondary, #4ECDC4);
  transform: translateX(32px);
}

@media (prefers-reduced-motion: reduce) {
  .login-required-overlay,
  .login-required-modal,
  .dm-send-overlay,
  .dm-detail-overlay,
  .dm-send-modal,
  .dm-detail-modal {
    transition-duration: 0.01ms !important;
  }
}

.chat-page-title {
  font-size: 14px;
  font-weight: 600;
}

.chat-main-empty-copy {
  text-align: center;
}
