/* Chat header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    height: var(--header-height);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.chat-header-name {
    font-weight: 500;
    font-size: var(--font-size-lg);
}

.chat-header-status {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

/* Message list */
.message-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 40px 8px 60px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

@media (max-width: 767px) {
    .message-list {
        padding: 8px 12px;
    }
}

.message-list .spinner {
    align-self: center;
    margin: 16px 0;
}

/* Date separator */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
}

.date-separator span {
    background: var(--color-bubble-system);
    padding: 5px 12px;
    border-radius: var(--radius-bubble);
    font-size: var(--font-size-xs);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
}

/* Message bubble */
.message {
    display: flex;
    flex-direction: column;
    max-width: 65%;
    position: relative;
}

@media (max-width: 767px) {
    .message {
        max-width: 85%;
    }
}

.message.outgoing {
    align-self: flex-end;
}

.message.incoming {
    align-self: flex-start;
}

.message-sender {
    font-size: var(--font-size-xs);
    font-weight: 600;
    margin-bottom: 2px;
    padding-left: 12px;
}

.message-bubble {
    padding: 6px 8px 8px;
    border-radius: var(--radius-bubble);
    position: relative;
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.outgoing .message-bubble {
    background: var(--color-bubble-out);
    border-top-right-radius: 0;
}

.message.incoming .message-bubble {
    background: var(--color-bubble-in);
    border-top-left-radius: 0;
}

.message-text {
    font-size: var(--font-size-base);
    line-height: 1.4;
    white-space: pre-wrap;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
    float: right;
    margin-left: 12px;
}

.message-time {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
}

.message-status {
    display: flex;
    color: var(--color-text-light);
}

.message-status.status-pending {
    color: var(--color-text-light);
}

.message-status.status-sent {
    color: var(--color-text-light);
}

.message-status.status-failed {
    color: var(--color-danger, #e53935);
}

.message-status.status-read {
    color: var(--color-info, #4fc3f7);
}

.message-status svg {
    width: 16px;
    height: 16px;
}

/* Pending message bubble opacity */
.message.outgoing .message-bubble:has(~ .message-reactions) .status-pending,
.message-bubble .status-pending {
    animation: pendingPulse 1.5s ease-in-out infinite;
}

@keyframes pendingPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.message-edited {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    font-style: italic;
}

/* Reply quote */
.message-reply {
    background: rgba(0,0,0,0.05);
    border-left: 4px solid var(--color-primary-light);
    border-radius: 4px;
    padding: 4px 8px;
    margin-bottom: 4px;
    cursor: pointer;
}

.message-reply-sender {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-primary-light);
}

.message-reply-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Media in messages */
.message-image {
    border-radius: var(--radius-sm);
    max-width: 330px;
    max-height: 330px;
    cursor: pointer;
    margin-bottom: 4px;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(0,0,0,0.04);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.message-file-icon {
    width: 32px;
    height: 32px;
    color: var(--color-primary-light);
}

.message-file-name {
    font-size: var(--font-size-sm);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Reactions */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.reaction-badge:hover {
    background: var(--color-hover);
}

.reaction-badge.own {
    border-color: var(--color-primary-light);
    background: rgba(18,140,126,0.1);
}

.reaction-badge-count {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

/* Redacted */
.message-redacted {
    font-style: italic;
    color: var(--color-text-light);
    font-size: var(--font-size-sm);
}

/* System message */
.system-message {
    align-self: center;
    background: var(--color-bubble-system);
    padding: 5px 12px;
    border-radius: var(--radius-bubble);
    font-size: var(--font-size-xs);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
    max-width: 80%;
    text-align: center;
}

/* Typing indicator */
.typing-indicator {
    padding: 4px 16px 4px 72px;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    min-height: 24px;
}

@media (max-width: 767px) {
    .typing-indicator {
        padding-left: 16px;
    }
}

.typing-dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 4px;
}

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

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Compose container */
#compose-container {
    flex-shrink: 0;
}

/* Compose area */
.compose-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
    min-height: var(--compose-min-height);
}

.compose-reply-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    border-left: 4px solid var(--color-primary-light);
    margin: 0 16px;
    border-radius: 4px;
}

.compose-reply-content {
    flex: 1;
    min-width: 0;
}

.compose-reply-sender {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-primary-light);
}

.compose-reply-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compose-input-wrap {
    flex: 1;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    display: flex;
    align-items: flex-end;
    padding: 4px;
}

.compose-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 8px 12px;
    font-size: var(--font-size-base);
    resize: none;
    max-height: 120px;
    min-height: 36px;
    line-height: 1.4;
    background: transparent;
    font-family: var(--font-family);
}

.compose-send {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--color-secondary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition-fast);
}

.compose-send:hover {
    background: #20c15e;
}

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

/* Image viewer overlay */
.image-viewer {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    cursor: pointer;
}

.image-viewer img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
}

.image-viewer-close {
    position: absolute;
    top: 16px;
    right: 16px;
    color: #fff;
    background: none;
    border: none;
    cursor: pointer;
}

/* Emoji picker */
.emoji-picker {
    position: fixed;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    z-index: var(--z-modal);
    max-width: 320px;
}

.emoji-picker button {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.emoji-picker button:hover {
    background: var(--color-hover);
}
