/* =============================================================
   chat.css — 실시간 채팅 위젯 (전체 채널 / DM / 그룹)
   styles.css 뒤에 로드되어 기존 .chat-* 기본 스타일 위에 3단 레이아웃
   (대화 목록 · 메시지 · 멤버)을 얹는다. 포털 톤(글래스 패널, --muted,
   sky 액센트)을 그대로 따르며 새 색을 만들지 않는다.
   (충돌 회피: 공유 styles.css 는 건드리지 않는 별도 파일)
   ============================================================= */

.chat-widget {
    --chat-online: #5eead4;
    --chat-offline: rgba(255, 255, 255, 0.26);
    --chat-accent: rgba(121, 212, 255, 0.9);
    --chat-line: rgba(255, 255, 255, 0.08);
}

/* display 를 지정한 요소는 UA 의 [hidden] { display: none } 을 덮어써 버린다.
   JS 가 .hidden 으로 토글하는 요소는 전부 여기서 다시 숨긴다. */
.chat-panel[hidden],
.chat-dialog[hidden],
.chat-icon-button[hidden],
.chat-unread[hidden],
.chat-dialog-label[hidden],
.chat-search-bar[hidden],
.chat-pinned[hidden],
.chat-composer-notice[hidden],
.chat-mentions[hidden] {
    display: none;
}

.chat-panel {
    display: grid;
    grid-template-columns: 12.5rem minmax(0, 1fr) 11.5rem;
    grid-template-rows: minmax(0, 1fr);
    width: min(48rem, calc(100vw - 2rem));
    height: min(30rem, calc(100vh - 9rem));
}

/* ---------- 좌: 대화 목록 ---------- */
.chat-rail {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--chat-line);
    background: rgba(255, 255, 255, 0.03);
}

.chat-rail-head,
.chat-members-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 0.85rem 0.6rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.chat-icon-button {
    display: inline-grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 1rem;
    line-height: 1;
}

.chat-icon-button:hover {
    border-color: var(--chat-accent);
    color: var(--chat-accent);
}

.chat-rail-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 0.5rem 0.75rem;
}

.chat-rail-group {
    margin-top: 0.6rem;
    padding: 0 0.35rem 0.3rem;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chat-rail-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    margin-bottom: 0.15rem;
    padding: 0.45rem 0.5rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-size: 0.85rem;
    text-align: left;
}

.chat-rail-item:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
}

.chat-rail-item.is-active {
    background: rgba(121, 212, 255, 0.14);
    color: var(--text);
    font-weight: 700;
}

.chat-rail-item.is-online .chat-presence-dot {
    background: var(--chat-online);
}

.chat-rail-item .chat-member-avatar {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.68rem;
}

.chat-rail-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-rail-badge {
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: rgba(255, 122, 72, 0.92);
    color: #170b04;
    font-size: 0.7rem;
    font-weight: 900;
    display: inline-grid;
    place-items: center;
}

/* ---------- 중앙: 메시지 ---------- */
.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.chat-header-copy {
    min-width: 0;
}

.chat-header-copy strong,
.chat-header-copy span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-messages {
    flex: 1;
    height: auto;
    min-height: 0;
}

.chat-message.is-own {
    background: rgba(121, 212, 255, 0.1);
}

.chat-message-author {
    color: var(--text);
    font-weight: 700;
}

.chat-empty {
    margin: auto;
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
}

.chat-status:empty {
    display: none;
}

.chat-status {
    margin: 0;
    padding: 0 0.85rem 0.7rem;
    color: var(--muted);
    font-size: 0.78rem;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* ---------- 검색 / 고정 공지 ---------- */
.chat-search-bar,
.chat-pinned {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    border-bottom: 1px solid var(--chat-line);
}

.chat-search-bar input {
    flex: 1;
    min-width: 0;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
}

.chat-pinned {
    background: rgba(121, 212, 255, 0.08);
}

.chat-pinned-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 0.8rem;
    text-align: left;
}

