#chat-icon {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: var(--brand-action);
    color: #333;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s ease;
    z-index: 1000;
}

.chat-notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    background-color: #e53935;
    border-radius: 50%;
    border: 2px solid #fff;
    z-index: 10;
}

.floating-icon-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    position: relative;
    z-index: 2;
}

.floating-icon-text {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    line-height: 1;
}

#chat-icon:hover {
    background-color: var(--brand-hover);
}

#chat-icon svg {
    position: relative;
    z-index: 2;
    color: #fff;
}

/* Dark mode overrides for chat icon */
html[data-theme="dark"] #chat-icon {
    background-color: #1e1e1e;
    color: #fff;
    border-color: #333;
}

html[data-theme="dark"] #chat-icon:hover {
    background-color: #2a2a2a;
}

html[data-theme="dark"] #chat-icon svg {
    color: #fff;
}

html[data-theme="dark"] .floating-icon-text {
    color: #aaa;
}

html[data-theme="dark"] .chat-notification-badge {
    border-color: #1e1e1e;
}

#chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 340px;
    padding: 10px;
    height: 540px;
    background-color: rgb(45, 45, 45);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overscroll-behavior: contain;
}

#chat-window.hidden {
    display: none;
}

#chat-header {
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

.chat-title {
    font-weight: 700;
    color: white;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-user-count {
    font-size: 14px;
    color: #62d99b;
    font-weight: 500;
}

.chat-controls button {
    background: none;
    border: none;
    cursor: pointer;
    margin-left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.chat-controls button img {
    width: 14px;
    height: 14px;
    opacity: 0.6;
    transition: opacity 0.2s ease, transform 0.4s ease;
    filter: brightness(0) invert(1); /* 이미지를 하얀색으로 변경 */
}

.chat-controls button:hover img {
    opacity: 1;
    transform: rotate(360deg);
}

#chat-messages {
    flex-grow: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    overflow-anchor: none;
    overscroll-behavior: contain;
}

#chat-messages::-webkit-scrollbar {
    width: 5px;
}

#chat-messages::-webkit-scrollbar-track {
    background: #424242;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 5px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a5a5a5;
}

.chat-message {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.chat-message .message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.chat-message .profile-pic {
    width: 26px;
    height: 26px;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 50%;
    background: #f4f5f7;
    object-fit: cover;
}

.chat-message .nickname {
    font-weight: 700;
    font-size: 14px;
    color: #ffba06; /* 이미지와 유사한 청록색 이름 */
}

.chat-message .bubble-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.chat-message .message-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    max-width: 200px;
    font-size: 14px;
    word-wrap: break-word;
    line-height: 1.4;
}

.chat-message .timestamp {
    font-size: 14px;
    color: #a0a0a0;
    margin-bottom: 2px;
    white-space: nowrap;
}

.chat-typing {
    display: flex;
    align-items: center;
    min-height: 34px;
    gap: 5px;
    margin: -2px 0 14px;
    color: #aeb2b8;
    font-size: 14px;
}

.chat-typing img {
    width: 26px;
    height: 26px;
    margin-right: 3px;
    padding: 2px;
    border-radius: 50%;
    background: #f4f5f7;
    object-fit: cover;
}

.chat-typing span {
    margin-right: 3px;
}

.chat-typing b {
    color: #ffba06;
}

.chat-typing i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #aeb2b8;
    animation: chat-typing-bounce 900ms ease-in-out infinite;
}

.chat-typing i:nth-of-type(2) { animation-delay: 140ms; }
.chat-typing i:nth-of-type(3) { animation-delay: 280ms; }

@keyframes chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* My messages */
.my-message {
    align-items: flex-end;
}

.my-message .bubble-row {
    padding-left: 0;
    padding-right: 0;
}

.my-message .message-bubble {
    background-color: #b2cad2;
    color: black;
    font-weight: 500;
    border-top-right-radius: 4px;
}

/* Other users' messages */
.other-message .message-bubble {
    background-color: #3e3e3e;
    color: #fff;
    border-top-left-radius: 4px;
}

.chat-new-messages {
    position: absolute;
    z-index: 12;
    right: 50%;
    bottom: 70px;
    display: flex;
    align-items: center;
    min-height: 38px;
    gap: 7px;
    padding: 0 14px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 20px;
    background: #17191d;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .34);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transform: translateX(50%);
    animation: chat-new-messages-in 180ms ease-out both;
}

.chat-new-messages[hidden] {
    display: none;
}

.chat-new-messages:active {
    transform: translateX(50%) scale(.96);
}

.chat-new-messages b {
    color:var(--brand-text);
    font-size: 15px;
}

@keyframes chat-new-messages-in {
    from { opacity: 0; transform: translate(50%, 7px); }
    to { opacity: 1; transform: translate(50%, 0); }
}

#chat-input-container {
    display: flex;
    align-items: center;
    position: relative;
    background: #242424;
    border: 1px solid #5f5f5f;
    border-radius: 43px;
}
#chat-send{
    background: #575757 !important;
}
#chat-input-container button {
    background: none;
    border: none;
    cursor: pointer;
}

#chat-input-container button img {
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(1); /* 이미지를 하얀색으로 변경 */
}
#emoji-button {
    position: absolute;
    right: 74px;
}

#chat-input {
    flex-grow: 1;
    border-radius: 5px;
    padding: 14px;
    border-radius: 34px;
    background: none;
    color: #fff;    
    outline: none;
    border: none;
}

#chat-send {
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 12px;
    cursor: pointer;
    margin-right: 4px;
}

#chat-send:hover {
    background-color: #0056b3;
}

#emoji-picker {
    position: absolute;
    bottom: 60px;
    left: 10px;
    width: 280px;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    padding: 10px;
}

#emoji-picker .emoji-category {
    margin-bottom: 10px;
}

#emoji-picker .emoji-category h5 {
    margin: 0 0 5px;
    font-size: 14px;
    color: #555;
}

#emoji-picker .emoji-list {
    display: flex;
    flex-wrap: wrap;
}

#emoji-picker .emoji-list span {
    cursor: pointer;
    font-size: 20px;
    padding: 5px;
    border-radius: 5px;
}

#emoji-picker .emoji-list span:hover {
    background-color: #f1f1f1;
}

.hidden {
    display: none;
}

/* Responsive Styles */
@media (max-width: 768px) {
    #chat-icon {
        display: none !important; /* 하단 네비게이션 사용하므로 숨김 */
    }

    #chat-window {
        width: 100% !important;
        height: calc(100% - 60px) !important; /* 하단 네비게이션(60px) 고려하여 높이 조정 */
        bottom: 60px !important; /* 하단 네비게이션 위로 띄움 */
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        transform: none !important;
        border-radius: 0 !important;
        z-index: 10000 !important; /* 최상단 노출 */
    }
    
    #chat-header {
        border-radius: 0 !important;
    }
    
    #chat-input-container {
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }
}


/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    #chat-icon,
    #chat-window,
    .chat-typing i {
        transition: none;
        animation: none;
    }
}

.no-motion #chat-icon,
.no-motion #chat-window,
.no-motion .chat-typing i {
    transition: none;
    animation: none;
}
