/* ============================================
   NexusChat - Chat Room Styles
   ============================================ */

/* ============================================
   聊天室視圖
   ============================================ */

.chatroom-view {
    bottom: 0 !important;
    z-index: var(--z-modal);
    transform: translateX(100%);
}

.chatroom-view.active {
    transform: translateX(0);
}

/* 聊天室標頭 */
.chatroom-header {
    height: var(--header-height);
    padding: 0 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.back-btn {
    flex-shrink: 0;
}

.chatroom-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    cursor: pointer;
}

.chatroom-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.chatroom-avatar img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.chatroom-details {
    flex: 1;
    min-width: 0;
}

.chatroom-details h2 {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatroom-status {
    font-size: 12px;
    color: var(--text-muted);
}

.chatroom-status.online {
    color: var(--success);
}

.chatroom-actions {
    display: flex;
    gap: 0;
}

/* ============================================
   訊息容器
   ============================================ */

.messages-container {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-secondary);
    -webkit-overflow-scrolling: touch;
}

/* 日期分隔線 */
.date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 0;
}

.date-divider span {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 4px 12px;
    border-radius: var(--radius-full);
}

/* 訊息群組 */
.message-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}

.message-group.sent {
    align-items: flex-end;
}

.message-group.received {
    align-items: flex-start;
}

/* 訊息包裝 */
.message-wrapper {
    display: flex;
    gap: 8px;
    max-width: 80%;
}

.message-group.sent .message-wrapper {
    flex-direction: row-reverse;
}

/* 訊息頭像 */
.message-avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    align-self: flex-end;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.message-group.sent .message-avatar {
    display: none;
}

/* 訊息內容 */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.message-sender {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
    padding-left: 12px;
}

.message-group.sent .message-sender {
    display: none;
}

/* 訊息氣泡 */
.message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
}

.message-group.sent .message-bubble {
    background: var(--bubble-sent);
    color: var(--bubble-sent-text);
    border-bottom-right-radius: 4px;
}

.message-group.sent .message-bubble:last-of-type {
    border-bottom-right-radius: 18px;
}

.message-group.received .message-bubble {
    background: var(--bubble-received);
    color: var(--bubble-received-text);
    border-bottom-left-radius: 4px;
}

.message-group.received .message-bubble:last-of-type {
    border-bottom-left-radius: 18px;
}

/* 訊息時間與狀態 */
.message-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    padding: 0 4px;
}

.message-group.sent .message-meta {
    justify-content: flex-end;
}

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

.message-status {
    display: flex;
    align-items: center;
}

.message-status svg {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
}

.message-status.read svg {
    color: var(--primary);
}

/* ============================================
   特殊訊息類型
   ============================================ */

/* 圖片訊息 */
.message-image {
    max-width: 240px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
}

.message-image img {
    width: 100%;
    display: block;
}

/* 貼圖訊息 */
.message-sticker {
    width: 120px;
    height: 120px;
    padding: 0;
    background: transparent !important;
}

.message-sticker img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 檔案訊息 */
.message-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    min-width: 200px;
    max-width: 280px;
}

.message-group.sent .message-file {
    background: rgba(255, 255, 255, 0.2);
}

.file-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.file-icon svg {
    width: 20px;
    height: 20px;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 12px;
    opacity: 0.7;
}

/* 語音訊息 */
.message-voice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    min-width: 160px;
}

.voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.message-group.received .voice-play-btn {
    background: var(--primary);
    color: white;
}

.voice-play-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message-group.received .voice-play-btn:hover {
    background: var(--primary-dark);
}

.voice-play-btn svg {
    width: 18px;
    height: 18px;
}

.voice-waveform {
    flex: 1;
    height: 28px;
    display: flex;
    align-items: center;
    gap: 2px;
}

.voice-bar {
    width: 3px;
    background: currentColor;
    border-radius: var(--radius-full);
    opacity: 0.5;
}

.voice-duration {
    font-size: 12px;
    opacity: 0.7;
    min-width: 36px;
    text-align: right;
}