.chat-search-hit {
    display: block;
    width: 100%;
    margin-bottom: 0.4rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--chat-line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    text-align: left;
}

.chat-search-hit:hover {
    border-color: var(--chat-accent);
}

/* ---------- 메시지 부가 요소 ---------- */
.chat-message {
    position: relative;
}

.chat-message.is-mention {
    border-left: 2px solid rgba(255, 156, 82, 0.85);
    background: rgba(255, 156, 82, 0.09);
}

.chat-message.is-pinned {
    box-shadow: inset 0 0 0 1px rgba(121, 212, 255, 0.28);
}

.chat-message.is-flash {
    animation: chatFlash 1.2s ease;
}

@keyframes chatFlash {
    from {
        background: rgba(121, 212, 255, 0.3);
    }
}

.chat-message-edited {
    margin-left: 0.35rem;
    color: var(--muted);
    font-size: 0.72rem;
}

.chat-message-body.is-deleted {
    color: var(--muted);
    font-style: italic;
}

.chat-mention {
    padding: 0 0.15rem;
    border-radius: 4px;
    background: rgba(121, 212, 255, 0.18);
    color: var(--chat-accent);
    font-weight: 700;
}

.chat-reply-quote {
    display: block;
    width: 100%;
    margin-bottom: 0.35rem;
    padding: 0.3rem 0.5rem;
    border-left: 2px solid rgba(255, 255, 255, 0.22);
    border-radius: 0 8px 8px 0;
    background: rgba(255, 255, 255, 0.05);
    color: var(--muted);
    font-size: 0.76rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.chat-reply-quote strong {
    color: var(--text);
}

.chat-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.4rem;
}

.chat-reaction {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    padding: 0.1rem 0.45rem;
    font-size: 0.75rem;
}

.chat-reaction.is-mine {
    border-color: var(--chat-accent);
    background: rgba(121, 212, 255, 0.16);
}

/* 액션 바 — 평소엔 숨고 말풍선에 올리면 나타난다 (디스코드 방식) */
.chat-message-actions {
    position: absolute;
    /* 자기 말풍선의 작성자 줄을 가리지 않도록 위쪽 여백으로 띄운다 (디스코드와 같은 방식) */
    bottom: calc(100% - 0.5rem);
    right: 0.5rem;
    display: flex;
    gap: 0.15rem;
    padding: 0.15rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    background: rgba(10, 20, 34, 0.96);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.chat-message:hover .chat-message-actions,
.chat-message:focus-within .chat-message-actions {
    opacity: 1;
    pointer-events: auto;
}

.chat-action {
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    padding: 0.15rem 0.35rem;
    font-size: 0.72rem;
    line-height: 1.2;
}

.chat-action:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.chat-action-emoji {
    font-size: 0.85rem;
}

/* 카카오톡식 안 읽은 사람 수 — 내 메시지 옆에만 붙는다 */
.chat-read-count {
    position: absolute;
    right: 0.55rem;
    bottom: 0.4rem;
    color: rgba(255, 200, 120, 0.95);
    font-size: 0.68rem;
    font-weight: 800;
}

/* ---------- 작성 영역 ---------- */
.chat-composer {
    position: relative;
    border-top: 1px solid var(--chat-line);
}

.chat-composer .chat-form {
    border-top: 0;
}

.chat-composer-notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0.85rem 0;
    color: var(--muted);
    font-size: 0.76rem;
}

.chat-mentions {
    position: absolute;
    left: 0.85rem;
    right: 0.85rem;
    bottom: 100%;
    display: flex;
    flex-direction: column;
    margin-bottom: 0.35rem;
    padding: 0.25rem;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 12px;
    background: rgba(10, 20, 34, 0.98);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

.chat-mention-option {
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    padding: 0.3rem 0.5rem;
    font-size: 0.82rem;
    text-align: left;
}

.chat-mention-option:hover {
    background: rgba(121, 212, 255, 0.16);
}

/* ---------- 우: 멤버 ---------- */
.chat-members {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-left: 1px solid var(--chat-line);
    background: rgba(255, 255, 255, 0.03);
}

.chat-member-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 0.5rem 0.75rem;
}

