/* ============================================
   P2P — INBOX & MESSAGING SYSTEM
   ============================================ */

.chat-panel {
    position: fixed;
    top: var(--navbar-height);
    right: 0;
    bottom: 0;
    width: var(--chat-panel-width);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid rgba(0, 0, 0, 0.05);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.03);
    transition: transform var(--transition-normal);
    animation: slideInRight 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.6));
    border-bottom: 1px solid var(--border-color);
}

.chat-panel-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: -0.02em;
}

.chat-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    transition: all var(--transition-fast);
}

.chat-close-btn:hover {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    transform: rotate(90deg);
}

/* ── Inbox List View ── */
.chat-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.chat-search {
    padding: var(--space-md) var(--space-lg);
}

.chat-search input {
    width: 100%;
    background: var(--color-bg-secondary);
    border: none;
    border-radius: 14px;
    padding: 12px 16px;
    font-size: var(--font-size-sm);
    transition: all var(--transition-fast);
}

.chat-search input:focus {
    background: white;
    box-shadow: 0 0 0 2px var(--color-accent);
}

.chat-conversations {
    flex: 1;
    padding: 0 var(--space-xs);
}

.chat-conversation-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 14px var(--space-lg);
    margin-bottom: 4px;
    border-radius: 16px;
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    border: 1px solid transparent;
}

.chat-conversation-item:hover {
    background: white;
    box-shadow: var(--shadow-sm);
    border-color: rgba(123, 47, 246, 0.1);
    transform: translateY(-1px);
}

.chat-conversation-item.active {
    background: var(--color-accent-glow);
    border-color: var(--color-accent);
}

.chat-conversation-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
    box-shadow: 0 4px 12px rgba(123, 47, 246, 0.2);
}

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

.chat-conversation-name {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.chat-conversation-preview {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conversation-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

/* ── Chat Window (Messaging Interface) ── */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #FDFEFE;
}

.chat-window-header {
    display: flex;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    background: white;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
    z-index: 10;
}

.chat-back-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

.chat-back-btn:hover {
    background: var(--color-bg-secondary);
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-user-info .avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
}

.chat-user-info .name-wrapper {
    display: flex;
    flex-direction: column;
}

#chat-user-name {
    font-weight: 700;
    font-size: 0.95rem;
}

.chat-status {
    font-size: 0.7rem;
    color: var(--color-success);
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.action-btn-whatsapp {
    padding: 6px 12px;
    background: #25D366;
    color: white;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.2s;
}

.action-btn-whatsapp:hover {
    transform: scale(1.05);
    background: #22c35e;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-image: radial-gradient(var(--border-color) 0.5px, transparent 0.5px);
    background-size: 20px 20px;
}

.chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.5;
    position: relative;
    box-shadow: var(--shadow-sm);
    animation: messagePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes messagePop {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.chat-message.sent {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-primary-light) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.received {
    align-self: flex-start;
    background: white;
    color: var(--color-text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.chat-message-time {
    font-size: 0.7rem;
    margin-top: 6px;
    opacity: 0.7;
    display: flex;
    justify-content: flex-end;
}

.chat-input-area {
    padding: var(--space-lg);
    background: white;
    display: flex;
    gap: 12px;
    align-items: center;
    border-top: 1px solid var(--border-color);
}

.chat-input-area input {
    flex: 1;
    border: 1.5px solid var(--border-color);
    border-radius: 14px;
    padding: 12px 18px;
    font-size: var(--font-size-sm);
    transition: all 0.2s;
}

.chat-input-area input:focus {
    border-color: var(--color-accent);
    outline: none;
    box-shadow: 0 0 0 3px var(--color-accent-glow);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: var(--color-accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--color-accent-glow);
}

.chat-send-btn:active {
    transform: translateY(0);
}

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 40px;
    text-align: center;
}

.chat-empty-state svg {
    margin-bottom: 24px;
    color: var(--color-accent);
    opacity: 0.2;
}

.chat-empty-state p {
    font-weight: 700;
    color: var(--color-text-primary);
}

.chat-empty-state small {
    color: var(--color-text-muted);
}

@media (max-width: 768px) {
    .chat-panel {
        width: 100%;
        top: 0;
        z-index: 2000;
    }
}