/* 채팅 위젯 Floating Button */
.chat-widget-button {
    position: fixed;
    bottom: 100px;
    right: 30px;
    z-index: 9998;
}

.chat-widget-button button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--border-border, #e9ecef);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: visible;
}

.chat-widget-button button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.chat-widget-button button:active {
    transform: scale(0.95);
}

.chat-widget-button button i {
    width: 24px;
    height: 24px;
    color: var(--text-color);
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 10px;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    padding: 0 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* 채팅 모달 */
#chatModal .modal-content,
.chat-modal-content {
    max-width: 1200px !important; /* 데스크탑에서 더 넓게 */
    width: 95% !important;
    max-height: 85vh !important;
    height: 85vh !important;
    display: flex;
    flex-direction: column;
}

/* 채팅 탭 */
.chat-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-primary, #e9ecef);
    background: var(--card-bg);
    flex-shrink: 0;
}

/* 관리자 패널 */
.chat-admin-panel {
    position: relative;
    padding: 8px 16px;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(245, 158, 11, 0.1) 100%);
    border-bottom: 1px solid var(--border-primary, #e9ecef);
}

.chat-admin-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #ef4444 0%, #f59e0b 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.chat-admin-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.chat-admin-toggle i {
    width: 16px;
    height: 16px;
}

.chat-admin-menu {
    position: absolute;
    top: 50px;
    left: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-primary, #e9ecef);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 220px;
    overflow: hidden;
}

