/* 메신저 — 완전 독립 스타일 */

/* ──────────────── 팝업 안내 다이얼로그 ──────────────── */
.messenger-info-dialog-dim {
    position: fixed;
    inset: 0;
    bottom: var(--ad-reserved, 40px);
    z-index: 10200;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: messengerFadeIn 0.15s ease-out;
    padding: 20px;
}
.messenger-info-dialog {
    background: #fff;
    border-radius: 14px;
    width: 460px;
    max-width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    color: #1e293b;
    overflow: hidden;
}
.messenger-info-head {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
    font-weight: 700;
    font-size: 1rem;
}
.messenger-info-head > span { flex: 1; }
.messenger-info-head-warn {
    background: #fef3c7;
    color: #92400e;
    border-bottom-color: #fcd34d;
}
.messenger-info-close {
    background: none; border: none; font-size: 1.1rem; cursor: pointer;
    padding: 2px 6px; color: #6b7280;
}
.messenger-info-close:hover { color: #1e293b; }
.messenger-info-body {
    padding: 16px 18px;
    overflow-y: auto;
    font-size: 0.88rem;
    line-height: 1.6;
    color: #374151;
}
.messenger-info-body p { margin: 6px 0; }
.messenger-info-note {
    margin: 12px 0;
    padding: 10px 12px;
    background: #eff6ff;
    border-left: 3px solid #2563eb;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #1e40af;
}
.messenger-info-details {
    margin-top: 10px;
    padding: 8px 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}
.messenger-info-details > summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    color: #1e293b;
    list-style: disclosure-closed;
    outline: none;
}
.messenger-info-details[open] > summary { list-style: disclosure-open; }
.messenger-info-details ol, .messenger-info-details ul { font-size: 0.85rem; color: #374151; }
.messenger-info-skip {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    font-size: 0.82rem;
    color: #6b7280;
    cursor: pointer;
    user-select: none;
}
.messenger-info-skip input { margin: 0; }
.messenger-info-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid #e5e7eb;
    background: #f8fafc;
}
.messenger-info-btn {
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.messenger-info-btn-cancel {
    background: #fff;
    border-color: #d1d5db;
    color: #374151;
}
.messenger-info-btn-cancel:hover { background: #f3f4f6; }
.messenger-info-btn-primary {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}
.messenger-info-btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }

/* 좁은 화면: 다이얼로그 세로 확장 */
@media (max-width: 520px) {
    .messenger-info-dialog { width: 100%; max-height: 90vh; border-radius: 12px; }
}

/* ──────────────── 드래그앤드롭 파일 업로드 오버레이 ──────────────── */
.msg-drop-overlay {
    position: absolute;
    inset: 0;
    z-index: 1000;
    background: rgba(37, 99, 235, 0.08);
    border: 3px dashed #2563eb;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;   /* 리스너는 view 에 이미 붙음; 오버레이는 hit-target X */
    opacity: 0;
    transition: opacity 0.12s ease-out;
}
.msg-drop-overlay.active {
    opacity: 1;
}
.msg-drop-inner {
    background: #fff;
    padding: 24px 32px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(37, 99, 235, 0.2);
    text-align: center;
    color: #1e40af;
}
.msg-drop-icon {
    font-size: 2.4rem;
    margin-bottom: 8px;
}
.msg-drop-text {
    font-size: 1rem;
    font-weight: 700;
    color: #1e40af;
}
.msg-drop-sub {
    font-size: 0.78rem;
    color: #6b7280;
    margin-top: 4px;
}

/* 스탠들언 모드 (/messenger 페이지) — 팝업 창 전체를 채움.
   position:fixed 대신 flex 컬럼으로 뷰포트 가득. body가 이미 height:100vh. */
.messenger-standalone-root {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    background: #fff;
    overflow: hidden;
}
.messenger-standalone-root .messenger-body {
    flex: 1;
    min-height: 0;
}
/* 스탠들언에서는 뒤로 버튼을 모바일처럼 항상 노출 (친구추가/채팅방 진입 시 유용) */
.messenger-standalone-root .messenger-header-back { display: inline-block; }

/* 모바일: 전체 화면 (하단 광고 영역 보호) */
.messenger-overlay {
    position: fixed;
    top: var(--app-shell-top, 0px);
    left: 0;
    right: 0;
    bottom: var(--ad-reserved, 40px);
    z-index: 10000;
    background: #fff;
    display: flex;
    flex-direction: column;
    animation: messengerSlideUp 0.25s ease-out;
}
/* 데스크탑: 우측 사이드 패널 (페이지 분할 — 메인 콘텐츠 옆에 배치) */
@media (min-width: 768px) {
    .messenger-overlay {
        position: fixed;
        top: var(--app-shell-top, 0px);
        right: 0;
        bottom: var(--ad-reserved, 0px);
        left: auto;
        width: 420px;
        max-width: 40vw;
        box-shadow: -4px 0 24px rgba(0,0,0,0.1);
        border-left: 1px solid #e5e7eb;
        animation: messengerSlideIn 0.25s ease-out;
    }
    /* 메인 콘텐츠 영역을 줄여서 메신저와 공존 */
    body.messenger-open {
        padding-right: 420px;
        transition: padding-right 0.25s ease-out;
    }
}
@keyframes messengerSlideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes messengerSlideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

/* 배경 딤 — 모바일만 (데스크탑은 페이지 분할) */
.messenger-dim {
    display: none;
}
@media (max-width: 767px) {
    .messenger-dim {
        display: block;
        position: fixed;
        top: var(--app-shell-top, 0px);
        left: 0;
        right: 0;
        bottom: var(--ad-reserved, 40px);
        z-index: 9999;
        background: rgba(0,0,0,0.3);
    }

    body.mobile-shell-open .messenger-overlay .messenger-header {
        display: none;
    }
}

/* 헤더 */
.messenger-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
    flex-shrink: 0;
}
.messenger-header-back {
    background: none; border: none; font-size: 1.3rem; cursor: pointer;
    padding: 4px 8px; margin-right: 8px; color: #374151;
}
@media (min-width: 768px) {
    .messenger-header-back { display: none; }
}
.messenger-header-title {
    font-size: 1.1rem; font-weight: 700; color: #1e293b; flex: 1;
}
.messenger-header-close {
    background: none; border: none; font-size: 1.2rem; cursor: pointer;
    padding: 4px 8px; color: #6b7280;
}