/* 位置訊息 */
.message-location {
    width: 240px;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.location-map {
    height: 120px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.location-map svg {
    width: 32px;
    height: 32px;
    color: var(--error);
}

.location-info {
    padding: 10px 12px;
}

.location-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
}

.location-address {
    font-size: 12px;
    opacity: 0.7;
}

/* 聯絡人訊息 */
.message-contact {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    min-width: 200px;
}

.contact-avatar-small {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    overflow: hidden;
    flex-shrink: 0;
}

.contact-avatar-small img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.contact-info-small {
    flex: 1;
    min-width: 0;
}

.contact-name-small {
    font-size: 14px;
    font-weight: 500;
}

.contact-phone {
    font-size: 12px;
    opacity: 0.7;
}

/* 回覆訊息 */
.message-reply {
    padding: 8px 12px;
    margin-bottom: 4px;
    border-left: 3px solid var(--primary);
    background: rgba(0, 0, 0, 0.05);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.message-group.sent .message-reply {
    background: rgba(255, 255, 255, 0.15);
}

.reply-author {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 2px;
}

.reply-text {
    font-size: 13px;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 系統訊息 */
.system-message {
    text-align: center;
    padding: 12px 16px;
}

.system-message span {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 6px 14px;
    border-radius: var(--radius-full);
}

/* 打字指示器 */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bubble-received);
    border-radius: 18px;
    max-width: fit-content;
}

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

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: var(--radius-full);
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-6px);
    }
}

/* ============================================
   輸入區域
   ============================================ */

.input-area {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px 12px;
    padding-bottom: calc(8px + var(--safe-area-bottom));
    flex-shrink: 0;
}

.input-toolbar {
    display: flex;
    gap: 4px;
    padding-bottom: 8px;
}

.toolbar-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.toolbar-btn:hover {
    background: var(--bg-hover);
    color: var(--primary);
}

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

.toolbar-btn svg {
    width: 22px;
    height: 22px;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

#message-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: 20px;
    font-size: 15px;
    resize: none;
    transition: all var(--transition-fast);
    line-height: 1.4;
}

#message-input::placeholder {
    color: var(--text-muted);
}

#message-input:focus {
    background: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

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

.send-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

.voice-btn {
    position: absolute;
    right: 12px;
    bottom: calc(8px + var(--safe-area-bottom));
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all var(--transition-fast);
    opacity: 0;
    pointer-events: none;
}

.voice-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

.voice-btn:hover {
    background: var(--primary-dark);
}

.voice-btn svg {
    width: 20px;
    height: 20px;
}

/* 錄音狀態 */
.input-area.recording {
    background: #FFF0F0;
}

.recording-indicator {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px;
}

.input-area.recording .recording-indicator {
    display: flex;
}

.input-area.recording .input-toolbar,
.input-area.recording .input-container {
    display: none;
}

.recording-dot {
    width: 12px;
    height: 12px;
    background: var(--error);
    border-radius: var(--radius-full);
    animation: recording-pulse 1s infinite;
}

@keyframes recording-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.recording-time {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--error);
}

.recording-waveform {
    flex: 1;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
}

.recording-bar {
    width: 3px;
    background: var(--error);
    border-radius: var(--radius-full);
    animation: recording-wave 0.5s infinite alternate;
}

.recording-bar:nth-child(1) { animation-delay: 0s; height: 12px; }
.recording-bar:nth-child(2) { animation-delay: 0.1s; height: 20px; }
.recording-bar:nth-child(3) { animation-delay: 0.2s; height: 16px; }
.recording-bar:nth-child(4) { animation-delay: 0.3s; height: 24px; }
.recording-bar:nth-child(5) { animation-delay: 0.4s; height: 18px; }
.recording-bar:nth-child(6) { animation-delay: 0.5s; height: 14px; }
.recording-bar:nth-child(7) { animation-delay: 0.6s; height: 22px; }

@keyframes recording-wave {
    to { height: 28px; }
}

.cancel-recording {
    padding: 8px 16px;
    background: var(--error);
    color: white;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
}

/* ============================================
   聊天選單
   ============================================ */

.chat-menu-overlay {
    position: fixed;
    inset: 0;
    background: var(--surface-overlay);
    z-index: var(--z-modal);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.chat-menu-overlay.open {
    opacity: 1;
    visibility: visible;
}

.chat-menu {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 80%;
    background: var(--surface);
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    z-index: calc(var(--z-modal) + 1);
    display: flex;
    flex-direction: column;
}

.chat-menu-overlay.open .chat-menu {
    transform: translateX(0);
}

.chat-menu-header {
    padding: 20px 16px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.chat-menu-avatar {
    width: 72px;
    height: 72px;
    margin: 0 auto 12px;
}

.chat-menu-avatar img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.chat-menu-name {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-menu-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-menu-content {
    flex: 1;
    overflow-y: auto;
}

.chat-menu-section {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.chat-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-menu-item:hover {
    background: var(--bg-hover);
}

.chat-menu-item svg {
    width: 22px;
    height: 22px;
    color: var(--text-secondary);
}

.chat-menu-item span {
    flex: 1;
    font-size: 15px;
}

.chat-menu-item .toggle {
    margin-left: auto;
}

.chat-menu-item.danger {
    color: var(--error);
}

.chat-menu-item.danger svg {
    color: var(--error);
}