.chat-member-group {
    margin-top: 0.6rem;
    padding: 0 0.35rem 0.3rem;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chat-member {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font-size: 0.82rem;
    text-align: left;
}

.chat-member:hover {
    background: rgba(255, 255, 255, 0.07);
}

.chat-member.is-offline .chat-member-name {
    color: var(--muted);
}

.chat-member-avatar {
    position: relative;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04));
    border: 1px solid rgba(255, 255, 255, 0.14);
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
}

.chat-member.is-offline .chat-member-avatar {
    opacity: 0.55;
}

.chat-avatar-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

.chat-presence-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 999px;
    border: 2px solid #0a1422;
    background: var(--chat-offline);
}

.chat-member.is-online .chat-presence-dot {
    background: var(--chat-online);
}

.chat-member-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-member-self {
    color: var(--muted);
    font-size: 0.7rem;
}

/* ---------- 그룹 만들기 / 멤버 추가 다이얼로그 ---------- */
.chat-dialog {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(3, 8, 16, 0.62);
    backdrop-filter: blur(6px);
}

.chat-dialog-panel {
    width: min(24rem, 100%);
    max-height: min(32rem, calc(100vh - 3rem));
    overflow-y: auto;
    padding: 1.1rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(8, 16, 29, 0.96);
    box-shadow: 0 26px 70px rgba(0, 0, 0, 0.5);
}

.chat-dialog-title {
    margin: 0 0 0.85rem;
    font-size: 1.05rem;
    font-weight: 800;
}

.chat-dialog-label {
    display: block;
    margin: 0.75rem 0 0.35rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.chat-dialog-panel input[type="text"] {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    padding: 0.55rem 0.75rem;
}

.chat-dialog-users {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    max-height: 12rem;
    overflow-y: auto;
    padding: 0.35rem;
    border: 1px solid var(--chat-line);
    border-radius: 12px;
}

.chat-dialog-user {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.35rem 0.4rem;
    border-radius: 10px;
    font-size: 0.85rem;
}

.chat-dialog-user:hover {
    background: rgba(255, 255, 255, 0.06);
}

.chat-dialog-empty {
    padding: 0.5rem 0.4rem;
    color: var(--muted);
    font-size: 0.8rem;
}

.chat-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

.chat-primary-button,
.chat-ghost-button {
    border-radius: 999px;
    padding: 0.5rem 1.1rem;
    font-weight: 800;
    font-size: 0.85rem;
}

.chat-primary-button {
    border: 0;
    background: linear-gradient(135deg, rgba(255, 156, 82, 0.92), rgba(255, 122, 72, 0.86));
    color: #170b04;
}

.chat-ghost-button {
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: transparent;
    color: var(--text);
}

/* ---------- 반응형 ---------- */
@media (max-width: 900px) {
    .chat-panel {
        grid-template-columns: 11rem minmax(0, 1fr);
        width: min(34rem, calc(100vw - 2rem));
    }

    .chat-members {
        display: none;
    }
}

@media (max-width: 560px) {
    .chat-panel {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        height: min(28rem, calc(100vh - 8rem));
    }

    .chat-rail {
        border-right: 0;
        border-bottom: 1px solid var(--chat-line);
    }

    .chat-rail-head {
        padding-bottom: 0.35rem;
    }

    .chat-rail-list {
        display: flex;
        gap: 0.35rem;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 0.5rem;
    }

    .chat-rail-group {
        display: none;
    }

    .chat-rail-item {
        flex: 0 0 auto;
        width: auto;
        margin-bottom: 0;
    }
}