/* 탭 */
.messenger-tabs {
    display: flex;
    border-bottom: 2px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}
.messenger-tab {
    flex: 1;
    padding: 12px 0;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    color: #6b7280;
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.messenger-tab:hover { color: #374151; }
.messenger-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}
.messenger-tab .tab-badge {
    display: inline-block;
    background: #ef4444;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 5px;
    margin-left: 4px;
    vertical-align: top;
}

/* 탭 콘텐츠 */
.messenger-body {
    flex: 1;
    overflow-y: auto;
    background: #f9fafb;
    /* 2026-04-28: 부모 페이지로 스크롤 bubble 차단 (iOS PWA에서 더블 스크롤 충돌 제거) */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* 2026-04-28: 채팅 메시지 리스트 — iOS 모멘텀/오버스크롤 최소 안정화.
   기존 시도(scroll-behavior:smooth + will-change + transform translateZ)는
   초기 로드 시 페이지 점프가 애니메이션화되어 오히려 "blink/슬라이드" 현상 유발.
   smooth/will-change/transform 모두 제거 — 점프는 즉시(instant) 가 가장 자연스럽다. */
.msg-scroll-area {
    overflow-y: auto;
    overscroll-behavior: contain;        /* 끝에서 부모로 스크롤 bubble 안 됨 */
    -webkit-overflow-scrolling: touch;   /* iOS 모멘텀 활성 */
    /* scroll-behavior 미지정 = auto(즉시) — 프로그램적 scrollTop 변경 시 점프 */
}
.messenger-tab-content {
    display: none;
    padding: 0;
    height: 100%;
}
.messenger-tab-content.active {
    display: flex;
    flex-direction: column;
}

/* 친구 탭 */
.msg-friend-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    gap: 6px;
    flex-wrap: wrap;  /* 2026-04-29 (#372): 좁은 폰에서 자동 줄바꿈 */
}
.msg-friend-header .msg-friend-search { min-width: 140px; }
@media (max-width: 380px) {
    .msg-friend-header .msg-friend-add-btn {
        padding: 8px 10px;
        font-size: 0.78rem;
    }
}
.msg-friend-search {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.85rem;
    outline: none;
}
.msg-friend-search:focus { border-color: #2563eb; }
.msg-friend-search-btn {
    padding: 8px 14px;
    background: #e2e8f0;
    color: #374151;
    border: none;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.msg-friend-search-btn:hover { background: #cbd5e1; }
.msg-friend-header-divider {
    width: 1px;
    height: 28px;
    background: #d1d5db;
    flex-shrink: 0;
    margin: 0 4px;
}
.msg-friend-add-btn {
    padding: 8px 14px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.msg-friend-add-btn:hover { background: #1d4ed8; }

/* 섹션 제목 */
.msg-section-title {
    padding: 8px 16px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #f1f5f9;
    border-bottom: 1px solid #e5e7eb;
}

/* 친구/요청 카드 */
.msg-friend-card {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.1s;
}
.msg-friend-card:hover { background: #f0f7ff; }
.msg-friend-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: #e0e7ff;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-right: 12px;
}
.msg-friend-info {
    flex: 1;
    min-width: 0;
}
.msg-friend-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #1e293b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.msg-friend-meta {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 2px;
}
.msg-friend-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.msg-btn-accept {
    padding: 5px 12px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.msg-btn-reject {
    padding: 5px 12px;
    background: #f3f4f6;
    color: #6b7280;
    border: none;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
}
.msg-btn-accept:hover { background: #1d4ed8; }
.msg-btn-reject:hover { background: #e5e7eb; }

/* 친구 추가 다이얼로그 */
.msg-add-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: var(--ad-reserved, 40px);
    z-index: 10100;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: messengerFadeIn 0.15s ease-out;
}
@keyframes messengerFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.msg-add-dialog {
    background: #fff;
    border-radius: 16px;
    width: 400px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(0,0,0,0.2);
}
.msg-add-dialog-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}
.msg-add-dialog-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    flex: 1;
}
.msg-add-dialog-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #6b7280;
    padding: 4px 8px;
}
.msg-add-dialog-body {
    padding: 20px;
}
.msg-add-mobile-tip {
    margin-top: 16px;
    padding: 10px 14px;
    background: #f0f7ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    font-size: 0.8rem;
    color: #1e40af;
    line-height: 1.4;
}
.msg-add-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.msg-add-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.9rem;
}
.msg-add-search-btn {
    padding: 10px 18px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.msg-search-result {
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
}
.msg-search-result .msg-btn-request {
    padding: 8px 16px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}
.msg-search-result .msg-btn-sms {
    padding: 8px 16px;
    background: #10b981;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}
.msg-empty {
    text-align: center;
    padding: 40px 16px;
    color: #9ca3af;
    font-size: 0.9rem;
}

/* 채팅 탭 (Phase 3 준비) */
.msg-chat-list { }
.msg-chat-card {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
}
.msg-chat-card:hover { background: #f0f7ff; }
.msg-chat-preview {
    flex: 1;
    min-width: 0;
}
.msg-chat-name {
    font-weight: 600;
    font-size: 0.88rem;
    color: #1e293b;
}
.msg-chat-last-msg {
    font-size: 0.78rem;
    color: #6b7280;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.msg-chat-time {
    font-size: 0.7rem;
    color: #9ca3af;
    flex-shrink: 0;
    margin-left: 8px;
}
.msg-chat-unread {
    background: #ef4444;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 10px;
    padding: 2px 6px;
    margin-left: 6px;
    flex-shrink: 0;
}

/* 채팅 첨부 카드 */
.msg-bubble .msg-attachment-card {
    width: min(252px, 70vw);
    max-width: 100%;
    display: grid;
    gap: 8px;
}
.msg-attachment-media {
    display: block;
    position: relative;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 10px;
    overflow: hidden;
    background: #0f172a;
    aspect-ratio: 4 / 3;
    cursor: pointer;
}
.msg-attachment-media-image img,
.msg-attachment-media-video video {
    display: block;
    width: 100%;
    height: 100%;
}
.msg-attachment-media-image img {
    object-fit: cover;
    transition: transform 0.16s ease;
}
.msg-attachment-media-image:hover img,
.msg-attachment-media-image:focus-visible img {
    transform: scale(1.015);
}
.msg-attachment-media-image.is-opening img {
    opacity: 0.72;
}
.msg-attachment-media-image.is-opening::after {
    content: "여는 중";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 6px 9px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.82);
    color: #fff;
    font-size: 0.74rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}
.msg-attachment-media-video {
    aspect-ratio: 16 / 9;
    cursor: default;
    position: relative;
}
.msg-attachment-media-video video {
    object-fit: contain;
    background: #000;
}
.msg-video-open {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.42);
    background: rgba(15,23,42,0.76);
    color: #fff;
    font-size: 17px;
    font-weight: 800;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.32);
}
.msg-video-open:hover,
.msg-video-open:focus-visible {
    background: rgba(30,41,59,0.94);
    outline: none;
}
.msg-video-open.is-opening {
    cursor: progress;
    opacity: 0.76;
}
.msg-attachment-audio audio {
    display: block;
    width: 100%;
    max-width: 100%;
}
.msg-attachment-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.msg-attachment-info {
    flex: 1;
    min-width: 0;
    display: grid;
    gap: 2px;
}
.msg-attachment-title {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-weight: 700;
    line-height: 1.2;
}
.msg-attachment-icon {
    flex: 0 0 auto;
    font-size: 0.9rem;
    line-height: 1;
}
.msg-attachment-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.msg-attachment-meta,
.msg-attachment-status {
    font-size: 0.72rem;
    line-height: 1.3;
    opacity: 0.78;
}
.msg-attachment-download {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 42px;
    min-height: 30px;
    padding: 6px 9px;
    border-radius: 8px;
    border: 1px solid rgba(37, 99, 235, 0.18);
    background: #2563eb;
    color: #fff;
    font-size: 0.76rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
}
.msg-attachment-download:hover,
.msg-attachment-download:focus-visible {
    background: #1d4ed8;
    outline: none;
}
.msg-attachment-download.is-loading {
    cursor: progress;
    opacity: 0.78;
}
.msg-attachment-spinner {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    border: 2px solid rgba(255,255,255,0.46);
    border-top-color: #fff;
    animation: msgAttachmentSpin 0.72s linear infinite;
}
.msg-bubble-mine .msg-attachment-download {
    background: #fff;
    color: #1d4ed8;
    border-color: rgba(255,255,255,0.65);
}
.msg-bubble-mine .msg-attachment-download:hover,
.msg-bubble-mine .msg-attachment-download:focus-visible {
    background: #eff6ff;
}
.msg-bubble-mine .msg-attachment-spinner {
    border-color: rgba(37, 99, 235, 0.25);
    border-top-color: #1d4ed8;
}
@keyframes msgAttachmentSpin {
    to { transform: rotate(360deg); }
}
@media (max-width: 420px) {
    .msg-bubble .msg-attachment-card {
        width: min(236px, 68vw);
    }
    .msg-attachment-download {
        padding-inline: 8px;
    }
}
