/* ============================================================
   실시간 단일 채팅 UI — 모바일 퍼스트
   main.css 의 .panel / .modal-overlay / .modal-card / .modal-btn
   을 공용으로 재사용한다.
   ============================================================ */

/* ---- workspace: 항상 세로 배치 (채팅은 에디터 아래) ---- */
.workspace {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.workspace-main {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.workspace-side {
    display: block;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
}

.chat-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.chat-header-main {
    min-width: 0;
    flex: 1 1 auto;
}

.chat-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: #1f2937;
}

.chat-desc {
    font-size: 0.88rem;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
}

.chat-header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex: 0 0 auto;
}

.chat-connection {
    font-size: 0.78rem;
    color: #9ca3af;
}

.chat-connection.ok {
    color: #10b981;
}

.chat-connection.error {
    color: #ef4444;
}

.chat-me {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}

.chat-me-label {
    font-size: 0.82rem;
    color: #6b7280;
    flex: 0 0 auto;
}

.chat-me-name {
    flex: 1 1 auto;
    min-width: 0;
    background: transparent;
    border: none;
    padding: 6px 10px;
    font-size: 0.95rem;
    font-weight: 700;
    color: #111827;
    cursor: pointer;
    border-radius: 6px;
    text-align: left;
    transition: background-color 0.15s ease;
    min-height: 36px;
}

.chat-me-name:hover,
.chat-me-name:focus-visible {
    background: #e5e7eb;
    outline: none;
}

.chat-me-name::after {
    content: ' ✏️';
    font-size: 0.85em;
    opacity: 0.7;
}

.chat-messages {
    height: 360px;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.chat-empty {
    text-align: center;
    color: #9ca3af;
    font-size: 0.9rem;
    padding: 32px 8px;
}

.chat-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 10px;
    line-height: 1.45;
    word-break: break-word;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-msg-head {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 0.78rem;
}

.chat-msg-nick {
    font-weight: 700;
    color: #374151;
}

.chat-msg-time {
    color: #9ca3af;
    font-size: 0.72rem;
}

.chat-msg-body {
    font-size: 0.95rem;
    color: #111827;
    white-space: pre-wrap;
}

.chat-msg.chat {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    align-self: flex-start;
}

.chat-msg.chat.mine {
    background: #dbeafe;
    border-color: #bfdbfe;
    align-self: flex-end;
}

.chat-msg.chat.mine .chat-msg-nick {
    color: #1d4ed8;
}

.chat-msg.system {
    max-width: 100%;
    align-self: center;
    text-align: center;
    background: transparent;
    border: none;
    padding: 2px 8px;
}

.chat-msg.system .chat-msg-body {
    font-size: 0.82rem;
    color: #6b7280;
    font-style: italic;
}

.chat-msg.system.rename .chat-msg-body {
    color: #0f766e;
}

.chat-msg.system.join .chat-msg-body {
    color: #2563eb;
}

.chat-msg.system.leave .chat-msg-body {
    color: #9ca3af;
}

.chat-form {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.chat-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 14px;
    font-size: 0.95rem;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #ffffff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    min-height: 44px;
}

.chat-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chat-input:disabled {
    background: #f3f4f6;
    color: #9ca3af;
    cursor: not-allowed;
}

.chat-send-btn {
    flex: 0 0 auto;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #ffffff;
    background: #2563eb;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    min-height: 44px;
    transition: background-color 0.15s ease, transform 0.05s ease;
}

.chat-send-btn:hover:not(:disabled) {
    background: #1d4ed8;
}

.chat-send-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.chat-send-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.nickname-edit-field {
    margin: 10px 0;
}

.nickname-edit-field input {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.95rem;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #ffffff;
    min-height: 44px;
}

.nickname-edit-field input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

@media (max-width: 480px) {
    .chat-messages {
        height: 300px;
    }

    .chat-msg {
        max-width: 92%;
    }
}
