:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --border-color: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --user-msg-bg: linear-gradient(135deg, #2563eb, #1d4ed8);
    --bot-msg-bg: #1e293b;
    --gemini-color: #38bdf8;
    --gemini-bg: rgba(56, 189, 248, 0.15);
    --muse-color: #c084fc;
    --muse-bg: rgba(192, 132, 252, 0.15);
    --accent: #3b82f6;
    --accent-hover: #1d4ed8;
    --success: #10b981;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

/* 전체 채팅 컨테이너 */
.chat-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    max-width: 1200px;
    background-color: var(--bg-primary);
    position: relative;
}

@media (min-width: 768px) {
    .chat-container {
        height: 96vh;
        margin: 2vh auto;
        border-radius: var(--radius-lg);
        border: 1px solid var(--border-color);
        box-shadow: var(--shadow);
    }
}

/* 상단 헤더 */
.chat-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.room-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #fff;
}

.room-info h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #eab308;
    transition: background-color 0.3s ease;
}

.status-dot.connected {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-dot.disconnected {
    background-color: #ef4444;
}

/* 참여자 배지 */
.participants-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.participant-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.82rem;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
}

.participant-badge.me input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-weight: 600;
    width: 65px;
    cursor: pointer;
}

.participant-badge.me input:focus {
    border-bottom: 1px solid var(--accent);
}

.participant-badge.bot.muse {
    color: var(--muse-color);
    background: var(--muse-bg);
    border-color: rgba(192, 132, 252, 0.3);
}

.participant-badge.bot.gemini {
    color: var(--gemini-color);
    background: var(--gemini-bg);
    border-color: rgba(56, 189, 248, 0.3);
}

.bot-icon {
    font-weight: 700;
    font-size: 0.75rem;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
}

/* 메시지 리스트 영역 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

/* 환영 카드 */
.system-welcome {
    display: flex;
    justify-content: center;
    margin: 10px 0;
}

.welcome-card {
    background: rgba(30, 41, 59, 0.8);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 18px 24px;
    max-width: 640px;
    width: 100%;
    color: var(--text-secondary);
    font-size: 0.88rem;
    line-height: 1.6;
}

.welcome-card h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 1rem;
}

.welcome-card ul {
    list-style: none;
    margin: 8px 0;
}

.welcome-card li {
    margin: 4px 0;
}

.welcome-card .tag {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-weight: 600;
    margin-right: 6px;
}

.welcome-card .file-guide {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* 개별 메시지 행 */
.message-row {
    display: flex;
    gap: 12px;
    max-width: 82%;
    animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-row.bot, .message-row.other {
    align-self: flex-start;
}

/* 아바타 */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.message-avatar.user-av {
    background: #3b82f6;
    color: #fff;
}

.message-avatar.gemini-av {
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    color: #fff;
}

.message-avatar.muse-av {
    background: linear-gradient(135deg, #9333ea, #c084fc);
    color: #fff;
}

.message-avatar.other-av {
    background: #64748b;
    color: #fff;
}

/* 말풍선 컨테이너 */
.message-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.message-row.user .message-header {
    justify-content: flex-end;
}

.message-sender {
    font-weight: 600;
    color: var(--text-primary);
}

.message-time {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* 말풍선 본문 */
.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.message-row.user .message-bubble {
    background: var(--user-msg-bg);
    color: #ffffff;
    border-top-right-radius: 4px;
}

.message-row.bot .message-bubble {
    background-color: var(--bot-msg-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-top-left-radius: 4px;
}

/* 코드 블록 스타일 */
.message-bubble pre {
    background: #090d16;
    padding: 12px;
    border-radius: 8px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.message-bubble code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.88rem;
}

/* 이미지 및 파일 첨부 스타일 */
.chat-image-preview {
    margin-top: 8px;
    max-width: 320px;
    max-height: 280px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-image-preview:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

/* 파일 다운로드 카드 */
.chat-file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-primary);
    transition: background 0.2s ease, border-color 0.2s ease;
    max-width: 380px;
}

.chat-file-card:hover {
    background: rgba(15, 23, 42, 0.9);
    border-color: var(--accent);
}

.file-card-icon {
    font-size: 1.6rem;
    color: var(--accent);
}

.file-card-details {
    flex: 1;
    overflow: hidden;
}

.file-card-name {
    font-weight: 500;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-card-size {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.file-card-download-btn {
    color: var(--accent);
    font-size: 1.1rem;
    padding: 4px;
}

/* 봇 타이핑 인디케이터 바 */
.typing-indicator-bar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 6px 20px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: transparent;
}

.typing-indicator-bar.active {
    display: flex;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* 하단 풋터 영역 */
.chat-footer {
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 12px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 퀵 멘션 버튼 */
.quick-mentions {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.mention-btn {
    border: none;
    outline: none;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.78rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.mention-btn.muse-btn {
    background: var(--muse-bg);
    color: var(--muse-color);
    border: 1px solid rgba(192, 132, 252, 0.3);
}

.mention-btn.gemini-btn {
    background: var(--gemini-bg);
    color: var(--gemini-color);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.mention-btn.all-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.mention-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.2);
}

/* 첨부 파일 미리보기 바 */
.attachment-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(15, 23, 42, 0.7);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    font-size: 0.82rem;
}

.preview-info {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.preview-info span:first-of-type {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.preview-size {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.remove-attachment-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s;
}

.remove-attachment-btn:hover {
    color: #ef4444;
}

/* 입력 폼 */
.input-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-primary);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: border-color 0.2s ease;
}

.input-form:focus-within {
    border-color: var(--accent);
}

.attach-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

textarea#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.45;
    resize: none;
    max-height: 140px;
    padding: 6px 0;
    font-family: inherit;
}

.send-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

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

/* 드래그 앤 드롭 오버레이 */
.drop-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.drop-overlay.active {
    display: flex;
}

.drop-modal {
    border: 2px dashed var(--accent);
    border-radius: var(--radius-lg);
    padding: 40px 60px;
    text-align: center;
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.drop-modal i {
    font-size: 3rem;
    color: var(--accent);
    margin-bottom: 12px;
}

.drop-modal p {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.drop-modal span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* 이미지 라이트박스 모달 */
.image-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.image-modal.active {
    display: flex;
}

.modal-content {
    max-width: 90%;
    max-height: 85%;
    border-radius: 8px;
    object-fit: contain;
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #fff;
    font-size: 36px;
    font-weight: bold;
    cursor: pointer;
}

#modalCaption {
    margin-top: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