.chat-admin-action {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-primary, #e9ecef);
    color: var(--text-primary);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-admin-action:last-child {
    border-bottom: none;
}

.chat-admin-action:hover {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.chat-admin-action i {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.chat-tab {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary, #666);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
}

.chat-tab:hover {
    color: var(--text-primary, #333);
    background: rgba(59, 130, 246, 0.05);
}

.chat-tab.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

.chat-tab-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #ef4444;
    color: white;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* 채팅 메시지 영역 */
.chat-modal-body {
    padding: 0;
    display: flex;
    flex: 1;
    overflow: hidden;
}

.chat-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-sidebar {
    width: 250px;
    border-left: 1px solid var(--border-primary, #e9ecef);
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    flex-shrink: 0;
}

.chat-user-list-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-primary, #e9ecef);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary, #333);
    flex-shrink: 0;
}

.chat-user-list-header i {
    width: 18px;
    height: 18px;
    color: var(--text-secondary, #666);
}

.chat-user-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-no-users {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary, #999);
    padding: 20px 10px;
}

.chat-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.chat-user-item:hover {
    background: rgba(59, 130, 246, 0.05);
}

.chat-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-primary, #e9ecef);
}

.chat-user-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-user-item.admin-user .chat-user-name {
    color: #f97316;
}

.chat-message {
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.1);
    border-radius: 12px;
    padding: 14px 16px;
    animation: messageSlideIn 0.3s ease;
    max-width: 85%;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.admin-message {
    background: rgba(249, 115, 22, 0.05);
    border-color: rgba(249, 115, 22, 0.2);
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.message-author {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.admin-icon {
    width: 14px;
    height: 14px;
    color: #f97316;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary, #666);
}

.message-content {
    font-size: 15px;
    color: var(--text-primary, #333);
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* 채팅 입력 영역 */
.chat-input-container {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-primary, #e9ecef);
    background: var(--card-bg);
    flex-shrink: 0;
}

#chatInput {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-primary, #e9ecef);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary, #333);
    font-size: 15px;
    resize: none;
    max-height: 150px;
    min-height: 46px;
    font-family: inherit;
    transition: border-color 0.2s ease;
}

#chatInput:focus {
    outline: none;
    border-color: #3b82f6;
}

#chatInput::placeholder {
    color: var(--text-secondary, #999);
}

.chat-send-btn, .chat-attach-btn {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn {
    background: #3b82f6;
    color: white;
}

.chat-send-btn:hover {
    background: #2563eb;
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
}

.chat-send-btn i {
    width: 18px;
    height: 18px;
}

.chat-attach-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-primary, #e9ecef);
    color: var(--text-secondary, #666);
}

.chat-attach-btn:hover {
    background: rgba(59, 130, 246, 0.05);
    border-color: #3b82f6;
    color: #3b82f6;
}

.chat-attach-btn:active {
    transform: scale(0.95);
}

.chat-attach-btn:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    opacity: 0.5;
}

.chat-attach-btn i {
    width: 18px;
    height: 18px;
}

/* 이미지/파일/오디오 메시지 스타일 */
.message-image { margin-top: 6px; }
.message-image a { display: block; max-width: 100%; }
.message-image img { max-width: 100%; max-height: 300px; border-radius: 6px; cursor: pointer; transition: opacity 0.2s ease; }
.message-image img:hover { opacity: 0.9; }

.message-audio {
    margin-top: 6px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--border-primary, #e9ecef);
    border-radius: 8px;
}
.audio-player { margin-bottom: 8px; }
.audio-player audio {
    width: 100%;
    height: 40px;
    border-radius: 6px;
}
.audio-info { display: flex; justify-content: space-between; align-items: center; }
.audio-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #333);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 8px;
}
.audio-size { font-size: 11px; color: var(--text-secondary, #666); flex-shrink: 0; }

.message-file { margin-top: 6px; }
.file-download-link { display: flex; align-items: center; gap: 12px; padding: 12px; background: rgba(255, 255, 255, 0.5); border: 1px solid var(--border-primary, #e9ecef); border-radius: 6px; text-decoration: none; transition: all 0.2s ease; }
.file-download-link:hover { background: rgba(59, 130, 246, 0.05); border-color: #3b82f6; }
.file-icon { width: 24px; height: 24px; color: #3b82f6; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 13px; font-weight: 500; color: var(--text-primary, #333); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 11px; color: var(--text-secondary, #666); margin-top: 2px; }
.download-icon { width: 18px; height: 18px; color: var(--text-secondary, #666); flex-shrink: 0; }


/* 데스크탑 최적화 (1024px 이상) */
@media (min-width: 1024px) {
    #chatModal .modal-content,
    .chat-modal-content {
        max-width: 1400px !important;
        width: 90% !important;
    }

    .chat-sidebar {
        width: 280px;
    }

    .chat-messages {
        padding: 24px 32px;
        gap: 18px;
    }

    .chat-message {
        max-width: 75%;
    }

    .message-content {
        font-size: 16px;
    }

    #chatInput {
        font-size: 16px;
        padding: 14px 18px;
        min-height: 52px;
    }

    .chat-input-container {
        padding: 20px 24px;
    }

    .chat-send-btn, .chat-attach-btn {
        width: 52px;
        height: 52px;
    }
}

/* 태블릿 (769px ~ 1023px) */
@media (min-width: 769px) and (max-width: 1023px) {
    #chatModal .modal-content,
    .chat-modal-content {
        max-width: 900px !important;
        width: 92% !important;
    }

    .chat-sidebar {
        width: 220px;
    }
}

/* 모바일 반응형 (768px 이하) */
@media (max-width: 768px) {
    .chat-widget-button {
        bottom: 80px;
        right: 20px;
    }

    .chat-widget-button button {
        width: 48px;
        height: 48px;
    }

    #chatModal .modal-content,
    .chat-modal-content {
        max-width: 100% !important;
        width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }

    .chat-sidebar {
        display: none; /* 모바일에서는 사이드바 숨김 */
    }

    .chat-messages {
        padding: 12px;
        gap: 10px;
    }

    .chat-message {
        max-width: 95%;
        padding: 10px 12px;
    }

    .message-content {
        font-size: 14px;
    }

    #chatInput {
        font-size: 14px;
        padding: 10px 12px;
        min-height: 40px;
    }

    .chat-input-container {
        padding: 10px 12px;
    }

    .chat-send-btn, .chat-attach-btn {
        width: 40px;
        height: 40px;
    }
}

/* 스크롤바 스타일링 */
.chat-messages::-webkit-scrollbar,
.chat-user-list::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-user-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-user-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    transition: background 0.2s ease;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-user-list::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

/* Firefox 스크롤바 */
.chat-messages,
.chat-user-list {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.03);
}
.chat-user-icon {
    width: 32px;
    height: 32px;
    padding: 6px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-secondary);
    flex-shrink: 0;
}

.dark-theme .chat-user-icon {
    background: rgba(255, 255, 255, 0.08);
}

/* 파일 업로드 프로그레스바 오버레이 */
.chat-upload-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.chat-upload-overlay.active {
    display: flex;
}

.chat-upload-modal {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px;
    min-width: 320px;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.chat-upload-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 24px;
}

.chat-progress-circle-container {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0 auto 24px;
}

.chat-progress-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.chat-progress-bg {
    fill: none;
    stroke: rgba(59, 130, 246, 0.1);
    stroke-width: 8;
}

.chat-progress-bar {
    fill: none;
    stroke: #3b82f6;
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.3s ease;
}

.chat-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.chat-progress-percent {
    font-size: 32px;
    font-weight: 700;
    color: #3b82f6;
    display: block;
    line-height: 1;
}

.chat-progress-speed {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 8px;
    display: block;
}

.chat-upload-file-info {
    margin-top: 16px;
}

.chat-upload-file-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-upload-file-size {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-upload-status {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 12px;
}

/* Image Lightbox */
.chat-image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.chat-image-lightbox.show {
    display: flex;
}

.chat-lightbox-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    cursor: zoom-out;
}

.chat-lightbox-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-lightbox-content img {
    max-width: 100%;
    max-height: 95vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.8);
}

.chat-lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 2;
    backdrop-filter: blur(10px);
}

.chat-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.chat-image-preview {
    cursor: zoom-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
